iwlegacy: fix IBSS mode crashes
[deliverable/linux.git] / drivers / net / wireless / libertas / cmd.c
CommitLineData
876c9d3a
MT
1/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
7919b89c 6#include <linux/kfifo.h>
e93156e7 7#include <linux/sched.h>
5a0e3ad6 8#include <linux/slab.h>
a45b6f4f 9#include <linux/if_arp.h>
e93156e7 10
876c9d3a 11#include "decl.h"
e86dc1ca 12#include "cfg.h"
6e66f03f 13#include "cmd.h"
876c9d3a 14
9fb7663d
DW
15#define CAL_NF(nf) ((s32)(-(s32)(nf)))
16#define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf)))
e93156e7 17
8db4a2b9
HS
18/**
19 * @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
876c9d3a 58/**
852e1f2a 59 * @brief Checks whether a command is allowed in Power Save mode
876c9d3a
MT
60 *
61 * @param command the command ID
852e1f2a 62 * @return 1 if allowed, 0 if not allowed
876c9d3a 63 */
852e1f2a 64static u8 is_command_allowed_in_ps(u16 cmd)
876c9d3a 65{
852e1f2a
DW
66 switch (cmd) {
67 case CMD_802_11_RSSI:
68 return 1;
66fceb69
AK
69 case CMD_802_11_HOST_SLEEP_CFG:
70 return 1;
852e1f2a
DW
71 default:
72 break;
876c9d3a 73 }
876c9d3a
MT
74 return 0;
75}
76
6e66f03f
DW
77/**
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)
876c9d3a 85{
6e66f03f
DW
86 struct cmd_ds_get_hw_spec cmd;
87 int ret = -1;
88 u32 i;
876c9d3a 89
9012b28a 90 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 91
6e66f03f
DW
92 memset(&cmd, 0, sizeof(cmd));
93 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
94 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
689442dc 95 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
6e66f03f
DW
96 if (ret)
97 goto out;
98
99 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
6e66f03f 100
dac10a9f
HS
101 /* 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 */
e174961c
JB
111 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
112 cmd.permanentaddr,
dac10a9f
HS
113 priv->fwrelease >> 24 & 0xff,
114 priv->fwrelease >> 16 & 0xff,
115 priv->fwrelease >> 8 & 0xff,
116 priv->fwrelease & 0xff,
117 priv->fwcapinfo);
6e66f03f
DW
118 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.
15483996
MV
124 *
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.
6e66f03f 127 */
15483996
MV
128 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;
6e66f03f
DW
132
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);
876c9d3a 147
75abde4d
VK
148 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 }
6e66f03f 155
6e66f03f 156out:
9012b28a 157 lbs_deb_leave(LBS_DEB_CMD);
6e66f03f 158 return ret;
876c9d3a
MT
159}
160
66fceb69
AK
161static 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);
1311843c 165 if (priv->is_host_sleep_activated) {
66fceb69
AK
166 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
582c1b53
AN
178int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
179 struct wol_config *p_wol_config)
6ce4fd2a
DW
180{
181 struct cmd_ds_host_sleep cmd_config;
182 int ret;
183
ae63a33e
DS
184 /*
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
9fae899c 192 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
6ce4fd2a 193 cmd_config.criteria = cpu_to_le32(criteria);
506e9025
DW
194 cmd_config.gpio = priv->wol_gpio;
195 cmd_config.gap = priv->wol_gap;
6ce4fd2a 196
582c1b53
AN
197 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
66fceb69
AK
203 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);
506e9025 206 if (!ret) {
66fceb69 207 if (p_wol_config)
582c1b53
AN
208 memcpy((uint8_t *) p_wol_config,
209 (uint8_t *)&cmd_config.wol_conf,
210 sizeof(struct wol_config));
506e9025 211 } else {
6ce4fd2a 212 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
6ce4fd2a 213 }
506e9025 214
6ce4fd2a
DW
215 return ret;
216}
217EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
218
0bb64087
DW
219/**
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)
876c9d3a 230{
0bb64087
DW
231 struct cmd_ds_802_11_ps_mode cmd;
232 int ret = 0;
876c9d3a 233
9012b28a 234 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 235
0bb64087
DW
236 memset(&cmd, 0, sizeof(cmd));
237 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
238 cmd.action = cpu_to_le16(cmd_action);
876c9d3a 239
0bb64087
DW
240 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;
876c9d3a
MT
252 }
253
0bb64087
DW
254 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;
876c9d3a
MT
262}
263
3fbe104c
DW
264int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
265 struct sleep_params *sp)
876c9d3a 266{
3fbe104c
DW
267 struct cmd_ds_802_11_sleep_params cmd;
268 int ret;
876c9d3a 269
9012b28a 270 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 271
0aef64d7 272 if (cmd_action == CMD_ACT_GET) {
3fbe104c
DW
273 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);
876c9d3a 281 }
3fbe104c
DW
282 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
283 cmd.action = cpu_to_le16(cmd_action);
876c9d3a 284
3fbe104c
DW
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);
300 }
301
302 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
303 return 0;
304}
305
49125454
AK
306static 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
1311843c
AK
360static 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
39fcf7a3
DW
419/**
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)
876c9d3a 429{
39fcf7a3
DW
430 struct cmd_ds_802_11_snmp_mib cmd;
431 int ret;
876c9d3a 432
9012b28a 433 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 434
39fcf7a3
DW
435 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);
876c9d3a 439
39fcf7a3
DW
440 switch (oid) {
441 case SNMP_MIB_OID_BSS_TYPE:
442 cmd.bufsize = cpu_to_le16(sizeof(u8));
fef0640e 443 cmd.value[0] = val;
39fcf7a3
DW
444 break;
445 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);
876c9d3a 452 break;
39fcf7a3
DW
453 default:
454 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
455 ret = -EINVAL;
456 goto out;
876c9d3a
MT
457 }
458
39fcf7a3
DW
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);
876c9d3a 461
39fcf7a3 462 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
876c9d3a 463
39fcf7a3
DW
464out:
465 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
466 return ret;
467}
876c9d3a 468
39fcf7a3
DW
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;
876c9d3a 482
39fcf7a3 483 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 484
39fcf7a3
DW
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);
876c9d3a 489
39fcf7a3
DW
490 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
491 if (ret)
492 goto out;
876c9d3a 493
39fcf7a3
DW
494 switch (le16_to_cpu(cmd.bufsize)) {
495 case sizeof(u8):
fef0640e 496 *out_val = cmd.value[0];
39fcf7a3
DW
497 break;
498 case sizeof(u16):
499 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
876c9d3a
MT
500 break;
501 default:
39fcf7a3
DW
502 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
503 oid, le16_to_cpu(cmd.bufsize));
876c9d3a
MT
504 break;
505 }
506
39fcf7a3
DW
507out:
508 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
509 return ret;
876c9d3a
MT
510}
511
87c8c72d
DW
512/**
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)
876c9d3a 524{
87c8c72d
DW
525 struct cmd_ds_802_11_rf_tx_power cmd;
526 int ret;
876c9d3a 527
9012b28a 528 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 529
87c8c72d
DW
530 memset(&cmd, 0, sizeof(cmd));
531 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
532 cmd.action = cpu_to_le16(CMD_ACT_GET);
533
534 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)
87bf24f3 538 *minlevel = cmd.minlevel;
87c8c72d 539 if (maxlevel)
87bf24f3 540 *maxlevel = cmd.maxlevel;
87c8c72d 541 }
876c9d3a 542
87c8c72d
DW
543 lbs_deb_leave(LBS_DEB_CMD);
544 return ret;
545}
876c9d3a 546
87c8c72d
DW
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;
876c9d3a 559
87c8c72d 560 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 561
87c8c72d
DW
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);
876c9d3a 566
87c8c72d
DW
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);
9012b28a
HS
570
571 lbs_deb_leave(LBS_DEB_CMD);
87c8c72d 572 return ret;
876c9d3a
MT
573}
574
a45b6f4f
DW
575/**
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)
965f8bbc 584{
a45b6f4f
DW
585 struct cmd_ds_802_11_monitor_mode cmd;
586 int ret;
965f8bbc 587
a45b6f4f
DW
588 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);
965f8bbc 593
a45b6f4f
DW
594 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;
965f8bbc
LCC
600 }
601
a45b6f4f
DW
602 lbs_deb_leave(LBS_DEB_CMD);
603 return ret;
965f8bbc
LCC
604}
605
2dd4b262
DW
606/**
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 */
a3cbfb08 613static int lbs_get_channel(struct lbs_private *priv)
876c9d3a 614{
2dd4b262
DW
615 struct cmd_ds_802_11_rf_channel cmd;
616 int ret = 0;
876c9d3a 617
8ff12da1 618 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 619
8d0c7fad 620 memset(&cmd, 0, sizeof(cmd));
2dd4b262
DW
621 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
622 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
876c9d3a 623
689442dc 624 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
2dd4b262
DW
625 if (ret)
626 goto out;
876c9d3a 627
cb182a60
DW
628 ret = le16_to_cpu(cmd.channel);
629 lbs_deb_cmd("current radio channel is %d\n", ret);
2dd4b262
DW
630
631out:
632 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
633 return ret;
634}
635
73ab1f25
HS
636int 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) {
c14951fe 645 priv->channel = ret;
73ab1f25
HS
646 ret = 0;
647 }
648 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
649 return ret;
650}
651
2dd4b262
DW
652/**
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;
96d46d5d 663#ifdef DEBUG
c14951fe 664 u8 old_channel = priv->channel;
96d46d5d 665#endif
2dd4b262
DW
666 int ret = 0;
667
668 lbs_deb_enter(LBS_DEB_CMD);
669
8d0c7fad 670 memset(&cmd, 0, sizeof(cmd));
2dd4b262
DW
671 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
689442dc 675 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
2dd4b262
DW
676 if (ret)
677 goto out;
678
c14951fe 679 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
cb182a60 680 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
c14951fe 681 priv->channel);
2dd4b262
DW
682
683out:
684 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
685 return ret;
876c9d3a
MT
686}
687
9fb7663d
DW
688/**
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
cc4b9d39
DW
721/**
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
4c7c6e00
DW
844/**
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)
876c9d3a 856{
4c7c6e00
DW
857 struct cmd_ds_reg_access cmd;
858 int ret = 0;
876c9d3a 859
9012b28a 860 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 861
4c7c6e00 862 BUG_ON(value == NULL);
876c9d3a 863
4c7c6e00
DW
864 memset(&cmd, 0, sizeof(cmd));
865 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
866 cmd.action = cpu_to_le16(CMD_ACT_GET);
876c9d3a 867
4c7c6e00
DW
868 if (reg != CMD_MAC_REG_ACCESS &&
869 reg != CMD_BBP_REG_ACCESS &&
870 reg != CMD_RF_REG_ACCESS) {
871 ret = -EINVAL;
872 goto out;
873 }
876c9d3a 874
4c7c6e00
DW
875 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 }
876c9d3a 882
4c7c6e00
DW
883out:
884 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
885 return ret;
886}
876c9d3a 887
4c7c6e00
DW
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;
876c9d3a 903
4c7c6e00 904 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 905
4c7c6e00
DW
906 memset(&cmd, 0, sizeof(cmd));
907 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
908 cmd.action = cpu_to_le16(CMD_ACT_SET);
876c9d3a 909
4c7c6e00
DW
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;
876c9d3a
MT
917 }
918
4c7c6e00
DW
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;
876c9d3a
MT
924}
925
681ffbb7
DW
926static void lbs_queue_cmd(struct lbs_private *priv,
927 struct cmd_ctrl_node *cmdnode)
876c9d3a
MT
928{
929 unsigned long flags;
681ffbb7 930 int addtail = 1;
876c9d3a 931
8ff12da1 932 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 933
c4ab4127
DW
934 if (!cmdnode) {
935 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
876c9d3a
MT
936 goto done;
937 }
d9896ee1
DW
938 if (!cmdnode->cmdbuf->size) {
939 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
940 goto done;
941 }
ae125bf8 942 cmdnode->result = 0;
876c9d3a
MT
943
944 /* Exit_PS command needs to be queued in the header always. */
ddac4526 945 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
0bb64087 946 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf;
ddac4526 947
0bb64087 948 if (psm->action == cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
aa21c004 949 if (priv->psstate != PS_STATE_FULL_POWER)
876c9d3a
MT
950 addtail = 0;
951 }
952 }
953
0bb64087 954 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_WAKEUP_CONFIRM)
66fceb69
AK
955 addtail = 0;
956
aa21c004 957 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 958
ac47246e 959 if (addtail)
aa21c004 960 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
ac47246e 961 else
aa21c004 962 list_add(&cmdnode->list, &priv->cmdpendingq);
876c9d3a 963
aa21c004 964 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 965
8ff12da1 966 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
c4ab4127 967 le16_to_cpu(cmdnode->cmdbuf->command));
876c9d3a
MT
968
969done:
8ff12da1 970 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
971}
972
18c52e7c
DW
973static void lbs_submit_command(struct lbs_private *priv,
974 struct cmd_ctrl_node *cmdnode)
876c9d3a
MT
975{
976 unsigned long flags;
ddac4526 977 struct cmd_header *cmd;
18c52e7c
DW
978 uint16_t cmdsize;
979 uint16_t command;
57962f0b 980 int timeo = 3 * HZ;
18c52e7c 981 int ret;
876c9d3a 982
8ff12da1 983 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 984
ddac4526 985 cmd = cmdnode->cmdbuf;
876c9d3a 986
aa21c004 987 spin_lock_irqsave(&priv->driver_lock, flags);
aa21c004 988 priv->cur_cmd = cmdnode;
aa21c004 989 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 990
ddac4526
DW
991 cmdsize = le16_to_cpu(cmd->size);
992 command = le16_to_cpu(cmd->command);
876c9d3a 993
18c52e7c 994 /* These commands take longer */
be0d76e4 995 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
57962f0b 996 timeo = 5 * HZ;
18c52e7c 997
e5225b39
HS
998 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
999 command, le16_to_cpu(cmd->seqnum), cmdsize);
1afc09ab 1000 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
8ff12da1 1001
ddac4526 1002 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
18c52e7c 1003
d9896ee1
DW
1004 if (ret) {
1005 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
18c52e7c
DW
1006 /* Let the timer kick in and retry, and potentially reset
1007 the whole thing if the condition persists */
57962f0b 1008 timeo = HZ/4;
1afc09ab 1009 }
876c9d3a 1010
49125454
AK
1011 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 }
876c9d3a 1022
18c52e7c 1023 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1024}
1025
876c9d3a
MT
1026/**
1027 * This function inserts command node to cmdfreeq
aa21c004 1028 * after cleans it. Requires priv->driver_lock held.
876c9d3a 1029 */
183aeac1 1030static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
5ba2f8a0 1031 struct cmd_ctrl_node *cmdnode)
876c9d3a 1032{
5ba2f8a0
DW
1033 lbs_deb_enter(LBS_DEB_HOST);
1034
1035 if (!cmdnode)
1036 goto out;
1037
5ba2f8a0
DW
1038 cmdnode->callback = NULL;
1039 cmdnode->callback_arg = 0;
876c9d3a 1040
5ba2f8a0 1041 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
876c9d3a 1042
5ba2f8a0
DW
1043 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1044 out:
1045 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1046}
1047
69f9032d
HS
1048static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1049 struct cmd_ctrl_node *ptempcmd)
876c9d3a
MT
1050{
1051 unsigned long flags;
1052
aa21c004 1053 spin_lock_irqsave(&priv->driver_lock, flags);
10078321 1054 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
aa21c004 1055 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1056}
1057
183aeac1
DW
1058void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1059 int result)
1060{
ae125bf8 1061 cmd->result = result;
5ba2f8a0
DW
1062 cmd->cmdwaitqwoken = 1;
1063 wake_up_interruptible(&cmd->cmdwait_q);
1064
8db4a2b9 1065 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
ad12d0f4 1066 __lbs_cleanup_and_insert_cmd(priv, cmd);
183aeac1
DW
1067 priv->cur_cmd = NULL;
1068}
1069
d5db2dfa 1070int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
876c9d3a 1071{
a7c45890 1072 struct cmd_ds_802_11_radio_control cmd;
d5db2dfa 1073 int ret = -EINVAL;
876c9d3a 1074
9012b28a 1075 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1076
a7c45890
DW
1077 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1078 cmd.action = cpu_to_le16(CMD_ACT_SET);
1079
d5db2dfa
DW
1080 /* Only v8 and below support setting the preamble */
1081 if (priv->fwrelease < 0x09000000) {
1082 switch (preamble) {
1083 case RADIO_PREAMBLE_SHORT:
d5db2dfa
DW
1084 case RADIO_PREAMBLE_AUTO:
1085 case RADIO_PREAMBLE_LONG:
1086 cmd.control = cpu_to_le16(preamble);
1087 break;
1088 default:
1089 goto out;
1090 }
1091 }
a7c45890 1092
d5db2dfa
DW
1093 if (radio_on)
1094 cmd.control |= cpu_to_le16(0x1);
1095 else {
1096 cmd.control &= cpu_to_le16(~0x1);
1097 priv->txpower_cur = 0;
a7c45890 1098 }
876c9d3a 1099
d5db2dfa
DW
1100 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1101 radio_on ? "ON" : "OFF", preamble);
a7c45890 1102
d5db2dfa 1103 priv->radio_on = radio_on;
a7c45890
DW
1104
1105 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
876c9d3a 1106
d5db2dfa 1107out:
9012b28a 1108 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1109 return ret;
1110}
1111
c97329e2 1112void lbs_set_mac_control(struct lbs_private *priv)
876c9d3a 1113{
835d3ac5 1114 struct cmd_ds_mac_control cmd;
876c9d3a 1115
9012b28a 1116 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1117
835d3ac5 1118 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
d9e9778c 1119 cmd.action = cpu_to_le16(priv->mac_control);
835d3ac5
HS
1120 cmd.reserved = 0;
1121
75bf45a7 1122 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
876c9d3a 1123
c97329e2 1124 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1125}
1126
876c9d3a
MT
1127/**
1128 * @brief This function allocates the command buffer and link
1129 * it to command free queue.
1130 *
69f9032d 1131 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1132 * @return 0 or -1
1133 */
69f9032d 1134int lbs_allocate_cmd_buffer(struct lbs_private *priv)
876c9d3a
MT
1135{
1136 int ret = 0;
ddac4526 1137 u32 bufsize;
876c9d3a 1138 u32 i;
ddac4526 1139 struct cmd_ctrl_node *cmdarray;
876c9d3a 1140
8ff12da1 1141 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1142
ddac4526
DW
1143 /* Allocate and initialize the command array */
1144 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1145 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
8ff12da1 1146 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
876c9d3a
MT
1147 ret = -1;
1148 goto done;
1149 }
ddac4526 1150 priv->cmd_array = cmdarray;
876c9d3a 1151
ddac4526
DW
1152 /* 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) {
8ff12da1 1156 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
876c9d3a
MT
1157 ret = -1;
1158 goto done;
1159 }
876c9d3a
MT
1160 }
1161
ddac4526
DW
1162 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]);
876c9d3a 1165 }
876c9d3a 1166 ret = 0;
9012b28a
HS
1167
1168done:
8ff12da1 1169 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
876c9d3a
MT
1170 return ret;
1171}
1172
1173/**
1174 * @brief This function frees the command buffer.
1175 *
69f9032d 1176 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1177 * @return 0 or -1
1178 */
69f9032d 1179int lbs_free_cmd_buffer(struct lbs_private *priv)
876c9d3a 1180{
ddac4526 1181 struct cmd_ctrl_node *cmdarray;
876c9d3a 1182 unsigned int i;
876c9d3a 1183
8ff12da1 1184 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
1185
1186 /* need to check if cmd array is allocated or not */
aa21c004 1187 if (priv->cmd_array == NULL) {
8ff12da1 1188 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
876c9d3a
MT
1189 goto done;
1190 }
1191
ddac4526 1192 cmdarray = priv->cmd_array;
876c9d3a
MT
1193
1194 /* Release shared memory buffers */
ddac4526
DW
1195 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1196 if (cmdarray[i].cmdbuf) {
1197 kfree(cmdarray[i].cmdbuf);
1198 cmdarray[i].cmdbuf = NULL;
876c9d3a
MT
1199 }
1200 }
1201
1202 /* Release cmd_ctrl_node */
aa21c004
DW
1203 if (priv->cmd_array) {
1204 kfree(priv->cmd_array);
1205 priv->cmd_array = NULL;
876c9d3a
MT
1206 }
1207
1208done:
8ff12da1 1209 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1210 return 0;
1211}
1212
1213/**
1214 * @brief This function gets a free command node if available in
1215 * command free queue.
1216 *
69f9032d 1217 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1218 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1219 */
d06956b5 1220static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv)
876c9d3a
MT
1221{
1222 struct cmd_ctrl_node *tempnode;
876c9d3a
MT
1223 unsigned long flags;
1224
8ff12da1
HS
1225 lbs_deb_enter(LBS_DEB_HOST);
1226
aa21c004 1227 if (!priv)
876c9d3a
MT
1228 return NULL;
1229
aa21c004 1230 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 1231
aa21c004
DW
1232 if (!list_empty(&priv->cmdfreeq)) {
1233 tempnode = list_first_entry(&priv->cmdfreeq,
abe3ed14
LZ
1234 struct cmd_ctrl_node, list);
1235 list_del(&tempnode->list);
876c9d3a 1236 } else {
8ff12da1 1237 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
876c9d3a
MT
1238 tempnode = NULL;
1239 }
1240
aa21c004 1241 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 1242
8ff12da1 1243 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1244 return tempnode;
1245}
1246
876c9d3a
MT
1247/**
1248 * @brief This function executes next command in command
877d0310 1249 * pending queue. It will put firmware back to PS mode
876c9d3a
MT
1250 * if applicable.
1251 *
69f9032d 1252 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1253 * @return 0 or -1
1254 */
69f9032d 1255int lbs_execute_next_command(struct lbs_private *priv)
876c9d3a 1256{
876c9d3a 1257 struct cmd_ctrl_node *cmdnode = NULL;
ddac4526 1258 struct cmd_header *cmd;
876c9d3a
MT
1259 unsigned long flags;
1260 int ret = 0;
1261
1afc09ab
HS
1262 /* 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 */
8ff12da1 1265 lbs_deb_enter(LBS_DEB_THREAD);
876c9d3a 1266
aa21c004 1267 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 1268
aa21c004 1269 if (priv->cur_cmd) {
8ff12da1 1270 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
aa21c004 1271 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1272 ret = -1;
1273 goto done;
1274 }
1275
aa21c004
DW
1276 if (!list_empty(&priv->cmdpendingq)) {
1277 cmdnode = list_first_entry(&priv->cmdpendingq,
abe3ed14 1278 struct cmd_ctrl_node, list);
876c9d3a
MT
1279 }
1280
aa21c004 1281 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1282
1283 if (cmdnode) {
ddac4526 1284 cmd = cmdnode->cmdbuf;
876c9d3a 1285
ddac4526 1286 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
aa21c004
DW
1287 if ((priv->psstate == PS_STATE_SLEEP) ||
1288 (priv->psstate == PS_STATE_PRE_SLEEP)) {
8ff12da1
HS
1289 lbs_deb_host(
1290 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
ddac4526 1291 le16_to_cpu(cmd->command),
aa21c004 1292 priv->psstate);
876c9d3a
MT
1293 ret = -1;
1294 goto done;
1295 }
8ff12da1 1296 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
ddac4526
DW
1297 "0x%04x in psstate %d\n",
1298 le16_to_cpu(cmd->command), priv->psstate);
aa21c004 1299 } else if (priv->psstate != PS_STATE_FULL_POWER) {
876c9d3a
MT
1300 /*
1301 * 1. Non-PS command:
1302 * Queue it. set needtowakeup to TRUE if current state
0bb64087
DW
1303 * is SLEEP, otherwise call send EXIT_PS.
1304 * 2. PS command but not EXIT_PS:
876c9d3a 1305 * Ignore it.
0bb64087 1306 * 3. PS command EXIT_PS:
876c9d3a
MT
1307 * Set needtowakeup to TRUE if current state is SLEEP,
1308 * otherwise send this command down to firmware
1309 * immediately.
1310 */
ddac4526 1311 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
876c9d3a
MT
1312 /* Prepare to send Exit PS,
1313 * this non PS command will be sent later */
aa21c004
DW
1314 if ((priv->psstate == PS_STATE_SLEEP)
1315 || (priv->psstate == PS_STATE_PRE_SLEEP)
876c9d3a
MT
1316 ) {
1317 /* w/ new scheme, it will not reach here.
1318 since it is blocked in main_thread. */
aa21c004 1319 priv->needtowakeup = 1;
0bb64087
DW
1320 } else {
1321 lbs_set_ps_mode(priv,
1322 PS_MODE_ACTION_EXIT_PS,
1323 false);
1324 }
876c9d3a
MT
1325
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 */
38bfab1a 1333 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
876c9d3a 1334
8ff12da1
HS
1335 lbs_deb_host(
1336 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
876c9d3a
MT
1337 psm->action);
1338 if (psm->action !=
0bb64087 1339 cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
8ff12da1
HS
1340 lbs_deb_host(
1341 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
abe3ed14 1342 list_del(&cmdnode->list);
183aeac1
DW
1343 spin_lock_irqsave(&priv->driver_lock, flags);
1344 lbs_complete_command(priv, cmdnode, 0);
1345 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1346
1347 ret = 0;
1348 goto done;
1349 }
1350
aa21c004
DW
1351 if ((priv->psstate == PS_STATE_SLEEP) ||
1352 (priv->psstate == PS_STATE_PRE_SLEEP)) {
8ff12da1
HS
1353 lbs_deb_host(
1354 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
abe3ed14 1355 list_del(&cmdnode->list);
183aeac1
DW
1356 spin_lock_irqsave(&priv->driver_lock, flags);
1357 lbs_complete_command(priv, cmdnode, 0);
1358 spin_unlock_irqrestore(&priv->driver_lock, flags);
aa21c004 1359 priv->needtowakeup = 1;
876c9d3a
MT
1360
1361 ret = 0;
1362 goto done;
1363 }
1364
8ff12da1
HS
1365 lbs_deb_host(
1366 "EXEC_NEXT_CMD: sending EXIT_PS\n");
876c9d3a
MT
1367 }
1368 }
abe3ed14 1369 list_del(&cmdnode->list);
8ff12da1 1370 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
ddac4526 1371 le16_to_cpu(cmd->command));
d9896ee1 1372 lbs_submit_command(priv, cmdnode);
876c9d3a
MT
1373 } else {
1374 /*
1375 * check if in power save mode, if yes, put the device back
1376 * to PS mode
1377 */
e86dc1ca
KD
1378#ifdef TODO
1379 /*
1380 * This was the old code for libertas+wext. Someone that
1381 * understands this beast should re-code it in a sane way.
1382 *
1383 * I actually don't understand why this is related to WPA
1384 * and to connection status, shouldn't powering should be
1385 * independ of such things?
1386 */
aa21c004
DW
1387 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1388 (priv->psstate == PS_STATE_FULL_POWER) &&
1389 ((priv->connect_status == LBS_CONNECTED) ||
602114ae 1390 lbs_mesh_connected(priv))) {
aa21c004
DW
1391 if (priv->secinfo.WPAenabled ||
1392 priv->secinfo.WPA2enabled) {
876c9d3a 1393 /* check for valid WPA group keys */
aa21c004
DW
1394 if (priv->wpa_mcast_key.len ||
1395 priv->wpa_unicast_key.len) {
8ff12da1 1396 lbs_deb_host(
876c9d3a
MT
1397 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1398 " go back to PS_SLEEP");
0bb64087
DW
1399 lbs_set_ps_mode(priv,
1400 PS_MODE_ACTION_ENTER_PS,
1401 false);
876c9d3a
MT
1402 }
1403 } else {
8ff12da1
HS
1404 lbs_deb_host(
1405 "EXEC_NEXT_CMD: cmdpendingq empty, "
1406 "go back to PS_SLEEP");
0bb64087
DW
1407 lbs_set_ps_mode(priv, PS_MODE_ACTION_ENTER_PS,
1408 false);
876c9d3a
MT
1409 }
1410 }
e86dc1ca 1411#endif
876c9d3a
MT
1412 }
1413
1414 ret = 0;
1415done:
8ff12da1 1416 lbs_deb_leave(LBS_DEB_THREAD);
876c9d3a
MT
1417 return ret;
1418}
1419
f539f2ef 1420static void lbs_send_confirmsleep(struct lbs_private *priv)
876c9d3a
MT
1421{
1422 unsigned long flags;
f539f2ef 1423 int ret;
876c9d3a 1424
8ff12da1 1425 lbs_deb_enter(LBS_DEB_HOST);
f539f2ef
HS
1426 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1427 sizeof(confirm_sleep));
876c9d3a 1428
f539f2ef
HS
1429 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1430 sizeof(confirm_sleep));
876c9d3a 1431 if (ret) {
f539f2ef 1432 lbs_pr_alert("confirm_sleep failed\n");
7919b89c 1433 goto out;
876c9d3a 1434 }
7919b89c
HS
1435
1436 spin_lock_irqsave(&priv->driver_lock, flags);
1437
a01f5450
HS
1438 /* We don't get a response on the sleep-confirmation */
1439 priv->dnld_sent = DNLD_RES_RECEIVED;
1440
66fceb69
AK
1441 if (priv->is_host_sleep_configured) {
1442 priv->is_host_sleep_activated = 1;
1443 wake_up_interruptible(&priv->host_sleep_q);
1444 }
1445
7919b89c 1446 /* If nothing to do, go back to sleep (?) */
e64c026d 1447 if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
7919b89c
HS
1448 priv->psstate = PS_STATE_SLEEP;
1449
1450 spin_unlock_irqrestore(&priv->driver_lock, flags);
1451
1452out:
f539f2ef 1453 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1454}
1455
876c9d3a
MT
1456/**
1457 * @brief This function checks condition and prepares to
1458 * send sleep confirm command to firmware if ok.
1459 *
69f9032d 1460 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1461 * @param psmode Power Saving mode
1462 * @return n/a
1463 */
d4ff0ef6 1464void lbs_ps_confirm_sleep(struct lbs_private *priv)
876c9d3a
MT
1465{
1466 unsigned long flags =0;
d4ff0ef6 1467 int allowed = 1;
876c9d3a 1468
8ff12da1 1469 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1470
a01f5450 1471 spin_lock_irqsave(&priv->driver_lock, flags);
634b8f49 1472 if (priv->dnld_sent) {
876c9d3a 1473 allowed = 0;
23d36eec 1474 lbs_deb_host("dnld_sent was set\n");
876c9d3a
MT
1475 }
1476
7919b89c 1477 /* In-progress command? */
aa21c004 1478 if (priv->cur_cmd) {
876c9d3a 1479 allowed = 0;
23d36eec 1480 lbs_deb_host("cur_cmd was set\n");
876c9d3a 1481 }
7919b89c
HS
1482
1483 /* Pending events or command responses? */
e64c026d 1484 if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
876c9d3a 1485 allowed = 0;
7919b89c 1486 lbs_deb_host("pending events or command responses\n");
876c9d3a 1487 }
aa21c004 1488 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1489
1490 if (allowed) {
10078321 1491 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
f539f2ef 1492 lbs_send_confirmsleep(priv);
876c9d3a 1493 } else {
8ff12da1 1494 lbs_deb_host("sleep confirm has been delayed\n");
876c9d3a
MT
1495 }
1496
8ff12da1 1497 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a 1498}
675787e2
HS
1499
1500
0112c9e9
AN
1501/**
1502 * @brief Configures the transmission power control functionality.
1503 *
1504 * @param priv A pointer to struct lbs_private structure
1505 * @param enable Transmission power control enable
1506 * @param p0 Power level when link quality is good (dBm).
1507 * @param p1 Power level when link quality is fair (dBm).
1508 * @param p2 Power level when link quality is poor (dBm).
1509 * @param usesnr Use Signal to Noise Ratio in TPC
1510 *
1511 * @return 0 on success
1512 */
1513int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1514 int8_t p2, int usesnr)
1515{
1516 struct cmd_ds_802_11_tpc_cfg cmd;
1517 int ret;
1518
1519 memset(&cmd, 0, sizeof(cmd));
1520 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1521 cmd.action = cpu_to_le16(CMD_ACT_SET);
1522 cmd.enable = !!enable;
3ed6e080 1523 cmd.usesnr = !!usesnr;
0112c9e9
AN
1524 cmd.P0 = p0;
1525 cmd.P1 = p1;
1526 cmd.P2 = p2;
1527
1528 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1529
1530 return ret;
1531}
1532
1533/**
1534 * @brief Configures the power adaptation settings.
1535 *
1536 * @param priv A pointer to struct lbs_private structure
1537 * @param enable Power adaptation enable
1538 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1539 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1540 * @param p2 Power level for 48 and 54 Mbps (dBm).
1541 *
1542 * @return 0 on Success
1543 */
1544
1545int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1546 int8_t p1, int8_t p2)
1547{
1548 struct cmd_ds_802_11_pa_cfg cmd;
1549 int ret;
1550
1551 memset(&cmd, 0, sizeof(cmd));
1552 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1553 cmd.action = cpu_to_le16(CMD_ACT_SET);
1554 cmd.enable = !!enable;
1555 cmd.P0 = p0;
1556 cmd.P1 = p1;
1557 cmd.P2 = p2;
1558
1559 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1560
1561 return ret;
1562}
1563
1564
6d898b19 1565struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
8db4a2b9
HS
1566 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1567 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1568 unsigned long callback_arg)
675787e2 1569{
675787e2 1570 struct cmd_ctrl_node *cmdnode;
675787e2
HS
1571
1572 lbs_deb_enter(LBS_DEB_HOST);
675787e2 1573
aa21c004 1574 if (priv->surpriseremoved) {
675787e2 1575 lbs_deb_host("PREP_CMD: card removed\n");
3399ea5f 1576 cmdnode = ERR_PTR(-ENOENT);
675787e2
HS
1577 goto done;
1578 }
1579
77ccdcf2
DW
1580 /* No commands are allowed in Deep Sleep until we toggle the GPIO
1581 * to wake up the card and it has signaled that it's ready.
1582 */
1583 if (!priv->is_auto_deep_sleep_enabled) {
1584 if (priv->is_deep_sleep) {
1585 lbs_deb_cmd("command not allowed in deep sleep\n");
1586 cmdnode = ERR_PTR(-EBUSY);
1587 goto done;
1588 }
63f275df
AK
1589 }
1590
d06956b5 1591 cmdnode = lbs_get_free_cmd_node(priv);
675787e2
HS
1592 if (cmdnode == NULL) {
1593 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1594
1595 /* Wake up main thread to execute next command */
1596 wake_up_interruptible(&priv->waitq);
3399ea5f 1597 cmdnode = ERR_PTR(-ENOBUFS);
675787e2
HS
1598 goto done;
1599 }
1600
448a51ae 1601 cmdnode->callback = callback;
1309b55b 1602 cmdnode->callback_arg = callback_arg;
675787e2 1603
7ad994de 1604 /* Copy the incoming command to the buffer */
ddac4526 1605 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
7ad994de 1606
675787e2 1607 /* Set sequence number, clean result, move to buffer */
aa21c004 1608 priv->seqnum++;
ddac4526
DW
1609 cmdnode->cmdbuf->command = cpu_to_le16(command);
1610 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1611 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1612 cmdnode->cmdbuf->result = 0;
675787e2
HS
1613
1614 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1615
675787e2 1616 cmdnode->cmdwaitqwoken = 0;
681ffbb7 1617 lbs_queue_cmd(priv, cmdnode);
675787e2
HS
1618 wake_up_interruptible(&priv->waitq);
1619
3399ea5f
DW
1620 done:
1621 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1622 return cmdnode;
1623}
1624
8db4a2b9
HS
1625void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1626 struct cmd_header *in_cmd, int in_cmd_size)
1627{
1628 lbs_deb_enter(LBS_DEB_CMD);
1629 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1630 lbs_cmd_async_callback, 0);
1631 lbs_deb_leave(LBS_DEB_CMD);
1632}
1633
3399ea5f
DW
1634int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1635 struct cmd_header *in_cmd, int in_cmd_size,
1636 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1637 unsigned long callback_arg)
1638{
1639 struct cmd_ctrl_node *cmdnode;
1640 unsigned long flags;
1641 int ret = 0;
1642
1643 lbs_deb_enter(LBS_DEB_HOST);
1644
1645 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1646 callback, callback_arg);
1647 if (IS_ERR(cmdnode)) {
1648 ret = PTR_ERR(cmdnode);
1649 goto done;
1650 }
1651
675787e2
HS
1652 might_sleep();
1653 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1654
aa21c004 1655 spin_lock_irqsave(&priv->driver_lock, flags);
ae125bf8
DW
1656 ret = cmdnode->result;
1657 if (ret)
1658 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1659 command, ret);
3399ea5f 1660
ad12d0f4 1661 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
aa21c004 1662 spin_unlock_irqrestore(&priv->driver_lock, flags);
675787e2
HS
1663
1664done:
1665 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1666 return ret;
1667}
14e865ba 1668EXPORT_SYMBOL_GPL(__lbs_cmd);
This page took 0.846106 seconds and 5 git commands to generate.