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
;
472 mwifiex_dbg_dump(adapter
, EVT_D
, "Event Buf:",
473 skb
->data
, skb
->len
);
476 mwifiex_dbg(adapter
, EVENT
, "EVENT: cause: %#x\n", eventcause
);
478 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
479 ret
= mwifiex_process_uap_event(priv
);
481 ret
= mwifiex_process_sta_event(priv
);
483 adapter
->event_cause
= 0;
484 adapter
->event_skb
= NULL
;
485 adapter
->if_ops
.event_complete(adapter
, skb
);
491 * This function prepares a command and send it to the firmware.
493 * Preparation includes -
494 * - Sanity tests to make sure the card is still present or the FW
496 * - Getting a new command node from the command free queue
497 * - Initializing the command node for default parameters
498 * - Fill up the non-default parameters and buffer pointers
499 * - Add the command to pending queue
501 int mwifiex_send_cmd(struct mwifiex_private
*priv
, u16 cmd_no
,
502 u16 cmd_action
, u32 cmd_oid
, void *data_buf
, bool sync
)
505 struct mwifiex_adapter
*adapter
= priv
->adapter
;
506 struct cmd_ctrl_node
*cmd_node
;
507 struct host_cmd_ds_command
*cmd_ptr
;
510 pr_err("PREP_CMD: adapter is NULL\n");
514 if (adapter
->is_suspended
) {
515 mwifiex_dbg(adapter
, ERROR
,
516 "PREP_CMD: device in suspended state\n");
520 if (adapter
->hs_enabling
&& cmd_no
!= HostCmd_CMD_802_11_HS_CFG_ENH
) {
521 mwifiex_dbg(adapter
, ERROR
,
522 "PREP_CMD: host entering sleep state\n");
526 if (adapter
->surprise_removed
) {
527 mwifiex_dbg(adapter
, ERROR
,
528 "PREP_CMD: card is removed\n");
532 if (adapter
->is_cmd_timedout
) {
533 mwifiex_dbg(adapter
, ERROR
,
534 "PREP_CMD: FW is in bad state\n");
538 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
539 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
540 mwifiex_dbg(adapter
, ERROR
,
541 "PREP_CMD: FW in reset state\n");
546 /* Get a new command node */
547 cmd_node
= mwifiex_get_cmd_node(adapter
);
550 mwifiex_dbg(adapter
, ERROR
,
551 "PREP_CMD: no free cmd node\n");
555 /* Initialize the command node */
556 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
, sync
);
558 if (!cmd_node
->cmd_skb
) {
559 mwifiex_dbg(adapter
, ERROR
,
560 "PREP_CMD: no free cmd buf\n");
564 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
565 0, sizeof(struct host_cmd_ds_command
));
567 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
568 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
571 /* Prepare command */
574 case HostCmd_CMD_UAP_SYS_CONFIG
:
575 case HostCmd_CMD_UAP_BSS_START
:
576 case HostCmd_CMD_UAP_BSS_STOP
:
577 case HostCmd_CMD_UAP_STA_DEAUTH
:
578 case HOST_CMD_APCMD_SYS_RESET
:
579 case HOST_CMD_APCMD_STA_LIST
:
580 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
585 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
591 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
592 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
595 /* Return error, since the command preparation failed */
597 mwifiex_dbg(adapter
, ERROR
,
598 "PREP_CMD: cmd %#x preparation failed\n",
600 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
605 if (cmd_no
== HostCmd_CMD_802_11_SCAN
||
606 cmd_no
== HostCmd_CMD_802_11_SCAN_EXT
) {
607 mwifiex_queue_scan_cmd(priv
, cmd_node
);
609 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
610 queue_work(adapter
->workqueue
, &adapter
->main_work
);
611 if (cmd_node
->wait_q_enabled
)
612 ret
= mwifiex_wait_queue_complete(adapter
, cmd_node
);
619 * This function returns a command to the command free queue.
621 * The function also calls the completion callback if required, before
622 * cleaning the command node and re-inserting it into the free queue.
625 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
626 struct cmd_ctrl_node
*cmd_node
)
633 if (cmd_node
->wait_q_enabled
)
634 mwifiex_complete_cmd(adapter
, cmd_node
);
636 mwifiex_clean_cmd_node(adapter
, cmd_node
);
638 /* Insert node into cmd_free_q */
639 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
640 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
641 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
644 /* This function reuses a command node. */
645 void mwifiex_recycle_cmd_node(struct mwifiex_adapter
*adapter
,
646 struct cmd_ctrl_node
*cmd_node
)
648 struct host_cmd_ds_command
*host_cmd
= (void *)cmd_node
->cmd_skb
->data
;
650 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
652 atomic_dec(&adapter
->cmd_pending
);
653 mwifiex_dbg(adapter
, CMD
,
654 "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
655 le16_to_cpu(host_cmd
->command
),
656 atomic_read(&adapter
->cmd_pending
));
660 * This function queues a command to the command pending queue.
662 * This in effect adds the command to the command list to be executed.
663 * Exit PS command is handled specially, by placing it always to the
664 * front of the command queue.
667 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
668 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
670 struct host_cmd_ds_command
*host_cmd
= NULL
;
674 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
676 mwifiex_dbg(adapter
, ERROR
, "QUEUE_CMD: host_cmd is NULL\n");
680 command
= le16_to_cpu(host_cmd
->command
);
682 /* Exit_PS command needs to be queued in the header always. */
683 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
684 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
685 &host_cmd
->params
.psmode_enh
;
686 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
687 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
688 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
693 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
695 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
697 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
698 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
700 atomic_inc(&adapter
->cmd_pending
);
701 mwifiex_dbg(adapter
, CMD
,
702 "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
703 command
, atomic_read(&adapter
->cmd_pending
));
707 * This function executes the next command in command pending queue.
709 * This function will fail if a command is already in processing stage,
710 * otherwise it will dequeue the first command from the command pending
711 * queue and send to the firmware.
713 * If the device is currently in host sleep mode, any commands, except the
714 * host sleep configuration command will de-activate the host sleep. For PS
715 * mode, the function will put the firmware back to sleep if applicable.
717 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
719 struct mwifiex_private
*priv
;
720 struct cmd_ctrl_node
*cmd_node
;
722 struct host_cmd_ds_command
*host_cmd
;
723 unsigned long cmd_flags
;
724 unsigned long cmd_pending_q_flags
;
726 /* Check if already in processing */
727 if (adapter
->curr_cmd
) {
728 mwifiex_dbg(adapter
, FATAL
,
729 "EXEC_NEXT_CMD: cmd in processing\n");
733 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
734 /* Check if any command is pending */
735 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
736 if (list_empty(&adapter
->cmd_pending_q
)) {
737 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
738 cmd_pending_q_flags
);
739 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
742 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
743 struct cmd_ctrl_node
, list
);
744 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
745 cmd_pending_q_flags
);
747 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
748 priv
= cmd_node
->priv
;
750 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
751 mwifiex_dbg(adapter
, ERROR
,
752 "%s: cannot send cmd in sleep state,\t"
753 "this should not happen\n", __func__
);
754 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
758 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
759 list_del(&cmd_node
->list
);
760 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
761 cmd_pending_q_flags
);
763 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
764 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
765 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
766 /* Any command sent to the firmware when host is in sleep
767 * mode should de-configure host sleep. We should skip the
768 * host sleep configuration command itself though
770 if (priv
&& (host_cmd
->command
!=
771 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
772 if (adapter
->hs_activated
) {
773 adapter
->is_hs_configured
= false;
774 mwifiex_hs_activated_event(priv
, false);
782 * This function handles the command response.
784 * After processing, the function cleans the command node and puts
785 * it back to the command free queue.
787 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
789 struct host_cmd_ds_command
*resp
;
790 struct mwifiex_private
*priv
=
791 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
793 uint16_t orig_cmdresp_no
;
795 uint16_t cmdresp_result
;
798 /* Now we got response from FW, cancel the command timer */
799 del_timer_sync(&adapter
->cmd_timer
);
801 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
802 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
803 mwifiex_dbg(adapter
, ERROR
,
804 "CMD_RESP: NULL curr_cmd, %#x\n",
805 le16_to_cpu(resp
->command
));
809 adapter
->is_cmd_timedout
= 0;
811 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
812 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
813 mwifiex_dbg(adapter
, ERROR
,
814 "CMD_RESP: %#x been canceled\n",
815 le16_to_cpu(resp
->command
));
816 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
817 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
818 adapter
->curr_cmd
= NULL
;
819 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
823 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
824 /* Copy original response back to response buffer */
825 struct mwifiex_ds_misc_cmd
*hostcmd
;
826 uint16_t size
= le16_to_cpu(resp
->size
);
827 mwifiex_dbg(adapter
, INFO
,
828 "info: host cmd resp size = %d\n", size
);
829 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
830 if (adapter
->curr_cmd
->data_buf
) {
831 hostcmd
= adapter
->curr_cmd
->data_buf
;
833 memcpy(hostcmd
->cmd
, resp
, size
);
836 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
838 /* Get BSS number and corresponding priv */
839 priv
= mwifiex_get_priv_by_id(adapter
,
840 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
841 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
843 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
844 /* Clear RET_BIT from HostCmd */
845 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
847 cmdresp_no
= le16_to_cpu(resp
->command
);
848 cmdresp_result
= le16_to_cpu(resp
->result
);
850 /* Save the last command response to debug log */
851 adapter
->dbg
.last_cmd_resp_index
=
852 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
853 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
856 mwifiex_dbg(adapter
, CMD
,
857 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
858 orig_cmdresp_no
, cmdresp_result
,
859 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
860 mwifiex_dbg_dump(adapter
, CMD_D
, "CMD_RESP buffer:", resp
,
861 le16_to_cpu(resp
->size
));
863 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
864 mwifiex_dbg(adapter
, ERROR
, "CMD_RESP: invalid cmd resp\n");
865 if (adapter
->curr_cmd
->wait_q_enabled
)
866 adapter
->cmd_wait_q
.status
= -1;
868 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
869 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
870 adapter
->curr_cmd
= NULL
;
871 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
875 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
876 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
877 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
878 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
879 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
881 /* handle response */
882 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
885 /* Check init command response */
886 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
888 mwifiex_dbg(adapter
, ERROR
,
889 "%s: cmd %#x failed during\t"
890 "initialization\n", __func__
, cmdresp_no
);
891 mwifiex_init_fw_complete(adapter
);
893 } else if (adapter
->last_init_cmd
== cmdresp_no
)
894 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
897 if (adapter
->curr_cmd
) {
898 if (adapter
->curr_cmd
->wait_q_enabled
)
899 adapter
->cmd_wait_q
.status
= ret
;
901 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
903 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
904 adapter
->curr_cmd
= NULL
;
905 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
912 * This function handles the timeout of command sending.
914 * It will re-send the same command again.
917 mwifiex_cmd_timeout_func(unsigned long function_context
)
919 struct mwifiex_adapter
*adapter
=
920 (struct mwifiex_adapter
*) function_context
;
921 struct cmd_ctrl_node
*cmd_node
;
923 adapter
->is_cmd_timedout
= 1;
924 if (!adapter
->curr_cmd
) {
925 mwifiex_dbg(adapter
, ERROR
,
926 "cmd: empty curr_cmd\n");
929 cmd_node
= adapter
->curr_cmd
;
931 adapter
->dbg
.timeout_cmd_id
=
932 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
933 adapter
->dbg
.timeout_cmd_act
=
934 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
935 mwifiex_dbg(adapter
, MSG
,
936 "%s: Timeout cmd id = %#x, act = %#x\n", __func__
,
937 adapter
->dbg
.timeout_cmd_id
,
938 adapter
->dbg
.timeout_cmd_act
);
940 mwifiex_dbg(adapter
, MSG
,
941 "num_data_h2c_failure = %d\n",
942 adapter
->dbg
.num_tx_host_to_card_failure
);
943 mwifiex_dbg(adapter
, MSG
,
944 "num_cmd_h2c_failure = %d\n",
945 adapter
->dbg
.num_cmd_host_to_card_failure
);
947 mwifiex_dbg(adapter
, MSG
,
948 "is_cmd_timedout = %d\n",
949 adapter
->is_cmd_timedout
);
950 mwifiex_dbg(adapter
, MSG
,
951 "num_tx_timeout = %d\n",
952 adapter
->dbg
.num_tx_timeout
);
954 mwifiex_dbg(adapter
, MSG
,
955 "last_cmd_index = %d\n",
956 adapter
->dbg
.last_cmd_index
);
957 mwifiex_dbg(adapter
, MSG
,
958 "last_cmd_id: %*ph\n",
959 (int)sizeof(adapter
->dbg
.last_cmd_id
),
960 adapter
->dbg
.last_cmd_id
);
961 mwifiex_dbg(adapter
, MSG
,
962 "last_cmd_act: %*ph\n",
963 (int)sizeof(adapter
->dbg
.last_cmd_act
),
964 adapter
->dbg
.last_cmd_act
);
966 mwifiex_dbg(adapter
, MSG
,
967 "last_cmd_resp_index = %d\n",
968 adapter
->dbg
.last_cmd_resp_index
);
969 mwifiex_dbg(adapter
, MSG
,
970 "last_cmd_resp_id: %*ph\n",
971 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
972 adapter
->dbg
.last_cmd_resp_id
);
974 mwifiex_dbg(adapter
, MSG
,
975 "last_event_index = %d\n",
976 adapter
->dbg
.last_event_index
);
977 mwifiex_dbg(adapter
, MSG
,
978 "last_event: %*ph\n",
979 (int)sizeof(adapter
->dbg
.last_event
),
980 adapter
->dbg
.last_event
);
982 mwifiex_dbg(adapter
, MSG
,
983 "data_sent=%d cmd_sent=%d\n",
984 adapter
->data_sent
, adapter
->cmd_sent
);
986 mwifiex_dbg(adapter
, MSG
,
987 "ps_mode=%d ps_state=%d\n",
988 adapter
->ps_mode
, adapter
->ps_state
);
990 if (cmd_node
->wait_q_enabled
) {
991 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
992 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
993 mwifiex_cancel_pending_ioctl(adapter
);
996 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
997 mwifiex_init_fw_complete(adapter
);
999 if (adapter
->if_ops
.device_dump
)
1000 adapter
->if_ops
.device_dump(adapter
);
1002 if (adapter
->if_ops
.card_reset
)
1003 adapter
->if_ops
.card_reset(adapter
);
1007 * This function cancels all the pending commands.
1009 * The current command, all commands in command pending queue and all scan
1010 * commands in scan pending queue are cancelled. All the completion callbacks
1011 * are called with failure status to ensure cleanup.
1014 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
1016 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
1017 unsigned long flags
, cmd_flags
;
1018 struct mwifiex_private
*priv
;
1021 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1022 /* Cancel current cmd */
1023 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
1024 adapter
->curr_cmd
->wait_q_enabled
= false;
1025 adapter
->cmd_wait_q
.status
= -1;
1026 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1028 /* Cancel all pending command */
1029 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1030 list_for_each_entry_safe(cmd_node
, tmp_node
,
1031 &adapter
->cmd_pending_q
, list
) {
1032 list_del(&cmd_node
->list
);
1033 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1035 if (cmd_node
->wait_q_enabled
) {
1036 adapter
->cmd_wait_q
.status
= -1;
1037 mwifiex_complete_cmd(adapter
, cmd_node
);
1038 cmd_node
->wait_q_enabled
= false;
1040 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1041 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1043 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1044 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1046 /* Cancel all pending scan command */
1047 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1048 list_for_each_entry_safe(cmd_node
, tmp_node
,
1049 &adapter
->scan_pending_q
, list
) {
1050 list_del(&cmd_node
->list
);
1052 cmd_node
->wait_q_enabled
= false;
1053 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1055 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1057 if (adapter
->scan_processing
) {
1058 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1059 adapter
->scan_processing
= false;
1060 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1061 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1062 priv
= adapter
->priv
[i
];
1065 if (priv
->scan_request
) {
1066 mwifiex_dbg(adapter
, WARN
, "info: aborting scan\n");
1067 cfg80211_scan_done(priv
->scan_request
, 1);
1068 priv
->scan_request
= NULL
;
1075 * This function cancels all pending commands that matches with
1076 * the given IOCTL request.
1078 * Both the current command buffer and the pending command queue are
1079 * searched for matching IOCTL request. The completion callback of
1080 * the matched command is called with failure status to ensure cleanup.
1081 * In case of scan commands, all pending commands in scan pending queue
1085 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1087 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1088 unsigned long cmd_flags
;
1089 unsigned long scan_pending_q_flags
;
1090 struct mwifiex_private
*priv
;
1093 if ((adapter
->curr_cmd
) &&
1094 (adapter
->curr_cmd
->wait_q_enabled
)) {
1095 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1096 cmd_node
= adapter
->curr_cmd
;
1097 cmd_node
->wait_q_enabled
= false;
1098 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1099 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1100 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1101 adapter
->curr_cmd
= NULL
;
1102 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1105 /* Cancel all pending scan command */
1106 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1107 scan_pending_q_flags
);
1108 list_for_each_entry_safe(cmd_node
, tmp_node
,
1109 &adapter
->scan_pending_q
, list
) {
1110 list_del(&cmd_node
->list
);
1111 cmd_node
->wait_q_enabled
= false;
1112 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1114 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1115 scan_pending_q_flags
);
1117 if (adapter
->scan_processing
) {
1118 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1119 adapter
->scan_processing
= false;
1120 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1121 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1122 priv
= adapter
->priv
[i
];
1125 if (priv
->scan_request
) {
1126 mwifiex_dbg(adapter
, WARN
, "info: aborting scan\n");
1127 cfg80211_scan_done(priv
->scan_request
, 1);
1128 priv
->scan_request
= NULL
;
1132 adapter
->cmd_wait_q
.status
= -1;
1136 * This function sends the sleep confirm command to firmware, if
1139 * The sleep confirm command cannot be issued if command response,
1140 * data response or event response is awaiting handling, or if we
1141 * are in the middle of sending a command, or expecting a command
1145 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1147 if (!adapter
->cmd_sent
&&
1148 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1149 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1151 mwifiex_dbg(adapter
, CMD
,
1152 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1153 (adapter
->cmd_sent
) ? "D" : "",
1154 (adapter
->curr_cmd
) ? "C" : "",
1155 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1159 * This function sends a Host Sleep activated event to applications.
1161 * This event is generated by the driver, with a blank event body.
1164 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1167 if (priv
->adapter
->is_hs_configured
) {
1168 priv
->adapter
->hs_activated
= true;
1169 mwifiex_update_rxreor_flags(priv
->adapter
,
1170 RXREOR_FORCE_NO_DROP
);
1171 mwifiex_dbg(priv
->adapter
, EVENT
,
1172 "event: hs_activated\n");
1173 priv
->adapter
->hs_activate_wait_q_woken
= true;
1174 wake_up_interruptible(
1175 &priv
->adapter
->hs_activate_wait_q
);
1177 mwifiex_dbg(priv
->adapter
, EVENT
,
1178 "event: HS not configured\n");
1181 mwifiex_dbg(priv
->adapter
, EVENT
,
1182 "event: hs_deactivated\n");
1183 priv
->adapter
->hs_activated
= false;
1188 * This function handles the command response of a Host Sleep configuration
1191 * Handling includes changing the header fields into CPU format
1192 * and setting the current host sleep activation status in driver.
1194 * In case host sleep status change, the function generates an event to
1195 * notify the applications.
1197 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1198 struct host_cmd_ds_command
*resp
)
1200 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1201 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1202 &resp
->params
.opt_hs_cfg
;
1203 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1205 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1206 adapter
->iface_type
!= MWIFIEX_USB
) {
1207 mwifiex_hs_activated_event(priv
, true);
1210 mwifiex_dbg(adapter
, CMD
,
1211 "cmd: CMD_RESP: HS_CFG cmd reply\t"
1212 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1213 resp
->result
, conditions
,
1214 phs_cfg
->params
.hs_config
.gpio
,
1215 phs_cfg
->params
.hs_config
.gap
);
1217 if (conditions
!= HS_CFG_CANCEL
) {
1218 adapter
->is_hs_configured
= true;
1219 if (adapter
->iface_type
== MWIFIEX_USB
)
1220 mwifiex_hs_activated_event(priv
, true);
1222 adapter
->is_hs_configured
= false;
1223 if (adapter
->hs_activated
)
1224 mwifiex_hs_activated_event(priv
, false);
1231 * This function wakes up the adapter and generates a Host Sleep
1232 * cancel event on receiving the power up interrupt.
1235 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1237 mwifiex_dbg(adapter
, INFO
,
1238 "info: %s: auto cancelling host sleep\t"
1239 "since there is interrupt from the firmware\n",
1242 adapter
->if_ops
.wakeup(adapter
);
1243 adapter
->hs_activated
= false;
1244 adapter
->is_hs_configured
= false;
1245 adapter
->is_suspended
= false;
1246 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1247 MWIFIEX_BSS_ROLE_ANY
),
1250 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1253 * This function handles the command response of a sleep confirm command.
1255 * The function sets the card state to SLEEP if the response indicates success.
1258 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1259 u8
*pbuf
, u32 upld_len
)
1261 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1262 struct mwifiex_private
*priv
=
1263 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1264 uint16_t result
= le16_to_cpu(cmd
->result
);
1265 uint16_t command
= le16_to_cpu(cmd
->command
);
1266 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1269 mwifiex_dbg(adapter
, ERROR
,
1270 "%s: cmd size is 0\n", __func__
);
1274 mwifiex_dbg(adapter
, CMD
,
1275 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
1276 command
, result
, le16_to_cpu(cmd
->size
), seq_num
);
1278 /* Get BSS number and corresponding priv */
1279 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1280 HostCmd_GET_BSS_TYPE(seq_num
));
1282 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1284 /* Update sequence number */
1285 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1286 /* Clear RET_BIT from HostCmd */
1287 command
&= HostCmd_CMD_ID_MASK
;
1289 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1290 mwifiex_dbg(adapter
, ERROR
,
1291 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1292 __func__
, command
, result
);
1297 mwifiex_dbg(adapter
, ERROR
,
1298 "%s: sleep confirm cmd failed\n",
1300 adapter
->pm_wakeup_card_req
= false;
1301 adapter
->ps_state
= PS_STATE_AWAKE
;
1304 adapter
->pm_wakeup_card_req
= true;
1305 if (adapter
->is_hs_configured
)
1306 mwifiex_hs_activated_event(mwifiex_get_priv
1307 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1309 adapter
->ps_state
= PS_STATE_SLEEP
;
1310 cmd
->command
= cpu_to_le16(command
);
1311 cmd
->seq_num
= cpu_to_le16(seq_num
);
1313 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1316 * This function prepares an enhanced power mode command.
1318 * This function can be used to disable power save or to configure
1319 * power save with auto PS or STA PS or auto deep sleep.
1321 * Preparation includes -
1322 * - Setting command ID, action and proper size
1323 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1324 * auto deep sleep TLV (as required)
1325 * - Ensuring correct endian-ness
1327 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1328 struct host_cmd_ds_command
*cmd
,
1329 u16 cmd_action
, uint16_t ps_bitmap
,
1330 struct mwifiex_ds_auto_ds
*auto_ds
)
1332 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1333 &cmd
->params
.psmode_enh
;
1337 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1338 if (cmd_action
== DIS_AUTO_PS
) {
1339 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1340 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1341 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1342 sizeof(psmode_enh
->params
.ps_bitmap
));
1343 } else if (cmd_action
== GET_PS
) {
1344 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1345 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1346 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1347 sizeof(psmode_enh
->params
.ps_bitmap
));
1348 } else if (cmd_action
== EN_AUTO_PS
) {
1349 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1350 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1351 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1352 sizeof(psmode_enh
->params
.ps_bitmap
);
1353 tlv
= (u8
*) cmd
+ cmd_size
;
1354 if (ps_bitmap
& BITMAP_STA_PS
) {
1355 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1356 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1357 (struct mwifiex_ie_types_ps_param
*) tlv
;
1358 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1359 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1360 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1361 sizeof(struct mwifiex_ie_types_header
));
1362 cmd_size
+= sizeof(*ps_tlv
);
1363 tlv
+= sizeof(*ps_tlv
);
1364 mwifiex_dbg(priv
->adapter
, CMD
,
1365 "cmd: PS Command: Enter PS\n");
1366 ps_mode
->null_pkt_interval
=
1367 cpu_to_le16(adapter
->null_pkt_interval
);
1368 ps_mode
->multiple_dtims
=
1369 cpu_to_le16(adapter
->multiple_dtim
);
1370 ps_mode
->bcn_miss_timeout
=
1371 cpu_to_le16(adapter
->bcn_miss_time_out
);
1372 ps_mode
->local_listen_interval
=
1373 cpu_to_le16(adapter
->local_listen_interval
);
1374 ps_mode
->adhoc_wake_period
=
1375 cpu_to_le16(adapter
->adhoc_awake_period
);
1376 ps_mode
->delay_to_ps
=
1377 cpu_to_le16(adapter
->delay_to_ps
);
1378 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1381 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1382 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1383 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1386 auto_ds_tlv
->header
.type
=
1387 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1388 auto_ds_tlv
->header
.len
=
1389 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1390 sizeof(struct mwifiex_ie_types_header
));
1391 cmd_size
+= sizeof(*auto_ds_tlv
);
1392 tlv
+= sizeof(*auto_ds_tlv
);
1394 idletime
= auto_ds
->idle_time
;
1395 mwifiex_dbg(priv
->adapter
, CMD
,
1396 "cmd: PS Command: Enter Auto Deep Sleep\n");
1397 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1399 cmd
->size
= cpu_to_le16(cmd_size
);
1405 * This function handles the command response of an enhanced power mode
1408 * Handling includes changing the header fields into CPU format
1409 * and setting the current enhanced power mode in driver.
1411 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1412 struct host_cmd_ds_command
*resp
,
1413 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1415 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1416 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1417 &resp
->params
.psmode_enh
;
1418 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1419 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1420 uint16_t auto_ps_bitmap
=
1421 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1423 mwifiex_dbg(adapter
, INFO
,
1424 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1425 __func__
, resp
->result
, action
);
1426 if (action
== EN_AUTO_PS
) {
1427 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1428 mwifiex_dbg(adapter
, CMD
,
1429 "cmd: Enabled auto deep sleep\n");
1430 priv
->adapter
->is_deep_sleep
= true;
1432 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1433 mwifiex_dbg(adapter
, CMD
,
1434 "cmd: Enabled STA power save\n");
1435 if (adapter
->sleep_period
.period
)
1436 mwifiex_dbg(adapter
, CMD
,
1437 "cmd: set to uapsd/pps mode\n");
1439 } else if (action
== DIS_AUTO_PS
) {
1440 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1441 priv
->adapter
->is_deep_sleep
= false;
1442 mwifiex_dbg(adapter
, CMD
,
1443 "cmd: Disabled auto deep sleep\n");
1445 if (ps_bitmap
& BITMAP_STA_PS
) {
1446 mwifiex_dbg(adapter
, CMD
,
1447 "cmd: Disabled STA power save\n");
1448 if (adapter
->sleep_period
.period
) {
1449 adapter
->delay_null_pkt
= false;
1450 adapter
->tx_lock_flag
= false;
1451 adapter
->pps_uapsd_mode
= false;
1454 } else if (action
== GET_PS
) {
1455 if (ps_bitmap
& BITMAP_STA_PS
)
1456 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1458 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1460 mwifiex_dbg(adapter
, CMD
,
1461 "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1464 /* This section is for get power save mode */
1465 if (ps_bitmap
& BITMAP_STA_PS
)
1466 pm_cfg
->param
.ps_mode
= 1;
1468 pm_cfg
->param
.ps_mode
= 0;
1475 * This function prepares command to get hardware specifications.
1477 * Preparation includes -
1478 * - Setting command ID, action and proper size
1479 * - Setting permanent address parameter
1480 * - Ensuring correct endian-ness
1482 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1483 struct host_cmd_ds_command
*cmd
)
1485 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1487 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1489 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1490 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1496 * This function handles the command response of get hardware
1499 * Handling includes changing the header fields into CPU format
1500 * and saving/updating the following parameters in driver -
1501 * - Firmware capability information
1502 * - Firmware band settings
1503 * - Ad-hoc start band and channel
1504 * - Ad-hoc 11n activation status
1505 * - Firmware release number
1506 * - Number of antennas
1507 * - Hardware address
1508 * - Hardware interface version
1509 * - Firmware version
1511 * - 11n capabilities
1512 * - MCS support fields
1515 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1516 struct host_cmd_ds_command
*resp
)
1518 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1519 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1520 struct mwifiex_ie_types_header
*tlv
;
1521 struct hw_spec_api_rev
*api_rev
;
1522 u16 resp_size
, api_id
;
1523 int i
, left_len
, parsed_len
= 0;
1525 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1527 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1528 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1530 adapter
->fw_bands
= BAND_B
;
1532 adapter
->config_bands
= adapter
->fw_bands
;
1534 if (adapter
->fw_bands
& BAND_A
) {
1535 if (adapter
->fw_bands
& BAND_GN
) {
1536 adapter
->config_bands
|= BAND_AN
;
1537 adapter
->fw_bands
|= BAND_AN
;
1539 if (adapter
->fw_bands
& BAND_AN
) {
1540 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1541 adapter
->adhoc_11n_enabled
= true;
1543 adapter
->adhoc_start_band
= BAND_A
;
1545 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1546 } else if (adapter
->fw_bands
& BAND_GN
) {
1547 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1548 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1549 adapter
->adhoc_11n_enabled
= true;
1550 } else if (adapter
->fw_bands
& BAND_G
) {
1551 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1552 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1553 } else if (adapter
->fw_bands
& BAND_B
) {
1554 adapter
->adhoc_start_band
= BAND_B
;
1555 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1558 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1559 adapter
->fw_api_ver
= (adapter
->fw_release_number
>> 16) & 0xff;
1560 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1562 if (le32_to_cpu(hw_spec
->dot_11ac_dev_cap
)) {
1563 adapter
->is_hw_11ac_capable
= true;
1566 adapter
->hw_dot_11ac_dev_cap
=
1567 le32_to_cpu(hw_spec
->dot_11ac_dev_cap
);
1568 adapter
->usr_dot_11ac_dev_cap_bg
= adapter
->hw_dot_11ac_dev_cap
1569 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1570 adapter
->usr_dot_11ac_dev_cap_a
= adapter
->hw_dot_11ac_dev_cap
1571 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1574 adapter
->hw_dot_11ac_mcs_support
=
1575 le32_to_cpu(hw_spec
->dot_11ac_mcs_support
);
1576 adapter
->usr_dot_11ac_mcs_support
=
1577 adapter
->hw_dot_11ac_mcs_support
;
1579 adapter
->is_hw_11ac_capable
= false;
1582 resp_size
= le16_to_cpu(resp
->size
) - S_DS_GEN
;
1583 if (resp_size
> sizeof(struct host_cmd_ds_get_hw_spec
)) {
1584 /* we have variable HW SPEC information */
1585 left_len
= resp_size
- sizeof(struct host_cmd_ds_get_hw_spec
);
1586 while (left_len
> sizeof(struct mwifiex_ie_types_header
)) {
1587 tlv
= (void *)&hw_spec
->tlvs
+ parsed_len
;
1588 switch (le16_to_cpu(tlv
->type
)) {
1589 case TLV_TYPE_API_REV
:
1590 api_rev
= (struct hw_spec_api_rev
*)tlv
;
1591 api_id
= le16_to_cpu(api_rev
->api_id
);
1593 case KEY_API_VER_ID
:
1594 adapter
->key_api_major_ver
=
1596 adapter
->key_api_minor_ver
=
1598 mwifiex_dbg(adapter
, INFO
,
1600 adapter
->key_api_major_ver
,
1601 adapter
->key_api_minor_ver
);
1604 adapter
->fw_api_ver
=
1606 mwifiex_dbg(adapter
, INFO
,
1607 "Firmware api version %d\n",
1608 adapter
->fw_api_ver
);
1611 mwifiex_dbg(adapter
, FATAL
,
1612 "Unknown api_id: %d\n",
1618 mwifiex_dbg(adapter
, FATAL
,
1619 "Unknown GET_HW_SPEC TLV type: %#x\n",
1620 le16_to_cpu(tlv
->type
));
1623 parsed_len
+= le16_to_cpu(tlv
->len
) +
1624 sizeof(struct mwifiex_ie_types_header
);
1625 left_len
-= le16_to_cpu(tlv
->len
) +
1626 sizeof(struct mwifiex_ie_types_header
);
1630 mwifiex_dbg(adapter
, INFO
,
1631 "info: GET_HW_SPEC: fw_release_number- %#x\n",
1632 adapter
->fw_release_number
);
1633 mwifiex_dbg(adapter
, INFO
,
1634 "info: GET_HW_SPEC: permanent addr: %pM\n",
1635 hw_spec
->permanent_addr
);
1636 mwifiex_dbg(adapter
, INFO
,
1637 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1638 le16_to_cpu(hw_spec
->hw_if_version
),
1639 le16_to_cpu(hw_spec
->version
));
1641 ether_addr_copy(priv
->adapter
->perm_addr
, hw_spec
->permanent_addr
);
1642 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1644 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1645 /* Use the region code to search for the index */
1646 if (adapter
->region_code
== region_code_index
[i
])
1649 /* If it's unidentified region code, use the default (USA) */
1650 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1651 adapter
->region_code
= 0x10;
1652 mwifiex_dbg(adapter
, WARN
,
1653 "cmd: unknown region code, use default (USA)\n");
1656 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1657 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1658 adapter
->user_dev_mcs_support
= adapter
->hw_dev_mcs_support
;
1660 if (adapter
->if_ops
.update_mp_end_port
)
1661 adapter
->if_ops
.update_mp_end_port(adapter
,
1662 le16_to_cpu(hw_spec
->mp_end_port
));
1664 if (adapter
->fw_api_ver
== MWIFIEX_FW_V15
)
1665 adapter
->scan_chan_gap_enabled
= true;