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>
9 #include <linux/if_arp.h>
16 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
);
19 * @brief Simple callback that copies response back into command
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
26 * @return 0 on success, error on failure
28 int lbs_cmd_copyback(struct lbs_private
*priv
, unsigned long extra
,
29 struct cmd_header
*resp
)
31 struct cmd_header
*buf
= (void *)extra
;
34 copy_len
= min(le16_to_cpu(buf
->size
), le16_to_cpu(resp
->size
));
35 memcpy(buf
, resp
, copy_len
);
38 EXPORT_SYMBOL_GPL(lbs_cmd_copyback
);
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.
46 * @param extra ignored
49 * @return 0 for success
51 static int lbs_cmd_async_callback(struct lbs_private
*priv
, unsigned long extra
,
52 struct cmd_header
*resp
)
59 * @brief Checks whether a command is allowed in Power Save mode
61 * @param command the command ID
62 * @return 1 if allowed, 0 if not allowed
64 static u8
is_command_allowed_in_ps(u16 cmd
)
69 case CMD_802_11_HOST_SLEEP_CFG
:
78 * @brief This function checks if the command is allowed.
80 * @param priv A pointer to lbs_private structure
81 * @return allowed or not allowed.
84 static int lbs_is_cmd_allowed(struct lbs_private
*priv
)
88 lbs_deb_enter(LBS_DEB_CMD
);
90 if (!priv
->is_auto_deep_sleep_enabled
) {
91 if (priv
->is_deep_sleep
) {
92 lbs_deb_cmd("command not allowed in deep sleep\n");
97 lbs_deb_leave(LBS_DEB_CMD
);
102 * @brief Updates the hardware details like MAC address and regulatory region
104 * @param priv A pointer to struct lbs_private structure
106 * @return 0 on success, error on failure
108 int lbs_update_hw_spec(struct lbs_private
*priv
)
110 struct cmd_ds_get_hw_spec cmd
;
114 lbs_deb_enter(LBS_DEB_CMD
);
116 memset(&cmd
, 0, sizeof(cmd
));
117 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
118 memcpy(cmd
.permanentaddr
, priv
->current_addr
, ETH_ALEN
);
119 ret
= lbs_cmd_with_response(priv
, CMD_GET_HW_SPEC
, &cmd
);
123 priv
->fwcapinfo
= le32_to_cpu(cmd
.fwcapinfo
);
125 /* The firmware release is in an interesting format: the patch
126 * level is in the most significant nibble ... so fix that: */
127 priv
->fwrelease
= le32_to_cpu(cmd
.fwrelease
);
128 priv
->fwrelease
= (priv
->fwrelease
<< 8) |
129 (priv
->fwrelease
>> 24 & 0xff);
131 /* Some firmware capabilities:
132 * CF card firmware 5.0.16p0: cap 0x00000303
133 * USB dongle firmware 5.110.17p2: cap 0x00000303
135 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
137 priv
->fwrelease
>> 24 & 0xff,
138 priv
->fwrelease
>> 16 & 0xff,
139 priv
->fwrelease
>> 8 & 0xff,
140 priv
->fwrelease
& 0xff,
142 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
143 cmd
.hwifversion
, cmd
.version
);
145 /* Clamp region code to 8-bit since FW spec indicates that it should
146 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
147 * returns non-zero high 8 bits here.
149 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
150 * need to check for this problem and handle it properly.
152 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V4
)
153 priv
->regioncode
= (le16_to_cpu(cmd
.regioncode
) >> 8) & 0xFF;
155 priv
->regioncode
= le16_to_cpu(cmd
.regioncode
) & 0xFF;
157 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
158 /* use the region code to search for the index */
159 if (priv
->regioncode
== lbs_region_code_to_index
[i
])
163 /* if it's unidentified region code, use the default (USA) */
164 if (i
>= MRVDRV_MAX_REGION_CODE
) {
165 priv
->regioncode
= 0x10;
166 lbs_pr_info("unidentified region code; using the default (USA)\n");
169 if (priv
->current_addr
[0] == 0xff)
170 memmove(priv
->current_addr
, cmd
.permanentaddr
, ETH_ALEN
);
172 memcpy(priv
->dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
174 memcpy(priv
->mesh_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
177 lbs_deb_leave(LBS_DEB_CMD
);
181 static int lbs_ret_host_sleep_cfg(struct lbs_private
*priv
, unsigned long dummy
,
182 struct cmd_header
*resp
)
184 lbs_deb_enter(LBS_DEB_CMD
);
185 if (priv
->is_host_sleep_activated
) {
186 priv
->is_host_sleep_configured
= 0;
187 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
188 priv
->is_host_sleep_activated
= 0;
189 wake_up_interruptible(&priv
->host_sleep_q
);
192 priv
->is_host_sleep_configured
= 1;
194 lbs_deb_leave(LBS_DEB_CMD
);
198 int lbs_host_sleep_cfg(struct lbs_private
*priv
, uint32_t criteria
,
199 struct wol_config
*p_wol_config
)
201 struct cmd_ds_host_sleep cmd_config
;
204 cmd_config
.hdr
.size
= cpu_to_le16(sizeof(cmd_config
));
205 cmd_config
.criteria
= cpu_to_le32(criteria
);
206 cmd_config
.gpio
= priv
->wol_gpio
;
207 cmd_config
.gap
= priv
->wol_gap
;
209 if (p_wol_config
!= NULL
)
210 memcpy((uint8_t *)&cmd_config
.wol_conf
, (uint8_t *)p_wol_config
,
211 sizeof(struct wol_config
));
213 cmd_config
.wol_conf
.action
= CMD_ACT_ACTION_NONE
;
215 ret
= __lbs_cmd(priv
, CMD_802_11_HOST_SLEEP_CFG
, &cmd_config
.hdr
,
216 le16_to_cpu(cmd_config
.hdr
.size
),
217 lbs_ret_host_sleep_cfg
, 0);
220 memcpy((uint8_t *) p_wol_config
,
221 (uint8_t *)&cmd_config
.wol_conf
,
222 sizeof(struct wol_config
));
224 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret
);
229 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg
);
231 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command
*cmd
,
234 struct cmd_ds_802_11_ps_mode
*psm
= &cmd
->params
.psmode
;
236 lbs_deb_enter(LBS_DEB_CMD
);
238 cmd
->command
= cpu_to_le16(CMD_802_11_PS_MODE
);
239 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode
) +
240 sizeof(struct cmd_header
));
241 psm
->action
= cpu_to_le16(cmd_action
);
242 psm
->multipledtim
= 0;
243 switch (cmd_action
) {
244 case CMD_SUBCMD_ENTER_PS
:
245 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
247 psm
->locallisteninterval
= 0;
248 psm
->nullpktinterval
= 0;
250 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM
);
253 case CMD_SUBCMD_EXIT_PS
:
254 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
257 case CMD_SUBCMD_SLEEP_CONFIRMED
:
258 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
265 lbs_deb_leave(LBS_DEB_CMD
);
269 int lbs_cmd_802_11_sleep_params(struct lbs_private
*priv
, uint16_t cmd_action
,
270 struct sleep_params
*sp
)
272 struct cmd_ds_802_11_sleep_params cmd
;
275 lbs_deb_enter(LBS_DEB_CMD
);
277 if (cmd_action
== CMD_ACT_GET
) {
278 memset(&cmd
, 0, sizeof(cmd
));
280 cmd
.error
= cpu_to_le16(sp
->sp_error
);
281 cmd
.offset
= cpu_to_le16(sp
->sp_offset
);
282 cmd
.stabletime
= cpu_to_le16(sp
->sp_stabletime
);
283 cmd
.calcontrol
= sp
->sp_calcontrol
;
284 cmd
.externalsleepclk
= sp
->sp_extsleepclk
;
285 cmd
.reserved
= cpu_to_le16(sp
->sp_reserved
);
287 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
288 cmd
.action
= cpu_to_le16(cmd_action
);
290 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SLEEP_PARAMS
, &cmd
);
293 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
294 "calcontrol 0x%x extsleepclk 0x%x\n",
295 le16_to_cpu(cmd
.error
), le16_to_cpu(cmd
.offset
),
296 le16_to_cpu(cmd
.stabletime
), cmd
.calcontrol
,
297 cmd
.externalsleepclk
);
299 sp
->sp_error
= le16_to_cpu(cmd
.error
);
300 sp
->sp_offset
= le16_to_cpu(cmd
.offset
);
301 sp
->sp_stabletime
= le16_to_cpu(cmd
.stabletime
);
302 sp
->sp_calcontrol
= cmd
.calcontrol
;
303 sp
->sp_extsleepclk
= cmd
.externalsleepclk
;
304 sp
->sp_reserved
= le16_to_cpu(cmd
.reserved
);
307 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
311 static int lbs_wait_for_ds_awake(struct lbs_private
*priv
)
315 lbs_deb_enter(LBS_DEB_CMD
);
317 if (priv
->is_deep_sleep
) {
318 if (!wait_event_interruptible_timeout(priv
->ds_awake_q
,
319 !priv
->is_deep_sleep
, (10 * HZ
))) {
320 lbs_pr_err("ds_awake_q: timer expired\n");
325 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
329 int lbs_set_deep_sleep(struct lbs_private
*priv
, int deep_sleep
)
333 lbs_deb_enter(LBS_DEB_CMD
);
336 if (priv
->is_deep_sleep
!= 1) {
337 lbs_deb_cmd("deep sleep: sleep\n");
338 BUG_ON(!priv
->enter_deep_sleep
);
339 ret
= priv
->enter_deep_sleep(priv
);
341 netif_stop_queue(priv
->dev
);
342 netif_carrier_off(priv
->dev
);
345 lbs_pr_err("deep sleep: already enabled\n");
348 if (priv
->is_deep_sleep
) {
349 lbs_deb_cmd("deep sleep: wakeup\n");
350 BUG_ON(!priv
->exit_deep_sleep
);
351 ret
= priv
->exit_deep_sleep(priv
);
353 ret
= lbs_wait_for_ds_awake(priv
);
355 lbs_pr_err("deep sleep: wakeup"
361 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
365 static int lbs_ret_host_sleep_activate(struct lbs_private
*priv
,
367 struct cmd_header
*cmd
)
369 lbs_deb_enter(LBS_DEB_FW
);
370 priv
->is_host_sleep_activated
= 1;
371 wake_up_interruptible(&priv
->host_sleep_q
);
372 lbs_deb_leave(LBS_DEB_FW
);
376 int lbs_set_host_sleep(struct lbs_private
*priv
, int host_sleep
)
378 struct cmd_header cmd
;
380 uint32_t criteria
= EHS_REMOVE_WAKEUP
;
382 lbs_deb_enter(LBS_DEB_CMD
);
385 if (priv
->is_host_sleep_activated
!= 1) {
386 memset(&cmd
, 0, sizeof(cmd
));
387 ret
= lbs_host_sleep_cfg(priv
, priv
->wol_criteria
,
388 (struct wol_config
*)NULL
);
390 lbs_pr_info("Host sleep configuration failed: "
394 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
395 ret
= __lbs_cmd(priv
,
396 CMD_802_11_HOST_SLEEP_ACTIVATE
,
399 lbs_ret_host_sleep_activate
, 0);
401 lbs_pr_info("HOST_SLEEP_ACTIVATE "
402 "failed: %d\n", ret
);
405 if (!wait_event_interruptible_timeout(
407 priv
->is_host_sleep_activated
,
409 lbs_pr_err("host_sleep_q: timer expired\n");
413 lbs_pr_err("host sleep: already enabled\n");
416 if (priv
->is_host_sleep_activated
)
417 ret
= lbs_host_sleep_cfg(priv
, criteria
,
418 (struct wol_config
*)NULL
);
425 * @brief Set an SNMP MIB value
427 * @param priv A pointer to struct lbs_private structure
428 * @param oid The OID to set in the firmware
429 * @param val Value to set the OID to
431 * @return 0 on success, error on failure
433 int lbs_set_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16 val
)
435 struct cmd_ds_802_11_snmp_mib cmd
;
438 lbs_deb_enter(LBS_DEB_CMD
);
440 memset(&cmd
, 0, sizeof (cmd
));
441 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
442 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
443 cmd
.oid
= cpu_to_le16((u16
) oid
);
446 case SNMP_MIB_OID_BSS_TYPE
:
447 cmd
.bufsize
= cpu_to_le16(sizeof(u8
));
450 case SNMP_MIB_OID_11D_ENABLE
:
451 case SNMP_MIB_OID_FRAG_THRESHOLD
:
452 case SNMP_MIB_OID_RTS_THRESHOLD
:
453 case SNMP_MIB_OID_SHORT_RETRY_LIMIT
:
454 case SNMP_MIB_OID_LONG_RETRY_LIMIT
:
455 cmd
.bufsize
= cpu_to_le16(sizeof(u16
));
456 *((__le16
*)(&cmd
.value
)) = cpu_to_le16(val
);
459 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid
);
464 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
465 le16_to_cpu(cmd
.oid
), le16_to_cpu(cmd
.bufsize
), val
);
467 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
470 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
475 * @brief Get an SNMP MIB value
477 * @param priv A pointer to struct lbs_private structure
478 * @param oid The OID to retrieve from the firmware
479 * @param out_val Location for the returned value
481 * @return 0 on success, error on failure
483 int lbs_get_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16
*out_val
)
485 struct cmd_ds_802_11_snmp_mib cmd
;
488 lbs_deb_enter(LBS_DEB_CMD
);
490 memset(&cmd
, 0, sizeof (cmd
));
491 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
492 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
493 cmd
.oid
= cpu_to_le16(oid
);
495 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
499 switch (le16_to_cpu(cmd
.bufsize
)) {
501 *out_val
= cmd
.value
[0];
504 *out_val
= le16_to_cpu(*((__le16
*)(&cmd
.value
)));
507 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
508 oid
, le16_to_cpu(cmd
.bufsize
));
513 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
518 * @brief Get the min, max, and current TX power
520 * @param priv A pointer to struct lbs_private structure
521 * @param curlevel Current power level in dBm
522 * @param minlevel Minimum supported power level in dBm (optional)
523 * @param maxlevel Maximum supported power level in dBm (optional)
525 * @return 0 on success, error on failure
527 int lbs_get_tx_power(struct lbs_private
*priv
, s16
*curlevel
, s16
*minlevel
,
530 struct cmd_ds_802_11_rf_tx_power cmd
;
533 lbs_deb_enter(LBS_DEB_CMD
);
535 memset(&cmd
, 0, sizeof(cmd
));
536 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
537 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
539 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
541 *curlevel
= le16_to_cpu(cmd
.curlevel
);
543 *minlevel
= cmd
.minlevel
;
545 *maxlevel
= cmd
.maxlevel
;
548 lbs_deb_leave(LBS_DEB_CMD
);
553 * @brief Set the TX power
555 * @param priv A pointer to struct lbs_private structure
556 * @param dbm The desired power level in dBm
558 * @return 0 on success, error on failure
560 int lbs_set_tx_power(struct lbs_private
*priv
, s16 dbm
)
562 struct cmd_ds_802_11_rf_tx_power cmd
;
565 lbs_deb_enter(LBS_DEB_CMD
);
567 memset(&cmd
, 0, sizeof(cmd
));
568 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
569 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
570 cmd
.curlevel
= cpu_to_le16(dbm
);
572 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm
);
574 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
576 lbs_deb_leave(LBS_DEB_CMD
);
581 * @brief Enable or disable monitor mode (only implemented on OLPC usb8388 FW)
583 * @param priv A pointer to struct lbs_private structure
584 * @param enable 1 to enable monitor mode, 0 to disable
586 * @return 0 on success, error on failure
588 int lbs_set_monitor_mode(struct lbs_private
*priv
, int enable
)
590 struct cmd_ds_802_11_monitor_mode cmd
;
593 memset(&cmd
, 0, sizeof(cmd
));
594 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
595 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
597 cmd
.mode
= cpu_to_le16(0x1);
599 lbs_deb_cmd("SET_MONITOR_MODE: %d\n", enable
);
601 ret
= lbs_cmd_with_response(priv
, CMD_802_11_MONITOR_MODE
, &cmd
);
603 priv
->dev
->type
= enable
? ARPHRD_IEEE80211_RADIOTAP
:
607 lbs_deb_leave(LBS_DEB_CMD
);
612 * @brief Get the radio channel
614 * @param priv A pointer to struct lbs_private structure
616 * @return The channel on success, error on failure
618 static int lbs_get_channel(struct lbs_private
*priv
)
620 struct cmd_ds_802_11_rf_channel cmd
;
623 lbs_deb_enter(LBS_DEB_CMD
);
625 memset(&cmd
, 0, sizeof(cmd
));
626 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
627 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET
);
629 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
633 ret
= le16_to_cpu(cmd
.channel
);
634 lbs_deb_cmd("current radio channel is %d\n", ret
);
637 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
641 int lbs_update_channel(struct lbs_private
*priv
)
645 /* the channel in f/w could be out of sync; get the current channel */
646 lbs_deb_enter(LBS_DEB_ASSOC
);
648 ret
= lbs_get_channel(priv
);
653 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
658 * @brief Set the radio channel
660 * @param priv A pointer to struct lbs_private structure
661 * @param channel The desired channel, or 0 to clear a locked channel
663 * @return 0 on success, error on failure
665 int lbs_set_channel(struct lbs_private
*priv
, u8 channel
)
667 struct cmd_ds_802_11_rf_channel cmd
;
669 u8 old_channel
= priv
->channel
;
673 lbs_deb_enter(LBS_DEB_CMD
);
675 memset(&cmd
, 0, sizeof(cmd
));
676 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
677 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET
);
678 cmd
.channel
= cpu_to_le16(channel
);
680 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
684 priv
->channel
= (uint8_t) le16_to_cpu(cmd
.channel
);
685 lbs_deb_cmd("channel switch from %d to %d\n", old_channel
,
689 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
693 static int lbs_cmd_reg_access(struct cmd_ds_command
*cmdptr
,
694 u8 cmd_action
, void *pdata_buf
)
696 struct lbs_offset_value
*offval
;
698 lbs_deb_enter(LBS_DEB_CMD
);
700 offval
= (struct lbs_offset_value
*)pdata_buf
;
702 switch (le16_to_cpu(cmdptr
->command
)) {
703 case CMD_MAC_REG_ACCESS
:
705 struct cmd_ds_mac_reg_access
*macreg
;
708 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access
)
709 + sizeof(struct cmd_header
));
711 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
714 macreg
->action
= cpu_to_le16(cmd_action
);
715 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
716 macreg
->value
= cpu_to_le32(offval
->value
);
721 case CMD_BBP_REG_ACCESS
:
723 struct cmd_ds_bbp_reg_access
*bbpreg
;
727 (struct cmd_ds_bbp_reg_access
)
728 + sizeof(struct cmd_header
));
730 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
733 bbpreg
->action
= cpu_to_le16(cmd_action
);
734 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
735 bbpreg
->value
= (u8
) offval
->value
;
740 case CMD_RF_REG_ACCESS
:
742 struct cmd_ds_rf_reg_access
*rfreg
;
746 (struct cmd_ds_rf_reg_access
) +
747 sizeof(struct cmd_header
));
749 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
752 rfreg
->action
= cpu_to_le16(cmd_action
);
753 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
754 rfreg
->value
= (u8
) offval
->value
;
763 lbs_deb_leave(LBS_DEB_CMD
);
767 static void lbs_queue_cmd(struct lbs_private
*priv
,
768 struct cmd_ctrl_node
*cmdnode
)
773 lbs_deb_enter(LBS_DEB_HOST
);
776 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
779 if (!cmdnode
->cmdbuf
->size
) {
780 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
785 /* Exit_PS command needs to be queued in the header always. */
786 if (le16_to_cpu(cmdnode
->cmdbuf
->command
) == CMD_802_11_PS_MODE
) {
787 struct cmd_ds_802_11_ps_mode
*psm
= (void *) &cmdnode
->cmdbuf
[1];
789 if (psm
->action
== cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
790 if (priv
->psstate
!= PS_STATE_FULL_POWER
)
795 if (le16_to_cpu(cmdnode
->cmdbuf
->command
) ==
796 CMD_802_11_WAKEUP_CONFIRM
)
799 spin_lock_irqsave(&priv
->driver_lock
, flags
);
802 list_add_tail(&cmdnode
->list
, &priv
->cmdpendingq
);
804 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
806 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
808 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
809 le16_to_cpu(cmdnode
->cmdbuf
->command
));
812 lbs_deb_leave(LBS_DEB_HOST
);
815 static void lbs_submit_command(struct lbs_private
*priv
,
816 struct cmd_ctrl_node
*cmdnode
)
819 struct cmd_header
*cmd
;
825 lbs_deb_enter(LBS_DEB_HOST
);
827 cmd
= cmdnode
->cmdbuf
;
829 spin_lock_irqsave(&priv
->driver_lock
, flags
);
830 priv
->cur_cmd
= cmdnode
;
831 priv
->cur_cmd_retcode
= 0;
832 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
834 cmdsize
= le16_to_cpu(cmd
->size
);
835 command
= le16_to_cpu(cmd
->command
);
837 /* These commands take longer */
838 if (command
== CMD_802_11_SCAN
|| command
== CMD_802_11_ASSOCIATE
)
841 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
842 command
, le16_to_cpu(cmd
->seqnum
), cmdsize
);
843 lbs_deb_hex(LBS_DEB_CMD
, "DNLD_CMD", (void *) cmdnode
->cmdbuf
, cmdsize
);
845 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmd
, cmdsize
);
848 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret
);
849 /* Let the timer kick in and retry, and potentially reset
850 the whole thing if the condition persists */
854 if (command
== CMD_802_11_DEEP_SLEEP
) {
855 if (priv
->is_auto_deep_sleep_enabled
) {
856 priv
->wakeup_dev_required
= 1;
859 priv
->is_deep_sleep
= 1;
860 lbs_complete_command(priv
, cmdnode
, 0);
862 /* Setup the timer after transmit command */
863 mod_timer(&priv
->command_timer
, jiffies
+ timeo
);
866 lbs_deb_leave(LBS_DEB_HOST
);
870 * This function inserts command node to cmdfreeq
871 * after cleans it. Requires priv->driver_lock held.
873 static void __lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
874 struct cmd_ctrl_node
*cmdnode
)
876 lbs_deb_enter(LBS_DEB_HOST
);
881 cmdnode
->callback
= NULL
;
882 cmdnode
->callback_arg
= 0;
884 memset(cmdnode
->cmdbuf
, 0, LBS_CMD_BUFFER_SIZE
);
886 list_add_tail(&cmdnode
->list
, &priv
->cmdfreeq
);
888 lbs_deb_leave(LBS_DEB_HOST
);
891 static void lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
892 struct cmd_ctrl_node
*ptempcmd
)
896 spin_lock_irqsave(&priv
->driver_lock
, flags
);
897 __lbs_cleanup_and_insert_cmd(priv
, ptempcmd
);
898 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
901 void lbs_complete_command(struct lbs_private
*priv
, struct cmd_ctrl_node
*cmd
,
904 if (cmd
== priv
->cur_cmd
)
905 priv
->cur_cmd_retcode
= result
;
907 cmd
->result
= result
;
908 cmd
->cmdwaitqwoken
= 1;
909 wake_up_interruptible(&cmd
->cmdwait_q
);
911 if (!cmd
->callback
|| cmd
->callback
== lbs_cmd_async_callback
)
912 __lbs_cleanup_and_insert_cmd(priv
, cmd
);
913 priv
->cur_cmd
= NULL
;
916 int lbs_set_radio(struct lbs_private
*priv
, u8 preamble
, u8 radio_on
)
918 struct cmd_ds_802_11_radio_control cmd
;
921 lbs_deb_enter(LBS_DEB_CMD
);
923 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
924 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
926 /* Only v8 and below support setting the preamble */
927 if (priv
->fwrelease
< 0x09000000) {
929 case RADIO_PREAMBLE_SHORT
:
930 case RADIO_PREAMBLE_AUTO
:
931 case RADIO_PREAMBLE_LONG
:
932 cmd
.control
= cpu_to_le16(preamble
);
940 cmd
.control
|= cpu_to_le16(0x1);
942 cmd
.control
&= cpu_to_le16(~0x1);
943 priv
->txpower_cur
= 0;
946 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
947 radio_on
? "ON" : "OFF", preamble
);
949 priv
->radio_on
= radio_on
;
951 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RADIO_CONTROL
, &cmd
);
954 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
958 void lbs_set_mac_control(struct lbs_private
*priv
)
960 struct cmd_ds_mac_control cmd
;
962 lbs_deb_enter(LBS_DEB_CMD
);
964 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
965 cmd
.action
= cpu_to_le16(priv
->mac_control
);
968 lbs_cmd_async(priv
, CMD_MAC_CONTROL
, &cmd
.hdr
, sizeof(cmd
));
970 lbs_deb_leave(LBS_DEB_CMD
);
974 * @brief This function implements command CMD_802_11D_DOMAIN_INFO
975 * @param priv pointer to struct lbs_private
976 * @param cmd pointer to cmd buffer
977 * @param cmdno cmd ID
978 * @param cmdOption cmd action
981 int lbs_cmd_802_11d_domain_info(struct lbs_private
*priv
,
982 struct cmd_ds_command
*cmd
,
985 struct cmd_ds_802_11d_domain_info
*pdomaininfo
=
986 &cmd
->params
.domaininfo
;
987 struct mrvl_ie_domain_param_set
*domain
= &pdomaininfo
->domain
;
988 u8 nr_triplet
= priv
->domain_reg
.no_triplet
;
990 lbs_deb_enter(LBS_DEB_11D
);
992 lbs_deb_11d("nr_triplet=%x\n", nr_triplet
);
994 pdomaininfo
->action
= cpu_to_le16(cmdoption
);
995 if (cmdoption
== CMD_ACT_GET
) {
996 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
997 sizeof(struct cmd_header
));
998 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
,
999 le16_to_cpu(cmd
->size
));
1003 domain
->header
.type
= cpu_to_le16(TLV_TYPE_DOMAIN
);
1004 memcpy(domain
->countrycode
, priv
->domain_reg
.country_code
,
1005 sizeof(domain
->countrycode
));
1007 domain
->header
.len
= cpu_to_le16(nr_triplet
1008 * sizeof(struct ieee80211_country_ie_triplet
)
1009 + sizeof(domain
->countrycode
));
1012 memcpy(domain
->triplet
, priv
->domain_reg
.triplet
,
1014 sizeof(struct ieee80211_country_ie_triplet
));
1016 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
1017 le16_to_cpu(domain
->header
.len
) +
1018 sizeof(struct mrvl_ie_header
) +
1019 sizeof(struct cmd_header
));
1021 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
1022 sizeof(struct cmd_header
));
1025 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
,
1026 le16_to_cpu(cmd
->size
));
1029 lbs_deb_enter(LBS_DEB_11D
);
1034 * @brief This function prepare the command before send to firmware.
1036 * @param priv A pointer to struct lbs_private structure
1037 * @param cmd_no command number
1038 * @param cmd_action command action: GET or SET
1039 * @param wait_option wait option: wait response or not
1040 * @param cmd_oid cmd oid: treated as sub command
1041 * @param pdata_buf A pointer to informaion buffer
1044 int lbs_prepare_and_send_command(struct lbs_private
*priv
,
1047 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1050 struct cmd_ctrl_node
*cmdnode
;
1051 struct cmd_ds_command
*cmdptr
;
1052 unsigned long flags
;
1054 lbs_deb_enter(LBS_DEB_HOST
);
1057 lbs_deb_host("PREP_CMD: priv is NULL\n");
1062 if (priv
->surpriseremoved
) {
1063 lbs_deb_host("PREP_CMD: card removed\n");
1068 if (!lbs_is_cmd_allowed(priv
)) {
1073 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
1075 if (cmdnode
== NULL
) {
1076 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1078 /* Wake up main thread to execute next command */
1079 wake_up_interruptible(&priv
->waitq
);
1084 cmdnode
->callback
= NULL
;
1085 cmdnode
->callback_arg
= (unsigned long)pdata_buf
;
1087 cmdptr
= (struct cmd_ds_command
*)cmdnode
->cmdbuf
;
1089 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no
);
1091 /* Set sequence number, command and INT option */
1093 cmdptr
->seqnum
= cpu_to_le16(priv
->seqnum
);
1095 cmdptr
->command
= cpu_to_le16(cmd_no
);
1099 case CMD_802_11_PS_MODE
:
1100 ret
= lbs_cmd_802_11_ps_mode(cmdptr
, cmd_action
);
1103 case CMD_MAC_REG_ACCESS
:
1104 case CMD_BBP_REG_ACCESS
:
1105 case CMD_RF_REG_ACCESS
:
1106 ret
= lbs_cmd_reg_access(cmdptr
, cmd_action
, pdata_buf
);
1109 case CMD_802_11_RSSI
:
1110 ret
= lbs_cmd_802_11_rssi(priv
, cmdptr
);
1113 case CMD_802_11_SET_AFC
:
1114 case CMD_802_11_GET_AFC
:
1116 cmdptr
->command
= cpu_to_le16(cmd_no
);
1117 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1118 sizeof(struct cmd_header
));
1120 memmove(&cmdptr
->params
.afc
,
1121 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1126 case CMD_802_11D_DOMAIN_INFO
:
1127 cmdptr
->command
= cpu_to_le16(cmd_no
);
1128 ret
= lbs_cmd_802_11d_domain_info(priv
, cmdptr
, cmd_action
);
1131 case CMD_802_11_TPC_CFG
:
1132 cmdptr
->command
= cpu_to_le16(CMD_802_11_TPC_CFG
);
1134 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1135 sizeof(struct cmd_header
));
1137 memmove(&cmdptr
->params
.tpccfg
,
1138 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1143 #ifdef CONFIG_LIBERTAS_MESH
1146 ret
= lbs_cmd_bt_access(cmdptr
, cmd_action
, pdata_buf
);
1149 case CMD_FWT_ACCESS
:
1150 ret
= lbs_cmd_fwt_access(cmdptr
, cmd_action
, pdata_buf
);
1155 case CMD_802_11_BEACON_CTRL
:
1156 ret
= lbs_cmd_bcn_ctrl(priv
, cmdptr
, cmd_action
);
1158 case CMD_802_11_DEEP_SLEEP
:
1159 cmdptr
->command
= cpu_to_le16(CMD_802_11_DEEP_SLEEP
);
1160 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_header
));
1163 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no
);
1168 /* return error, since the command preparation failed */
1170 lbs_deb_host("PREP_CMD: command preparation failed\n");
1171 lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
1176 cmdnode
->cmdwaitqwoken
= 0;
1178 lbs_queue_cmd(priv
, cmdnode
);
1179 wake_up_interruptible(&priv
->waitq
);
1181 if (wait_option
& CMD_OPTION_WAITFORRSP
) {
1182 lbs_deb_host("PREP_CMD: wait for response\n");
1184 wait_event_interruptible(cmdnode
->cmdwait_q
,
1185 cmdnode
->cmdwaitqwoken
);
1188 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1189 if (priv
->cur_cmd_retcode
) {
1190 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1191 priv
->cur_cmd_retcode
);
1192 priv
->cur_cmd_retcode
= 0;
1195 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1198 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1203 * @brief This function allocates the command buffer and link
1204 * it to command free queue.
1206 * @param priv A pointer to struct lbs_private structure
1209 int lbs_allocate_cmd_buffer(struct lbs_private
*priv
)
1214 struct cmd_ctrl_node
*cmdarray
;
1216 lbs_deb_enter(LBS_DEB_HOST
);
1218 /* Allocate and initialize the command array */
1219 bufsize
= sizeof(struct cmd_ctrl_node
) * LBS_NUM_CMD_BUFFERS
;
1220 if (!(cmdarray
= kzalloc(bufsize
, GFP_KERNEL
))) {
1221 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1225 priv
->cmd_array
= cmdarray
;
1227 /* Allocate and initialize each command buffer in the command array */
1228 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1229 cmdarray
[i
].cmdbuf
= kzalloc(LBS_CMD_BUFFER_SIZE
, GFP_KERNEL
);
1230 if (!cmdarray
[i
].cmdbuf
) {
1231 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1237 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1238 init_waitqueue_head(&cmdarray
[i
].cmdwait_q
);
1239 lbs_cleanup_and_insert_cmd(priv
, &cmdarray
[i
]);
1244 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1249 * @brief This function frees the command buffer.
1251 * @param priv A pointer to struct lbs_private structure
1254 int lbs_free_cmd_buffer(struct lbs_private
*priv
)
1256 struct cmd_ctrl_node
*cmdarray
;
1259 lbs_deb_enter(LBS_DEB_HOST
);
1261 /* need to check if cmd array is allocated or not */
1262 if (priv
->cmd_array
== NULL
) {
1263 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1267 cmdarray
= priv
->cmd_array
;
1269 /* Release shared memory buffers */
1270 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1271 if (cmdarray
[i
].cmdbuf
) {
1272 kfree(cmdarray
[i
].cmdbuf
);
1273 cmdarray
[i
].cmdbuf
= NULL
;
1277 /* Release cmd_ctrl_node */
1278 if (priv
->cmd_array
) {
1279 kfree(priv
->cmd_array
);
1280 priv
->cmd_array
= NULL
;
1284 lbs_deb_leave(LBS_DEB_HOST
);
1289 * @brief This function gets a free command node if available in
1290 * command free queue.
1292 * @param priv A pointer to struct lbs_private structure
1293 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1295 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
)
1297 struct cmd_ctrl_node
*tempnode
;
1298 unsigned long flags
;
1300 lbs_deb_enter(LBS_DEB_HOST
);
1305 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1307 if (!list_empty(&priv
->cmdfreeq
)) {
1308 tempnode
= list_first_entry(&priv
->cmdfreeq
,
1309 struct cmd_ctrl_node
, list
);
1310 list_del(&tempnode
->list
);
1312 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1316 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1318 lbs_deb_leave(LBS_DEB_HOST
);
1323 * @brief This function executes next command in command
1324 * pending queue. It will put firmware back to PS mode
1327 * @param priv A pointer to struct lbs_private structure
1330 int lbs_execute_next_command(struct lbs_private
*priv
)
1332 struct cmd_ctrl_node
*cmdnode
= NULL
;
1333 struct cmd_header
*cmd
;
1334 unsigned long flags
;
1337 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1338 * only caller to us is lbs_thread() and we get even when a
1339 * data packet is received */
1340 lbs_deb_enter(LBS_DEB_THREAD
);
1342 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1344 if (priv
->cur_cmd
) {
1345 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1346 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1351 if (!list_empty(&priv
->cmdpendingq
)) {
1352 cmdnode
= list_first_entry(&priv
->cmdpendingq
,
1353 struct cmd_ctrl_node
, list
);
1356 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1359 cmd
= cmdnode
->cmdbuf
;
1361 if (is_command_allowed_in_ps(le16_to_cpu(cmd
->command
))) {
1362 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1363 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1365 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1366 le16_to_cpu(cmd
->command
),
1371 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1372 "0x%04x in psstate %d\n",
1373 le16_to_cpu(cmd
->command
), priv
->psstate
);
1374 } else if (priv
->psstate
!= PS_STATE_FULL_POWER
) {
1376 * 1. Non-PS command:
1377 * Queue it. set needtowakeup to TRUE if current state
1378 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1379 * 2. PS command but not Exit_PS:
1381 * 3. PS command Exit_PS:
1382 * Set needtowakeup to TRUE if current state is SLEEP,
1383 * otherwise send this command down to firmware
1386 if (cmd
->command
!= cpu_to_le16(CMD_802_11_PS_MODE
)) {
1387 /* Prepare to send Exit PS,
1388 * this non PS command will be sent later */
1389 if ((priv
->psstate
== PS_STATE_SLEEP
)
1390 || (priv
->psstate
== PS_STATE_PRE_SLEEP
)
1392 /* w/ new scheme, it will not reach here.
1393 since it is blocked in main_thread. */
1394 priv
->needtowakeup
= 1;
1396 lbs_ps_wakeup(priv
, 0);
1402 * PS command. Ignore it if it is not Exit_PS.
1403 * otherwise send it down immediately.
1405 struct cmd_ds_802_11_ps_mode
*psm
= (void *)&cmd
[1];
1408 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1411 cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
1413 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1414 list_del(&cmdnode
->list
);
1415 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1416 lbs_complete_command(priv
, cmdnode
, 0);
1417 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1423 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1424 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1426 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1427 list_del(&cmdnode
->list
);
1428 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1429 lbs_complete_command(priv
, cmdnode
, 0);
1430 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1431 priv
->needtowakeup
= 1;
1438 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1441 list_del(&cmdnode
->list
);
1442 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1443 le16_to_cpu(cmd
->command
));
1444 lbs_submit_command(priv
, cmdnode
);
1447 * check if in power save mode, if yes, put the device back
1452 * This was the old code for libertas+wext. Someone that
1453 * understands this beast should re-code it in a sane way.
1455 * I actually don't understand why this is related to WPA
1456 * and to connection status, shouldn't powering should be
1457 * independ of such things?
1459 if ((priv
->psmode
!= LBS802_11POWERMODECAM
) &&
1460 (priv
->psstate
== PS_STATE_FULL_POWER
) &&
1461 ((priv
->connect_status
== LBS_CONNECTED
) ||
1462 lbs_mesh_connected(priv
))) {
1463 if (priv
->secinfo
.WPAenabled
||
1464 priv
->secinfo
.WPA2enabled
) {
1465 /* check for valid WPA group keys */
1466 if (priv
->wpa_mcast_key
.len
||
1467 priv
->wpa_unicast_key
.len
) {
1469 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1470 " go back to PS_SLEEP");
1471 lbs_ps_sleep(priv
, 0);
1475 "EXEC_NEXT_CMD: cmdpendingq empty, "
1476 "go back to PS_SLEEP");
1477 lbs_ps_sleep(priv
, 0);
1485 lbs_deb_leave(LBS_DEB_THREAD
);
1489 static void lbs_send_confirmsleep(struct lbs_private
*priv
)
1491 unsigned long flags
;
1494 lbs_deb_enter(LBS_DEB_HOST
);
1495 lbs_deb_hex(LBS_DEB_HOST
, "sleep confirm", (u8
*) &confirm_sleep
,
1496 sizeof(confirm_sleep
));
1498 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) &confirm_sleep
,
1499 sizeof(confirm_sleep
));
1501 lbs_pr_alert("confirm_sleep failed\n");
1505 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1507 /* We don't get a response on the sleep-confirmation */
1508 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
1510 if (priv
->is_host_sleep_configured
) {
1511 priv
->is_host_sleep_activated
= 1;
1512 wake_up_interruptible(&priv
->host_sleep_q
);
1515 /* If nothing to do, go back to sleep (?) */
1516 if (!kfifo_len(&priv
->event_fifo
) && !priv
->resp_len
[priv
->resp_idx
])
1517 priv
->psstate
= PS_STATE_SLEEP
;
1519 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1522 lbs_deb_leave(LBS_DEB_HOST
);
1525 void lbs_ps_sleep(struct lbs_private
*priv
, int wait_option
)
1527 lbs_deb_enter(LBS_DEB_HOST
);
1530 * PS is currently supported only in Infrastructure mode
1531 * Remove this check if it is to be supported in IBSS mode also
1534 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1535 CMD_SUBCMD_ENTER_PS
, wait_option
, 0, NULL
);
1537 lbs_deb_leave(LBS_DEB_HOST
);
1541 * @brief This function sends Exit_PS command to firmware.
1543 * @param priv A pointer to struct lbs_private structure
1544 * @param wait_option wait response or not
1547 void lbs_ps_wakeup(struct lbs_private
*priv
, int wait_option
)
1551 lbs_deb_enter(LBS_DEB_HOST
);
1553 Localpsmode
= cpu_to_le32(LBS802_11POWERMODECAM
);
1555 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1557 wait_option
, 0, &Localpsmode
);
1559 lbs_deb_leave(LBS_DEB_HOST
);
1563 * @brief This function checks condition and prepares to
1564 * send sleep confirm command to firmware if ok.
1566 * @param priv A pointer to struct lbs_private structure
1567 * @param psmode Power Saving mode
1570 void lbs_ps_confirm_sleep(struct lbs_private
*priv
)
1572 unsigned long flags
=0;
1575 lbs_deb_enter(LBS_DEB_HOST
);
1577 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1578 if (priv
->dnld_sent
) {
1580 lbs_deb_host("dnld_sent was set\n");
1583 /* In-progress command? */
1584 if (priv
->cur_cmd
) {
1586 lbs_deb_host("cur_cmd was set\n");
1589 /* Pending events or command responses? */
1590 if (kfifo_len(&priv
->event_fifo
) || priv
->resp_len
[priv
->resp_idx
]) {
1592 lbs_deb_host("pending events or command responses\n");
1594 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1597 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1598 lbs_send_confirmsleep(priv
);
1600 lbs_deb_host("sleep confirm has been delayed\n");
1603 lbs_deb_leave(LBS_DEB_HOST
);
1608 * @brief Configures the transmission power control functionality.
1610 * @param priv A pointer to struct lbs_private structure
1611 * @param enable Transmission power control enable
1612 * @param p0 Power level when link quality is good (dBm).
1613 * @param p1 Power level when link quality is fair (dBm).
1614 * @param p2 Power level when link quality is poor (dBm).
1615 * @param usesnr Use Signal to Noise Ratio in TPC
1617 * @return 0 on success
1619 int lbs_set_tpc_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
, int8_t p1
,
1620 int8_t p2
, int usesnr
)
1622 struct cmd_ds_802_11_tpc_cfg cmd
;
1625 memset(&cmd
, 0, sizeof(cmd
));
1626 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1627 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1628 cmd
.enable
= !!enable
;
1629 cmd
.usesnr
= !!usesnr
;
1634 ret
= lbs_cmd_with_response(priv
, CMD_802_11_TPC_CFG
, &cmd
);
1640 * @brief Configures the power adaptation settings.
1642 * @param priv A pointer to struct lbs_private structure
1643 * @param enable Power adaptation enable
1644 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1645 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1646 * @param p2 Power level for 48 and 54 Mbps (dBm).
1648 * @return 0 on Success
1651 int lbs_set_power_adapt_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
,
1652 int8_t p1
, int8_t p2
)
1654 struct cmd_ds_802_11_pa_cfg cmd
;
1657 memset(&cmd
, 0, sizeof(cmd
));
1658 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1659 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1660 cmd
.enable
= !!enable
;
1665 ret
= lbs_cmd_with_response(priv
, CMD_802_11_PA_CFG
, &cmd
);
1671 struct cmd_ctrl_node
*__lbs_cmd_async(struct lbs_private
*priv
,
1672 uint16_t command
, struct cmd_header
*in_cmd
, int in_cmd_size
,
1673 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
1674 unsigned long callback_arg
)
1676 struct cmd_ctrl_node
*cmdnode
;
1678 lbs_deb_enter(LBS_DEB_HOST
);
1680 if (priv
->surpriseremoved
) {
1681 lbs_deb_host("PREP_CMD: card removed\n");
1682 cmdnode
= ERR_PTR(-ENOENT
);
1686 if (!lbs_is_cmd_allowed(priv
)) {
1687 cmdnode
= ERR_PTR(-EBUSY
);
1691 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
1692 if (cmdnode
== NULL
) {
1693 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1695 /* Wake up main thread to execute next command */
1696 wake_up_interruptible(&priv
->waitq
);
1697 cmdnode
= ERR_PTR(-ENOBUFS
);
1701 cmdnode
->callback
= callback
;
1702 cmdnode
->callback_arg
= callback_arg
;
1704 /* Copy the incoming command to the buffer */
1705 memcpy(cmdnode
->cmdbuf
, in_cmd
, in_cmd_size
);
1707 /* Set sequence number, clean result, move to buffer */
1709 cmdnode
->cmdbuf
->command
= cpu_to_le16(command
);
1710 cmdnode
->cmdbuf
->size
= cpu_to_le16(in_cmd_size
);
1711 cmdnode
->cmdbuf
->seqnum
= cpu_to_le16(priv
->seqnum
);
1712 cmdnode
->cmdbuf
->result
= 0;
1714 lbs_deb_host("PREP_CMD: command 0x%04x\n", command
);
1716 cmdnode
->cmdwaitqwoken
= 0;
1717 lbs_queue_cmd(priv
, cmdnode
);
1718 wake_up_interruptible(&priv
->waitq
);
1721 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %p", cmdnode
);
1725 void lbs_cmd_async(struct lbs_private
*priv
, uint16_t command
,
1726 struct cmd_header
*in_cmd
, int in_cmd_size
)
1728 lbs_deb_enter(LBS_DEB_CMD
);
1729 __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
1730 lbs_cmd_async_callback
, 0);
1731 lbs_deb_leave(LBS_DEB_CMD
);
1734 int __lbs_cmd(struct lbs_private
*priv
, uint16_t command
,
1735 struct cmd_header
*in_cmd
, int in_cmd_size
,
1736 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
1737 unsigned long callback_arg
)
1739 struct cmd_ctrl_node
*cmdnode
;
1740 unsigned long flags
;
1743 lbs_deb_enter(LBS_DEB_HOST
);
1745 cmdnode
= __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
1746 callback
, callback_arg
);
1747 if (IS_ERR(cmdnode
)) {
1748 ret
= PTR_ERR(cmdnode
);
1753 wait_event_interruptible(cmdnode
->cmdwait_q
, cmdnode
->cmdwaitqwoken
);
1755 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1756 ret
= cmdnode
->result
;
1758 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1761 __lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
1762 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1765 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1768 EXPORT_SYMBOL_GPL(__lbs_cmd
);