2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
30 * This function initializes a command node.
32 * The actual allocation of the node is not done by this function. It only
33 * initiates a node by filling it with default parameters. Similarly,
34 * allocation of the different buffers used (IOCTL buffer, data buffer) are
35 * not done by this function either.
38 mwifiex_init_cmd_node(struct mwifiex_private
*priv
,
39 struct cmd_ctrl_node
*cmd_node
,
40 u32 cmd_oid
, void *data_buf
, bool sync
)
42 cmd_node
->priv
= priv
;
43 cmd_node
->cmd_oid
= cmd_oid
;
45 cmd_node
->wait_q_enabled
= true;
46 cmd_node
->cmd_wait_q_woken
= false;
47 cmd_node
->condition
= &cmd_node
->cmd_wait_q_woken
;
49 cmd_node
->data_buf
= data_buf
;
50 cmd_node
->cmd_skb
= cmd_node
->skb
;
54 * This function returns a command node from the free queue depending upon
57 static struct cmd_ctrl_node
*
58 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
60 struct cmd_ctrl_node
*cmd_node
;
63 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
64 if (list_empty(&adapter
->cmd_free_q
)) {
65 mwifiex_dbg(adapter
, ERROR
,
66 "GET_CMD_NODE: cmd node not available\n");
67 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
70 cmd_node
= list_first_entry(&adapter
->cmd_free_q
,
71 struct cmd_ctrl_node
, list
);
72 list_del(&cmd_node
->list
);
73 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
79 * This function cleans up a command node.
81 * The function resets the fields including the buffer pointers.
82 * This function does not try to free the buffers. They must be
83 * freed before calling this function.
85 * This function will however call the receive completion callback
86 * in case a response buffer is still available before resetting
90 mwifiex_clean_cmd_node(struct mwifiex_adapter
*adapter
,
91 struct cmd_ctrl_node
*cmd_node
)
93 cmd_node
->cmd_oid
= 0;
94 cmd_node
->cmd_flag
= 0;
95 cmd_node
->data_buf
= NULL
;
96 cmd_node
->wait_q_enabled
= false;
98 if (cmd_node
->cmd_skb
)
99 skb_trim(cmd_node
->cmd_skb
, 0);
101 if (cmd_node
->resp_skb
) {
102 adapter
->if_ops
.cmdrsp_complete(adapter
, cmd_node
->resp_skb
);
103 cmd_node
->resp_skb
= NULL
;
108 * This function sends a host command to the firmware.
110 * The function copies the host command into the driver command
111 * buffer, which will be transferred to the firmware later by the
114 static int mwifiex_cmd_host_cmd(struct mwifiex_private
*priv
,
115 struct host_cmd_ds_command
*cmd
,
116 struct mwifiex_ds_misc_cmd
*pcmd_ptr
)
118 /* Copy the HOST command to command buffer */
119 memcpy(cmd
, pcmd_ptr
->cmd
, pcmd_ptr
->len
);
120 mwifiex_dbg(priv
->adapter
, CMD
,
121 "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
126 * This function downloads a command to the firmware.
128 * The function performs sanity tests, sets the command sequence
129 * number and size, converts the header fields to CPU format before
130 * sending. Afterwards, it logs the command ID and action for debugging
131 * and sets up the command timeout timer.
133 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
134 struct cmd_ctrl_node
*cmd_node
)
137 struct mwifiex_adapter
*adapter
= priv
->adapter
;
139 struct host_cmd_ds_command
*host_cmd
;
145 if (!adapter
|| !cmd_node
)
148 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
151 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
152 mwifiex_dbg(adapter
, ERROR
,
153 "DNLD_CMD: host_cmd is null\t"
154 "or cmd size is 0, not sending\n");
155 if (cmd_node
->wait_q_enabled
)
156 adapter
->cmd_wait_q
.status
= -1;
157 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
161 cmd_code
= le16_to_cpu(host_cmd
->command
);
162 cmd_size
= le16_to_cpu(host_cmd
->size
);
164 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
&&
165 cmd_code
!= HostCmd_CMD_FUNC_SHUTDOWN
&&
166 cmd_code
!= HostCmd_CMD_FUNC_INIT
) {
167 mwifiex_dbg(adapter
, ERROR
,
168 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
170 if (cmd_node
->wait_q_enabled
)
171 mwifiex_complete_cmd(adapter
, cmd_node
);
172 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
173 queue_work(adapter
->workqueue
, &adapter
->main_work
);
177 /* Set command sequence number */
179 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
181 cmd_node
->priv
->bss_num
,
182 cmd_node
->priv
->bss_type
));
184 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
185 adapter
->curr_cmd
= cmd_node
;
186 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
188 /* Adjust skb length */
189 if (cmd_node
->cmd_skb
->len
> cmd_size
)
191 * cmd_size is less than sizeof(struct host_cmd_ds_command).
192 * Trim off the unused portion.
194 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
195 else if (cmd_node
->cmd_skb
->len
< cmd_size
)
197 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
198 * because we have appended custom IE TLV. Increase skb length
201 skb_put(cmd_node
->cmd_skb
, cmd_size
- cmd_node
->cmd_skb
->len
);
203 mwifiex_dbg(adapter
, CMD
,
204 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
206 le16_to_cpu(*(__le16
*)((u8
*)host_cmd
+ S_DS_GEN
)),
207 cmd_size
, le16_to_cpu(host_cmd
->seq_num
));
208 mwifiex_dbg_dump(adapter
, CMD_D
, "cmd buffer:", host_cmd
, cmd_size
);
210 if (adapter
->iface_type
== MWIFIEX_USB
) {
211 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
212 skb_push(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
213 memcpy(cmd_node
->cmd_skb
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
214 adapter
->cmd_sent
= true;
215 ret
= adapter
->if_ops
.host_to_card(adapter
,
216 MWIFIEX_USB_EP_CMD_EVENT
,
217 cmd_node
->cmd_skb
, NULL
);
218 skb_pull(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
220 cmd_node
->cmd_skb
= NULL
;
222 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
223 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
224 cmd_node
->cmd_skb
, NULL
);
225 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
229 mwifiex_dbg(adapter
, ERROR
,
230 "DNLD_CMD: host to card failed\n");
231 if (adapter
->iface_type
== MWIFIEX_USB
)
232 adapter
->cmd_sent
= false;
233 if (cmd_node
->wait_q_enabled
)
234 adapter
->cmd_wait_q
.status
= -1;
235 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
237 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
238 adapter
->curr_cmd
= NULL
;
239 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
241 adapter
->dbg
.num_cmd_host_to_card_failure
++;
245 /* Save the last command id and action to debug log */
246 adapter
->dbg
.last_cmd_index
=
247 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
248 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
249 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
250 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
252 /* Clear BSS_NO_BITS from HostCmd */
253 cmd_code
&= HostCmd_CMD_ID_MASK
;
255 /* Setup the timer after transmit command */
256 mod_timer(&adapter
->cmd_timer
,
257 jiffies
+ msecs_to_jiffies(MWIFIEX_TIMER_10S
));
263 * This function downloads a sleep confirm command to the firmware.
265 * The function performs sanity tests, sets the command sequence
266 * number and size, converts the header fields to CPU format before
269 * No responses are needed for sleep confirm command.
271 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
274 struct mwifiex_private
*priv
;
275 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
=
276 (struct mwifiex_opt_sleep_confirm
*)
277 adapter
->sleep_cfm
->data
;
278 struct sk_buff
*sleep_cfm_tmp
;
281 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
284 sleep_cfm_buf
->seq_num
=
285 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
286 (adapter
->seq_num
, priv
->bss_num
,
289 mwifiex_dbg(adapter
, CMD
,
290 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
291 le16_to_cpu(sleep_cfm_buf
->command
),
292 le16_to_cpu(sleep_cfm_buf
->action
),
293 le16_to_cpu(sleep_cfm_buf
->size
),
294 le16_to_cpu(sleep_cfm_buf
->seq_num
));
295 mwifiex_dbg_dump(adapter
, CMD_D
, "SLEEP_CFM buffer: ", sleep_cfm_buf
,
296 le16_to_cpu(sleep_cfm_buf
->size
));
298 if (adapter
->iface_type
== MWIFIEX_USB
) {
300 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
302 skb_put(sleep_cfm_tmp
, sizeof(struct mwifiex_opt_sleep_confirm
)
304 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
305 memcpy(sleep_cfm_tmp
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
306 memcpy(sleep_cfm_tmp
->data
+ MWIFIEX_TYPE_LEN
,
307 adapter
->sleep_cfm
->data
,
308 sizeof(struct mwifiex_opt_sleep_confirm
));
309 ret
= adapter
->if_ops
.host_to_card(adapter
,
310 MWIFIEX_USB_EP_CMD_EVENT
,
311 sleep_cfm_tmp
, NULL
);
313 dev_kfree_skb_any(sleep_cfm_tmp
);
315 skb_push(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
316 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
317 adapter
->sleep_cfm
, NULL
);
318 skb_pull(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
322 mwifiex_dbg(adapter
, ERROR
, "SLEEP_CFM: failed\n");
323 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
327 if (!le16_to_cpu(sleep_cfm_buf
->resp_ctrl
))
328 /* Response is not needed for sleep confirm command */
329 adapter
->ps_state
= PS_STATE_SLEEP
;
331 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
333 if (!le16_to_cpu(sleep_cfm_buf
->resp_ctrl
) &&
334 (adapter
->is_hs_configured
&&
335 !adapter
->sleep_period
.period
)) {
336 adapter
->pm_wakeup_card_req
= true;
337 mwifiex_hs_activated_event(mwifiex_get_priv
338 (adapter
, MWIFIEX_BSS_ROLE_ANY
), true);
345 * This function allocates the command buffers and links them to
346 * the command free queue.
348 * The driver uses a pre allocated number of command buffers, which
349 * are created at driver initializations and freed at driver cleanup.
350 * Every command needs to obtain a command buffer from this pool before
351 * it can be issued. The command free queue lists the command buffers
352 * currently free to use, while the command pending queue lists the
353 * command buffers already in use and awaiting handling. Command buffers
354 * are returned to the free queue after use.
356 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
358 struct cmd_ctrl_node
*cmd_array
;
361 /* Allocate and initialize struct cmd_ctrl_node */
362 cmd_array
= kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER
,
363 sizeof(struct cmd_ctrl_node
), GFP_KERNEL
);
367 adapter
->cmd_pool
= cmd_array
;
369 /* Allocate and initialize command buffers */
370 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
371 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
372 if (!cmd_array
[i
].skb
) {
373 mwifiex_dbg(adapter
, ERROR
,
374 "unable to allocate command buffer\n");
379 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
380 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
386 * This function frees the command buffers.
388 * The function calls the completion callback for all the command
389 * buffers that still have response buffers associated with them.
391 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
393 struct cmd_ctrl_node
*cmd_array
;
396 /* Need to check if cmd pool is allocated or not */
397 if (!adapter
->cmd_pool
) {
398 mwifiex_dbg(adapter
, FATAL
,
399 "info: FREE_CMD_BUF: cmd_pool is null\n");
403 cmd_array
= adapter
->cmd_pool
;
405 /* Release shared memory buffers */
406 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
407 if (cmd_array
[i
].skb
) {
408 mwifiex_dbg(adapter
, CMD
,
409 "cmd: free cmd buffer %d\n", i
);
410 dev_kfree_skb_any(cmd_array
[i
].skb
);
412 if (!cmd_array
[i
].resp_skb
)
415 if (adapter
->iface_type
== MWIFIEX_USB
)
416 adapter
->if_ops
.cmdrsp_complete(adapter
,
417 cmd_array
[i
].resp_skb
);
419 dev_kfree_skb_any(cmd_array
[i
].resp_skb
);
421 /* Release struct cmd_ctrl_node */
422 if (adapter
->cmd_pool
) {
423 mwifiex_dbg(adapter
, CMD
,
424 "cmd: free cmd pool\n");
425 kfree(adapter
->cmd_pool
);
426 adapter
->cmd_pool
= NULL
;
433 * This function handles events generated by firmware.
435 * Event body of events received from firmware are not used (though they are
436 * saved), only the event ID is used. Some events are re-invoked by
437 * the driver, with a new event body.
439 * After processing, the function calls the completion callback
442 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
445 struct mwifiex_private
*priv
=
446 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
447 struct sk_buff
*skb
= adapter
->event_skb
;
448 u32 eventcause
= adapter
->event_cause
;
449 struct mwifiex_rxinfo
*rx_info
;
451 /* Save the last event to debug log */
452 adapter
->dbg
.last_event_index
=
453 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
454 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
457 /* Get BSS number and corresponding priv */
458 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
459 EVENT_GET_BSS_TYPE(eventcause
));
461 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
463 /* Clear BSS_NO_BITS from event */
464 eventcause
&= EVENT_ID_MASK
;
465 adapter
->event_cause
= eventcause
;
468 rx_info
= MWIFIEX_SKB_RXCB(skb
);
469 memset(rx_info
, 0, sizeof(*rx_info
));
470 rx_info
->bss_num
= priv
->bss_num
;
471 rx_info
->bss_type
= priv
->bss_type
;
474 mwifiex_dbg(adapter
, EVENT
, "EVENT: cause: %#x\n", eventcause
);
475 mwifiex_dbg_dump(adapter
, EVT_D
, "Event Buf:", skb
->data
, skb
->len
);
477 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
478 ret
= mwifiex_process_uap_event(priv
);
480 ret
= mwifiex_process_sta_event(priv
);
482 adapter
->event_cause
= 0;
483 adapter
->event_skb
= NULL
;
484 adapter
->if_ops
.event_complete(adapter
, skb
);
490 * This function prepares a command and send it to the firmware.
492 * Preparation includes -
493 * - Sanity tests to make sure the card is still present or the FW
495 * - Getting a new command node from the command free queue
496 * - Initializing the command node for default parameters
497 * - Fill up the non-default parameters and buffer pointers
498 * - Add the command to pending queue
500 int mwifiex_send_cmd(struct mwifiex_private
*priv
, u16 cmd_no
,
501 u16 cmd_action
, u32 cmd_oid
, void *data_buf
, bool sync
)
504 struct mwifiex_adapter
*adapter
= priv
->adapter
;
505 struct cmd_ctrl_node
*cmd_node
;
506 struct host_cmd_ds_command
*cmd_ptr
;
509 pr_err("PREP_CMD: adapter is NULL\n");
513 if (adapter
->is_suspended
) {
514 mwifiex_dbg(adapter
, ERROR
,
515 "PREP_CMD: device in suspended state\n");
519 if (adapter
->hs_enabling
&& cmd_no
!= HostCmd_CMD_802_11_HS_CFG_ENH
) {
520 mwifiex_dbg(adapter
, ERROR
,
521 "PREP_CMD: host entering sleep state\n");
525 if (adapter
->surprise_removed
) {
526 mwifiex_dbg(adapter
, ERROR
,
527 "PREP_CMD: card is removed\n");
531 if (adapter
->is_cmd_timedout
) {
532 mwifiex_dbg(adapter
, ERROR
,
533 "PREP_CMD: FW is in bad state\n");
537 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
538 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
539 mwifiex_dbg(adapter
, ERROR
,
540 "PREP_CMD: FW in reset state\n");
545 /* Get a new command node */
546 cmd_node
= mwifiex_get_cmd_node(adapter
);
549 mwifiex_dbg(adapter
, ERROR
,
550 "PREP_CMD: no free cmd node\n");
554 /* Initialize the command node */
555 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
, sync
);
557 if (!cmd_node
->cmd_skb
) {
558 mwifiex_dbg(adapter
, ERROR
,
559 "PREP_CMD: no free cmd buf\n");
563 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
564 0, sizeof(struct host_cmd_ds_command
));
566 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
567 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
570 /* Prepare command */
573 case HostCmd_CMD_UAP_SYS_CONFIG
:
574 case HostCmd_CMD_UAP_BSS_START
:
575 case HostCmd_CMD_UAP_BSS_STOP
:
576 case HostCmd_CMD_UAP_STA_DEAUTH
:
577 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
582 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
588 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
589 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
592 /* Return error, since the command preparation failed */
594 mwifiex_dbg(adapter
, ERROR
,
595 "PREP_CMD: cmd %#x preparation failed\n",
597 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
602 if (cmd_no
== HostCmd_CMD_802_11_SCAN
||
603 cmd_no
== HostCmd_CMD_802_11_SCAN_EXT
) {
604 mwifiex_queue_scan_cmd(priv
, cmd_node
);
606 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
607 queue_work(adapter
->workqueue
, &adapter
->main_work
);
608 if (cmd_node
->wait_q_enabled
)
609 ret
= mwifiex_wait_queue_complete(adapter
, cmd_node
);
616 * This function returns a command to the command free queue.
618 * The function also calls the completion callback if required, before
619 * cleaning the command node and re-inserting it into the free queue.
622 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
623 struct cmd_ctrl_node
*cmd_node
)
630 if (cmd_node
->wait_q_enabled
)
631 mwifiex_complete_cmd(adapter
, cmd_node
);
633 mwifiex_clean_cmd_node(adapter
, cmd_node
);
635 /* Insert node into cmd_free_q */
636 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
637 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
638 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
641 /* This function reuses a command node. */
642 void mwifiex_recycle_cmd_node(struct mwifiex_adapter
*adapter
,
643 struct cmd_ctrl_node
*cmd_node
)
645 struct host_cmd_ds_command
*host_cmd
= (void *)cmd_node
->cmd_skb
->data
;
647 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
649 atomic_dec(&adapter
->cmd_pending
);
650 mwifiex_dbg(adapter
, CMD
,
651 "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
652 le16_to_cpu(host_cmd
->command
),
653 atomic_read(&adapter
->cmd_pending
));
657 * This function queues a command to the command pending queue.
659 * This in effect adds the command to the command list to be executed.
660 * Exit PS command is handled specially, by placing it always to the
661 * front of the command queue.
664 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
665 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
667 struct host_cmd_ds_command
*host_cmd
= NULL
;
671 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
673 mwifiex_dbg(adapter
, ERROR
, "QUEUE_CMD: host_cmd is NULL\n");
677 command
= le16_to_cpu(host_cmd
->command
);
679 /* Exit_PS command needs to be queued in the header always. */
680 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
681 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
682 &host_cmd
->params
.psmode_enh
;
683 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
684 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
685 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
690 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
692 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
694 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
695 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
697 atomic_inc(&adapter
->cmd_pending
);
698 mwifiex_dbg(adapter
, CMD
,
699 "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
700 command
, atomic_read(&adapter
->cmd_pending
));
704 * This function executes the next command in command pending queue.
706 * This function will fail if a command is already in processing stage,
707 * otherwise it will dequeue the first command from the command pending
708 * queue and send to the firmware.
710 * If the device is currently in host sleep mode, any commands, except the
711 * host sleep configuration command will de-activate the host sleep. For PS
712 * mode, the function will put the firmware back to sleep if applicable.
714 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
716 struct mwifiex_private
*priv
;
717 struct cmd_ctrl_node
*cmd_node
;
719 struct host_cmd_ds_command
*host_cmd
;
720 unsigned long cmd_flags
;
721 unsigned long cmd_pending_q_flags
;
723 /* Check if already in processing */
724 if (adapter
->curr_cmd
) {
725 mwifiex_dbg(adapter
, FATAL
,
726 "EXEC_NEXT_CMD: cmd in processing\n");
730 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
731 /* Check if any command is pending */
732 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
733 if (list_empty(&adapter
->cmd_pending_q
)) {
734 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
735 cmd_pending_q_flags
);
736 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
739 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
740 struct cmd_ctrl_node
, list
);
741 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
742 cmd_pending_q_flags
);
744 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
745 priv
= cmd_node
->priv
;
747 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
748 mwifiex_dbg(adapter
, ERROR
,
749 "%s: cannot send cmd in sleep state,\t"
750 "this should not happen\n", __func__
);
751 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
755 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
756 list_del(&cmd_node
->list
);
757 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
758 cmd_pending_q_flags
);
760 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
761 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
762 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
763 /* Any command sent to the firmware when host is in sleep
764 * mode should de-configure host sleep. We should skip the
765 * host sleep configuration command itself though
767 if (priv
&& (host_cmd
->command
!=
768 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
769 if (adapter
->hs_activated
) {
770 adapter
->is_hs_configured
= false;
771 mwifiex_hs_activated_event(priv
, false);
779 * This function handles the command response.
781 * After processing, the function cleans the command node and puts
782 * it back to the command free queue.
784 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
786 struct host_cmd_ds_command
*resp
;
787 struct mwifiex_private
*priv
=
788 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
790 uint16_t orig_cmdresp_no
;
792 uint16_t cmdresp_result
;
795 /* Now we got response from FW, cancel the command timer */
796 del_timer_sync(&adapter
->cmd_timer
);
798 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
799 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
800 mwifiex_dbg(adapter
, ERROR
,
801 "CMD_RESP: NULL curr_cmd, %#x\n",
802 le16_to_cpu(resp
->command
));
806 adapter
->is_cmd_timedout
= 0;
808 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
809 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
810 mwifiex_dbg(adapter
, ERROR
,
811 "CMD_RESP: %#x been canceled\n",
812 le16_to_cpu(resp
->command
));
813 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
814 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
815 adapter
->curr_cmd
= NULL
;
816 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
820 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
821 /* Copy original response back to response buffer */
822 struct mwifiex_ds_misc_cmd
*hostcmd
;
823 uint16_t size
= le16_to_cpu(resp
->size
);
824 mwifiex_dbg(adapter
, INFO
,
825 "info: host cmd resp size = %d\n", size
);
826 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
827 if (adapter
->curr_cmd
->data_buf
) {
828 hostcmd
= adapter
->curr_cmd
->data_buf
;
830 memcpy(hostcmd
->cmd
, resp
, size
);
833 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
835 /* Get BSS number and corresponding priv */
836 priv
= mwifiex_get_priv_by_id(adapter
,
837 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
838 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
840 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
841 /* Clear RET_BIT from HostCmd */
842 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
844 cmdresp_no
= le16_to_cpu(resp
->command
);
845 cmdresp_result
= le16_to_cpu(resp
->result
);
847 /* Save the last command response to debug log */
848 adapter
->dbg
.last_cmd_resp_index
=
849 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
850 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
853 mwifiex_dbg(adapter
, CMD
,
854 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
855 orig_cmdresp_no
, cmdresp_result
,
856 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
857 mwifiex_dbg_dump(adapter
, CMD_D
, "CMD_RESP buffer:", resp
,
858 le16_to_cpu(resp
->size
));
860 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
861 mwifiex_dbg(adapter
, ERROR
, "CMD_RESP: invalid cmd resp\n");
862 if (adapter
->curr_cmd
->wait_q_enabled
)
863 adapter
->cmd_wait_q
.status
= -1;
865 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
866 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
867 adapter
->curr_cmd
= NULL
;
868 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
872 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
873 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
874 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
875 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
876 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
878 /* handle response */
879 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
882 /* Check init command response */
883 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
885 mwifiex_dbg(adapter
, ERROR
,
886 "%s: cmd %#x failed during\t"
887 "initialization\n", __func__
, cmdresp_no
);
888 mwifiex_init_fw_complete(adapter
);
890 } else if (adapter
->last_init_cmd
== cmdresp_no
)
891 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
894 if (adapter
->curr_cmd
) {
895 if (adapter
->curr_cmd
->wait_q_enabled
)
896 adapter
->cmd_wait_q
.status
= ret
;
898 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
900 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
901 adapter
->curr_cmd
= NULL
;
902 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
909 * This function handles the timeout of command sending.
911 * It will re-send the same command again.
914 mwifiex_cmd_timeout_func(unsigned long function_context
)
916 struct mwifiex_adapter
*adapter
=
917 (struct mwifiex_adapter
*) function_context
;
918 struct cmd_ctrl_node
*cmd_node
;
920 adapter
->is_cmd_timedout
= 1;
921 if (!adapter
->curr_cmd
) {
922 mwifiex_dbg(adapter
, ERROR
,
923 "cmd: empty curr_cmd\n");
926 cmd_node
= adapter
->curr_cmd
;
928 adapter
->dbg
.timeout_cmd_id
=
929 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
930 adapter
->dbg
.timeout_cmd_act
=
931 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
932 mwifiex_dbg(adapter
, MSG
,
933 "%s: Timeout cmd id = %#x, act = %#x\n", __func__
,
934 adapter
->dbg
.timeout_cmd_id
,
935 adapter
->dbg
.timeout_cmd_act
);
937 mwifiex_dbg(adapter
, MSG
,
938 "num_data_h2c_failure = %d\n",
939 adapter
->dbg
.num_tx_host_to_card_failure
);
940 mwifiex_dbg(adapter
, MSG
,
941 "num_cmd_h2c_failure = %d\n",
942 adapter
->dbg
.num_cmd_host_to_card_failure
);
944 mwifiex_dbg(adapter
, MSG
,
945 "is_cmd_timedout = %d\n",
946 adapter
->is_cmd_timedout
);
947 mwifiex_dbg(adapter
, MSG
,
948 "num_tx_timeout = %d\n",
949 adapter
->dbg
.num_tx_timeout
);
951 mwifiex_dbg(adapter
, MSG
,
952 "last_cmd_index = %d\n",
953 adapter
->dbg
.last_cmd_index
);
954 mwifiex_dbg(adapter
, MSG
,
955 "last_cmd_id: %*ph\n",
956 (int)sizeof(adapter
->dbg
.last_cmd_id
),
957 adapter
->dbg
.last_cmd_id
);
958 mwifiex_dbg(adapter
, MSG
,
959 "last_cmd_act: %*ph\n",
960 (int)sizeof(adapter
->dbg
.last_cmd_act
),
961 adapter
->dbg
.last_cmd_act
);
963 mwifiex_dbg(adapter
, MSG
,
964 "last_cmd_resp_index = %d\n",
965 adapter
->dbg
.last_cmd_resp_index
);
966 mwifiex_dbg(adapter
, MSG
,
967 "last_cmd_resp_id: %*ph\n",
968 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
969 adapter
->dbg
.last_cmd_resp_id
);
971 mwifiex_dbg(adapter
, MSG
,
972 "last_event_index = %d\n",
973 adapter
->dbg
.last_event_index
);
974 mwifiex_dbg(adapter
, MSG
,
975 "last_event: %*ph\n",
976 (int)sizeof(adapter
->dbg
.last_event
),
977 adapter
->dbg
.last_event
);
979 mwifiex_dbg(adapter
, MSG
,
980 "data_sent=%d cmd_sent=%d\n",
981 adapter
->data_sent
, adapter
->cmd_sent
);
983 mwifiex_dbg(adapter
, MSG
,
984 "ps_mode=%d ps_state=%d\n",
985 adapter
->ps_mode
, adapter
->ps_state
);
987 if (cmd_node
->wait_q_enabled
) {
988 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
989 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
990 mwifiex_cancel_pending_ioctl(adapter
);
993 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
994 mwifiex_init_fw_complete(adapter
);
996 if (adapter
->if_ops
.device_dump
)
997 adapter
->if_ops
.device_dump(adapter
);
999 if (adapter
->if_ops
.card_reset
)
1000 adapter
->if_ops
.card_reset(adapter
);
1004 * This function cancels all the pending commands.
1006 * The current command, all commands in command pending queue and all scan
1007 * commands in scan pending queue are cancelled. All the completion callbacks
1008 * are called with failure status to ensure cleanup.
1011 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
1013 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
1014 unsigned long flags
, cmd_flags
;
1015 struct mwifiex_private
*priv
;
1018 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1019 /* Cancel current cmd */
1020 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
1021 adapter
->curr_cmd
->wait_q_enabled
= false;
1022 adapter
->cmd_wait_q
.status
= -1;
1023 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1025 /* Cancel all pending command */
1026 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1027 list_for_each_entry_safe(cmd_node
, tmp_node
,
1028 &adapter
->cmd_pending_q
, list
) {
1029 list_del(&cmd_node
->list
);
1030 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1032 if (cmd_node
->wait_q_enabled
) {
1033 adapter
->cmd_wait_q
.status
= -1;
1034 mwifiex_complete_cmd(adapter
, cmd_node
);
1035 cmd_node
->wait_q_enabled
= false;
1037 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1038 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1040 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1041 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1043 /* Cancel all pending scan command */
1044 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1045 list_for_each_entry_safe(cmd_node
, tmp_node
,
1046 &adapter
->scan_pending_q
, list
) {
1047 list_del(&cmd_node
->list
);
1049 cmd_node
->wait_q_enabled
= false;
1050 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1052 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1054 if (adapter
->scan_processing
) {
1055 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1056 adapter
->scan_processing
= false;
1057 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1058 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1059 priv
= adapter
->priv
[i
];
1062 if (priv
->scan_request
) {
1063 mwifiex_dbg(adapter
, WARN
, "info: aborting scan\n");
1064 cfg80211_scan_done(priv
->scan_request
, 1);
1065 priv
->scan_request
= NULL
;
1072 * This function cancels all pending commands that matches with
1073 * the given IOCTL request.
1075 * Both the current command buffer and the pending command queue are
1076 * searched for matching IOCTL request. The completion callback of
1077 * the matched command is called with failure status to ensure cleanup.
1078 * In case of scan commands, all pending commands in scan pending queue
1082 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1084 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1085 unsigned long cmd_flags
;
1086 unsigned long scan_pending_q_flags
;
1087 struct mwifiex_private
*priv
;
1090 if ((adapter
->curr_cmd
) &&
1091 (adapter
->curr_cmd
->wait_q_enabled
)) {
1092 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1093 cmd_node
= adapter
->curr_cmd
;
1094 cmd_node
->wait_q_enabled
= false;
1095 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1096 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1097 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1098 adapter
->curr_cmd
= NULL
;
1099 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1102 /* Cancel all pending scan command */
1103 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1104 scan_pending_q_flags
);
1105 list_for_each_entry_safe(cmd_node
, tmp_node
,
1106 &adapter
->scan_pending_q
, list
) {
1107 list_del(&cmd_node
->list
);
1108 cmd_node
->wait_q_enabled
= false;
1109 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1111 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1112 scan_pending_q_flags
);
1114 if (adapter
->scan_processing
) {
1115 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1116 adapter
->scan_processing
= false;
1117 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1118 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1119 priv
= adapter
->priv
[i
];
1122 if (priv
->scan_request
) {
1123 mwifiex_dbg(adapter
, WARN
, "info: aborting scan\n");
1124 cfg80211_scan_done(priv
->scan_request
, 1);
1125 priv
->scan_request
= NULL
;
1129 adapter
->cmd_wait_q
.status
= -1;
1133 * This function sends the sleep confirm command to firmware, if
1136 * The sleep confirm command cannot be issued if command response,
1137 * data response or event response is awaiting handling, or if we
1138 * are in the middle of sending a command, or expecting a command
1142 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1144 if (!adapter
->cmd_sent
&&
1145 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1146 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1148 mwifiex_dbg(adapter
, CMD
,
1149 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1150 (adapter
->cmd_sent
) ? "D" : "",
1151 (adapter
->curr_cmd
) ? "C" : "",
1152 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1156 * This function sends a Host Sleep activated event to applications.
1158 * This event is generated by the driver, with a blank event body.
1161 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1164 if (priv
->adapter
->is_hs_configured
) {
1165 priv
->adapter
->hs_activated
= true;
1166 mwifiex_update_rxreor_flags(priv
->adapter
,
1167 RXREOR_FORCE_NO_DROP
);
1168 mwifiex_dbg(priv
->adapter
, EVENT
,
1169 "event: hs_activated\n");
1170 priv
->adapter
->hs_activate_wait_q_woken
= true;
1171 wake_up_interruptible(
1172 &priv
->adapter
->hs_activate_wait_q
);
1174 mwifiex_dbg(priv
->adapter
, EVENT
,
1175 "event: HS not configured\n");
1178 mwifiex_dbg(priv
->adapter
, EVENT
,
1179 "event: hs_deactivated\n");
1180 priv
->adapter
->hs_activated
= false;
1185 * This function handles the command response of a Host Sleep configuration
1188 * Handling includes changing the header fields into CPU format
1189 * and setting the current host sleep activation status in driver.
1191 * In case host sleep status change, the function generates an event to
1192 * notify the applications.
1194 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1195 struct host_cmd_ds_command
*resp
)
1197 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1198 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1199 &resp
->params
.opt_hs_cfg
;
1200 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1202 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1203 adapter
->iface_type
!= MWIFIEX_USB
) {
1204 mwifiex_hs_activated_event(priv
, true);
1207 mwifiex_dbg(adapter
, CMD
,
1208 "cmd: CMD_RESP: HS_CFG cmd reply\t"
1209 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1210 resp
->result
, conditions
,
1211 phs_cfg
->params
.hs_config
.gpio
,
1212 phs_cfg
->params
.hs_config
.gap
);
1214 if (conditions
!= HS_CFG_CANCEL
) {
1215 adapter
->is_hs_configured
= true;
1216 if (adapter
->iface_type
== MWIFIEX_USB
)
1217 mwifiex_hs_activated_event(priv
, true);
1219 adapter
->is_hs_configured
= false;
1220 if (adapter
->hs_activated
)
1221 mwifiex_hs_activated_event(priv
, false);
1228 * This function wakes up the adapter and generates a Host Sleep
1229 * cancel event on receiving the power up interrupt.
1232 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1234 mwifiex_dbg(adapter
, INFO
,
1235 "info: %s: auto cancelling host sleep\t"
1236 "since there is interrupt from the firmware\n",
1239 adapter
->if_ops
.wakeup(adapter
);
1240 adapter
->hs_activated
= false;
1241 adapter
->is_hs_configured
= false;
1242 adapter
->is_suspended
= false;
1243 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1244 MWIFIEX_BSS_ROLE_ANY
),
1247 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1250 * This function handles the command response of a sleep confirm command.
1252 * The function sets the card state to SLEEP if the response indicates success.
1255 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1256 u8
*pbuf
, u32 upld_len
)
1258 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1259 struct mwifiex_private
*priv
=
1260 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1261 uint16_t result
= le16_to_cpu(cmd
->result
);
1262 uint16_t command
= le16_to_cpu(cmd
->command
);
1263 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1266 mwifiex_dbg(adapter
, ERROR
,
1267 "%s: cmd size is 0\n", __func__
);
1271 mwifiex_dbg(adapter
, CMD
,
1272 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
1273 command
, result
, le16_to_cpu(cmd
->size
), seq_num
);
1275 /* Get BSS number and corresponding priv */
1276 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1277 HostCmd_GET_BSS_TYPE(seq_num
));
1279 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1281 /* Update sequence number */
1282 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1283 /* Clear RET_BIT from HostCmd */
1284 command
&= HostCmd_CMD_ID_MASK
;
1286 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1287 mwifiex_dbg(adapter
, ERROR
,
1288 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1289 __func__
, command
, result
);
1294 mwifiex_dbg(adapter
, ERROR
,
1295 "%s: sleep confirm cmd failed\n",
1297 adapter
->pm_wakeup_card_req
= false;
1298 adapter
->ps_state
= PS_STATE_AWAKE
;
1301 adapter
->pm_wakeup_card_req
= true;
1302 if (adapter
->is_hs_configured
)
1303 mwifiex_hs_activated_event(mwifiex_get_priv
1304 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1306 adapter
->ps_state
= PS_STATE_SLEEP
;
1307 cmd
->command
= cpu_to_le16(command
);
1308 cmd
->seq_num
= cpu_to_le16(seq_num
);
1310 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1313 * This function prepares an enhanced power mode command.
1315 * This function can be used to disable power save or to configure
1316 * power save with auto PS or STA PS or auto deep sleep.
1318 * Preparation includes -
1319 * - Setting command ID, action and proper size
1320 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1321 * auto deep sleep TLV (as required)
1322 * - Ensuring correct endian-ness
1324 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1325 struct host_cmd_ds_command
*cmd
,
1326 u16 cmd_action
, uint16_t ps_bitmap
,
1327 struct mwifiex_ds_auto_ds
*auto_ds
)
1329 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1330 &cmd
->params
.psmode_enh
;
1334 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1335 if (cmd_action
== DIS_AUTO_PS
) {
1336 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1337 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1338 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1339 sizeof(psmode_enh
->params
.ps_bitmap
));
1340 } else if (cmd_action
== GET_PS
) {
1341 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1342 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1343 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1344 sizeof(psmode_enh
->params
.ps_bitmap
));
1345 } else if (cmd_action
== EN_AUTO_PS
) {
1346 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1347 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1348 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1349 sizeof(psmode_enh
->params
.ps_bitmap
);
1350 tlv
= (u8
*) cmd
+ cmd_size
;
1351 if (ps_bitmap
& BITMAP_STA_PS
) {
1352 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1353 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1354 (struct mwifiex_ie_types_ps_param
*) tlv
;
1355 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1356 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1357 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1358 sizeof(struct mwifiex_ie_types_header
));
1359 cmd_size
+= sizeof(*ps_tlv
);
1360 tlv
+= sizeof(*ps_tlv
);
1361 mwifiex_dbg(priv
->adapter
, CMD
,
1362 "cmd: PS Command: Enter PS\n");
1363 ps_mode
->null_pkt_interval
=
1364 cpu_to_le16(adapter
->null_pkt_interval
);
1365 ps_mode
->multiple_dtims
=
1366 cpu_to_le16(adapter
->multiple_dtim
);
1367 ps_mode
->bcn_miss_timeout
=
1368 cpu_to_le16(adapter
->bcn_miss_time_out
);
1369 ps_mode
->local_listen_interval
=
1370 cpu_to_le16(adapter
->local_listen_interval
);
1371 ps_mode
->adhoc_wake_period
=
1372 cpu_to_le16(adapter
->adhoc_awake_period
);
1373 ps_mode
->delay_to_ps
=
1374 cpu_to_le16(adapter
->delay_to_ps
);
1375 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1378 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1379 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1380 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1383 auto_ds_tlv
->header
.type
=
1384 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1385 auto_ds_tlv
->header
.len
=
1386 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1387 sizeof(struct mwifiex_ie_types_header
));
1388 cmd_size
+= sizeof(*auto_ds_tlv
);
1389 tlv
+= sizeof(*auto_ds_tlv
);
1391 idletime
= auto_ds
->idle_time
;
1392 mwifiex_dbg(priv
->adapter
, CMD
,
1393 "cmd: PS Command: Enter Auto Deep Sleep\n");
1394 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1396 cmd
->size
= cpu_to_le16(cmd_size
);
1402 * This function handles the command response of an enhanced power mode
1405 * Handling includes changing the header fields into CPU format
1406 * and setting the current enhanced power mode in driver.
1408 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1409 struct host_cmd_ds_command
*resp
,
1410 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1412 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1413 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1414 &resp
->params
.psmode_enh
;
1415 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1416 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1417 uint16_t auto_ps_bitmap
=
1418 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1420 mwifiex_dbg(adapter
, INFO
,
1421 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1422 __func__
, resp
->result
, action
);
1423 if (action
== EN_AUTO_PS
) {
1424 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1425 mwifiex_dbg(adapter
, CMD
,
1426 "cmd: Enabled auto deep sleep\n");
1427 priv
->adapter
->is_deep_sleep
= true;
1429 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1430 mwifiex_dbg(adapter
, CMD
,
1431 "cmd: Enabled STA power save\n");
1432 if (adapter
->sleep_period
.period
)
1433 mwifiex_dbg(adapter
, CMD
,
1434 "cmd: set to uapsd/pps mode\n");
1436 } else if (action
== DIS_AUTO_PS
) {
1437 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1438 priv
->adapter
->is_deep_sleep
= false;
1439 mwifiex_dbg(adapter
, CMD
,
1440 "cmd: Disabled auto deep sleep\n");
1442 if (ps_bitmap
& BITMAP_STA_PS
) {
1443 mwifiex_dbg(adapter
, CMD
,
1444 "cmd: Disabled STA power save\n");
1445 if (adapter
->sleep_period
.period
) {
1446 adapter
->delay_null_pkt
= false;
1447 adapter
->tx_lock_flag
= false;
1448 adapter
->pps_uapsd_mode
= false;
1451 } else if (action
== GET_PS
) {
1452 if (ps_bitmap
& BITMAP_STA_PS
)
1453 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1455 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1457 mwifiex_dbg(adapter
, CMD
,
1458 "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1461 /* This section is for get power save mode */
1462 if (ps_bitmap
& BITMAP_STA_PS
)
1463 pm_cfg
->param
.ps_mode
= 1;
1465 pm_cfg
->param
.ps_mode
= 0;
1472 * This function prepares command to get hardware specifications.
1474 * Preparation includes -
1475 * - Setting command ID, action and proper size
1476 * - Setting permanent address parameter
1477 * - Ensuring correct endian-ness
1479 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1480 struct host_cmd_ds_command
*cmd
)
1482 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1484 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1486 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1487 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1493 * This function handles the command response of get hardware
1496 * Handling includes changing the header fields into CPU format
1497 * and saving/updating the following parameters in driver -
1498 * - Firmware capability information
1499 * - Firmware band settings
1500 * - Ad-hoc start band and channel
1501 * - Ad-hoc 11n activation status
1502 * - Firmware release number
1503 * - Number of antennas
1504 * - Hardware address
1505 * - Hardware interface version
1506 * - Firmware version
1508 * - 11n capabilities
1509 * - MCS support fields
1512 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1513 struct host_cmd_ds_command
*resp
)
1515 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1516 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1517 struct mwifiex_ie_types_header
*tlv
;
1518 struct hw_spec_api_rev
*api_rev
;
1519 u16 resp_size
, api_id
;
1520 int i
, left_len
, parsed_len
= 0;
1522 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1524 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1525 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1527 adapter
->fw_bands
= BAND_B
;
1529 adapter
->config_bands
= adapter
->fw_bands
;
1531 if (adapter
->fw_bands
& BAND_A
) {
1532 if (adapter
->fw_bands
& BAND_GN
) {
1533 adapter
->config_bands
|= BAND_AN
;
1534 adapter
->fw_bands
|= BAND_AN
;
1536 if (adapter
->fw_bands
& BAND_AN
) {
1537 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1538 adapter
->adhoc_11n_enabled
= true;
1540 adapter
->adhoc_start_band
= BAND_A
;
1542 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1543 } else if (adapter
->fw_bands
& BAND_GN
) {
1544 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1545 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1546 adapter
->adhoc_11n_enabled
= true;
1547 } else if (adapter
->fw_bands
& BAND_G
) {
1548 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1549 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1550 } else if (adapter
->fw_bands
& BAND_B
) {
1551 adapter
->adhoc_start_band
= BAND_B
;
1552 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1555 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1556 adapter
->fw_api_ver
= (adapter
->fw_release_number
>> 16) & 0xff;
1557 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1559 if (le32_to_cpu(hw_spec
->dot_11ac_dev_cap
)) {
1560 adapter
->is_hw_11ac_capable
= true;
1563 adapter
->hw_dot_11ac_dev_cap
=
1564 le32_to_cpu(hw_spec
->dot_11ac_dev_cap
);
1565 adapter
->usr_dot_11ac_dev_cap_bg
= adapter
->hw_dot_11ac_dev_cap
1566 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1567 adapter
->usr_dot_11ac_dev_cap_a
= adapter
->hw_dot_11ac_dev_cap
1568 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1571 adapter
->hw_dot_11ac_mcs_support
=
1572 le32_to_cpu(hw_spec
->dot_11ac_mcs_support
);
1573 adapter
->usr_dot_11ac_mcs_support
=
1574 adapter
->hw_dot_11ac_mcs_support
;
1576 adapter
->is_hw_11ac_capable
= false;
1579 resp_size
= le16_to_cpu(resp
->size
) - S_DS_GEN
;
1580 if (resp_size
> sizeof(struct host_cmd_ds_get_hw_spec
)) {
1581 /* we have variable HW SPEC information */
1582 left_len
= resp_size
- sizeof(struct host_cmd_ds_get_hw_spec
);
1583 while (left_len
> sizeof(struct mwifiex_ie_types_header
)) {
1584 tlv
= (void *)&hw_spec
->tlvs
+ parsed_len
;
1585 switch (le16_to_cpu(tlv
->type
)) {
1586 case TLV_TYPE_API_REV
:
1587 api_rev
= (struct hw_spec_api_rev
*)tlv
;
1588 api_id
= le16_to_cpu(api_rev
->api_id
);
1590 case KEY_API_VER_ID
:
1591 adapter
->key_api_major_ver
=
1593 adapter
->key_api_minor_ver
=
1595 mwifiex_dbg(adapter
, INFO
,
1597 adapter
->key_api_major_ver
,
1598 adapter
->key_api_minor_ver
);
1601 adapter
->fw_api_ver
=
1603 mwifiex_dbg(adapter
, INFO
,
1604 "Firmware api version %d\n",
1605 adapter
->fw_api_ver
);
1608 mwifiex_dbg(adapter
, FATAL
,
1609 "Unknown api_id: %d\n",
1615 mwifiex_dbg(adapter
, FATAL
,
1616 "Unknown GET_HW_SPEC TLV type: %#x\n",
1617 le16_to_cpu(tlv
->type
));
1620 parsed_len
+= le16_to_cpu(tlv
->len
) +
1621 sizeof(struct mwifiex_ie_types_header
);
1622 left_len
-= le16_to_cpu(tlv
->len
) +
1623 sizeof(struct mwifiex_ie_types_header
);
1627 mwifiex_dbg(adapter
, INFO
,
1628 "info: GET_HW_SPEC: fw_release_number- %#x\n",
1629 adapter
->fw_release_number
);
1630 mwifiex_dbg(adapter
, INFO
,
1631 "info: GET_HW_SPEC: permanent addr: %pM\n",
1632 hw_spec
->permanent_addr
);
1633 mwifiex_dbg(adapter
, INFO
,
1634 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1635 le16_to_cpu(hw_spec
->hw_if_version
),
1636 le16_to_cpu(hw_spec
->version
));
1638 ether_addr_copy(priv
->adapter
->perm_addr
, hw_spec
->permanent_addr
);
1639 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1641 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1642 /* Use the region code to search for the index */
1643 if (adapter
->region_code
== region_code_index
[i
])
1646 /* If it's unidentified region code, use the default (USA) */
1647 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1648 adapter
->region_code
= 0x10;
1649 mwifiex_dbg(adapter
, WARN
,
1650 "cmd: unknown region code, use default (USA)\n");
1653 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1654 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1655 adapter
->user_dev_mcs_support
= adapter
->hw_dev_mcs_support
;
1657 if (adapter
->if_ops
.update_mp_end_port
)
1658 adapter
->if_ops
.update_mp_end_port(adapter
,
1659 le16_to_cpu(hw_spec
->mp_end_port
));
1661 if (adapter
->fw_api_ver
== MWIFIEX_FW_V15
)
1662 adapter
->scan_chan_gap_enabled
= true;