blob: 65fd50d31764d8aab395d42e4602865af9216ac7 [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
John W. Linville7e272fc2008-09-24 18:13:14 -04006#include <net/lib80211.h>
Holger Schurig7919b892008-04-01 14:50:43 +02007#include <linux/kfifo.h>
Holger Schurige93156e2009-10-22 15:30:58 +02008#include <linux/sched.h>
9
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "decl.h"
12#include "defs.h"
13#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020014#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015#include "wext.h"
Holger Schurig2d465022009-10-22 15:30:48 +020016#include "scan.h"
Dan Williams6e66f032007-12-11 12:42:16 -050017#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018
Holger Schurige93156e2009-10-22 15:30:58 +020019
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050020static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010021
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010023 * @brief Simple callback that copies response back into command
24 *
25 * @param priv A pointer to struct lbs_private structure
26 * @param extra A pointer to the original command structure for which
27 * 'resp' is a response
28 * @param resp A pointer to the command response
29 *
30 * @return 0 on success, error on failure
31 */
32int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
33 struct cmd_header *resp)
34{
35 struct cmd_header *buf = (void *)extra;
36 uint16_t copy_len;
37
38 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
39 memcpy(buf, resp, copy_len);
40 return 0;
41}
42EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
43
44/**
45 * @brief Simple callback that ignores the result. Use this if
46 * you just want to send a command to the hardware, but don't
47 * care for the result.
48 *
49 * @param priv ignored
50 * @param extra ignored
51 * @param resp ignored
52 *
53 * @return 0 for success
54 */
55static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
56 struct cmd_header *resp)
57{
58 return 0;
59}
60
61
62/**
Dan Williams852e1f22007-12-10 15:24:47 -050063 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 *
65 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050066 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067 */
Dan Williams852e1f22007-12-10 15:24:47 -050068static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069{
Dan Williams852e1f22007-12-10 15:24:47 -050070 switch (cmd) {
71 case CMD_802_11_RSSI:
72 return 1;
73 default:
74 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 return 0;
77}
78
Dan Williams6e66f032007-12-11 12:42:16 -050079/**
Amitkumar Karwar63f275d2009-10-06 19:20:28 -070080 * @brief This function checks if the command is allowed.
81 *
82 * @param priv A pointer to lbs_private structure
83 * @return allowed or not allowed.
84 */
85
86static int lbs_is_cmd_allowed(struct lbs_private *priv)
87{
88 int ret = 1;
89
90 lbs_deb_enter(LBS_DEB_CMD);
91
92 if (!priv->is_auto_deep_sleep_enabled) {
93 if (priv->is_deep_sleep) {
94 lbs_deb_cmd("command not allowed in deep sleep\n");
95 ret = 0;
96 }
97 }
98
99 lbs_deb_leave(LBS_DEB_CMD);
100 return ret;
101}
102
103/**
Dan Williams6e66f032007-12-11 12:42:16 -0500104 * @brief Updates the hardware details like MAC address and regulatory region
105 *
106 * @param priv A pointer to struct lbs_private structure
107 *
108 * @return 0 on success, error on failure
109 */
110int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111{
Dan Williams6e66f032007-12-11 12:42:16 -0500112 struct cmd_ds_get_hw_spec cmd;
113 int ret = -1;
114 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
Holger Schurig9012b282007-05-25 11:27:16 -0400116 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117
Dan Williams6e66f032007-12-11 12:42:16 -0500118 memset(&cmd, 0, sizeof(cmd));
119 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
120 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -0500121 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -0500122 if (ret)
123 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124
Dan Williams6e66f032007-12-11 12:42:16 -0500125 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500126
Holger Schurigdac10a92008-01-16 15:55:22 +0100127 /* The firmware release is in an interesting format: the patch
128 * level is in the most significant nibble ... so fix that: */
129 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
130 priv->fwrelease = (priv->fwrelease << 8) |
131 (priv->fwrelease >> 24 & 0xff);
132
133 /* Some firmware capabilities:
134 * CF card firmware 5.0.16p0: cap 0x00000303
135 * USB dongle firmware 5.110.17p2: cap 0x00000303
136 */
Johannes Berge1749612008-10-27 15:59:26 -0700137 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
138 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100139 priv->fwrelease >> 24 & 0xff,
140 priv->fwrelease >> 16 & 0xff,
141 priv->fwrelease >> 8 & 0xff,
142 priv->fwrelease & 0xff,
143 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500144 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
145 cmd.hwifversion, cmd.version);
146
Bing Zhao684d6b32009-03-25 09:51:16 -0700147 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
148 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
149 /* 5.110.22 have mesh command with 0xa3 command id */
150 /* 10.0.0.p0 FW brings in mesh config command with different id */
151 /* Check FW version MSB and initialize mesh_fw_ver */
152 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
153 priv->mesh_fw_ver = MESH_FW_OLD;
154 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
155 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
156 priv->mesh_fw_ver = MESH_FW_NEW;
157 else
158 priv->mesh_fw_ver = MESH_NONE;
159
Dan Williams6e66f032007-12-11 12:42:16 -0500160 /* Clamp region code to 8-bit since FW spec indicates that it should
161 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
162 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200163 *
164 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
165 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500166 */
Marek Vasut15483992009-07-16 19:19:53 +0200167 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
168 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
169 else
170 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500171
172 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
173 /* use the region code to search for the index */
174 if (priv->regioncode == lbs_region_code_to_index[i])
175 break;
176 }
177
178 /* if it's unidentified region code, use the default (USA) */
179 if (i >= MRVDRV_MAX_REGION_CODE) {
180 priv->regioncode = 0x10;
181 lbs_pr_info("unidentified region code; using the default (USA)\n");
182 }
183
184 if (priv->current_addr[0] == 0xff)
185 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
186
187 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
188 if (priv->mesh_dev)
189 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
190
191 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
192 ret = -1;
193 goto out;
194 }
195
Dan Williams6e66f032007-12-11 12:42:16 -0500196out:
Holger Schurig9012b282007-05-25 11:27:16 -0400197 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500198 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199}
200
Anna Neal582c1b52008-10-20 16:46:56 -0700201int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
202 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500203{
204 struct cmd_ds_host_sleep cmd_config;
205 int ret;
206
David Woodhouse9fae8992007-12-15 03:46:44 -0500207 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500208 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500209 cmd_config.gpio = priv->wol_gpio;
210 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500211
Anna Neal582c1b52008-10-20 16:46:56 -0700212 if (p_wol_config != NULL)
213 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
214 sizeof(struct wol_config));
215 else
216 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
217
David Woodhouse689442d2007-12-12 16:00:42 -0500218 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500219 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700220 if (criteria) {
221 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
222 priv->wol_criteria = criteria;
223 } else
224 memcpy((uint8_t *) p_wol_config,
225 (uint8_t *)&cmd_config.wol_conf,
226 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500227 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500228 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500229 }
David Woodhouse506e9022007-12-12 20:06:06 -0500230
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500231 return ret;
232}
233EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
234
Holger Schurige98a88d2008-03-19 14:25:58 +0100235static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236 u16 cmd_action)
237{
238 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
Holger Schurig9012b282007-05-25 11:27:16 -0400240 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241
Dan Williams0aef64d2007-08-02 11:31:18 -0400242 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400243 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200244 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 psm->action = cpu_to_le16(cmd_action);
246 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400247 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400248 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400249 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250
Holger Schurig252cf0d2007-08-02 13:09:34 -0400251 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400252 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400254 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255 break;
256
Dan Williams0aef64d2007-08-02 11:31:18 -0400257 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400258 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259 break;
260
Dan Williams0aef64d2007-08-02 11:31:18 -0400261 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400262 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263 break;
264
265 default:
266 break;
267 }
268
Holger Schurig9012b282007-05-25 11:27:16 -0400269 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 return 0;
271}
272
David Woodhouse3fbe1042007-12-17 23:48:31 -0500273int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
274 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500276 struct cmd_ds_802_11_sleep_params cmd;
277 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278
Holger Schurig9012b282007-05-25 11:27:16 -0400279 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
Dan Williams0aef64d2007-08-02 11:31:18 -0400281 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500282 memset(&cmd, 0, sizeof(cmd));
283 } else {
284 cmd.error = cpu_to_le16(sp->sp_error);
285 cmd.offset = cpu_to_le16(sp->sp_offset);
286 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
287 cmd.calcontrol = sp->sp_calcontrol;
288 cmd.externalsleepclk = sp->sp_extsleepclk;
289 cmd.reserved = cpu_to_le16(sp->sp_reserved);
290 }
291 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
292 cmd.action = cpu_to_le16(cmd_action);
293
294 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
295
296 if (!ret) {
297 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
298 "calcontrol 0x%x extsleepclk 0x%x\n",
299 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
300 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
301 cmd.externalsleepclk);
302
303 sp->sp_error = le16_to_cpu(cmd.error);
304 sp->sp_offset = le16_to_cpu(cmd.offset);
305 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
306 sp->sp_calcontrol = cmd.calcontrol;
307 sp->sp_extsleepclk = cmd.externalsleepclk;
308 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 }
310
David Woodhouse3fbe1042007-12-17 23:48:31 -0500311 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 return 0;
313}
314
Amitkumar Karwar49125452009-09-30 20:04:38 -0700315static int lbs_wait_for_ds_awake(struct lbs_private *priv)
316{
317 int ret = 0;
318
319 lbs_deb_enter(LBS_DEB_CMD);
320
321 if (priv->is_deep_sleep) {
322 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
323 !priv->is_deep_sleep, (10 * HZ))) {
324 lbs_pr_err("ds_awake_q: timer expired\n");
325 ret = -1;
326 }
327 }
328
329 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
330 return ret;
331}
332
333int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
334{
335 int ret = 0;
336
337 lbs_deb_enter(LBS_DEB_CMD);
338
339 if (deep_sleep) {
340 if (priv->is_deep_sleep != 1) {
341 lbs_deb_cmd("deep sleep: sleep\n");
342 BUG_ON(!priv->enter_deep_sleep);
343 ret = priv->enter_deep_sleep(priv);
344 if (!ret) {
345 netif_stop_queue(priv->dev);
346 netif_carrier_off(priv->dev);
347 }
348 } else {
349 lbs_pr_err("deep sleep: already enabled\n");
350 }
351 } else {
352 if (priv->is_deep_sleep) {
353 lbs_deb_cmd("deep sleep: wakeup\n");
354 BUG_ON(!priv->exit_deep_sleep);
355 ret = priv->exit_deep_sleep(priv);
356 if (!ret) {
357 ret = lbs_wait_for_ds_awake(priv);
358 if (ret)
359 lbs_pr_err("deep sleep: wakeup"
360 "failed\n");
361 }
362 }
363 }
364
365 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
366 return ret;
367}
368
Dan Williams39fcf7a2008-09-10 12:49:00 -0400369/**
370 * @brief Set an SNMP MIB value
371 *
372 * @param priv A pointer to struct lbs_private structure
373 * @param oid The OID to set in the firmware
374 * @param val Value to set the OID to
375 *
376 * @return 0 on success, error on failure
377 */
378int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400380 struct cmd_ds_802_11_snmp_mib cmd;
381 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
Holger Schurig9012b282007-05-25 11:27:16 -0400383 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384
Dan Williams39fcf7a2008-09-10 12:49:00 -0400385 memset(&cmd, 0, sizeof (cmd));
386 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
387 cmd.action = cpu_to_le16(CMD_ACT_SET);
388 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389
Dan Williams39fcf7a2008-09-10 12:49:00 -0400390 switch (oid) {
391 case SNMP_MIB_OID_BSS_TYPE:
392 cmd.bufsize = cpu_to_le16(sizeof(u8));
393 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400395 case SNMP_MIB_OID_11D_ENABLE:
396 case SNMP_MIB_OID_FRAG_THRESHOLD:
397 case SNMP_MIB_OID_RTS_THRESHOLD:
398 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
399 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
400 cmd.bufsize = cpu_to_le16(sizeof(u16));
401 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402 break;
403 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400404 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
405 ret = -EINVAL;
406 goto out;
407 }
408
409 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
410 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
411
412 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
413
414out:
415 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
416 return ret;
417}
418
419/**
420 * @brief Get an SNMP MIB value
421 *
422 * @param priv A pointer to struct lbs_private structure
423 * @param oid The OID to retrieve from the firmware
424 * @param out_val Location for the returned value
425 *
426 * @return 0 on success, error on failure
427 */
428int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
429{
430 struct cmd_ds_802_11_snmp_mib cmd;
431 int ret;
432
433 lbs_deb_enter(LBS_DEB_CMD);
434
435 memset(&cmd, 0, sizeof (cmd));
436 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
437 cmd.action = cpu_to_le16(CMD_ACT_GET);
438 cmd.oid = cpu_to_le16(oid);
439
440 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
441 if (ret)
442 goto out;
443
444 switch (le16_to_cpu(cmd.bufsize)) {
445 case sizeof(u8):
446 if (oid == SNMP_MIB_OID_BSS_TYPE) {
447 if (cmd.value[0] == 2)
448 *out_val = IW_MODE_ADHOC;
449 else
450 *out_val = IW_MODE_INFRA;
451 } else
452 *out_val = cmd.value[0];
453 break;
454 case sizeof(u16):
455 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
456 break;
457 default:
458 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
459 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 break;
461 }
462
Dan Williams39fcf7a2008-09-10 12:49:00 -0400463out:
464 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
465 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466}
467
Dan Williams87c8c722008-08-19 15:15:35 -0400468/**
469 * @brief Get the min, max, and current TX power
470 *
471 * @param priv A pointer to struct lbs_private structure
472 * @param curlevel Current power level in dBm
473 * @param minlevel Minimum supported power level in dBm (optional)
474 * @param maxlevel Maximum supported power level in dBm (optional)
475 *
476 * @return 0 on success, error on failure
477 */
478int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
479 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480{
Dan Williams87c8c722008-08-19 15:15:35 -0400481 struct cmd_ds_802_11_rf_tx_power cmd;
482 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
Holger Schurig9012b282007-05-25 11:27:16 -0400484 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485
Dan Williams87c8c722008-08-19 15:15:35 -0400486 memset(&cmd, 0, sizeof(cmd));
487 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
488 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489
Dan Williams87c8c722008-08-19 15:15:35 -0400490 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
491 if (ret == 0) {
492 *curlevel = le16_to_cpu(cmd.curlevel);
493 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100494 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400495 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100496 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200497 }
Holger Schurig9012b282007-05-25 11:27:16 -0400498
499 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400500 return ret;
501}
502
503/**
504 * @brief Set the TX power
505 *
506 * @param priv A pointer to struct lbs_private structure
507 * @param dbm The desired power level in dBm
508 *
509 * @return 0 on success, error on failure
510 */
511int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
512{
513 struct cmd_ds_802_11_rf_tx_power cmd;
514 int ret;
515
516 lbs_deb_enter(LBS_DEB_CMD);
517
518 memset(&cmd, 0, sizeof(cmd));
519 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
520 cmd.action = cpu_to_le16(CMD_ACT_SET);
521 cmd.curlevel = cpu_to_le16(dbm);
522
523 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
524
525 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
526
527 lbs_deb_leave(LBS_DEB_CMD);
528 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529}
530
Holger Schurige98a88d2008-03-19 14:25:58 +0100531static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400532 u16 cmd_action, void *pdata_buf)
533{
534 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
535
536 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
537 cmd->size =
538 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200539 sizeof(struct cmd_header));
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400540
541 monitor->action = cpu_to_le16(cmd_action);
542 if (cmd_action == CMD_ACT_SET) {
543 monitor->mode =
544 cpu_to_le16((u16) (*(u32 *) pdata_buf));
545 }
546
547 return 0;
548}
549
Dan Williams2dd4b262007-12-11 16:54:15 -0500550/**
551 * @brief Get the radio channel
552 *
553 * @param priv A pointer to struct lbs_private structure
554 *
555 * @return The channel on success, error on failure
556 */
Holger Schuriga3cbfb02009-10-16 17:33:56 +0200557static int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558{
Dan Williams2dd4b262007-12-11 16:54:15 -0500559 struct cmd_ds_802_11_rf_channel cmd;
560 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561
Holger Schurig8ff12da2007-08-02 11:54:31 -0400562 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200564 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500565 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
566 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
David Woodhouse689442d2007-12-12 16:00:42 -0500568 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500569 if (ret)
570 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571
Dan Williamscb182a62007-12-11 17:35:51 -0500572 ret = le16_to_cpu(cmd.channel);
573 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500574
575out:
576 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
577 return ret;
578}
579
Holger Schurig73ab1f22008-04-02 16:52:19 +0200580int lbs_update_channel(struct lbs_private *priv)
581{
582 int ret;
583
584 /* the channel in f/w could be out of sync; get the current channel */
585 lbs_deb_enter(LBS_DEB_ASSOC);
586
587 ret = lbs_get_channel(priv);
588 if (ret > 0) {
Holger Schurigc14951f2009-10-22 15:30:50 +0200589 priv->channel = ret;
Holger Schurig73ab1f22008-04-02 16:52:19 +0200590 ret = 0;
591 }
592 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
593 return ret;
594}
595
Dan Williams2dd4b262007-12-11 16:54:15 -0500596/**
597 * @brief Set the radio channel
598 *
599 * @param priv A pointer to struct lbs_private structure
600 * @param channel The desired channel, or 0 to clear a locked channel
601 *
602 * @return 0 on success, error on failure
603 */
604int lbs_set_channel(struct lbs_private *priv, u8 channel)
605{
606 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530607#ifdef DEBUG
Holger Schurigc14951f2009-10-22 15:30:50 +0200608 u8 old_channel = priv->channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530609#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500610 int ret = 0;
611
612 lbs_deb_enter(LBS_DEB_CMD);
613
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200614 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500615 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
616 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
617 cmd.channel = cpu_to_le16(channel);
618
David Woodhouse689442d2007-12-12 16:00:42 -0500619 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500620 if (ret)
621 goto out;
622
Holger Schurigc14951f2009-10-22 15:30:50 +0200623 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
Dan Williamscb182a62007-12-11 17:35:51 -0500624 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
Holger Schurigc14951f2009-10-22 15:30:50 +0200625 priv->channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500626
627out:
628 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
629 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200630}
631
Holger Schurige98a88d2008-03-19 14:25:58 +0100632static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 u8 cmd_action, void *pdata_buf)
634{
Holger Schurig10078322007-11-15 18:05:47 -0500635 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636
Holger Schurig9012b282007-05-25 11:27:16 -0400637 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638
Holger Schurig10078322007-11-15 18:05:47 -0500639 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000641 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400642 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 {
644 struct cmd_ds_mac_reg_access *macreg;
645
646 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400647 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200648 + sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 macreg =
650 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
651 macreg;
652
653 macreg->action = cpu_to_le16(cmd_action);
654 macreg->offset = cpu_to_le16((u16) offval->offset);
655 macreg->value = cpu_to_le32(offval->value);
656
657 break;
658 }
659
Dan Williams0aef64d2007-08-02 11:31:18 -0400660 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661 {
662 struct cmd_ds_bbp_reg_access *bbpreg;
663
664 cmdptr->size =
665 cpu_to_le16(sizeof
666 (struct cmd_ds_bbp_reg_access)
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200667 + sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200668 bbpreg =
669 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
670 bbpreg;
671
672 bbpreg->action = cpu_to_le16(cmd_action);
673 bbpreg->offset = cpu_to_le16((u16) offval->offset);
674 bbpreg->value = (u8) offval->value;
675
676 break;
677 }
678
Dan Williams0aef64d2007-08-02 11:31:18 -0400679 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680 {
681 struct cmd_ds_rf_reg_access *rfreg;
682
683 cmdptr->size =
684 cpu_to_le16(sizeof
685 (struct cmd_ds_rf_reg_access) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200686 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200687 rfreg =
688 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
689 rfreg;
690
691 rfreg->action = cpu_to_le16(cmd_action);
692 rfreg->offset = cpu_to_le16((u16) offval->offset);
693 rfreg->value = (u8) offval->value;
694
695 break;
696 }
697
698 default:
699 break;
700 }
701
Holger Schurig9012b282007-05-25 11:27:16 -0400702 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703 return 0;
704}
705
Holger Schurige98a88d2008-03-19 14:25:58 +0100706static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 u16 cmd_action, void *pdata_buf)
708{
709 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400710 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711
Dan Williams0aef64d2007-08-02 11:31:18 -0400712 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200713 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
714 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 cmd->result = 0;
716 bt_access->action = cpu_to_le16(cmd_action);
717
718 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400719 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400721 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400723 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400725 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400727 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
729 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400730 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400732 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400733 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
734 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400735 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400736 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200737 default:
738 break;
739 }
Holger Schurig8ff12da2007-08-02 11:54:31 -0400740 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 return 0;
742}
743
Holger Schurige98a88d2008-03-19 14:25:58 +0100744static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 u16 cmd_action, void *pdata_buf)
746{
747 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400748 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749
Dan Williams0aef64d2007-08-02 11:31:18 -0400750 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200751 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
752 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753 cmd->result = 0;
754
755 if (pdata_buf)
756 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
757 else
758 memset(fwt_access, 0, sizeof(*fwt_access));
759
760 fwt_access->action = cpu_to_le16(cmd_action);
761
Holger Schurig8ff12da2007-08-02 11:54:31 -0400762 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763 return 0;
764}
765
David Woodhouse301eacb2007-12-11 15:23:59 -0500766int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
767 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768{
David Woodhouse301eacb2007-12-11 15:23:59 -0500769 int ret;
770
Holger Schurig8ff12da2007-08-02 11:54:31 -0400771 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772
David Woodhouse301eacb2007-12-11 15:23:59 -0500773 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -0500774 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -0500775 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776
David Woodhouse301eacb2007-12-11 15:23:59 -0500777 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778
David Woodhouse689442d2007-12-12 16:00:42 -0500779 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig8ff12da2007-08-02 11:54:31 -0400781 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -0500782 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200783}
784
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700785static int __lbs_mesh_config_send(struct lbs_private *priv,
786 struct cmd_ds_mesh_config *cmd,
787 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700788{
789 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -0700790 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700791
792 lbs_deb_enter(LBS_DEB_CMD);
793
Bing Zhao684d6b32009-03-25 09:51:16 -0700794 /*
795 * Command id is 0xac for v10 FW along with mesh interface
796 * id in bits 14-13-12.
797 */
798 if (priv->mesh_fw_ver == MESH_FW_NEW)
799 command = CMD_MESH_CONFIG |
800 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
801
802 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700803 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
804 cmd->hdr.result = 0;
805
806 cmd->type = cpu_to_le16(type);
807 cmd->action = cpu_to_le16(action);
808
Bing Zhao684d6b32009-03-25 09:51:16 -0700809 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700810
811 lbs_deb_leave(LBS_DEB_CMD);
812 return ret;
813}
814
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700815int lbs_mesh_config_send(struct lbs_private *priv,
816 struct cmd_ds_mesh_config *cmd,
817 uint16_t action, uint16_t type)
818{
819 int ret;
820
821 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
822 return -EOPNOTSUPP;
823
824 ret = __lbs_mesh_config_send(priv, cmd, action, type);
825 return ret;
826}
827
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700828/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
829 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
830 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
831 * lbs_mesh_config_send.
832 */
833int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -0500834{
835 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700836 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -0400837 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -0500838
839 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -0500840 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700841 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -0500842
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700843 switch (action) {
844 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +0100845 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700846 ie->val.oui[0] = 0x00;
847 ie->val.oui[1] = 0x50;
848 ie->val.oui[2] = 0x43;
849 ie->val.type = MARVELL_MESH_IE_TYPE;
850 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
851 ie->val.version = MARVELL_MESH_IE_VERSION;
852 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
853 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
854 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
855 ie->val.mesh_id_len = priv->mesh_ssid_len;
856 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +0100857 ie->len = sizeof(struct mrvl_meshie_val) -
Holger Schurig243e84e2009-10-22 15:30:47 +0200858 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700859 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
860 break;
861 case CMD_ACT_MESH_CONFIG_STOP:
862 break;
863 default:
864 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -0500865 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700866 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
867 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -0400868 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700869
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700870 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500871}
872
David Woodhouse681ffbb2007-12-15 20:04:54 -0500873static void lbs_queue_cmd(struct lbs_private *priv,
874 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875{
876 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -0500877 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878
Holger Schurig8ff12da2007-08-02 11:54:31 -0400879 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880
David Woodhousec4ab4122007-12-15 00:41:51 -0500881 if (!cmdnode) {
882 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 goto done;
884 }
David Woodhoused9896ee2007-12-15 00:09:25 -0500885 if (!cmdnode->cmdbuf->size) {
886 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
887 goto done;
888 }
David Woodhouseae125bf2007-12-15 04:22:52 -0500889 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890
891 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -0500892 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -0500893 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -0500894
Dan Williams0aef64d2007-08-02 11:31:18 -0400895 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000896 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200897 addtail = 0;
898 }
899 }
900
David Woodhouseaa21c002007-12-08 20:04:36 +0000901 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200902
David Woodhouseac472462007-12-08 00:35:00 +0000903 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +0000904 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +0000905 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000906 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907
David Woodhouseaa21c002007-12-08 20:04:36 +0000908 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
Holger Schurig8ff12da2007-08-02 11:54:31 -0400910 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -0500911 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912
913done:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400914 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200915}
916
David Woodhouse18c52e72007-12-17 16:03:58 -0500917static void lbs_submit_command(struct lbs_private *priv,
918 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919{
920 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -0500921 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -0500922 uint16_t cmdsize;
923 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +0200924 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500925 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926
Holger Schurig8ff12da2007-08-02 11:54:31 -0400927 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928
Dan Williamsddac4522007-12-11 13:49:39 -0500929 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930
David Woodhouseaa21c002007-12-08 20:04:36 +0000931 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +0000932 priv->cur_cmd = cmdnode;
933 priv->cur_cmd_retcode = 0;
934 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935
Dan Williamsddac4522007-12-11 13:49:39 -0500936 cmdsize = le16_to_cpu(cmd->size);
937 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200938
David Woodhouse18c52e72007-12-17 16:03:58 -0500939 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400940 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +0200941 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500942
Holger Schurige5225b32008-03-26 10:04:44 +0100943 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
944 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +0100945 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400946
Dan Williamsddac4522007-12-11 13:49:39 -0500947 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -0500948
David Woodhoused9896ee2007-12-15 00:09:25 -0500949 if (ret) {
950 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -0500951 /* Let the timer kick in and retry, and potentially reset
952 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +0200953 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +0100954 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200955
Amitkumar Karwar49125452009-09-30 20:04:38 -0700956 if (command == CMD_802_11_DEEP_SLEEP) {
957 if (priv->is_auto_deep_sleep_enabled) {
958 priv->wakeup_dev_required = 1;
959 priv->dnld_sent = 0;
960 }
961 priv->is_deep_sleep = 1;
962 lbs_complete_command(priv, cmdnode, 0);
963 } else {
964 /* Setup the timer after transmit command */
965 mod_timer(&priv->command_timer, jiffies + timeo);
966 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200967
David Woodhouse18c52e72007-12-17 16:03:58 -0500968 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969}
970
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200971/**
972 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +0000973 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 */
David Woodhouse183aeac2007-12-15 01:52:54 -0500975static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500976 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500978 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200979
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500980 if (!cmdnode)
981 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500983 cmdnode->callback = NULL;
984 cmdnode->callback_arg = 0;
985
986 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
987
988 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
989 out:
990 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991}
992
Holger Schurig69f90322007-11-23 15:43:44 +0100993static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
994 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995{
996 unsigned long flags;
997
David Woodhouseaa21c002007-12-08 20:04:36 +0000998 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -0500999 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001000 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001}
1002
David Woodhouse183aeac2007-12-15 01:52:54 -05001003void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1004 int result)
1005{
1006 if (cmd == priv->cur_cmd)
1007 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001008
David Woodhouseae125bf2007-12-15 04:22:52 -05001009 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001010 cmd->cmdwaitqwoken = 1;
1011 wake_up_interruptible(&cmd->cmdwait_q);
1012
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001013 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001014 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001015 priv->cur_cmd = NULL;
1016}
1017
Dan Williamsd5db2df2008-08-21 17:51:07 -04001018int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001019{
David Woodhousea7c45892007-12-17 22:43:48 -05001020 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001021 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022
Holger Schurig9012b282007-05-25 11:27:16 -04001023 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001024
David Woodhousea7c45892007-12-17 22:43:48 -05001025 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1026 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001027
Dan Williamsd5db2df2008-08-21 17:51:07 -04001028 /* Only v8 and below support setting the preamble */
1029 if (priv->fwrelease < 0x09000000) {
1030 switch (preamble) {
1031 case RADIO_PREAMBLE_SHORT:
1032 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1033 goto out;
1034 /* Fall through */
1035 case RADIO_PREAMBLE_AUTO:
1036 case RADIO_PREAMBLE_LONG:
1037 cmd.control = cpu_to_le16(preamble);
1038 break;
1039 default:
1040 goto out;
1041 }
David Woodhousea7c45892007-12-17 22:43:48 -05001042 }
1043
Dan Williamsd5db2df2008-08-21 17:51:07 -04001044 if (radio_on)
1045 cmd.control |= cpu_to_le16(0x1);
1046 else {
1047 cmd.control &= cpu_to_le16(~0x1);
1048 priv->txpower_cur = 0;
1049 }
David Woodhousea7c45892007-12-17 22:43:48 -05001050
Dan Williamsd5db2df2008-08-21 17:51:07 -04001051 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1052 radio_on ? "ON" : "OFF", preamble);
1053
1054 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001055
1056 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001057
Dan Williamsd5db2df2008-08-21 17:51:07 -04001058out:
Holger Schurig9012b282007-05-25 11:27:16 -04001059 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 return ret;
1061}
1062
Holger Schurigc97329e2008-03-18 11:20:21 +01001063void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001065 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066
Holger Schurig9012b282007-05-25 11:27:16 -04001067 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001068
Holger Schurig835d3ac2008-03-12 16:05:40 +01001069 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001070 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001071 cmd.reserved = 0;
1072
David Woodhouse75bf45a2008-05-20 13:32:45 +01001073 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074
Holger Schurigc97329e2008-03-18 11:20:21 +01001075 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076}
1077
1078/**
1079 * @brief This function prepare the command before send to firmware.
1080 *
Holger Schurig69f90322007-11-23 15:43:44 +01001081 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001082 * @param cmd_no command number
1083 * @param cmd_action command action: GET or SET
1084 * @param wait_option wait option: wait response or not
1085 * @param cmd_oid cmd oid: treated as sub command
1086 * @param pdata_buf A pointer to informaion buffer
1087 * @return 0 or -1
1088 */
Holger Schurig69f90322007-11-23 15:43:44 +01001089int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090 u16 cmd_no,
1091 u16 cmd_action,
1092 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1093{
1094 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095 struct cmd_ctrl_node *cmdnode;
1096 struct cmd_ds_command *cmdptr;
1097 unsigned long flags;
1098
Holger Schurig8ff12da2007-08-02 11:54:31 -04001099 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100
David Woodhouseaa21c002007-12-08 20:04:36 +00001101 if (!priv) {
1102 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103 ret = -1;
1104 goto done;
1105 }
1106
David Woodhouseaa21c002007-12-08 20:04:36 +00001107 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001108 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109 ret = -1;
1110 goto done;
1111 }
1112
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001113 if (!lbs_is_cmd_allowed(priv)) {
1114 ret = -EBUSY;
1115 goto done;
1116 }
1117
Holger Schurig0d61d042007-12-05 17:58:06 +01001118 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119
1120 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001121 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122
1123 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001124 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125 ret = -1;
1126 goto done;
1127 }
1128
Holger Schurige98a88d2008-03-19 14:25:58 +01001129 cmdnode->callback = NULL;
1130 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001131
Dan Williamsddac4522007-12-11 13:49:39 -05001132 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133
Holger Schurig8ff12da2007-08-02 11:54:31 -04001134 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001137 priv->seqnum++;
1138 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001139
David Woodhouse981f1872007-05-25 23:36:54 -04001140 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001141 cmdptr->result = 0;
1142
1143 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001144 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001145 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001146 break;
1147
Dan Williams0aef64d2007-08-02 11:31:18 -04001148 case CMD_MAC_REG_ACCESS:
1149 case CMD_BBP_REG_ACCESS:
1150 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001151 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152 break;
1153
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001154 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001155 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001156 cmd_action, pdata_buf);
1157 break;
1158
Dan Williams0aef64d2007-08-02 11:31:18 -04001159 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001160 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001161 break;
1162
Dan Williams0aef64d2007-08-02 11:31:18 -04001163 case CMD_802_11_SET_AFC:
1164 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165
1166 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001167 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001168 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001169
1170 memmove(&cmdptr->params.afc,
1171 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1172
1173 ret = 0;
1174 goto done;
1175
Dan Williams0aef64d2007-08-02 11:31:18 -04001176 case CMD_802_11_TPC_CFG:
1177 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178 cmdptr->size =
1179 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001180 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181
1182 memmove(&cmdptr->params.tpccfg,
1183 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1184
1185 ret = 0;
1186 break;
David Woodhouse5844d122007-12-18 02:01:37 -05001187
Dan Williams0aef64d2007-08-02 11:31:18 -04001188 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001189 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001190 break;
1191
Dan Williams0aef64d2007-08-02 11:31:18 -04001192 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001193 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001194 break;
1195
Brajesh Dave96287ac2007-11-20 17:44:28 -05001196 case CMD_802_11_BEACON_CTRL:
1197 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1198 break;
Amitkumar Karwar49125452009-09-30 20:04:38 -07001199 case CMD_802_11_DEEP_SLEEP:
1200 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001201 cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
Amitkumar Karwar49125452009-09-30 20:04:38 -07001202 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001203 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001204 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001205 ret = -1;
1206 break;
1207 }
1208
1209 /* return error, since the command preparation failed */
1210 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001211 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001212 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001213 ret = -1;
1214 goto done;
1215 }
1216
1217 cmdnode->cmdwaitqwoken = 0;
1218
David Woodhouse681ffbb2007-12-15 20:04:54 -05001219 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001220 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221
Dan Williams0aef64d2007-08-02 11:31:18 -04001222 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001223 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224 might_sleep();
1225 wait_event_interruptible(cmdnode->cmdwait_q,
1226 cmdnode->cmdwaitqwoken);
1227 }
1228
David Woodhouseaa21c002007-12-08 20:04:36 +00001229 spin_lock_irqsave(&priv->driver_lock, flags);
1230 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001231 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001232 priv->cur_cmd_retcode);
1233 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234 ret = -1;
1235 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001236 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001237
1238done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001239 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001240 return ret;
1241}
1242
1243/**
1244 * @brief This function allocates the command buffer and link
1245 * it to command free queue.
1246 *
Holger Schurig69f90322007-11-23 15:43:44 +01001247 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248 * @return 0 or -1
1249 */
Holger Schurig69f90322007-11-23 15:43:44 +01001250int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001251{
1252 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001253 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001255 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256
Holger Schurig8ff12da2007-08-02 11:54:31 -04001257 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258
Dan Williamsddac4522007-12-11 13:49:39 -05001259 /* Allocate and initialize the command array */
1260 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1261 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001262 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001263 ret = -1;
1264 goto done;
1265 }
Dan Williamsddac4522007-12-11 13:49:39 -05001266 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001267
Dan Williamsddac4522007-12-11 13:49:39 -05001268 /* Allocate and initialize each command buffer in the command array */
1269 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1270 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1271 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001272 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001273 ret = -1;
1274 goto done;
1275 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001276 }
1277
Dan Williamsddac4522007-12-11 13:49:39 -05001278 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1279 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1280 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001282 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001283
1284done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001285 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001286 return ret;
1287}
1288
1289/**
1290 * @brief This function frees the command buffer.
1291 *
Holger Schurig69f90322007-11-23 15:43:44 +01001292 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001293 * @return 0 or -1
1294 */
Holger Schurig69f90322007-11-23 15:43:44 +01001295int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001296{
Dan Williamsddac4522007-12-11 13:49:39 -05001297 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001298 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299
Holger Schurig8ff12da2007-08-02 11:54:31 -04001300 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001301
1302 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001303 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001304 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305 goto done;
1306 }
1307
Dan Williamsddac4522007-12-11 13:49:39 -05001308 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001309
1310 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001311 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1312 if (cmdarray[i].cmdbuf) {
1313 kfree(cmdarray[i].cmdbuf);
1314 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001315 }
1316 }
1317
1318 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001319 if (priv->cmd_array) {
1320 kfree(priv->cmd_array);
1321 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001322 }
1323
1324done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001325 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 return 0;
1327}
1328
1329/**
1330 * @brief This function gets a free command node if available in
1331 * command free queue.
1332 *
Holger Schurig69f90322007-11-23 15:43:44 +01001333 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001334 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1335 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001336static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337{
1338 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001339 unsigned long flags;
1340
Holger Schurig8ff12da2007-08-02 11:54:31 -04001341 lbs_deb_enter(LBS_DEB_HOST);
1342
David Woodhouseaa21c002007-12-08 20:04:36 +00001343 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344 return NULL;
1345
David Woodhouseaa21c002007-12-08 20:04:36 +00001346 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347
David Woodhouseaa21c002007-12-08 20:04:36 +00001348 if (!list_empty(&priv->cmdfreeq)) {
1349 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001350 struct cmd_ctrl_node, list);
1351 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001353 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 tempnode = NULL;
1355 }
1356
David Woodhouseaa21c002007-12-08 20:04:36 +00001357 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358
Holger Schurig8ff12da2007-08-02 11:54:31 -04001359 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360 return tempnode;
1361}
1362
1363/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001365 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366 * if applicable.
1367 *
Holger Schurig69f90322007-11-23 15:43:44 +01001368 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001369 * @return 0 or -1
1370 */
Holger Schurig69f90322007-11-23 15:43:44 +01001371int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001373 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001374 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001375 unsigned long flags;
1376 int ret = 0;
1377
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001378 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1379 * only caller to us is lbs_thread() and we get even when a
1380 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001381 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001382
David Woodhouseaa21c002007-12-08 20:04:36 +00001383 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001386 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001387 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388 ret = -1;
1389 goto done;
1390 }
1391
David Woodhouseaa21c002007-12-08 20:04:36 +00001392 if (!list_empty(&priv->cmdpendingq)) {
1393 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001394 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395 }
1396
David Woodhouseaa21c002007-12-08 20:04:36 +00001397 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398
1399 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001400 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401
Dan Williamsddac4522007-12-11 13:49:39 -05001402 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001403 if ((priv->psstate == PS_STATE_SLEEP) ||
1404 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001405 lbs_deb_host(
1406 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001407 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001408 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 ret = -1;
1410 goto done;
1411 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001412 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001413 "0x%04x in psstate %d\n",
1414 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001415 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 /*
1417 * 1. Non-PS command:
1418 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001419 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420 * 2. PS command but not Exit_PS:
1421 * Ignore it.
1422 * 3. PS command Exit_PS:
1423 * Set needtowakeup to TRUE if current state is SLEEP,
1424 * otherwise send this command down to firmware
1425 * immediately.
1426 */
Dan Williamsddac4522007-12-11 13:49:39 -05001427 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001428 /* Prepare to send Exit PS,
1429 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001430 if ((priv->psstate == PS_STATE_SLEEP)
1431 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001432 ) {
1433 /* w/ new scheme, it will not reach here.
1434 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001435 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436 } else
Holger Schurig10078322007-11-15 18:05:47 -05001437 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001438
1439 ret = 0;
1440 goto done;
1441 } else {
1442 /*
1443 * PS command. Ignore it if it is not Exit_PS.
1444 * otherwise send it down immediately.
1445 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001446 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001447
Holger Schurig8ff12da2007-08-02 11:54:31 -04001448 lbs_deb_host(
1449 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001450 psm->action);
1451 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001452 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001453 lbs_deb_host(
1454 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001455 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001456 spin_lock_irqsave(&priv->driver_lock, flags);
1457 lbs_complete_command(priv, cmdnode, 0);
1458 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459
1460 ret = 0;
1461 goto done;
1462 }
1463
David Woodhouseaa21c002007-12-08 20:04:36 +00001464 if ((priv->psstate == PS_STATE_SLEEP) ||
1465 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001466 lbs_deb_host(
1467 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001468 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001469 spin_lock_irqsave(&priv->driver_lock, flags);
1470 lbs_complete_command(priv, cmdnode, 0);
1471 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001472 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001473
1474 ret = 0;
1475 goto done;
1476 }
1477
Holger Schurig8ff12da2007-08-02 11:54:31 -04001478 lbs_deb_host(
1479 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480 }
1481 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001482 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001483 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001484 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001485 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 } else {
1487 /*
1488 * check if in power save mode, if yes, put the device back
1489 * to PS mode
1490 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001491 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1492 (priv->psstate == PS_STATE_FULL_POWER) &&
1493 ((priv->connect_status == LBS_CONNECTED) ||
1494 (priv->mesh_connect_status == LBS_CONNECTED))) {
1495 if (priv->secinfo.WPAenabled ||
1496 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001498 if (priv->wpa_mcast_key.len ||
1499 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001500 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001501 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1502 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001503 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001504 }
1505 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001506 lbs_deb_host(
1507 "EXEC_NEXT_CMD: cmdpendingq empty, "
1508 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001509 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001510 }
1511 }
1512 }
1513
1514 ret = 0;
1515done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001516 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001517 return ret;
1518}
1519
Holger Schurigf539f2e2008-03-26 13:22:11 +01001520static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521{
1522 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001523 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001524
Holger Schurig8ff12da2007-08-02 11:54:31 -04001525 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001526 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1527 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001528
Holger Schurigf539f2e2008-03-26 13:22:11 +01001529 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1530 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001531 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001532 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001533 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001534 }
Holger Schurig7919b892008-04-01 14:50:43 +02001535
1536 spin_lock_irqsave(&priv->driver_lock, flags);
1537
Holger Schuriga01f5452008-06-04 11:10:40 +02001538 /* We don't get a response on the sleep-confirmation */
1539 priv->dnld_sent = DNLD_RES_RECEIVED;
1540
Holger Schurig7919b892008-04-01 14:50:43 +02001541 /* If nothing to do, go back to sleep (?) */
1542 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1543 priv->psstate = PS_STATE_SLEEP;
1544
1545 spin_unlock_irqrestore(&priv->driver_lock, flags);
1546
1547out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001548 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001549}
1550
Holger Schurig69f90322007-11-23 15:43:44 +01001551void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001552{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001553 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554
1555 /*
1556 * PS is currently supported only in Infrastructure mode
1557 * Remove this check if it is to be supported in IBSS mode also
1558 */
1559
Holger Schurig10078322007-11-15 18:05:47 -05001560 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001561 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562
Holger Schurig8ff12da2007-08-02 11:54:31 -04001563 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564}
1565
1566/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001567 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 *
Holger Schurig69f90322007-11-23 15:43:44 +01001569 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 * @param wait_option wait response or not
1571 * @return n/a
1572 */
Holger Schurig69f90322007-11-23 15:43:44 +01001573void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574{
David Woodhouse981f1872007-05-25 23:36:54 -04001575 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576
Holger Schurig8ff12da2007-08-02 11:54:31 -04001577 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578
Holger Schurig10078322007-11-15 18:05:47 -05001579 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001580
Holger Schurig10078322007-11-15 18:05:47 -05001581 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001582 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583 wait_option, 0, &Localpsmode);
1584
Holger Schurig8ff12da2007-08-02 11:54:31 -04001585 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586}
1587
1588/**
1589 * @brief This function checks condition and prepares to
1590 * send sleep confirm command to firmware if ok.
1591 *
Holger Schurig69f90322007-11-23 15:43:44 +01001592 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593 * @param psmode Power Saving mode
1594 * @return n/a
1595 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001596void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001597{
1598 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001599 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600
Holger Schurig8ff12da2007-08-02 11:54:31 -04001601 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001602
Holger Schuriga01f5452008-06-04 11:10:40 +02001603 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001604 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001606 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001607 }
1608
Holger Schurig7919b892008-04-01 14:50:43 +02001609 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001610 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001612 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613 }
Holger Schurig7919b892008-04-01 14:50:43 +02001614
1615 /* Pending events or command responses? */
1616 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001617 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001618 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001620 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621
1622 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001623 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001624 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001626 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627 }
1628
Holger Schurig8ff12da2007-08-02 11:54:31 -04001629 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630}
Holger Schurig675787e2007-12-05 17:58:11 +01001631
1632
Anna Neal0112c9e2008-09-11 11:17:25 -07001633/**
1634 * @brief Configures the transmission power control functionality.
1635 *
1636 * @param priv A pointer to struct lbs_private structure
1637 * @param enable Transmission power control enable
1638 * @param p0 Power level when link quality is good (dBm).
1639 * @param p1 Power level when link quality is fair (dBm).
1640 * @param p2 Power level when link quality is poor (dBm).
1641 * @param usesnr Use Signal to Noise Ratio in TPC
1642 *
1643 * @return 0 on success
1644 */
1645int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1646 int8_t p2, int usesnr)
1647{
1648 struct cmd_ds_802_11_tpc_cfg cmd;
1649 int ret;
1650
1651 memset(&cmd, 0, sizeof(cmd));
1652 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1653 cmd.action = cpu_to_le16(CMD_ACT_SET);
1654 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001655 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001656 cmd.P0 = p0;
1657 cmd.P1 = p1;
1658 cmd.P2 = p2;
1659
1660 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1661
1662 return ret;
1663}
1664
1665/**
1666 * @brief Configures the power adaptation settings.
1667 *
1668 * @param priv A pointer to struct lbs_private structure
1669 * @param enable Power adaptation enable
1670 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1671 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1672 * @param p2 Power level for 48 and 54 Mbps (dBm).
1673 *
1674 * @return 0 on Success
1675 */
1676
1677int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1678 int8_t p1, int8_t p2)
1679{
1680 struct cmd_ds_802_11_pa_cfg cmd;
1681 int ret;
1682
1683 memset(&cmd, 0, sizeof(cmd));
1684 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1685 cmd.action = cpu_to_le16(CMD_ACT_SET);
1686 cmd.enable = !!enable;
1687 cmd.P0 = p0;
1688 cmd.P1 = p1;
1689 cmd.P2 = p2;
1690
1691 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1692
1693 return ret;
1694}
1695
1696
Holger Schurig6d898b12009-10-14 16:49:53 +02001697struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001698 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1699 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1700 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01001701{
Holger Schurig675787e2007-12-05 17:58:11 +01001702 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01001703
1704 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01001705
David Woodhouseaa21c002007-12-08 20:04:36 +00001706 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01001707 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05001708 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01001709 goto done;
1710 }
1711
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001712 if (!lbs_is_cmd_allowed(priv)) {
1713 cmdnode = ERR_PTR(-EBUSY);
1714 goto done;
1715 }
1716
Holger Schurig675787e2007-12-05 17:58:11 +01001717 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01001718 if (cmdnode == NULL) {
1719 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1720
1721 /* Wake up main thread to execute next command */
1722 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05001723 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01001724 goto done;
1725 }
1726
David Woodhouse448a51a2007-12-08 00:59:54 +00001727 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05001728 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01001729
Dan Williams7ad994d2007-12-11 12:33:30 -05001730 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05001731 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05001732
Holger Schurig675787e2007-12-05 17:58:11 +01001733 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00001734 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05001735 cmdnode->cmdbuf->command = cpu_to_le16(command);
1736 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1737 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1738 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01001739
1740 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1741
Holger Schurig675787e2007-12-05 17:58:11 +01001742 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001743 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01001744 wake_up_interruptible(&priv->waitq);
1745
David Woodhouse3399ea52007-12-15 03:09:33 -05001746 done:
1747 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1748 return cmdnode;
1749}
1750
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001751void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1752 struct cmd_header *in_cmd, int in_cmd_size)
1753{
1754 lbs_deb_enter(LBS_DEB_CMD);
1755 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1756 lbs_cmd_async_callback, 0);
1757 lbs_deb_leave(LBS_DEB_CMD);
1758}
1759
David Woodhouse3399ea52007-12-15 03:09:33 -05001760int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1761 struct cmd_header *in_cmd, int in_cmd_size,
1762 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1763 unsigned long callback_arg)
1764{
1765 struct cmd_ctrl_node *cmdnode;
1766 unsigned long flags;
1767 int ret = 0;
1768
1769 lbs_deb_enter(LBS_DEB_HOST);
1770
1771 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1772 callback, callback_arg);
1773 if (IS_ERR(cmdnode)) {
1774 ret = PTR_ERR(cmdnode);
1775 goto done;
1776 }
1777
Holger Schurig675787e2007-12-05 17:58:11 +01001778 might_sleep();
1779 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1780
David Woodhouseaa21c002007-12-08 20:04:36 +00001781 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05001782 ret = cmdnode->result;
1783 if (ret)
1784 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1785 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05001786
David Woodhousead12d0f2007-12-15 02:06:16 -05001787 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00001788 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01001789
1790done:
1791 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1792 return ret;
1793}
Dan Williams14e865b2007-12-10 15:11:23 -05001794EXPORT_SYMBOL_GPL(__lbs_cmd);