2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <linux/kfifo.h>
7 #include <linux/sched.h>
8 #include <linux/slab.h>
15 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
);
18 * @brief Simple callback that copies response back into command
20 * @param priv A pointer to struct lbs_private structure
21 * @param extra A pointer to the original command structure for which
22 * 'resp' is a response
23 * @param resp A pointer to the command response
25 * @return 0 on success, error on failure
27 int lbs_cmd_copyback(struct lbs_private
*priv
, unsigned long extra
,
28 struct cmd_header
*resp
)
30 struct cmd_header
*buf
= (void *)extra
;
33 copy_len
= min(le16_to_cpu(buf
->size
), le16_to_cpu(resp
->size
));
34 memcpy(buf
, resp
, copy_len
);
37 EXPORT_SYMBOL_GPL(lbs_cmd_copyback
);
40 * @brief Simple callback that ignores the result. Use this if
41 * you just want to send a command to the hardware, but don't
42 * care for the result.
45 * @param extra ignored
48 * @return 0 for success
50 static int lbs_cmd_async_callback(struct lbs_private
*priv
, unsigned long extra
,
51 struct cmd_header
*resp
)
58 * @brief Checks whether a command is allowed in Power Save mode
60 * @param command the command ID
61 * @return 1 if allowed, 0 if not allowed
63 static u8
is_command_allowed_in_ps(u16 cmd
)
68 case CMD_802_11_HOST_SLEEP_CFG
:
77 * @brief This function checks if the command is allowed.
79 * @param priv A pointer to lbs_private structure
80 * @return allowed or not allowed.
83 static int lbs_is_cmd_allowed(struct lbs_private
*priv
)
87 lbs_deb_enter(LBS_DEB_CMD
);
89 if (!priv
->is_auto_deep_sleep_enabled
) {
90 if (priv
->is_deep_sleep
) {
91 lbs_deb_cmd("command not allowed in deep sleep\n");
96 lbs_deb_leave(LBS_DEB_CMD
);
101 * @brief Updates the hardware details like MAC address and regulatory region
103 * @param priv A pointer to struct lbs_private structure
105 * @return 0 on success, error on failure
107 int lbs_update_hw_spec(struct lbs_private
*priv
)
109 struct cmd_ds_get_hw_spec cmd
;
113 lbs_deb_enter(LBS_DEB_CMD
);
115 memset(&cmd
, 0, sizeof(cmd
));
116 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
117 memcpy(cmd
.permanentaddr
, priv
->current_addr
, ETH_ALEN
);
118 ret
= lbs_cmd_with_response(priv
, CMD_GET_HW_SPEC
, &cmd
);
122 priv
->fwcapinfo
= le32_to_cpu(cmd
.fwcapinfo
);
124 /* The firmware release is in an interesting format: the patch
125 * level is in the most significant nibble ... so fix that: */
126 priv
->fwrelease
= le32_to_cpu(cmd
.fwrelease
);
127 priv
->fwrelease
= (priv
->fwrelease
<< 8) |
128 (priv
->fwrelease
>> 24 & 0xff);
130 /* Some firmware capabilities:
131 * CF card firmware 5.0.16p0: cap 0x00000303
132 * USB dongle firmware 5.110.17p2: cap 0x00000303
134 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
136 priv
->fwrelease
>> 24 & 0xff,
137 priv
->fwrelease
>> 16 & 0xff,
138 priv
->fwrelease
>> 8 & 0xff,
139 priv
->fwrelease
& 0xff,
141 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
142 cmd
.hwifversion
, cmd
.version
);
144 /* Clamp region code to 8-bit since FW spec indicates that it should
145 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
146 * returns non-zero high 8 bits here.
148 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
149 * need to check for this problem and handle it properly.
151 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V4
)
152 priv
->regioncode
= (le16_to_cpu(cmd
.regioncode
) >> 8) & 0xFF;
154 priv
->regioncode
= le16_to_cpu(cmd
.regioncode
) & 0xFF;
156 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
157 /* use the region code to search for the index */
158 if (priv
->regioncode
== lbs_region_code_to_index
[i
])
162 /* if it's unidentified region code, use the default (USA) */
163 if (i
>= MRVDRV_MAX_REGION_CODE
) {
164 priv
->regioncode
= 0x10;
165 lbs_pr_info("unidentified region code; using the default (USA)\n");
168 if (priv
->current_addr
[0] == 0xff)
169 memmove(priv
->current_addr
, cmd
.permanentaddr
, ETH_ALEN
);
171 memcpy(priv
->dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
173 memcpy(priv
->mesh_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
176 lbs_deb_leave(LBS_DEB_CMD
);
180 static int lbs_ret_host_sleep_cfg(struct lbs_private
*priv
, unsigned long dummy
,
181 struct cmd_header
*resp
)
183 lbs_deb_enter(LBS_DEB_CMD
);
184 if (priv
->is_host_sleep_activated
) {
185 priv
->is_host_sleep_configured
= 0;
186 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
187 priv
->is_host_sleep_activated
= 0;
188 wake_up_interruptible(&priv
->host_sleep_q
);
191 priv
->is_host_sleep_configured
= 1;
193 lbs_deb_leave(LBS_DEB_CMD
);
197 int lbs_host_sleep_cfg(struct lbs_private
*priv
, uint32_t criteria
,
198 struct wol_config
*p_wol_config
)
200 struct cmd_ds_host_sleep cmd_config
;
203 cmd_config
.hdr
.size
= cpu_to_le16(sizeof(cmd_config
));
204 cmd_config
.criteria
= cpu_to_le32(criteria
);
205 cmd_config
.gpio
= priv
->wol_gpio
;
206 cmd_config
.gap
= priv
->wol_gap
;
208 if (p_wol_config
!= NULL
)
209 memcpy((uint8_t *)&cmd_config
.wol_conf
, (uint8_t *)p_wol_config
,
210 sizeof(struct wol_config
));
212 cmd_config
.wol_conf
.action
= CMD_ACT_ACTION_NONE
;
214 ret
= __lbs_cmd(priv
, CMD_802_11_HOST_SLEEP_CFG
, &cmd_config
.hdr
,
215 le16_to_cpu(cmd_config
.hdr
.size
),
216 lbs_ret_host_sleep_cfg
, 0);
219 memcpy((uint8_t *) p_wol_config
,
220 (uint8_t *)&cmd_config
.wol_conf
,
221 sizeof(struct wol_config
));
223 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret
);
228 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg
);
230 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command
*cmd
,
233 struct cmd_ds_802_11_ps_mode
*psm
= &cmd
->params
.psmode
;
235 lbs_deb_enter(LBS_DEB_CMD
);
237 cmd
->command
= cpu_to_le16(CMD_802_11_PS_MODE
);
238 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode
) +
239 sizeof(struct cmd_header
));
240 psm
->action
= cpu_to_le16(cmd_action
);
241 psm
->multipledtim
= 0;
242 switch (cmd_action
) {
243 case CMD_SUBCMD_ENTER_PS
:
244 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
246 psm
->locallisteninterval
= 0;
247 psm
->nullpktinterval
= 0;
249 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM
);
252 case CMD_SUBCMD_EXIT_PS
:
253 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
256 case CMD_SUBCMD_SLEEP_CONFIRMED
:
257 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
264 lbs_deb_leave(LBS_DEB_CMD
);
268 int lbs_cmd_802_11_sleep_params(struct lbs_private
*priv
, uint16_t cmd_action
,
269 struct sleep_params
*sp
)
271 struct cmd_ds_802_11_sleep_params cmd
;
274 lbs_deb_enter(LBS_DEB_CMD
);
276 if (cmd_action
== CMD_ACT_GET
) {
277 memset(&cmd
, 0, sizeof(cmd
));
279 cmd
.error
= cpu_to_le16(sp
->sp_error
);
280 cmd
.offset
= cpu_to_le16(sp
->sp_offset
);
281 cmd
.stabletime
= cpu_to_le16(sp
->sp_stabletime
);
282 cmd
.calcontrol
= sp
->sp_calcontrol
;
283 cmd
.externalsleepclk
= sp
->sp_extsleepclk
;
284 cmd
.reserved
= cpu_to_le16(sp
->sp_reserved
);
286 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
287 cmd
.action
= cpu_to_le16(cmd_action
);
289 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SLEEP_PARAMS
, &cmd
);
292 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
293 "calcontrol 0x%x extsleepclk 0x%x\n",
294 le16_to_cpu(cmd
.error
), le16_to_cpu(cmd
.offset
),
295 le16_to_cpu(cmd
.stabletime
), cmd
.calcontrol
,
296 cmd
.externalsleepclk
);
298 sp
->sp_error
= le16_to_cpu(cmd
.error
);
299 sp
->sp_offset
= le16_to_cpu(cmd
.offset
);
300 sp
->sp_stabletime
= le16_to_cpu(cmd
.stabletime
);
301 sp
->sp_calcontrol
= cmd
.calcontrol
;
302 sp
->sp_extsleepclk
= cmd
.externalsleepclk
;
303 sp
->sp_reserved
= le16_to_cpu(cmd
.reserved
);
306 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
310 static int lbs_wait_for_ds_awake(struct lbs_private
*priv
)
314 lbs_deb_enter(LBS_DEB_CMD
);
316 if (priv
->is_deep_sleep
) {
317 if (!wait_event_interruptible_timeout(priv
->ds_awake_q
,
318 !priv
->is_deep_sleep
, (10 * HZ
))) {
319 lbs_pr_err("ds_awake_q: timer expired\n");
324 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
328 int lbs_set_deep_sleep(struct lbs_private
*priv
, int deep_sleep
)
332 lbs_deb_enter(LBS_DEB_CMD
);
335 if (priv
->is_deep_sleep
!= 1) {
336 lbs_deb_cmd("deep sleep: sleep\n");
337 BUG_ON(!priv
->enter_deep_sleep
);
338 ret
= priv
->enter_deep_sleep(priv
);
340 netif_stop_queue(priv
->dev
);
341 netif_carrier_off(priv
->dev
);
344 lbs_pr_err("deep sleep: already enabled\n");
347 if (priv
->is_deep_sleep
) {
348 lbs_deb_cmd("deep sleep: wakeup\n");
349 BUG_ON(!priv
->exit_deep_sleep
);
350 ret
= priv
->exit_deep_sleep(priv
);
352 ret
= lbs_wait_for_ds_awake(priv
);
354 lbs_pr_err("deep sleep: wakeup"
360 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
364 static int lbs_ret_host_sleep_activate(struct lbs_private
*priv
,
366 struct cmd_header
*cmd
)
368 lbs_deb_enter(LBS_DEB_FW
);
369 priv
->is_host_sleep_activated
= 1;
370 wake_up_interruptible(&priv
->host_sleep_q
);
371 lbs_deb_leave(LBS_DEB_FW
);
375 int lbs_set_host_sleep(struct lbs_private
*priv
, int host_sleep
)
377 struct cmd_header cmd
;
379 uint32_t criteria
= EHS_REMOVE_WAKEUP
;
381 lbs_deb_enter(LBS_DEB_CMD
);
384 if (priv
->is_host_sleep_activated
!= 1) {
385 memset(&cmd
, 0, sizeof(cmd
));
386 ret
= lbs_host_sleep_cfg(priv
, priv
->wol_criteria
,
387 (struct wol_config
*)NULL
);
389 lbs_pr_info("Host sleep configuration failed: "
393 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
394 ret
= __lbs_cmd(priv
,
395 CMD_802_11_HOST_SLEEP_ACTIVATE
,
398 lbs_ret_host_sleep_activate
, 0);
400 lbs_pr_info("HOST_SLEEP_ACTIVATE "
401 "failed: %d\n", ret
);
404 if (!wait_event_interruptible_timeout(
406 priv
->is_host_sleep_activated
,
408 lbs_pr_err("host_sleep_q: timer expired\n");
412 lbs_pr_err("host sleep: already enabled\n");
415 if (priv
->is_host_sleep_activated
)
416 ret
= lbs_host_sleep_cfg(priv
, criteria
,
417 (struct wol_config
*)NULL
);
424 * @brief Set an SNMP MIB value
426 * @param priv A pointer to struct lbs_private structure
427 * @param oid The OID to set in the firmware
428 * @param val Value to set the OID to
430 * @return 0 on success, error on failure
432 int lbs_set_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16 val
)
434 struct cmd_ds_802_11_snmp_mib cmd
;
437 lbs_deb_enter(LBS_DEB_CMD
);
439 memset(&cmd
, 0, sizeof (cmd
));
440 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
441 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
442 cmd
.oid
= cpu_to_le16((u16
) oid
);
445 case SNMP_MIB_OID_BSS_TYPE
:
446 cmd
.bufsize
= cpu_to_le16(sizeof(u8
));
449 case SNMP_MIB_OID_11D_ENABLE
:
450 case SNMP_MIB_OID_FRAG_THRESHOLD
:
451 case SNMP_MIB_OID_RTS_THRESHOLD
:
452 case SNMP_MIB_OID_SHORT_RETRY_LIMIT
:
453 case SNMP_MIB_OID_LONG_RETRY_LIMIT
:
454 cmd
.bufsize
= cpu_to_le16(sizeof(u16
));
455 *((__le16
*)(&cmd
.value
)) = cpu_to_le16(val
);
458 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid
);
463 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
464 le16_to_cpu(cmd
.oid
), le16_to_cpu(cmd
.bufsize
), val
);
466 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
469 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
474 * @brief Get an SNMP MIB value
476 * @param priv A pointer to struct lbs_private structure
477 * @param oid The OID to retrieve from the firmware
478 * @param out_val Location for the returned value
480 * @return 0 on success, error on failure
482 int lbs_get_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16
*out_val
)
484 struct cmd_ds_802_11_snmp_mib cmd
;
487 lbs_deb_enter(LBS_DEB_CMD
);
489 memset(&cmd
, 0, sizeof (cmd
));
490 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
491 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
492 cmd
.oid
= cpu_to_le16(oid
);
494 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
498 switch (le16_to_cpu(cmd
.bufsize
)) {
500 *out_val
= cmd
.value
[0];
503 *out_val
= le16_to_cpu(*((__le16
*)(&cmd
.value
)));
506 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
507 oid
, le16_to_cpu(cmd
.bufsize
));
512 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
517 * @brief Get the min, max, and current TX power
519 * @param priv A pointer to struct lbs_private structure
520 * @param curlevel Current power level in dBm
521 * @param minlevel Minimum supported power level in dBm (optional)
522 * @param maxlevel Maximum supported power level in dBm (optional)
524 * @return 0 on success, error on failure
526 int lbs_get_tx_power(struct lbs_private
*priv
, s16
*curlevel
, s16
*minlevel
,
529 struct cmd_ds_802_11_rf_tx_power cmd
;
532 lbs_deb_enter(LBS_DEB_CMD
);
534 memset(&cmd
, 0, sizeof(cmd
));
535 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
536 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
538 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
540 *curlevel
= le16_to_cpu(cmd
.curlevel
);
542 *minlevel
= cmd
.minlevel
;
544 *maxlevel
= cmd
.maxlevel
;
547 lbs_deb_leave(LBS_DEB_CMD
);
552 * @brief Set the TX power
554 * @param priv A pointer to struct lbs_private structure
555 * @param dbm The desired power level in dBm
557 * @return 0 on success, error on failure
559 int lbs_set_tx_power(struct lbs_private
*priv
, s16 dbm
)
561 struct cmd_ds_802_11_rf_tx_power cmd
;
564 lbs_deb_enter(LBS_DEB_CMD
);
566 memset(&cmd
, 0, sizeof(cmd
));
567 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
568 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
569 cmd
.curlevel
= cpu_to_le16(dbm
);
571 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm
);
573 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
575 lbs_deb_leave(LBS_DEB_CMD
);
579 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command
*cmd
,
580 u16 cmd_action
, void *pdata_buf
)
582 struct cmd_ds_802_11_monitor_mode
*monitor
= &cmd
->params
.monitor
;
584 cmd
->command
= cpu_to_le16(CMD_802_11_MONITOR_MODE
);
586 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode
) +
587 sizeof(struct cmd_header
));
589 monitor
->action
= cpu_to_le16(cmd_action
);
590 if (cmd_action
== CMD_ACT_SET
) {
592 cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
599 * @brief Get the radio channel
601 * @param priv A pointer to struct lbs_private structure
603 * @return The channel on success, error on failure
605 static int lbs_get_channel(struct lbs_private
*priv
)
607 struct cmd_ds_802_11_rf_channel cmd
;
610 lbs_deb_enter(LBS_DEB_CMD
);
612 memset(&cmd
, 0, sizeof(cmd
));
613 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
614 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET
);
616 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
620 ret
= le16_to_cpu(cmd
.channel
);
621 lbs_deb_cmd("current radio channel is %d\n", ret
);
624 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
628 int lbs_update_channel(struct lbs_private
*priv
)
632 /* the channel in f/w could be out of sync; get the current channel */
633 lbs_deb_enter(LBS_DEB_ASSOC
);
635 ret
= lbs_get_channel(priv
);
640 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
645 * @brief Set the radio channel
647 * @param priv A pointer to struct lbs_private structure
648 * @param channel The desired channel, or 0 to clear a locked channel
650 * @return 0 on success, error on failure
652 int lbs_set_channel(struct lbs_private
*priv
, u8 channel
)
654 struct cmd_ds_802_11_rf_channel cmd
;
656 u8 old_channel
= priv
->channel
;
660 lbs_deb_enter(LBS_DEB_CMD
);
662 memset(&cmd
, 0, sizeof(cmd
));
663 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
664 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET
);
665 cmd
.channel
= cpu_to_le16(channel
);
667 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
671 priv
->channel
= (uint8_t) le16_to_cpu(cmd
.channel
);
672 lbs_deb_cmd("channel switch from %d to %d\n", old_channel
,
676 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
680 static int lbs_cmd_reg_access(struct cmd_ds_command
*cmdptr
,
681 u8 cmd_action
, void *pdata_buf
)
683 struct lbs_offset_value
*offval
;
685 lbs_deb_enter(LBS_DEB_CMD
);
687 offval
= (struct lbs_offset_value
*)pdata_buf
;
689 switch (le16_to_cpu(cmdptr
->command
)) {
690 case CMD_MAC_REG_ACCESS
:
692 struct cmd_ds_mac_reg_access
*macreg
;
695 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access
)
696 + sizeof(struct cmd_header
));
698 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
701 macreg
->action
= cpu_to_le16(cmd_action
);
702 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
703 macreg
->value
= cpu_to_le32(offval
->value
);
708 case CMD_BBP_REG_ACCESS
:
710 struct cmd_ds_bbp_reg_access
*bbpreg
;
714 (struct cmd_ds_bbp_reg_access
)
715 + sizeof(struct cmd_header
));
717 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
720 bbpreg
->action
= cpu_to_le16(cmd_action
);
721 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
722 bbpreg
->value
= (u8
) offval
->value
;
727 case CMD_RF_REG_ACCESS
:
729 struct cmd_ds_rf_reg_access
*rfreg
;
733 (struct cmd_ds_rf_reg_access
) +
734 sizeof(struct cmd_header
));
736 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
739 rfreg
->action
= cpu_to_le16(cmd_action
);
740 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
741 rfreg
->value
= (u8
) offval
->value
;
750 lbs_deb_leave(LBS_DEB_CMD
);
754 static void lbs_queue_cmd(struct lbs_private
*priv
,
755 struct cmd_ctrl_node
*cmdnode
)
760 lbs_deb_enter(LBS_DEB_HOST
);
763 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
766 if (!cmdnode
->cmdbuf
->size
) {
767 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
772 /* Exit_PS command needs to be queued in the header always. */
773 if (le16_to_cpu(cmdnode
->cmdbuf
->command
) == CMD_802_11_PS_MODE
) {
774 struct cmd_ds_802_11_ps_mode
*psm
= (void *) &cmdnode
->cmdbuf
[1];
776 if (psm
->action
== cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
777 if (priv
->psstate
!= PS_STATE_FULL_POWER
)
782 if (le16_to_cpu(cmdnode
->cmdbuf
->command
) ==
783 CMD_802_11_WAKEUP_CONFIRM
)
786 spin_lock_irqsave(&priv
->driver_lock
, flags
);
789 list_add_tail(&cmdnode
->list
, &priv
->cmdpendingq
);
791 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
793 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
795 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
796 le16_to_cpu(cmdnode
->cmdbuf
->command
));
799 lbs_deb_leave(LBS_DEB_HOST
);
802 static void lbs_submit_command(struct lbs_private
*priv
,
803 struct cmd_ctrl_node
*cmdnode
)
806 struct cmd_header
*cmd
;
812 lbs_deb_enter(LBS_DEB_HOST
);
814 cmd
= cmdnode
->cmdbuf
;
816 spin_lock_irqsave(&priv
->driver_lock
, flags
);
817 priv
->cur_cmd
= cmdnode
;
818 priv
->cur_cmd_retcode
= 0;
819 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
821 cmdsize
= le16_to_cpu(cmd
->size
);
822 command
= le16_to_cpu(cmd
->command
);
824 /* These commands take longer */
825 if (command
== CMD_802_11_SCAN
|| command
== CMD_802_11_ASSOCIATE
)
828 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
829 command
, le16_to_cpu(cmd
->seqnum
), cmdsize
);
830 lbs_deb_hex(LBS_DEB_CMD
, "DNLD_CMD", (void *) cmdnode
->cmdbuf
, cmdsize
);
832 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmd
, cmdsize
);
835 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret
);
836 /* Let the timer kick in and retry, and potentially reset
837 the whole thing if the condition persists */
841 if (command
== CMD_802_11_DEEP_SLEEP
) {
842 if (priv
->is_auto_deep_sleep_enabled
) {
843 priv
->wakeup_dev_required
= 1;
846 priv
->is_deep_sleep
= 1;
847 lbs_complete_command(priv
, cmdnode
, 0);
849 /* Setup the timer after transmit command */
850 mod_timer(&priv
->command_timer
, jiffies
+ timeo
);
853 lbs_deb_leave(LBS_DEB_HOST
);
857 * This function inserts command node to cmdfreeq
858 * after cleans it. Requires priv->driver_lock held.
860 static void __lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
861 struct cmd_ctrl_node
*cmdnode
)
863 lbs_deb_enter(LBS_DEB_HOST
);
868 cmdnode
->callback
= NULL
;
869 cmdnode
->callback_arg
= 0;
871 memset(cmdnode
->cmdbuf
, 0, LBS_CMD_BUFFER_SIZE
);
873 list_add_tail(&cmdnode
->list
, &priv
->cmdfreeq
);
875 lbs_deb_leave(LBS_DEB_HOST
);
878 static void lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
879 struct cmd_ctrl_node
*ptempcmd
)
883 spin_lock_irqsave(&priv
->driver_lock
, flags
);
884 __lbs_cleanup_and_insert_cmd(priv
, ptempcmd
);
885 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
888 void lbs_complete_command(struct lbs_private
*priv
, struct cmd_ctrl_node
*cmd
,
891 if (cmd
== priv
->cur_cmd
)
892 priv
->cur_cmd_retcode
= result
;
894 cmd
->result
= result
;
895 cmd
->cmdwaitqwoken
= 1;
896 wake_up_interruptible(&cmd
->cmdwait_q
);
898 if (!cmd
->callback
|| cmd
->callback
== lbs_cmd_async_callback
)
899 __lbs_cleanup_and_insert_cmd(priv
, cmd
);
900 priv
->cur_cmd
= NULL
;
903 int lbs_set_radio(struct lbs_private
*priv
, u8 preamble
, u8 radio_on
)
905 struct cmd_ds_802_11_radio_control cmd
;
908 lbs_deb_enter(LBS_DEB_CMD
);
910 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
911 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
913 /* Only v8 and below support setting the preamble */
914 if (priv
->fwrelease
< 0x09000000) {
916 case RADIO_PREAMBLE_SHORT
:
917 case RADIO_PREAMBLE_AUTO
:
918 case RADIO_PREAMBLE_LONG
:
919 cmd
.control
= cpu_to_le16(preamble
);
927 cmd
.control
|= cpu_to_le16(0x1);
929 cmd
.control
&= cpu_to_le16(~0x1);
930 priv
->txpower_cur
= 0;
933 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
934 radio_on
? "ON" : "OFF", preamble
);
936 priv
->radio_on
= radio_on
;
938 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RADIO_CONTROL
, &cmd
);
941 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
945 void lbs_set_mac_control(struct lbs_private
*priv
)
947 struct cmd_ds_mac_control cmd
;
949 lbs_deb_enter(LBS_DEB_CMD
);
951 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
952 cmd
.action
= cpu_to_le16(priv
->mac_control
);
955 lbs_cmd_async(priv
, CMD_MAC_CONTROL
, &cmd
.hdr
, sizeof(cmd
));
957 lbs_deb_leave(LBS_DEB_CMD
);
961 * @brief This function implements command CMD_802_11D_DOMAIN_INFO
962 * @param priv pointer to struct lbs_private
963 * @param cmd pointer to cmd buffer
964 * @param cmdno cmd ID
965 * @param cmdOption cmd action
968 int lbs_cmd_802_11d_domain_info(struct lbs_private
*priv
,
969 struct cmd_ds_command
*cmd
,
972 struct cmd_ds_802_11d_domain_info
*pdomaininfo
=
973 &cmd
->params
.domaininfo
;
974 struct mrvl_ie_domain_param_set
*domain
= &pdomaininfo
->domain
;
975 u8 nr_triplet
= priv
->domain_reg
.no_triplet
;
977 lbs_deb_enter(LBS_DEB_11D
);
979 lbs_deb_11d("nr_triplet=%x\n", nr_triplet
);
981 pdomaininfo
->action
= cpu_to_le16(cmdoption
);
982 if (cmdoption
== CMD_ACT_GET
) {
983 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
984 sizeof(struct cmd_header
));
985 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
,
986 le16_to_cpu(cmd
->size
));
990 domain
->header
.type
= cpu_to_le16(TLV_TYPE_DOMAIN
);
991 memcpy(domain
->countrycode
, priv
->domain_reg
.country_code
,
992 sizeof(domain
->countrycode
));
994 domain
->header
.len
= cpu_to_le16(nr_triplet
995 * sizeof(struct ieee80211_country_ie_triplet
)
996 + sizeof(domain
->countrycode
));
999 memcpy(domain
->triplet
, priv
->domain_reg
.triplet
,
1001 sizeof(struct ieee80211_country_ie_triplet
));
1003 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
1004 le16_to_cpu(domain
->header
.len
) +
1005 sizeof(struct mrvl_ie_header
) +
1006 sizeof(struct cmd_header
));
1008 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
1009 sizeof(struct cmd_header
));
1012 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
,
1013 le16_to_cpu(cmd
->size
));
1016 lbs_deb_enter(LBS_DEB_11D
);
1021 * @brief This function prepare the command before send to firmware.
1023 * @param priv A pointer to struct lbs_private structure
1024 * @param cmd_no command number
1025 * @param cmd_action command action: GET or SET
1026 * @param wait_option wait option: wait response or not
1027 * @param cmd_oid cmd oid: treated as sub command
1028 * @param pdata_buf A pointer to informaion buffer
1031 int lbs_prepare_and_send_command(struct lbs_private
*priv
,
1034 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1037 struct cmd_ctrl_node
*cmdnode
;
1038 struct cmd_ds_command
*cmdptr
;
1039 unsigned long flags
;
1041 lbs_deb_enter(LBS_DEB_HOST
);
1044 lbs_deb_host("PREP_CMD: priv is NULL\n");
1049 if (priv
->surpriseremoved
) {
1050 lbs_deb_host("PREP_CMD: card removed\n");
1055 if (!lbs_is_cmd_allowed(priv
)) {
1060 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
1062 if (cmdnode
== NULL
) {
1063 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1065 /* Wake up main thread to execute next command */
1066 wake_up_interruptible(&priv
->waitq
);
1071 cmdnode
->callback
= NULL
;
1072 cmdnode
->callback_arg
= (unsigned long)pdata_buf
;
1074 cmdptr
= (struct cmd_ds_command
*)cmdnode
->cmdbuf
;
1076 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no
);
1078 /* Set sequence number, command and INT option */
1080 cmdptr
->seqnum
= cpu_to_le16(priv
->seqnum
);
1082 cmdptr
->command
= cpu_to_le16(cmd_no
);
1086 case CMD_802_11_PS_MODE
:
1087 ret
= lbs_cmd_802_11_ps_mode(cmdptr
, cmd_action
);
1090 case CMD_MAC_REG_ACCESS
:
1091 case CMD_BBP_REG_ACCESS
:
1092 case CMD_RF_REG_ACCESS
:
1093 ret
= lbs_cmd_reg_access(cmdptr
, cmd_action
, pdata_buf
);
1096 case CMD_802_11_MONITOR_MODE
:
1097 ret
= lbs_cmd_802_11_monitor_mode(cmdptr
,
1098 cmd_action
, pdata_buf
);
1101 case CMD_802_11_RSSI
:
1102 ret
= lbs_cmd_802_11_rssi(priv
, cmdptr
);
1105 case CMD_802_11_SET_AFC
:
1106 case CMD_802_11_GET_AFC
:
1108 cmdptr
->command
= cpu_to_le16(cmd_no
);
1109 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1110 sizeof(struct cmd_header
));
1112 memmove(&cmdptr
->params
.afc
,
1113 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1118 case CMD_802_11D_DOMAIN_INFO
:
1119 cmdptr
->command
= cpu_to_le16(cmd_no
);
1120 ret
= lbs_cmd_802_11d_domain_info(priv
, cmdptr
, cmd_action
);
1123 case CMD_802_11_TPC_CFG
:
1124 cmdptr
->command
= cpu_to_le16(CMD_802_11_TPC_CFG
);
1126 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1127 sizeof(struct cmd_header
));
1129 memmove(&cmdptr
->params
.tpccfg
,
1130 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1135 #ifdef CONFIG_LIBERTAS_MESH
1138 ret
= lbs_cmd_bt_access(cmdptr
, cmd_action
, pdata_buf
);
1141 case CMD_FWT_ACCESS
:
1142 ret
= lbs_cmd_fwt_access(cmdptr
, cmd_action
, pdata_buf
);
1147 case CMD_802_11_BEACON_CTRL
:
1148 ret
= lbs_cmd_bcn_ctrl(priv
, cmdptr
, cmd_action
);
1150 case CMD_802_11_DEEP_SLEEP
:
1151 cmdptr
->command
= cpu_to_le16(CMD_802_11_DEEP_SLEEP
);
1152 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_header
));
1155 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no
);
1160 /* return error, since the command preparation failed */
1162 lbs_deb_host("PREP_CMD: command preparation failed\n");
1163 lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
1168 cmdnode
->cmdwaitqwoken
= 0;
1170 lbs_queue_cmd(priv
, cmdnode
);
1171 wake_up_interruptible(&priv
->waitq
);
1173 if (wait_option
& CMD_OPTION_WAITFORRSP
) {
1174 lbs_deb_host("PREP_CMD: wait for response\n");
1176 wait_event_interruptible(cmdnode
->cmdwait_q
,
1177 cmdnode
->cmdwaitqwoken
);
1180 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1181 if (priv
->cur_cmd_retcode
) {
1182 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1183 priv
->cur_cmd_retcode
);
1184 priv
->cur_cmd_retcode
= 0;
1187 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1190 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1195 * @brief This function allocates the command buffer and link
1196 * it to command free queue.
1198 * @param priv A pointer to struct lbs_private structure
1201 int lbs_allocate_cmd_buffer(struct lbs_private
*priv
)
1206 struct cmd_ctrl_node
*cmdarray
;
1208 lbs_deb_enter(LBS_DEB_HOST
);
1210 /* Allocate and initialize the command array */
1211 bufsize
= sizeof(struct cmd_ctrl_node
) * LBS_NUM_CMD_BUFFERS
;
1212 if (!(cmdarray
= kzalloc(bufsize
, GFP_KERNEL
))) {
1213 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1217 priv
->cmd_array
= cmdarray
;
1219 /* Allocate and initialize each command buffer in the command array */
1220 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1221 cmdarray
[i
].cmdbuf
= kzalloc(LBS_CMD_BUFFER_SIZE
, GFP_KERNEL
);
1222 if (!cmdarray
[i
].cmdbuf
) {
1223 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1229 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1230 init_waitqueue_head(&cmdarray
[i
].cmdwait_q
);
1231 lbs_cleanup_and_insert_cmd(priv
, &cmdarray
[i
]);
1236 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1241 * @brief This function frees the command buffer.
1243 * @param priv A pointer to struct lbs_private structure
1246 int lbs_free_cmd_buffer(struct lbs_private
*priv
)
1248 struct cmd_ctrl_node
*cmdarray
;
1251 lbs_deb_enter(LBS_DEB_HOST
);
1253 /* need to check if cmd array is allocated or not */
1254 if (priv
->cmd_array
== NULL
) {
1255 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1259 cmdarray
= priv
->cmd_array
;
1261 /* Release shared memory buffers */
1262 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1263 if (cmdarray
[i
].cmdbuf
) {
1264 kfree(cmdarray
[i
].cmdbuf
);
1265 cmdarray
[i
].cmdbuf
= NULL
;
1269 /* Release cmd_ctrl_node */
1270 if (priv
->cmd_array
) {
1271 kfree(priv
->cmd_array
);
1272 priv
->cmd_array
= NULL
;
1276 lbs_deb_leave(LBS_DEB_HOST
);
1281 * @brief This function gets a free command node if available in
1282 * command free queue.
1284 * @param priv A pointer to struct lbs_private structure
1285 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1287 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
)
1289 struct cmd_ctrl_node
*tempnode
;
1290 unsigned long flags
;
1292 lbs_deb_enter(LBS_DEB_HOST
);
1297 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1299 if (!list_empty(&priv
->cmdfreeq
)) {
1300 tempnode
= list_first_entry(&priv
->cmdfreeq
,
1301 struct cmd_ctrl_node
, list
);
1302 list_del(&tempnode
->list
);
1304 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1308 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1310 lbs_deb_leave(LBS_DEB_HOST
);
1315 * @brief This function executes next command in command
1316 * pending queue. It will put firmware back to PS mode
1319 * @param priv A pointer to struct lbs_private structure
1322 int lbs_execute_next_command(struct lbs_private
*priv
)
1324 struct cmd_ctrl_node
*cmdnode
= NULL
;
1325 struct cmd_header
*cmd
;
1326 unsigned long flags
;
1329 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1330 * only caller to us is lbs_thread() and we get even when a
1331 * data packet is received */
1332 lbs_deb_enter(LBS_DEB_THREAD
);
1334 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1336 if (priv
->cur_cmd
) {
1337 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1338 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1343 if (!list_empty(&priv
->cmdpendingq
)) {
1344 cmdnode
= list_first_entry(&priv
->cmdpendingq
,
1345 struct cmd_ctrl_node
, list
);
1348 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1351 cmd
= cmdnode
->cmdbuf
;
1353 if (is_command_allowed_in_ps(le16_to_cpu(cmd
->command
))) {
1354 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1355 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1357 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1358 le16_to_cpu(cmd
->command
),
1363 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1364 "0x%04x in psstate %d\n",
1365 le16_to_cpu(cmd
->command
), priv
->psstate
);
1366 } else if (priv
->psstate
!= PS_STATE_FULL_POWER
) {
1368 * 1. Non-PS command:
1369 * Queue it. set needtowakeup to TRUE if current state
1370 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1371 * 2. PS command but not Exit_PS:
1373 * 3. PS command Exit_PS:
1374 * Set needtowakeup to TRUE if current state is SLEEP,
1375 * otherwise send this command down to firmware
1378 if (cmd
->command
!= cpu_to_le16(CMD_802_11_PS_MODE
)) {
1379 /* Prepare to send Exit PS,
1380 * this non PS command will be sent later */
1381 if ((priv
->psstate
== PS_STATE_SLEEP
)
1382 || (priv
->psstate
== PS_STATE_PRE_SLEEP
)
1384 /* w/ new scheme, it will not reach here.
1385 since it is blocked in main_thread. */
1386 priv
->needtowakeup
= 1;
1388 lbs_ps_wakeup(priv
, 0);
1394 * PS command. Ignore it if it is not Exit_PS.
1395 * otherwise send it down immediately.
1397 struct cmd_ds_802_11_ps_mode
*psm
= (void *)&cmd
[1];
1400 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1403 cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
1405 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1406 list_del(&cmdnode
->list
);
1407 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1408 lbs_complete_command(priv
, cmdnode
, 0);
1409 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1415 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1416 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1418 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1419 list_del(&cmdnode
->list
);
1420 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1421 lbs_complete_command(priv
, cmdnode
, 0);
1422 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1423 priv
->needtowakeup
= 1;
1430 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1433 list_del(&cmdnode
->list
);
1434 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1435 le16_to_cpu(cmd
->command
));
1436 lbs_submit_command(priv
, cmdnode
);
1439 * check if in power save mode, if yes, put the device back
1444 * This was the old code for libertas+wext. Someone that
1445 * understands this beast should re-code it in a sane way.
1447 * I actually don't understand why this is related to WPA
1448 * and to connection status, shouldn't powering should be
1449 * independ of such things?
1451 if ((priv
->psmode
!= LBS802_11POWERMODECAM
) &&
1452 (priv
->psstate
== PS_STATE_FULL_POWER
) &&
1453 ((priv
->connect_status
== LBS_CONNECTED
) ||
1454 lbs_mesh_connected(priv
))) {
1455 if (priv
->secinfo
.WPAenabled
||
1456 priv
->secinfo
.WPA2enabled
) {
1457 /* check for valid WPA group keys */
1458 if (priv
->wpa_mcast_key
.len
||
1459 priv
->wpa_unicast_key
.len
) {
1461 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1462 " go back to PS_SLEEP");
1463 lbs_ps_sleep(priv
, 0);
1467 "EXEC_NEXT_CMD: cmdpendingq empty, "
1468 "go back to PS_SLEEP");
1469 lbs_ps_sleep(priv
, 0);
1477 lbs_deb_leave(LBS_DEB_THREAD
);
1481 static void lbs_send_confirmsleep(struct lbs_private
*priv
)
1483 unsigned long flags
;
1486 lbs_deb_enter(LBS_DEB_HOST
);
1487 lbs_deb_hex(LBS_DEB_HOST
, "sleep confirm", (u8
*) &confirm_sleep
,
1488 sizeof(confirm_sleep
));
1490 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) &confirm_sleep
,
1491 sizeof(confirm_sleep
));
1493 lbs_pr_alert("confirm_sleep failed\n");
1497 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1499 /* We don't get a response on the sleep-confirmation */
1500 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
1502 if (priv
->is_host_sleep_configured
) {
1503 priv
->is_host_sleep_activated
= 1;
1504 wake_up_interruptible(&priv
->host_sleep_q
);
1507 /* If nothing to do, go back to sleep (?) */
1508 if (!kfifo_len(&priv
->event_fifo
) && !priv
->resp_len
[priv
->resp_idx
])
1509 priv
->psstate
= PS_STATE_SLEEP
;
1511 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1514 lbs_deb_leave(LBS_DEB_HOST
);
1517 void lbs_ps_sleep(struct lbs_private
*priv
, int wait_option
)
1519 lbs_deb_enter(LBS_DEB_HOST
);
1522 * PS is currently supported only in Infrastructure mode
1523 * Remove this check if it is to be supported in IBSS mode also
1526 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1527 CMD_SUBCMD_ENTER_PS
, wait_option
, 0, NULL
);
1529 lbs_deb_leave(LBS_DEB_HOST
);
1533 * @brief This function sends Exit_PS command to firmware.
1535 * @param priv A pointer to struct lbs_private structure
1536 * @param wait_option wait response or not
1539 void lbs_ps_wakeup(struct lbs_private
*priv
, int wait_option
)
1543 lbs_deb_enter(LBS_DEB_HOST
);
1545 Localpsmode
= cpu_to_le32(LBS802_11POWERMODECAM
);
1547 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1549 wait_option
, 0, &Localpsmode
);
1551 lbs_deb_leave(LBS_DEB_HOST
);
1555 * @brief This function checks condition and prepares to
1556 * send sleep confirm command to firmware if ok.
1558 * @param priv A pointer to struct lbs_private structure
1559 * @param psmode Power Saving mode
1562 void lbs_ps_confirm_sleep(struct lbs_private
*priv
)
1564 unsigned long flags
=0;
1567 lbs_deb_enter(LBS_DEB_HOST
);
1569 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1570 if (priv
->dnld_sent
) {
1572 lbs_deb_host("dnld_sent was set\n");
1575 /* In-progress command? */
1576 if (priv
->cur_cmd
) {
1578 lbs_deb_host("cur_cmd was set\n");
1581 /* Pending events or command responses? */
1582 if (kfifo_len(&priv
->event_fifo
) || priv
->resp_len
[priv
->resp_idx
]) {
1584 lbs_deb_host("pending events or command responses\n");
1586 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1589 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1590 lbs_send_confirmsleep(priv
);
1592 lbs_deb_host("sleep confirm has been delayed\n");
1595 lbs_deb_leave(LBS_DEB_HOST
);
1600 * @brief Configures the transmission power control functionality.
1602 * @param priv A pointer to struct lbs_private structure
1603 * @param enable Transmission power control enable
1604 * @param p0 Power level when link quality is good (dBm).
1605 * @param p1 Power level when link quality is fair (dBm).
1606 * @param p2 Power level when link quality is poor (dBm).
1607 * @param usesnr Use Signal to Noise Ratio in TPC
1609 * @return 0 on success
1611 int lbs_set_tpc_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
, int8_t p1
,
1612 int8_t p2
, int usesnr
)
1614 struct cmd_ds_802_11_tpc_cfg cmd
;
1617 memset(&cmd
, 0, sizeof(cmd
));
1618 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1619 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1620 cmd
.enable
= !!enable
;
1621 cmd
.usesnr
= !!usesnr
;
1626 ret
= lbs_cmd_with_response(priv
, CMD_802_11_TPC_CFG
, &cmd
);
1632 * @brief Configures the power adaptation settings.
1634 * @param priv A pointer to struct lbs_private structure
1635 * @param enable Power adaptation enable
1636 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1637 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1638 * @param p2 Power level for 48 and 54 Mbps (dBm).
1640 * @return 0 on Success
1643 int lbs_set_power_adapt_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
,
1644 int8_t p1
, int8_t p2
)
1646 struct cmd_ds_802_11_pa_cfg cmd
;
1649 memset(&cmd
, 0, sizeof(cmd
));
1650 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1651 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1652 cmd
.enable
= !!enable
;
1657 ret
= lbs_cmd_with_response(priv
, CMD_802_11_PA_CFG
, &cmd
);
1663 struct cmd_ctrl_node
*__lbs_cmd_async(struct lbs_private
*priv
,
1664 uint16_t command
, struct cmd_header
*in_cmd
, int in_cmd_size
,
1665 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
1666 unsigned long callback_arg
)
1668 struct cmd_ctrl_node
*cmdnode
;
1670 lbs_deb_enter(LBS_DEB_HOST
);
1672 if (priv
->surpriseremoved
) {
1673 lbs_deb_host("PREP_CMD: card removed\n");
1674 cmdnode
= ERR_PTR(-ENOENT
);
1678 if (!lbs_is_cmd_allowed(priv
)) {
1679 cmdnode
= ERR_PTR(-EBUSY
);
1683 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
1684 if (cmdnode
== NULL
) {
1685 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1687 /* Wake up main thread to execute next command */
1688 wake_up_interruptible(&priv
->waitq
);
1689 cmdnode
= ERR_PTR(-ENOBUFS
);
1693 cmdnode
->callback
= callback
;
1694 cmdnode
->callback_arg
= callback_arg
;
1696 /* Copy the incoming command to the buffer */
1697 memcpy(cmdnode
->cmdbuf
, in_cmd
, in_cmd_size
);
1699 /* Set sequence number, clean result, move to buffer */
1701 cmdnode
->cmdbuf
->command
= cpu_to_le16(command
);
1702 cmdnode
->cmdbuf
->size
= cpu_to_le16(in_cmd_size
);
1703 cmdnode
->cmdbuf
->seqnum
= cpu_to_le16(priv
->seqnum
);
1704 cmdnode
->cmdbuf
->result
= 0;
1706 lbs_deb_host("PREP_CMD: command 0x%04x\n", command
);
1708 cmdnode
->cmdwaitqwoken
= 0;
1709 lbs_queue_cmd(priv
, cmdnode
);
1710 wake_up_interruptible(&priv
->waitq
);
1713 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %p", cmdnode
);
1717 void lbs_cmd_async(struct lbs_private
*priv
, uint16_t command
,
1718 struct cmd_header
*in_cmd
, int in_cmd_size
)
1720 lbs_deb_enter(LBS_DEB_CMD
);
1721 __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
1722 lbs_cmd_async_callback
, 0);
1723 lbs_deb_leave(LBS_DEB_CMD
);
1726 int __lbs_cmd(struct lbs_private
*priv
, uint16_t command
,
1727 struct cmd_header
*in_cmd
, int in_cmd_size
,
1728 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
1729 unsigned long callback_arg
)
1731 struct cmd_ctrl_node
*cmdnode
;
1732 unsigned long flags
;
1735 lbs_deb_enter(LBS_DEB_HOST
);
1737 cmdnode
= __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
1738 callback
, callback_arg
);
1739 if (IS_ERR(cmdnode
)) {
1740 ret
= PTR_ERR(cmdnode
);
1745 wait_event_interruptible(cmdnode
->cmdwait_q
, cmdnode
->cmdwaitqwoken
);
1747 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1748 ret
= cmdnode
->result
;
1750 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1753 __lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
1754 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1757 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1760 EXPORT_SYMBOL_GPL(__lbs_cmd
);