blob: f3ac62431a3085c7eee695e98987ba140cb53d02 [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
Holger Schurig7919b892008-04-01 14:50:43 +02006#include <linux/kfifo.h>
Holger Schurige93156e2009-10-22 15:30:58 +02007#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Dan Williamsa45b6f42010-07-27 12:54:34 -07009#include <linux/if_arp.h>
Holger Schurige93156e2009-10-22 15:30:58 +020010
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "decl.h"
Kiran Divekare86dc1c2010-06-14 22:01:26 +053012#include "cfg.h"
Dan Williams6e66f032007-12-11 12:42:16 -050013#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014
Dan Williams9fb76632010-07-27 12:55:21 -070015#define CAL_NF(nf) ((s32)(-(s32)(nf)))
16#define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf)))
Holger Schurige93156e2009-10-22 15:30:58 +020017
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010019 * @brief Simple callback that copies response back into command
20 *
21 * @param priv A pointer to struct lbs_private structure
22 * @param extra A pointer to the original command structure for which
23 * 'resp' is a response
24 * @param resp A pointer to the command response
25 *
26 * @return 0 on success, error on failure
27 */
28int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
29 struct cmd_header *resp)
30{
31 struct cmd_header *buf = (void *)extra;
32 uint16_t copy_len;
33
34 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
35 memcpy(buf, resp, copy_len);
36 return 0;
37}
38EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
39
40/**
41 * @brief Simple callback that ignores the result. Use this if
42 * you just want to send a command to the hardware, but don't
43 * care for the result.
44 *
45 * @param priv ignored
46 * @param extra ignored
47 * @param resp ignored
48 *
49 * @return 0 for success
50 */
51static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
52 struct cmd_header *resp)
53{
54 return 0;
55}
56
57
58/**
Dan Williams852e1f22007-12-10 15:24:47 -050059 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060 *
61 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050062 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 */
Dan Williams852e1f22007-12-10 15:24:47 -050064static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065{
Dan Williams852e1f22007-12-10 15:24:47 -050066 switch (cmd) {
67 case CMD_802_11_RSSI:
68 return 1;
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070069 case CMD_802_11_HOST_SLEEP_CFG:
70 return 1;
Dan Williams852e1f22007-12-10 15:24:47 -050071 default:
72 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 return 0;
75}
76
Dan Williams6e66f032007-12-11 12:42:16 -050077/**
78 * @brief Updates the hardware details like MAC address and regulatory region
79 *
80 * @param priv A pointer to struct lbs_private structure
81 *
82 * @return 0 on success, error on failure
83 */
84int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085{
Dan Williams6e66f032007-12-11 12:42:16 -050086 struct cmd_ds_get_hw_spec cmd;
87 int ret = -1;
88 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
Holger Schurig9012b282007-05-25 11:27:16 -040090 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091
Dan Williams6e66f032007-12-11 12:42:16 -050092 memset(&cmd, 0, sizeof(cmd));
93 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
94 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050095 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050096 if (ret)
97 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098
Dan Williams6e66f032007-12-11 12:42:16 -050099 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500100
Holger Schurigdac10a92008-01-16 15:55:22 +0100101 /* The firmware release is in an interesting format: the patch
102 * level is in the most significant nibble ... so fix that: */
103 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
104 priv->fwrelease = (priv->fwrelease << 8) |
105 (priv->fwrelease >> 24 & 0xff);
106
107 /* Some firmware capabilities:
108 * CF card firmware 5.0.16p0: cap 0x00000303
109 * USB dongle firmware 5.110.17p2: cap 0x00000303
110 */
Johannes Berge1749612008-10-27 15:59:26 -0700111 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
112 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100113 priv->fwrelease >> 24 & 0xff,
114 priv->fwrelease >> 16 & 0xff,
115 priv->fwrelease >> 8 & 0xff,
116 priv->fwrelease & 0xff,
117 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500118 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
119 cmd.hwifversion, cmd.version);
120
121 /* Clamp region code to 8-bit since FW spec indicates that it should
122 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
123 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200124 *
125 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
126 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500127 */
Marek Vasut15483992009-07-16 19:19:53 +0200128 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
129 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
130 else
131 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500132
133 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
134 /* use the region code to search for the index */
135 if (priv->regioncode == lbs_region_code_to_index[i])
136 break;
137 }
138
139 /* if it's unidentified region code, use the default (USA) */
140 if (i >= MRVDRV_MAX_REGION_CODE) {
141 priv->regioncode = 0x10;
142 lbs_pr_info("unidentified region code; using the default (USA)\n");
143 }
144
145 if (priv->current_addr[0] == 0xff)
146 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
147
Vasily Khoruzhick75abde42011-01-21 22:44:49 +0200148 if (!priv->copied_hwaddr) {
149 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
150 if (priv->mesh_dev)
151 memcpy(priv->mesh_dev->dev_addr,
152 priv->current_addr, ETH_ALEN);
153 priv->copied_hwaddr = 1;
154 }
Dan Williams6e66f032007-12-11 12:42:16 -0500155
Dan Williams6e66f032007-12-11 12:42:16 -0500156out:
Holger Schurig9012b282007-05-25 11:27:16 -0400157 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500158 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159}
160
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700161static int lbs_ret_host_sleep_cfg(struct lbs_private *priv, unsigned long dummy,
162 struct cmd_header *resp)
163{
164 lbs_deb_enter(LBS_DEB_CMD);
Amitkumar Karwar13118432010-07-08 06:43:48 +0530165 if (priv->is_host_sleep_activated) {
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700166 priv->is_host_sleep_configured = 0;
167 if (priv->psstate == PS_STATE_FULL_POWER) {
168 priv->is_host_sleep_activated = 0;
169 wake_up_interruptible(&priv->host_sleep_q);
170 }
171 } else {
172 priv->is_host_sleep_configured = 1;
173 }
174 lbs_deb_leave(LBS_DEB_CMD);
175 return 0;
176}
177
Anna Neal582c1b52008-10-20 16:46:56 -0700178int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
179 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500180{
181 struct cmd_ds_host_sleep cmd_config;
182 int ret;
183
Deepak Saxenaae63a332010-10-31 13:40:33 +0000184 /*
185 * Certain firmware versions do not support EHS_REMOVE_WAKEUP command
186 * and the card will return a failure. Since we need to be
187 * able to reset the mask, in those cases we set a 0 mask instead.
188 */
189 if (criteria == EHS_REMOVE_WAKEUP && !priv->ehs_remove_supported)
190 criteria = 0;
191
David Woodhouse9fae8992007-12-15 03:46:44 -0500192 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500193 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500194 cmd_config.gpio = priv->wol_gpio;
195 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500196
Anna Neal582c1b52008-10-20 16:46:56 -0700197 if (p_wol_config != NULL)
198 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
199 sizeof(struct wol_config));
200 else
201 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
202
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700203 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config.hdr,
204 le16_to_cpu(cmd_config.hdr.size),
205 lbs_ret_host_sleep_cfg, 0);
David Woodhouse506e9022007-12-12 20:06:06 -0500206 if (!ret) {
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700207 if (p_wol_config)
Anna Neal582c1b52008-10-20 16:46:56 -0700208 memcpy((uint8_t *) p_wol_config,
209 (uint8_t *)&cmd_config.wol_conf,
210 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500211 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500212 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500213 }
David Woodhouse506e9022007-12-12 20:06:06 -0500214
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500215 return ret;
216}
217EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
218
Dan Williams0bb64082010-07-27 13:08:08 -0700219/**
220 * @brief Sets the Power Save mode
221 *
222 * @param priv A pointer to struct lbs_private structure
223 * @param cmd_action The Power Save operation (PS_MODE_ACTION_ENTER_PS or
224 * PS_MODE_ACTION_EXIT_PS)
225 * @param block Whether to block on a response or not
226 *
227 * @return 0 on success, error on failure
228 */
229int lbs_set_ps_mode(struct lbs_private *priv, u16 cmd_action, bool block)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230{
Dan Williams0bb64082010-07-27 13:08:08 -0700231 struct cmd_ds_802_11_ps_mode cmd;
232 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233
Holger Schurig9012b282007-05-25 11:27:16 -0400234 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235
Dan Williams0bb64082010-07-27 13:08:08 -0700236 memset(&cmd, 0, sizeof(cmd));
237 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
238 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
Dan Williams0bb64082010-07-27 13:08:08 -0700240 if (cmd_action == PS_MODE_ACTION_ENTER_PS) {
241 lbs_deb_cmd("PS_MODE: action ENTER_PS\n");
242 cmd.multipledtim = cpu_to_le16(1); /* Default DTIM multiple */
243 } else if (cmd_action == PS_MODE_ACTION_EXIT_PS) {
244 lbs_deb_cmd("PS_MODE: action EXIT_PS\n");
245 } else {
246 /* We don't handle CONFIRM_SLEEP here because it needs to
247 * be fastpathed to the firmware.
248 */
249 lbs_deb_cmd("PS_MODE: unknown action 0x%X\n", cmd_action);
250 ret = -EOPNOTSUPP;
251 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 }
253
Dan Williams0bb64082010-07-27 13:08:08 -0700254 if (block)
255 ret = lbs_cmd_with_response(priv, CMD_802_11_PS_MODE, &cmd);
256 else
257 lbs_cmd_async(priv, CMD_802_11_PS_MODE, &cmd.hdr, sizeof (cmd));
258
259out:
260 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
261 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200262}
263
David Woodhouse3fbe1042007-12-17 23:48:31 -0500264int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
265 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500267 struct cmd_ds_802_11_sleep_params cmd;
268 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269
Holger Schurig9012b282007-05-25 11:27:16 -0400270 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200271
Dan Williams0aef64d2007-08-02 11:31:18 -0400272 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500273 memset(&cmd, 0, sizeof(cmd));
274 } else {
275 cmd.error = cpu_to_le16(sp->sp_error);
276 cmd.offset = cpu_to_le16(sp->sp_offset);
277 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
278 cmd.calcontrol = sp->sp_calcontrol;
279 cmd.externalsleepclk = sp->sp_extsleepclk;
280 cmd.reserved = cpu_to_le16(sp->sp_reserved);
281 }
282 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
283 cmd.action = cpu_to_le16(cmd_action);
284
285 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
286
287 if (!ret) {
288 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
289 "calcontrol 0x%x extsleepclk 0x%x\n",
290 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
291 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
292 cmd.externalsleepclk);
293
294 sp->sp_error = le16_to_cpu(cmd.error);
295 sp->sp_offset = le16_to_cpu(cmd.offset);
296 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
297 sp->sp_calcontrol = cmd.calcontrol;
298 sp->sp_extsleepclk = cmd.externalsleepclk;
299 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 }
301
David Woodhouse3fbe1042007-12-17 23:48:31 -0500302 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 return 0;
304}
305
Amitkumar Karwar49125452009-09-30 20:04:38 -0700306static int lbs_wait_for_ds_awake(struct lbs_private *priv)
307{
308 int ret = 0;
309
310 lbs_deb_enter(LBS_DEB_CMD);
311
312 if (priv->is_deep_sleep) {
313 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
314 !priv->is_deep_sleep, (10 * HZ))) {
315 lbs_pr_err("ds_awake_q: timer expired\n");
316 ret = -1;
317 }
318 }
319
320 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
321 return ret;
322}
323
324int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
325{
326 int ret = 0;
327
328 lbs_deb_enter(LBS_DEB_CMD);
329
330 if (deep_sleep) {
331 if (priv->is_deep_sleep != 1) {
332 lbs_deb_cmd("deep sleep: sleep\n");
333 BUG_ON(!priv->enter_deep_sleep);
334 ret = priv->enter_deep_sleep(priv);
335 if (!ret) {
336 netif_stop_queue(priv->dev);
337 netif_carrier_off(priv->dev);
338 }
339 } else {
340 lbs_pr_err("deep sleep: already enabled\n");
341 }
342 } else {
343 if (priv->is_deep_sleep) {
344 lbs_deb_cmd("deep sleep: wakeup\n");
345 BUG_ON(!priv->exit_deep_sleep);
346 ret = priv->exit_deep_sleep(priv);
347 if (!ret) {
348 ret = lbs_wait_for_ds_awake(priv);
349 if (ret)
350 lbs_pr_err("deep sleep: wakeup"
351 "failed\n");
352 }
353 }
354 }
355
356 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
357 return ret;
358}
359
Amitkumar Karwar13118432010-07-08 06:43:48 +0530360static int lbs_ret_host_sleep_activate(struct lbs_private *priv,
361 unsigned long dummy,
362 struct cmd_header *cmd)
363{
364 lbs_deb_enter(LBS_DEB_FW);
365 priv->is_host_sleep_activated = 1;
366 wake_up_interruptible(&priv->host_sleep_q);
367 lbs_deb_leave(LBS_DEB_FW);
368 return 0;
369}
370
371int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
372{
373 struct cmd_header cmd;
374 int ret = 0;
375 uint32_t criteria = EHS_REMOVE_WAKEUP;
376
377 lbs_deb_enter(LBS_DEB_CMD);
378
379 if (host_sleep) {
380 if (priv->is_host_sleep_activated != 1) {
381 memset(&cmd, 0, sizeof(cmd));
382 ret = lbs_host_sleep_cfg(priv, priv->wol_criteria,
383 (struct wol_config *)NULL);
384 if (ret) {
385 lbs_pr_info("Host sleep configuration failed: "
386 "%d\n", ret);
387 return ret;
388 }
389 if (priv->psstate == PS_STATE_FULL_POWER) {
390 ret = __lbs_cmd(priv,
391 CMD_802_11_HOST_SLEEP_ACTIVATE,
392 &cmd,
393 sizeof(cmd),
394 lbs_ret_host_sleep_activate, 0);
395 if (ret)
396 lbs_pr_info("HOST_SLEEP_ACTIVATE "
397 "failed: %d\n", ret);
398 }
399
400 if (!wait_event_interruptible_timeout(
401 priv->host_sleep_q,
402 priv->is_host_sleep_activated,
403 (10 * HZ))) {
404 lbs_pr_err("host_sleep_q: timer expired\n");
405 ret = -1;
406 }
407 } else {
408 lbs_pr_err("host sleep: already enabled\n");
409 }
410 } else {
411 if (priv->is_host_sleep_activated)
412 ret = lbs_host_sleep_cfg(priv, criteria,
413 (struct wol_config *)NULL);
414 }
415
416 return ret;
417}
418
Dan Williams39fcf7a2008-09-10 12:49:00 -0400419/**
420 * @brief Set an SNMP MIB value
421 *
422 * @param priv A pointer to struct lbs_private structure
423 * @param oid The OID to set in the firmware
424 * @param val Value to set the OID to
425 *
426 * @return 0 on success, error on failure
427 */
428int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400430 struct cmd_ds_802_11_snmp_mib cmd;
431 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432
Holger Schurig9012b282007-05-25 11:27:16 -0400433 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200434
Dan Williams39fcf7a2008-09-10 12:49:00 -0400435 memset(&cmd, 0, sizeof (cmd));
436 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
437 cmd.action = cpu_to_le16(CMD_ACT_SET);
438 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439
Dan Williams39fcf7a2008-09-10 12:49:00 -0400440 switch (oid) {
441 case SNMP_MIB_OID_BSS_TYPE:
442 cmd.bufsize = cpu_to_le16(sizeof(u8));
Holger Schurigfef06402009-10-22 15:30:59 +0200443 cmd.value[0] = val;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400445 case SNMP_MIB_OID_11D_ENABLE:
446 case SNMP_MIB_OID_FRAG_THRESHOLD:
447 case SNMP_MIB_OID_RTS_THRESHOLD:
448 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
449 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
450 cmd.bufsize = cpu_to_le16(sizeof(u16));
451 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 break;
453 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400454 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
455 ret = -EINVAL;
456 goto out;
457 }
458
459 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
460 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
461
462 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
463
464out:
465 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
466 return ret;
467}
468
469/**
470 * @brief Get an SNMP MIB value
471 *
472 * @param priv A pointer to struct lbs_private structure
473 * @param oid The OID to retrieve from the firmware
474 * @param out_val Location for the returned value
475 *
476 * @return 0 on success, error on failure
477 */
478int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
479{
480 struct cmd_ds_802_11_snmp_mib cmd;
481 int ret;
482
483 lbs_deb_enter(LBS_DEB_CMD);
484
485 memset(&cmd, 0, sizeof (cmd));
486 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
487 cmd.action = cpu_to_le16(CMD_ACT_GET);
488 cmd.oid = cpu_to_le16(oid);
489
490 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
491 if (ret)
492 goto out;
493
494 switch (le16_to_cpu(cmd.bufsize)) {
495 case sizeof(u8):
Holger Schurigfef06402009-10-22 15:30:59 +0200496 *out_val = cmd.value[0];
Dan Williams39fcf7a2008-09-10 12:49:00 -0400497 break;
498 case sizeof(u16):
499 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
500 break;
501 default:
502 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
503 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504 break;
505 }
506
Dan Williams39fcf7a2008-09-10 12:49:00 -0400507out:
508 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
509 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510}
511
Dan Williams87c8c722008-08-19 15:15:35 -0400512/**
513 * @brief Get the min, max, and current TX power
514 *
515 * @param priv A pointer to struct lbs_private structure
516 * @param curlevel Current power level in dBm
517 * @param minlevel Minimum supported power level in dBm (optional)
518 * @param maxlevel Maximum supported power level in dBm (optional)
519 *
520 * @return 0 on success, error on failure
521 */
522int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
523 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524{
Dan Williams87c8c722008-08-19 15:15:35 -0400525 struct cmd_ds_802_11_rf_tx_power cmd;
526 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527
Holger Schurig9012b282007-05-25 11:27:16 -0400528 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
Dan Williams87c8c722008-08-19 15:15:35 -0400530 memset(&cmd, 0, sizeof(cmd));
531 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
532 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533
Dan Williams87c8c722008-08-19 15:15:35 -0400534 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
535 if (ret == 0) {
536 *curlevel = le16_to_cpu(cmd.curlevel);
537 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100538 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400539 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100540 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200541 }
Holger Schurig9012b282007-05-25 11:27:16 -0400542
543 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400544 return ret;
545}
546
547/**
548 * @brief Set the TX power
549 *
550 * @param priv A pointer to struct lbs_private structure
551 * @param dbm The desired power level in dBm
552 *
553 * @return 0 on success, error on failure
554 */
555int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
556{
557 struct cmd_ds_802_11_rf_tx_power cmd;
558 int ret;
559
560 lbs_deb_enter(LBS_DEB_CMD);
561
562 memset(&cmd, 0, sizeof(cmd));
563 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
564 cmd.action = cpu_to_le16(CMD_ACT_SET);
565 cmd.curlevel = cpu_to_le16(dbm);
566
567 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
568
569 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
570
571 lbs_deb_leave(LBS_DEB_CMD);
572 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573}
574
Dan Williamsa45b6f42010-07-27 12:54:34 -0700575/**
576 * @brief Enable or disable monitor mode (only implemented on OLPC usb8388 FW)
577 *
578 * @param priv A pointer to struct lbs_private structure
579 * @param enable 1 to enable monitor mode, 0 to disable
580 *
581 * @return 0 on success, error on failure
582 */
583int lbs_set_monitor_mode(struct lbs_private *priv, int enable)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400584{
Dan Williamsa45b6f42010-07-27 12:54:34 -0700585 struct cmd_ds_802_11_monitor_mode cmd;
586 int ret;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400587
Dan Williamsa45b6f42010-07-27 12:54:34 -0700588 memset(&cmd, 0, sizeof(cmd));
589 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
590 cmd.action = cpu_to_le16(CMD_ACT_SET);
591 if (enable)
592 cmd.mode = cpu_to_le16(0x1);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400593
Dan Williamsa45b6f42010-07-27 12:54:34 -0700594 lbs_deb_cmd("SET_MONITOR_MODE: %d\n", enable);
595
596 ret = lbs_cmd_with_response(priv, CMD_802_11_MONITOR_MODE, &cmd);
597 if (ret == 0) {
598 priv->dev->type = enable ? ARPHRD_IEEE80211_RADIOTAP :
599 ARPHRD_ETHER;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400600 }
601
Dan Williamsa45b6f42010-07-27 12:54:34 -0700602 lbs_deb_leave(LBS_DEB_CMD);
603 return ret;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400604}
605
Dan Williams2dd4b262007-12-11 16:54:15 -0500606/**
607 * @brief Get the radio channel
608 *
609 * @param priv A pointer to struct lbs_private structure
610 *
611 * @return The channel on success, error on failure
612 */
Holger Schuriga3cbfb02009-10-16 17:33:56 +0200613static int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614{
Dan Williams2dd4b262007-12-11 16:54:15 -0500615 struct cmd_ds_802_11_rf_channel cmd;
616 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617
Holger Schurig8ff12da2007-08-02 11:54:31 -0400618 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200620 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500621 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
622 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623
David Woodhouse689442d2007-12-12 16:00:42 -0500624 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500625 if (ret)
626 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627
Dan Williamscb182a62007-12-11 17:35:51 -0500628 ret = le16_to_cpu(cmd.channel);
629 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500630
631out:
632 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
633 return ret;
634}
635
Holger Schurig73ab1f22008-04-02 16:52:19 +0200636int lbs_update_channel(struct lbs_private *priv)
637{
638 int ret;
639
640 /* the channel in f/w could be out of sync; get the current channel */
641 lbs_deb_enter(LBS_DEB_ASSOC);
642
643 ret = lbs_get_channel(priv);
644 if (ret > 0) {
Holger Schurigc14951f2009-10-22 15:30:50 +0200645 priv->channel = ret;
Holger Schurig73ab1f22008-04-02 16:52:19 +0200646 ret = 0;
647 }
648 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
649 return ret;
650}
651
Dan Williams2dd4b262007-12-11 16:54:15 -0500652/**
653 * @brief Set the radio channel
654 *
655 * @param priv A pointer to struct lbs_private structure
656 * @param channel The desired channel, or 0 to clear a locked channel
657 *
658 * @return 0 on success, error on failure
659 */
660int lbs_set_channel(struct lbs_private *priv, u8 channel)
661{
662 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530663#ifdef DEBUG
Holger Schurigc14951f2009-10-22 15:30:50 +0200664 u8 old_channel = priv->channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530665#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500666 int ret = 0;
667
668 lbs_deb_enter(LBS_DEB_CMD);
669
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200670 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500671 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
672 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
673 cmd.channel = cpu_to_le16(channel);
674
David Woodhouse689442d2007-12-12 16:00:42 -0500675 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500676 if (ret)
677 goto out;
678
Holger Schurigc14951f2009-10-22 15:30:50 +0200679 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
Dan Williamscb182a62007-12-11 17:35:51 -0500680 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
Holger Schurigc14951f2009-10-22 15:30:50 +0200681 priv->channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500682
683out:
684 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
685 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686}
687
Dan Williams9fb76632010-07-27 12:55:21 -0700688/**
689 * @brief Get current RSSI and noise floor
690 *
691 * @param priv A pointer to struct lbs_private structure
692 * @param rssi On successful return, signal level in mBm
693 *
694 * @return The channel on success, error on failure
695 */
696int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf)
697{
698 struct cmd_ds_802_11_rssi cmd;
699 int ret = 0;
700
701 lbs_deb_enter(LBS_DEB_CMD);
702
703 BUG_ON(rssi == NULL);
704 BUG_ON(nf == NULL);
705
706 memset(&cmd, 0, sizeof(cmd));
707 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
708 /* Average SNR over last 8 beacons */
709 cmd.n_or_snr = cpu_to_le16(8);
710
711 ret = lbs_cmd_with_response(priv, CMD_802_11_RSSI, &cmd);
712 if (ret == 0) {
713 *nf = CAL_NF(le16_to_cpu(cmd.nf));
714 *rssi = CAL_RSSI(le16_to_cpu(cmd.n_or_snr), le16_to_cpu(cmd.nf));
715 }
716
717 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
718 return ret;
719}
720
Dan Williamscc4b9d32010-07-27 12:56:05 -0700721/**
722 * @brief Send regulatory and 802.11d domain information to the firmware
723 *
724 * @param priv pointer to struct lbs_private
725 * @param request cfg80211 regulatory request structure
726 * @param bands the device's supported bands and channels
727 *
728 * @return 0 on success, error code on failure
729*/
730int lbs_set_11d_domain_info(struct lbs_private *priv,
731 struct regulatory_request *request,
732 struct ieee80211_supported_band **bands)
733{
734 struct cmd_ds_802_11d_domain_info cmd;
735 struct mrvl_ie_domain_param_set *domain = &cmd.domain;
736 struct ieee80211_country_ie_triplet *t;
737 enum ieee80211_band band;
738 struct ieee80211_channel *ch;
739 u8 num_triplet = 0;
740 u8 num_parsed_chan = 0;
741 u8 first_channel = 0, next_chan = 0, max_pwr = 0;
742 u8 i, flag = 0;
743 size_t triplet_size;
744 int ret;
745
746 lbs_deb_enter(LBS_DEB_11D);
747
748 memset(&cmd, 0, sizeof(cmd));
749 cmd.action = cpu_to_le16(CMD_ACT_SET);
750
751 lbs_deb_11d("Setting country code '%c%c'\n",
752 request->alpha2[0], request->alpha2[1]);
753
754 domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
755
756 /* Set country code */
757 domain->country_code[0] = request->alpha2[0];
758 domain->country_code[1] = request->alpha2[1];
759 domain->country_code[2] = ' ';
760
761 /* Now set up the channel triplets; firmware is somewhat picky here
762 * and doesn't validate channel numbers and spans; hence it would
763 * interpret a triplet of (36, 4, 20) as channels 36, 37, 38, 39. Since
764 * the last 3 aren't valid channels, the driver is responsible for
765 * splitting that up into 4 triplet pairs of (36, 1, 20) + (40, 1, 20)
766 * etc.
767 */
768 for (band = 0;
769 (band < IEEE80211_NUM_BANDS) && (num_triplet < MAX_11D_TRIPLETS);
770 band++) {
771
772 if (!bands[band])
773 continue;
774
775 for (i = 0;
776 (i < bands[band]->n_channels) && (num_triplet < MAX_11D_TRIPLETS);
777 i++) {
778 ch = &bands[band]->channels[i];
779 if (ch->flags & IEEE80211_CHAN_DISABLED)
780 continue;
781
782 if (!flag) {
783 flag = 1;
784 next_chan = first_channel = (u32) ch->hw_value;
785 max_pwr = ch->max_power;
786 num_parsed_chan = 1;
787 continue;
788 }
789
790 if ((ch->hw_value == next_chan + 1) &&
791 (ch->max_power == max_pwr)) {
792 /* Consolidate adjacent channels */
793 next_chan++;
794 num_parsed_chan++;
795 } else {
796 /* Add this triplet */
797 lbs_deb_11d("11D triplet (%d, %d, %d)\n",
798 first_channel, num_parsed_chan,
799 max_pwr);
800 t = &domain->triplet[num_triplet];
801 t->chans.first_channel = first_channel;
802 t->chans.num_channels = num_parsed_chan;
803 t->chans.max_power = max_pwr;
804 num_triplet++;
805 flag = 0;
806 }
807 }
808
809 if (flag) {
810 /* Add last triplet */
811 lbs_deb_11d("11D triplet (%d, %d, %d)\n", first_channel,
812 num_parsed_chan, max_pwr);
813 t = &domain->triplet[num_triplet];
814 t->chans.first_channel = first_channel;
815 t->chans.num_channels = num_parsed_chan;
816 t->chans.max_power = max_pwr;
817 num_triplet++;
818 }
819 }
820
821 lbs_deb_11d("# triplets %d\n", num_triplet);
822
823 /* Set command header sizes */
824 triplet_size = num_triplet * sizeof(struct ieee80211_country_ie_triplet);
825 domain->header.len = cpu_to_le16(sizeof(domain->country_code) +
826 triplet_size);
827
828 lbs_deb_hex(LBS_DEB_11D, "802.11D domain param set",
829 (u8 *) &cmd.domain.country_code,
830 le16_to_cpu(domain->header.len));
831
832 cmd.hdr.size = cpu_to_le16(sizeof(cmd.hdr) +
833 sizeof(cmd.action) +
834 sizeof(cmd.domain.header) +
835 sizeof(cmd.domain.country_code) +
836 triplet_size);
837
838 ret = lbs_cmd_with_response(priv, CMD_802_11D_DOMAIN_INFO, &cmd);
839
840 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
841 return ret;
842}
843
Dan Williams4c7c6e002010-07-27 13:01:07 -0700844/**
845 * @brief Read a MAC, Baseband, or RF register
846 *
847 * @param priv pointer to struct lbs_private
848 * @param cmd register command, one of CMD_MAC_REG_ACCESS,
849 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
850 * @param offset byte offset of the register to get
851 * @param value on success, the value of the register at 'offset'
852 *
853 * @return 0 on success, error code on failure
854*/
855int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856{
Dan Williams4c7c6e002010-07-27 13:01:07 -0700857 struct cmd_ds_reg_access cmd;
858 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859
Holger Schurig9012b282007-05-25 11:27:16 -0400860 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861
Dan Williams4c7c6e002010-07-27 13:01:07 -0700862 BUG_ON(value == NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863
Dan Williams4c7c6e002010-07-27 13:01:07 -0700864 memset(&cmd, 0, sizeof(cmd));
865 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
866 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867
Dan Williams4c7c6e002010-07-27 13:01:07 -0700868 if (reg != CMD_MAC_REG_ACCESS &&
869 reg != CMD_BBP_REG_ACCESS &&
870 reg != CMD_RF_REG_ACCESS) {
871 ret = -EINVAL;
872 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 }
874
Dan Williams4c7c6e002010-07-27 13:01:07 -0700875 ret = lbs_cmd_with_response(priv, reg, &cmd);
876 if (ret) {
877 if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
878 *value = cmd.value.bbp_rf;
879 else if (reg == CMD_MAC_REG_ACCESS)
880 *value = le32_to_cpu(cmd.value.mac);
881 }
882
883out:
884 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
885 return ret;
886}
887
888/**
889 * @brief Write a MAC, Baseband, or RF register
890 *
891 * @param priv pointer to struct lbs_private
892 * @param cmd register command, one of CMD_MAC_REG_ACCESS,
893 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
894 * @param offset byte offset of the register to set
895 * @param value the value to write to the register at 'offset'
896 *
897 * @return 0 on success, error code on failure
898*/
899int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value)
900{
901 struct cmd_ds_reg_access cmd;
902 int ret = 0;
903
904 lbs_deb_enter(LBS_DEB_CMD);
905
906 memset(&cmd, 0, sizeof(cmd));
907 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
908 cmd.action = cpu_to_le16(CMD_ACT_SET);
909
910 if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
911 cmd.value.bbp_rf = (u8) (value & 0xFF);
912 else if (reg == CMD_MAC_REG_ACCESS)
913 cmd.value.mac = cpu_to_le32(value);
914 else {
915 ret = -EINVAL;
916 goto out;
917 }
918
919 ret = lbs_cmd_with_response(priv, reg, &cmd);
920
921out:
922 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
923 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924}
925
David Woodhouse681ffbb2007-12-15 20:04:54 -0500926static void lbs_queue_cmd(struct lbs_private *priv,
927 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928{
929 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -0500930 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931
Holger Schurig8ff12da2007-08-02 11:54:31 -0400932 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200933
David Woodhousec4ab4122007-12-15 00:41:51 -0500934 if (!cmdnode) {
935 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200936 goto done;
937 }
David Woodhoused9896ee2007-12-15 00:09:25 -0500938 if (!cmdnode->cmdbuf->size) {
939 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
940 goto done;
941 }
David Woodhouseae125bf2007-12-15 04:22:52 -0500942 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200943
944 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -0500945 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
Dan Williams0bb64082010-07-27 13:08:08 -0700946 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf;
Dan Williamsddac4522007-12-11 13:49:39 -0500947
Dan Williams0bb64082010-07-27 13:08:08 -0700948 if (psm->action == cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000949 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950 addtail = 0;
951 }
952 }
953
Dan Williams0bb64082010-07-27 13:08:08 -0700954 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_WAKEUP_CONFIRM)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700955 addtail = 0;
956
David Woodhouseaa21c002007-12-08 20:04:36 +0000957 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958
David Woodhouseac472462007-12-08 00:35:00 +0000959 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +0000960 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +0000961 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000962 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200963
David Woodhouseaa21c002007-12-08 20:04:36 +0000964 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200965
Holger Schurig8ff12da2007-08-02 11:54:31 -0400966 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -0500967 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200968
969done:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400970 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200971}
972
David Woodhouse18c52e72007-12-17 16:03:58 -0500973static void lbs_submit_command(struct lbs_private *priv,
974 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200975{
976 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -0500977 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -0500978 uint16_t cmdsize;
979 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +0200980 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500981 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982
Holger Schurig8ff12da2007-08-02 11:54:31 -0400983 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200984
Dan Williamsddac4522007-12-11 13:49:39 -0500985 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200986
David Woodhouseaa21c002007-12-08 20:04:36 +0000987 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +0000988 priv->cur_cmd = cmdnode;
David Woodhouseaa21c002007-12-08 20:04:36 +0000989 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990
Dan Williamsddac4522007-12-11 13:49:39 -0500991 cmdsize = le16_to_cpu(cmd->size);
992 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200993
David Woodhouse18c52e72007-12-17 16:03:58 -0500994 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400995 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +0200996 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500997
Holger Schurige5225b32008-03-26 10:04:44 +0100998 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
999 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001000 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001001
Dan Williamsddac4522007-12-11 13:49:39 -05001002 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001003
David Woodhoused9896ee2007-12-15 00:09:25 -05001004 if (ret) {
1005 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001006 /* Let the timer kick in and retry, and potentially reset
1007 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001008 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001009 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010
Amitkumar Karwar49125452009-09-30 20:04:38 -07001011 if (command == CMD_802_11_DEEP_SLEEP) {
1012 if (priv->is_auto_deep_sleep_enabled) {
1013 priv->wakeup_dev_required = 1;
1014 priv->dnld_sent = 0;
1015 }
1016 priv->is_deep_sleep = 1;
1017 lbs_complete_command(priv, cmdnode, 0);
1018 } else {
1019 /* Setup the timer after transmit command */
1020 mod_timer(&priv->command_timer, jiffies + timeo);
1021 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022
David Woodhouse18c52e72007-12-17 16:03:58 -05001023 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001024}
1025
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001026/**
1027 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001028 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001030static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001031 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001033 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001035 if (!cmdnode)
1036 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001038 cmdnode->callback = NULL;
1039 cmdnode->callback_arg = 0;
1040
1041 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1042
1043 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1044 out:
1045 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046}
1047
Holger Schurig69f90322007-11-23 15:43:44 +01001048static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1049 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050{
1051 unsigned long flags;
1052
David Woodhouseaa21c002007-12-08 20:04:36 +00001053 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001054 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001055 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056}
1057
David Woodhouse183aeac2007-12-15 01:52:54 -05001058void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1059 int result)
1060{
David Woodhouseae125bf2007-12-15 04:22:52 -05001061 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001062 cmd->cmdwaitqwoken = 1;
1063 wake_up_interruptible(&cmd->cmdwait_q);
1064
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001065 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001066 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001067 priv->cur_cmd = NULL;
1068}
1069
Dan Williamsd5db2df2008-08-21 17:51:07 -04001070int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071{
David Woodhousea7c45892007-12-17 22:43:48 -05001072 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001073 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074
Holger Schurig9012b282007-05-25 11:27:16 -04001075 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076
David Woodhousea7c45892007-12-17 22:43:48 -05001077 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1078 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001079
Dan Williamsd5db2df2008-08-21 17:51:07 -04001080 /* Only v8 and below support setting the preamble */
1081 if (priv->fwrelease < 0x09000000) {
1082 switch (preamble) {
1083 case RADIO_PREAMBLE_SHORT:
Dan Williamsd5db2df2008-08-21 17:51:07 -04001084 case RADIO_PREAMBLE_AUTO:
1085 case RADIO_PREAMBLE_LONG:
1086 cmd.control = cpu_to_le16(preamble);
1087 break;
1088 default:
1089 goto out;
1090 }
David Woodhousea7c45892007-12-17 22:43:48 -05001091 }
1092
Dan Williamsd5db2df2008-08-21 17:51:07 -04001093 if (radio_on)
1094 cmd.control |= cpu_to_le16(0x1);
1095 else {
1096 cmd.control &= cpu_to_le16(~0x1);
1097 priv->txpower_cur = 0;
1098 }
David Woodhousea7c45892007-12-17 22:43:48 -05001099
Dan Williamsd5db2df2008-08-21 17:51:07 -04001100 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1101 radio_on ? "ON" : "OFF", preamble);
1102
1103 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001104
1105 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106
Dan Williamsd5db2df2008-08-21 17:51:07 -04001107out:
Holger Schurig9012b282007-05-25 11:27:16 -04001108 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109 return ret;
1110}
1111
Holger Schurigc97329e2008-03-18 11:20:21 +01001112void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001113{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001114 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115
Holger Schurig9012b282007-05-25 11:27:16 -04001116 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117
Holger Schurig835d3ac2008-03-12 16:05:40 +01001118 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001119 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001120 cmd.reserved = 0;
1121
David Woodhouse75bf45a2008-05-20 13:32:45 +01001122 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123
Holger Schurigc97329e2008-03-18 11:20:21 +01001124 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125}
1126
1127/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128 * @brief This function allocates the command buffer and link
1129 * it to command free queue.
1130 *
Holger Schurig69f90322007-11-23 15:43:44 +01001131 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001132 * @return 0 or -1
1133 */
Holger Schurig69f90322007-11-23 15:43:44 +01001134int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135{
1136 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001137 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001139 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001140
Holger Schurig8ff12da2007-08-02 11:54:31 -04001141 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142
Dan Williamsddac4522007-12-11 13:49:39 -05001143 /* Allocate and initialize the command array */
1144 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1145 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001146 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147 ret = -1;
1148 goto done;
1149 }
Dan Williamsddac4522007-12-11 13:49:39 -05001150 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151
Dan Williamsddac4522007-12-11 13:49:39 -05001152 /* Allocate and initialize each command buffer in the command array */
1153 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1154 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1155 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001156 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001157 ret = -1;
1158 goto done;
1159 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160 }
1161
Dan Williamsddac4522007-12-11 13:49:39 -05001162 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1163 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1164 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001166 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001167
1168done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001169 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 return ret;
1171}
1172
1173/**
1174 * @brief This function frees the command buffer.
1175 *
Holger Schurig69f90322007-11-23 15:43:44 +01001176 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001177 * @return 0 or -1
1178 */
Holger Schurig69f90322007-11-23 15:43:44 +01001179int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180{
Dan Williamsddac4522007-12-11 13:49:39 -05001181 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001182 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183
Holger Schurig8ff12da2007-08-02 11:54:31 -04001184 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185
1186 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001187 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001188 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189 goto done;
1190 }
1191
Dan Williamsddac4522007-12-11 13:49:39 -05001192 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001193
1194 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001195 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1196 if (cmdarray[i].cmdbuf) {
1197 kfree(cmdarray[i].cmdbuf);
1198 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199 }
1200 }
1201
1202 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001203 if (priv->cmd_array) {
1204 kfree(priv->cmd_array);
1205 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001206 }
1207
1208done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001209 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210 return 0;
1211}
1212
1213/**
1214 * @brief This function gets a free command node if available in
1215 * command free queue.
1216 *
Holger Schurig69f90322007-11-23 15:43:44 +01001217 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001218 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1219 */
Dan Williamsd06956b2010-07-27 13:16:24 -07001220static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221{
1222 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223 unsigned long flags;
1224
Holger Schurig8ff12da2007-08-02 11:54:31 -04001225 lbs_deb_enter(LBS_DEB_HOST);
1226
David Woodhouseaa21c002007-12-08 20:04:36 +00001227 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001228 return NULL;
1229
David Woodhouseaa21c002007-12-08 20:04:36 +00001230 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231
David Woodhouseaa21c002007-12-08 20:04:36 +00001232 if (!list_empty(&priv->cmdfreeq)) {
1233 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001234 struct cmd_ctrl_node, list);
1235 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001236 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001237 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238 tempnode = NULL;
1239 }
1240
David Woodhouseaa21c002007-12-08 20:04:36 +00001241 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001242
Holger Schurig8ff12da2007-08-02 11:54:31 -04001243 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001244 return tempnode;
1245}
1246
1247/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001249 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250 * if applicable.
1251 *
Holger Schurig69f90322007-11-23 15:43:44 +01001252 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 * @return 0 or -1
1254 */
Holger Schurig69f90322007-11-23 15:43:44 +01001255int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001258 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259 unsigned long flags;
1260 int ret = 0;
1261
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001262 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1263 * only caller to us is lbs_thread() and we get even when a
1264 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001265 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001266
David Woodhouseaa21c002007-12-08 20:04:36 +00001267 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268
David Woodhouseaa21c002007-12-08 20:04:36 +00001269 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001270 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001271 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272 ret = -1;
1273 goto done;
1274 }
1275
David Woodhouseaa21c002007-12-08 20:04:36 +00001276 if (!list_empty(&priv->cmdpendingq)) {
1277 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001278 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279 }
1280
David Woodhouseaa21c002007-12-08 20:04:36 +00001281 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001282
1283 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001284 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001285
Dan Williamsddac4522007-12-11 13:49:39 -05001286 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001287 if ((priv->psstate == PS_STATE_SLEEP) ||
1288 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001289 lbs_deb_host(
1290 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001291 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001292 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001293 ret = -1;
1294 goto done;
1295 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001296 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001297 "0x%04x in psstate %d\n",
1298 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001299 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300 /*
1301 * 1. Non-PS command:
1302 * Queue it. set needtowakeup to TRUE if current state
Dan Williams0bb64082010-07-27 13:08:08 -07001303 * is SLEEP, otherwise call send EXIT_PS.
1304 * 2. PS command but not EXIT_PS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305 * Ignore it.
Dan Williams0bb64082010-07-27 13:08:08 -07001306 * 3. PS command EXIT_PS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307 * Set needtowakeup to TRUE if current state is SLEEP,
1308 * otherwise send this command down to firmware
1309 * immediately.
1310 */
Dan Williamsddac4522007-12-11 13:49:39 -05001311 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312 /* Prepare to send Exit PS,
1313 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001314 if ((priv->psstate == PS_STATE_SLEEP)
1315 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316 ) {
1317 /* w/ new scheme, it will not reach here.
1318 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001319 priv->needtowakeup = 1;
Dan Williams0bb64082010-07-27 13:08:08 -07001320 } else {
1321 lbs_set_ps_mode(priv,
1322 PS_MODE_ACTION_EXIT_PS,
1323 false);
1324 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001325
1326 ret = 0;
1327 goto done;
1328 } else {
1329 /*
1330 * PS command. Ignore it if it is not Exit_PS.
1331 * otherwise send it down immediately.
1332 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001333 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001334
Holger Schurig8ff12da2007-08-02 11:54:31 -04001335 lbs_deb_host(
1336 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337 psm->action);
1338 if (psm->action !=
Dan Williams0bb64082010-07-27 13:08:08 -07001339 cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001340 lbs_deb_host(
1341 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
David Woodhouse183aeac2007-12-15 01:52:54 -05001342 spin_lock_irqsave(&priv->driver_lock, flags);
Paul Fox2ae1b8b32011-05-09 10:40:42 +01001343 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001344 lbs_complete_command(priv, cmdnode, 0);
1345 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001346
1347 ret = 0;
1348 goto done;
1349 }
1350
David Woodhouseaa21c002007-12-08 20:04:36 +00001351 if ((priv->psstate == PS_STATE_SLEEP) ||
1352 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001353 lbs_deb_host(
1354 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
David Woodhouse183aeac2007-12-15 01:52:54 -05001355 spin_lock_irqsave(&priv->driver_lock, flags);
Paul Fox2ae1b8b32011-05-09 10:40:42 +01001356 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001357 lbs_complete_command(priv, cmdnode, 0);
1358 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001359 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360
1361 ret = 0;
1362 goto done;
1363 }
1364
Holger Schurig8ff12da2007-08-02 11:54:31 -04001365 lbs_deb_host(
1366 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 }
1368 }
Paul Fox2ae1b8b32011-05-09 10:40:42 +01001369 spin_lock_irqsave(&priv->driver_lock, flags);
Li Zefanabe3ed12007-12-06 13:01:21 +01001370 list_del(&cmdnode->list);
Paul Fox2ae1b8b32011-05-09 10:40:42 +01001371 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001372 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001373 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001374 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001375 } else {
1376 /*
1377 * check if in power save mode, if yes, put the device back
1378 * to PS mode
1379 */
Kiran Divekare86dc1c2010-06-14 22:01:26 +05301380#ifdef TODO
1381 /*
1382 * This was the old code for libertas+wext. Someone that
1383 * understands this beast should re-code it in a sane way.
1384 *
1385 * I actually don't understand why this is related to WPA
1386 * and to connection status, shouldn't powering should be
1387 * independ of such things?
1388 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001389 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1390 (priv->psstate == PS_STATE_FULL_POWER) &&
1391 ((priv->connect_status == LBS_CONNECTED) ||
Holger Schurig602114a2009-12-02 15:26:01 +01001392 lbs_mesh_connected(priv))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001393 if (priv->secinfo.WPAenabled ||
1394 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001396 if (priv->wpa_mcast_key.len ||
1397 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001398 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1400 " go back to PS_SLEEP");
Dan Williams0bb64082010-07-27 13:08:08 -07001401 lbs_set_ps_mode(priv,
1402 PS_MODE_ACTION_ENTER_PS,
1403 false);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001404 }
1405 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001406 lbs_deb_host(
1407 "EXEC_NEXT_CMD: cmdpendingq empty, "
1408 "go back to PS_SLEEP");
Dan Williams0bb64082010-07-27 13:08:08 -07001409 lbs_set_ps_mode(priv, PS_MODE_ACTION_ENTER_PS,
1410 false);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001411 }
1412 }
Kiran Divekare86dc1c2010-06-14 22:01:26 +05301413#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001414 }
1415
1416 ret = 0;
1417done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001418 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419 return ret;
1420}
1421
Holger Schurigf539f2e2008-03-26 13:22:11 +01001422static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001423{
1424 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001425 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426
Holger Schurig8ff12da2007-08-02 11:54:31 -04001427 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001428 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1429 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001430
Holger Schurigf539f2e2008-03-26 13:22:11 +01001431 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1432 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001434 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001435 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436 }
Holger Schurig7919b892008-04-01 14:50:43 +02001437
1438 spin_lock_irqsave(&priv->driver_lock, flags);
1439
Holger Schuriga01f5452008-06-04 11:10:40 +02001440 /* We don't get a response on the sleep-confirmation */
1441 priv->dnld_sent = DNLD_RES_RECEIVED;
1442
Amitkumar Karwar66fceb62010-05-19 03:24:38 -07001443 if (priv->is_host_sleep_configured) {
1444 priv->is_host_sleep_activated = 1;
1445 wake_up_interruptible(&priv->host_sleep_q);
1446 }
1447
Holger Schurig7919b892008-04-01 14:50:43 +02001448 /* If nothing to do, go back to sleep (?) */
Stefani Seibolde64c0262009-12-21 14:37:28 -08001449 if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
Holger Schurig7919b892008-04-01 14:50:43 +02001450 priv->psstate = PS_STATE_SLEEP;
1451
1452 spin_unlock_irqrestore(&priv->driver_lock, flags);
1453
1454out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001455 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456}
1457
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458/**
1459 * @brief This function checks condition and prepares to
1460 * send sleep confirm command to firmware if ok.
1461 *
Holger Schurig69f90322007-11-23 15:43:44 +01001462 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463 * @param psmode Power Saving mode
1464 * @return n/a
1465 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001466void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467{
1468 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001469 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470
Holger Schurig8ff12da2007-08-02 11:54:31 -04001471 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472
Holger Schuriga01f5452008-06-04 11:10:40 +02001473 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001474 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001475 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001476 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477 }
1478
Holger Schurig7919b892008-04-01 14:50:43 +02001479 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001480 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001482 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483 }
Holger Schurig7919b892008-04-01 14:50:43 +02001484
1485 /* Pending events or command responses? */
Stefani Seibolde64c0262009-12-21 14:37:28 -08001486 if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001488 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001489 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001490 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001491
1492 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001493 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001494 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001496 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497 }
1498
Holger Schurig8ff12da2007-08-02 11:54:31 -04001499 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500}
Holger Schurig675787e2007-12-05 17:58:11 +01001501
1502
Anna Neal0112c9e2008-09-11 11:17:25 -07001503/**
1504 * @brief Configures the transmission power control functionality.
1505 *
1506 * @param priv A pointer to struct lbs_private structure
1507 * @param enable Transmission power control enable
1508 * @param p0 Power level when link quality is good (dBm).
1509 * @param p1 Power level when link quality is fair (dBm).
1510 * @param p2 Power level when link quality is poor (dBm).
1511 * @param usesnr Use Signal to Noise Ratio in TPC
1512 *
1513 * @return 0 on success
1514 */
1515int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1516 int8_t p2, int usesnr)
1517{
1518 struct cmd_ds_802_11_tpc_cfg cmd;
1519 int ret;
1520
1521 memset(&cmd, 0, sizeof(cmd));
1522 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1523 cmd.action = cpu_to_le16(CMD_ACT_SET);
1524 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001525 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001526 cmd.P0 = p0;
1527 cmd.P1 = p1;
1528 cmd.P2 = p2;
1529
1530 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1531
1532 return ret;
1533}
1534
1535/**
1536 * @brief Configures the power adaptation settings.
1537 *
1538 * @param priv A pointer to struct lbs_private structure
1539 * @param enable Power adaptation enable
1540 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1541 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1542 * @param p2 Power level for 48 and 54 Mbps (dBm).
1543 *
1544 * @return 0 on Success
1545 */
1546
1547int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1548 int8_t p1, int8_t p2)
1549{
1550 struct cmd_ds_802_11_pa_cfg cmd;
1551 int ret;
1552
1553 memset(&cmd, 0, sizeof(cmd));
1554 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1555 cmd.action = cpu_to_le16(CMD_ACT_SET);
1556 cmd.enable = !!enable;
1557 cmd.P0 = p0;
1558 cmd.P1 = p1;
1559 cmd.P2 = p2;
1560
1561 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1562
1563 return ret;
1564}
1565
1566
Holger Schurig6d898b12009-10-14 16:49:53 +02001567struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001568 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1569 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1570 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01001571{
Holger Schurig675787e2007-12-05 17:58:11 +01001572 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01001573
1574 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01001575
David Woodhouseaa21c002007-12-08 20:04:36 +00001576 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01001577 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05001578 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01001579 goto done;
1580 }
1581
Dan Williams77ccdcf2010-07-27 13:15:45 -07001582 /* No commands are allowed in Deep Sleep until we toggle the GPIO
1583 * to wake up the card and it has signaled that it's ready.
1584 */
1585 if (!priv->is_auto_deep_sleep_enabled) {
1586 if (priv->is_deep_sleep) {
1587 lbs_deb_cmd("command not allowed in deep sleep\n");
1588 cmdnode = ERR_PTR(-EBUSY);
1589 goto done;
1590 }
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001591 }
1592
Dan Williamsd06956b2010-07-27 13:16:24 -07001593 cmdnode = lbs_get_free_cmd_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01001594 if (cmdnode == NULL) {
1595 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1596
1597 /* Wake up main thread to execute next command */
1598 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05001599 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01001600 goto done;
1601 }
1602
David Woodhouse448a51a2007-12-08 00:59:54 +00001603 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05001604 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01001605
Dan Williams7ad994d2007-12-11 12:33:30 -05001606 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05001607 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05001608
Holger Schurig675787e2007-12-05 17:58:11 +01001609 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00001610 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05001611 cmdnode->cmdbuf->command = cpu_to_le16(command);
1612 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1613 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1614 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01001615
1616 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1617
Holger Schurig675787e2007-12-05 17:58:11 +01001618 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001619 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01001620 wake_up_interruptible(&priv->waitq);
1621
David Woodhouse3399ea52007-12-15 03:09:33 -05001622 done:
1623 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1624 return cmdnode;
1625}
1626
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001627void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1628 struct cmd_header *in_cmd, int in_cmd_size)
1629{
1630 lbs_deb_enter(LBS_DEB_CMD);
1631 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1632 lbs_cmd_async_callback, 0);
1633 lbs_deb_leave(LBS_DEB_CMD);
1634}
1635
David Woodhouse3399ea52007-12-15 03:09:33 -05001636int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1637 struct cmd_header *in_cmd, int in_cmd_size,
1638 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1639 unsigned long callback_arg)
1640{
1641 struct cmd_ctrl_node *cmdnode;
1642 unsigned long flags;
1643 int ret = 0;
1644
1645 lbs_deb_enter(LBS_DEB_HOST);
1646
1647 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1648 callback, callback_arg);
1649 if (IS_ERR(cmdnode)) {
1650 ret = PTR_ERR(cmdnode);
1651 goto done;
1652 }
1653
Holger Schurig675787e2007-12-05 17:58:11 +01001654 might_sleep();
1655 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1656
David Woodhouseaa21c002007-12-08 20:04:36 +00001657 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05001658 ret = cmdnode->result;
1659 if (ret)
1660 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1661 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05001662
David Woodhousead12d0f2007-12-15 02:06:16 -05001663 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00001664 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01001665
1666done:
1667 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1668 return ret;
1669}
Dan Williams14e865b2007-12-10 15:11:23 -05001670EXPORT_SYMBOL_GPL(__lbs_cmd);