2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011, 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
)
42 cmd_node
->priv
= priv
;
43 cmd_node
->cmd_oid
= cmd_oid
;
44 if (priv
->adapter
->cmd_wait_q_required
) {
45 cmd_node
->wait_q_enabled
= priv
->adapter
->cmd_wait_q_required
;
46 priv
->adapter
->cmd_wait_q_required
= false;
47 cmd_node
->cmd_wait_q_woken
= false;
48 cmd_node
->condition
= &cmd_node
->cmd_wait_q_woken
;
50 cmd_node
->data_buf
= data_buf
;
51 cmd_node
->cmd_skb
= cmd_node
->skb
;
55 * This function returns a command node from the free queue depending upon
58 static struct cmd_ctrl_node
*
59 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
61 struct cmd_ctrl_node
*cmd_node
;
64 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
65 if (list_empty(&adapter
->cmd_free_q
)) {
66 dev_err(adapter
->dev
, "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 dev_dbg(priv
->adapter
->dev
, "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
125 * This function downloads a command to the firmware.
127 * The function performs sanity tests, sets the command sequence
128 * number and size, converts the header fields to CPU format before
129 * sending. Afterwards, it logs the command ID and action for debugging
130 * and sets up the command timeout timer.
132 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
133 struct cmd_ctrl_node
*cmd_node
)
136 struct mwifiex_adapter
*adapter
= priv
->adapter
;
138 struct host_cmd_ds_command
*host_cmd
;
141 struct timeval tstamp
;
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 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
153 " or cmd size is 0, not sending\n");
154 if (cmd_node
->wait_q_enabled
)
155 adapter
->cmd_wait_q
.status
= -1;
156 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
160 /* Set command sequence number */
162 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
164 cmd_node
->priv
->bss_num
,
165 cmd_node
->priv
->bss_type
));
167 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
168 adapter
->curr_cmd
= cmd_node
;
169 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
171 cmd_code
= le16_to_cpu(host_cmd
->command
);
172 cmd_size
= le16_to_cpu(host_cmd
->size
);
174 /* Adjust skb length */
175 if (cmd_node
->cmd_skb
->len
> cmd_size
)
177 * cmd_size is less than sizeof(struct host_cmd_ds_command).
178 * Trim off the unused portion.
180 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
181 else if (cmd_node
->cmd_skb
->len
< cmd_size
)
183 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
184 * because we have appended custom IE TLV. Increase skb length
187 skb_put(cmd_node
->cmd_skb
, cmd_size
- cmd_node
->cmd_skb
->len
);
189 do_gettimeofday(&tstamp
);
190 dev_dbg(adapter
->dev
, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
192 tstamp
.tv_sec
, tstamp
.tv_usec
, cmd_code
,
193 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
194 le16_to_cpu(host_cmd
->seq_num
));
196 if (adapter
->iface_type
== MWIFIEX_USB
) {
197 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
198 skb_push(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
199 memcpy(cmd_node
->cmd_skb
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
200 adapter
->cmd_sent
= true;
201 ret
= adapter
->if_ops
.host_to_card(adapter
,
202 MWIFIEX_USB_EP_CMD_EVENT
,
203 cmd_node
->cmd_skb
, NULL
);
204 skb_pull(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
206 cmd_node
->cmd_skb
= NULL
;
208 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
209 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
210 cmd_node
->cmd_skb
, NULL
);
211 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
215 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
216 if (adapter
->iface_type
== MWIFIEX_USB
)
217 adapter
->cmd_sent
= false;
218 if (cmd_node
->wait_q_enabled
)
219 adapter
->cmd_wait_q
.status
= -1;
220 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
222 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
223 adapter
->curr_cmd
= NULL
;
224 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
226 adapter
->dbg
.num_cmd_host_to_card_failure
++;
230 /* Save the last command id and action to debug log */
231 adapter
->dbg
.last_cmd_index
=
232 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
233 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
234 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
235 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
237 /* Clear BSS_NO_BITS from HostCmd */
238 cmd_code
&= HostCmd_CMD_ID_MASK
;
240 /* Setup the timer after transmit command */
241 mod_timer(&adapter
->cmd_timer
,
242 jiffies
+ (MWIFIEX_TIMER_10S
* HZ
) / 1000);
248 * This function downloads a sleep confirm command to the firmware.
250 * The function performs sanity tests, sets the command sequence
251 * number and size, converts the header fields to CPU format before
254 * No responses are needed for sleep confirm command.
256 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
259 struct mwifiex_private
*priv
;
260 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
=
261 (struct mwifiex_opt_sleep_confirm
*)
262 adapter
->sleep_cfm
->data
;
263 struct sk_buff
*sleep_cfm_tmp
;
266 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
268 sleep_cfm_buf
->seq_num
=
269 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
270 (adapter
->seq_num
, priv
->bss_num
,
274 if (adapter
->iface_type
== MWIFIEX_USB
) {
276 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
278 skb_put(sleep_cfm_tmp
, sizeof(struct mwifiex_opt_sleep_confirm
)
280 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
281 memcpy(sleep_cfm_tmp
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
282 memcpy(sleep_cfm_tmp
->data
+ MWIFIEX_TYPE_LEN
,
283 adapter
->sleep_cfm
->data
,
284 sizeof(struct mwifiex_opt_sleep_confirm
));
285 ret
= adapter
->if_ops
.host_to_card(adapter
,
286 MWIFIEX_USB_EP_CMD_EVENT
,
287 sleep_cfm_tmp
, NULL
);
289 dev_kfree_skb_any(sleep_cfm_tmp
);
291 skb_push(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
292 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
293 adapter
->sleep_cfm
, NULL
);
294 skb_pull(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
298 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
299 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
302 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
303 == MWIFIEX_BSS_ROLE_STA
) {
304 if (!sleep_cfm_buf
->resp_ctrl
)
305 /* Response is not needed for sleep
307 adapter
->ps_state
= PS_STATE_SLEEP
;
309 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
311 if (!sleep_cfm_buf
->resp_ctrl
&&
312 (adapter
->is_hs_configured
&&
313 !adapter
->sleep_period
.period
)) {
314 adapter
->pm_wakeup_card_req
= true;
315 mwifiex_hs_activated_event(mwifiex_get_priv
316 (adapter
, MWIFIEX_BSS_ROLE_STA
), true);
324 * This function allocates the command buffers and links them to
325 * the command free queue.
327 * The driver uses a pre allocated number of command buffers, which
328 * are created at driver initializations and freed at driver cleanup.
329 * Every command needs to obtain a command buffer from this pool before
330 * it can be issued. The command free queue lists the command buffers
331 * currently free to use, while the command pending queue lists the
332 * command buffers already in use and awaiting handling. Command buffers
333 * are returned to the free queue after use.
335 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
337 struct cmd_ctrl_node
*cmd_array
;
340 /* Allocate and initialize struct cmd_ctrl_node */
341 cmd_array
= kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER
,
342 sizeof(struct cmd_ctrl_node
), GFP_KERNEL
);
346 adapter
->cmd_pool
= cmd_array
;
348 /* Allocate and initialize command buffers */
349 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
350 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
351 if (!cmd_array
[i
].skb
) {
352 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
357 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
358 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
364 * This function frees the command buffers.
366 * The function calls the completion callback for all the command
367 * buffers that still have response buffers associated with them.
369 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
371 struct cmd_ctrl_node
*cmd_array
;
374 /* Need to check if cmd pool is allocated or not */
375 if (!adapter
->cmd_pool
) {
376 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
380 cmd_array
= adapter
->cmd_pool
;
382 /* Release shared memory buffers */
383 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
384 if (cmd_array
[i
].skb
) {
385 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
386 dev_kfree_skb_any(cmd_array
[i
].skb
);
388 if (!cmd_array
[i
].resp_skb
)
391 if (adapter
->iface_type
== MWIFIEX_USB
)
392 adapter
->if_ops
.cmdrsp_complete(adapter
,
393 cmd_array
[i
].resp_skb
);
395 dev_kfree_skb_any(cmd_array
[i
].resp_skb
);
397 /* Release struct cmd_ctrl_node */
398 if (adapter
->cmd_pool
) {
399 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
400 kfree(adapter
->cmd_pool
);
401 adapter
->cmd_pool
= NULL
;
408 * This function handles events generated by firmware.
410 * Event body of events received from firmware are not used (though they are
411 * saved), only the event ID is used. Some events are re-invoked by
412 * the driver, with a new event body.
414 * After processing, the function calls the completion callback
417 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
420 struct mwifiex_private
*priv
=
421 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
422 struct sk_buff
*skb
= adapter
->event_skb
;
423 u32 eventcause
= adapter
->event_cause
;
424 struct timeval tstamp
;
425 struct mwifiex_rxinfo
*rx_info
;
427 /* Save the last event to debug log */
428 adapter
->dbg
.last_event_index
=
429 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
430 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
433 /* Get BSS number and corresponding priv */
434 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
435 EVENT_GET_BSS_TYPE(eventcause
));
437 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
438 /* Clear BSS_NO_BITS from event */
439 eventcause
&= EVENT_ID_MASK
;
440 adapter
->event_cause
= eventcause
;
443 rx_info
= MWIFIEX_SKB_RXCB(skb
);
444 rx_info
->bss_num
= priv
->bss_num
;
445 rx_info
->bss_type
= priv
->bss_type
;
448 if (eventcause
!= EVENT_PS_SLEEP
&& eventcause
!= EVENT_PS_AWAKE
) {
449 do_gettimeofday(&tstamp
);
450 dev_dbg(adapter
->dev
, "event: %lu.%lu: cause: %#x\n",
451 tstamp
.tv_sec
, tstamp
.tv_usec
, eventcause
);
453 /* Handle PS_SLEEP/AWAKE events on STA */
454 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
456 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
459 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
460 ret
= mwifiex_process_uap_event(priv
);
462 ret
= mwifiex_process_sta_event(priv
);
464 adapter
->event_cause
= 0;
465 adapter
->event_skb
= NULL
;
466 adapter
->if_ops
.event_complete(adapter
, skb
);
472 * This function is used to send synchronous command to the firmware.
474 * it allocates a wait queue for the command and wait for the command
477 int mwifiex_send_cmd_sync(struct mwifiex_private
*priv
, uint16_t cmd_no
,
478 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
481 struct mwifiex_adapter
*adapter
= priv
->adapter
;
483 adapter
->cmd_wait_q_required
= true;
485 ret
= mwifiex_send_cmd_async(priv
, cmd_no
, cmd_action
, cmd_oid
,
488 ret
= mwifiex_wait_queue_complete(adapter
);
495 * This function prepares a command and asynchronously send it to the firmware.
497 * Preparation includes -
498 * - Sanity tests to make sure the card is still present or the FW
500 * - Getting a new command node from the command free queue
501 * - Initializing the command node for default parameters
502 * - Fill up the non-default parameters and buffer pointers
503 * - Add the command to pending queue
505 int mwifiex_send_cmd_async(struct mwifiex_private
*priv
, uint16_t cmd_no
,
506 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
509 struct mwifiex_adapter
*adapter
= priv
->adapter
;
510 struct cmd_ctrl_node
*cmd_node
;
511 struct host_cmd_ds_command
*cmd_ptr
;
514 pr_err("PREP_CMD: adapter is NULL\n");
518 if (adapter
->is_suspended
) {
519 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
523 if (adapter
->surprise_removed
) {
524 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
528 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
529 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
530 dev_err(adapter
->dev
, "PREP_CMD: FW in reset state\n");
535 /* Get a new command node */
536 cmd_node
= mwifiex_get_cmd_node(adapter
);
539 dev_err(adapter
->dev
, "PREP_CMD: no free cmd node\n");
543 /* Initialize the command node */
544 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
);
546 if (!cmd_node
->cmd_skb
) {
547 dev_err(adapter
->dev
, "PREP_CMD: no free cmd buf\n");
551 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
552 0, sizeof(struct host_cmd_ds_command
));
554 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
555 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
558 /* Prepare command */
561 case HostCmd_CMD_UAP_SYS_CONFIG
:
562 case HostCmd_CMD_UAP_BSS_START
:
563 case HostCmd_CMD_UAP_BSS_STOP
:
564 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
569 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
575 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
576 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
579 /* Return error, since the command preparation failed */
581 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
583 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
588 if (cmd_no
== HostCmd_CMD_802_11_SCAN
) {
589 mwifiex_queue_scan_cmd(priv
, cmd_node
);
591 adapter
->cmd_queued
= cmd_node
;
592 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
593 queue_work(adapter
->workqueue
, &adapter
->main_work
);
600 * This function returns a command to the command free queue.
602 * The function also calls the completion callback if required, before
603 * cleaning the command node and re-inserting it into the free queue.
606 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
607 struct cmd_ctrl_node
*cmd_node
)
614 if (cmd_node
->wait_q_enabled
)
615 mwifiex_complete_cmd(adapter
, cmd_node
);
617 mwifiex_clean_cmd_node(adapter
, cmd_node
);
619 /* Insert node into cmd_free_q */
620 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
621 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
622 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
626 * This function queues a command to the command pending queue.
628 * This in effect adds the command to the command list to be executed.
629 * Exit PS command is handled specially, by placing it always to the
630 * front of the command queue.
633 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
634 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
636 struct host_cmd_ds_command
*host_cmd
= NULL
;
640 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
642 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
646 command
= le16_to_cpu(host_cmd
->command
);
648 /* Exit_PS command needs to be queued in the header always. */
649 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
650 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
651 &host_cmd
->params
.psmode_enh
;
652 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
653 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
654 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
659 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
661 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
663 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
664 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
666 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command
);
670 * This function executes the next command in command pending queue.
672 * This function will fail if a command is already in processing stage,
673 * otherwise it will dequeue the first command from the command pending
674 * queue and send to the firmware.
676 * If the device is currently in host sleep mode, any commands, except the
677 * host sleep configuration command will de-activate the host sleep. For PS
678 * mode, the function will put the firmware back to sleep if applicable.
680 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
682 struct mwifiex_private
*priv
;
683 struct cmd_ctrl_node
*cmd_node
;
685 struct host_cmd_ds_command
*host_cmd
;
686 unsigned long cmd_flags
;
687 unsigned long cmd_pending_q_flags
;
689 /* Check if already in processing */
690 if (adapter
->curr_cmd
) {
691 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
695 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
696 /* Check if any command is pending */
697 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
698 if (list_empty(&adapter
->cmd_pending_q
)) {
699 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
700 cmd_pending_q_flags
);
701 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
704 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
705 struct cmd_ctrl_node
, list
);
706 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
707 cmd_pending_q_flags
);
709 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
710 priv
= cmd_node
->priv
;
712 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
713 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
714 " this should not happen\n", __func__
);
715 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
719 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
720 list_del(&cmd_node
->list
);
721 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
722 cmd_pending_q_flags
);
724 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
725 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
726 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
727 /* Any command sent to the firmware when host is in sleep
728 * mode should de-configure host sleep. We should skip the
729 * host sleep configuration command itself though
731 if (priv
&& (host_cmd
->command
!=
732 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
733 if (adapter
->hs_activated
) {
734 adapter
->is_hs_configured
= false;
735 mwifiex_hs_activated_event(priv
, false);
743 * This function handles the command response.
745 * After processing, the function cleans the command node and puts
746 * it back to the command free queue.
748 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
750 struct host_cmd_ds_command
*resp
;
751 struct mwifiex_private
*priv
=
752 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
754 uint16_t orig_cmdresp_no
;
756 uint16_t cmdresp_result
;
757 struct timeval tstamp
;
760 /* Now we got response from FW, cancel the command timer */
761 del_timer(&adapter
->cmd_timer
);
763 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
764 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
765 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
766 le16_to_cpu(resp
->command
));
770 adapter
->num_cmd_timeout
= 0;
772 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
773 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
774 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
775 le16_to_cpu(resp
->command
));
776 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
777 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
778 adapter
->curr_cmd
= NULL
;
779 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
783 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
784 /* Copy original response back to response buffer */
785 struct mwifiex_ds_misc_cmd
*hostcmd
;
786 uint16_t size
= le16_to_cpu(resp
->size
);
787 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
788 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
789 if (adapter
->curr_cmd
->data_buf
) {
790 hostcmd
= adapter
->curr_cmd
->data_buf
;
792 memcpy(hostcmd
->cmd
, resp
, size
);
795 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
797 /* Get BSS number and corresponding priv */
798 priv
= mwifiex_get_priv_by_id(adapter
,
799 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
800 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
802 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
803 /* Clear RET_BIT from HostCmd */
804 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
806 cmdresp_no
= le16_to_cpu(resp
->command
);
807 cmdresp_result
= le16_to_cpu(resp
->result
);
809 /* Save the last command response to debug log */
810 adapter
->dbg
.last_cmd_resp_index
=
811 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
812 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
815 do_gettimeofday(&tstamp
);
816 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
817 " len %d, seqno 0x%x\n",
818 tstamp
.tv_sec
, tstamp
.tv_usec
, orig_cmdresp_no
, cmdresp_result
,
819 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
821 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
822 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
823 if (adapter
->curr_cmd
->wait_q_enabled
)
824 adapter
->cmd_wait_q
.status
= -1;
826 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
827 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
828 adapter
->curr_cmd
= NULL
;
829 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
833 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
834 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
835 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
836 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
837 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
839 /* handle response */
840 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
843 /* Check init command response */
844 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
846 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
847 "initialization\n", __func__
, cmdresp_no
);
848 mwifiex_init_fw_complete(adapter
);
850 } else if (adapter
->last_init_cmd
== cmdresp_no
)
851 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
854 if (adapter
->curr_cmd
) {
855 if (adapter
->curr_cmd
->wait_q_enabled
)
856 adapter
->cmd_wait_q
.status
= ret
;
858 /* Clean up and put current command back to cmd_free_q */
859 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
861 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
862 adapter
->curr_cmd
= NULL
;
863 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
870 * This function handles the timeout of command sending.
872 * It will re-send the same command again.
875 mwifiex_cmd_timeout_func(unsigned long function_context
)
877 struct mwifiex_adapter
*adapter
=
878 (struct mwifiex_adapter
*) function_context
;
879 struct cmd_ctrl_node
*cmd_node
;
880 struct timeval tstamp
;
882 adapter
->num_cmd_timeout
++;
883 adapter
->dbg
.num_cmd_timeout
++;
884 if (!adapter
->curr_cmd
) {
885 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
888 cmd_node
= adapter
->curr_cmd
;
890 adapter
->dbg
.timeout_cmd_id
=
891 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
892 adapter
->dbg
.timeout_cmd_act
=
893 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
894 do_gettimeofday(&tstamp
);
895 dev_err(adapter
->dev
,
896 "%s: Timeout cmd id (%lu.%lu) = %#x, act = %#x\n",
897 __func__
, tstamp
.tv_sec
, tstamp
.tv_usec
,
898 adapter
->dbg
.timeout_cmd_id
,
899 adapter
->dbg
.timeout_cmd_act
);
901 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
902 adapter
->dbg
.num_tx_host_to_card_failure
);
903 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
904 adapter
->dbg
.num_cmd_host_to_card_failure
);
906 dev_err(adapter
->dev
, "num_cmd_timeout = %d\n",
907 adapter
->dbg
.num_cmd_timeout
);
908 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
909 adapter
->dbg
.num_tx_timeout
);
911 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
912 adapter
->dbg
.last_cmd_index
);
913 dev_err(adapter
->dev
, "last_cmd_id: %*ph\n",
914 (int)sizeof(adapter
->dbg
.last_cmd_id
),
915 adapter
->dbg
.last_cmd_id
);
916 dev_err(adapter
->dev
, "last_cmd_act: %*ph\n",
917 (int)sizeof(adapter
->dbg
.last_cmd_act
),
918 adapter
->dbg
.last_cmd_act
);
920 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
921 adapter
->dbg
.last_cmd_resp_index
);
922 dev_err(adapter
->dev
, "last_cmd_resp_id: %*ph\n",
923 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
924 adapter
->dbg
.last_cmd_resp_id
);
926 dev_err(adapter
->dev
, "last_event_index = %d\n",
927 adapter
->dbg
.last_event_index
);
928 dev_err(adapter
->dev
, "last_event: %*ph\n",
929 (int)sizeof(adapter
->dbg
.last_event
),
930 adapter
->dbg
.last_event
);
932 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
933 adapter
->data_sent
, adapter
->cmd_sent
);
935 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
936 adapter
->ps_mode
, adapter
->ps_state
);
938 if (cmd_node
->wait_q_enabled
) {
939 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
940 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
941 mwifiex_cancel_pending_ioctl(adapter
);
942 /* reset cmd_sent flag to unblock new commands */
943 adapter
->cmd_sent
= false;
946 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
947 mwifiex_init_fw_complete(adapter
);
949 if (adapter
->if_ops
.card_reset
)
950 adapter
->if_ops
.card_reset(adapter
);
954 * This function cancels all the pending commands.
956 * The current command, all commands in command pending queue and all scan
957 * commands in scan pending queue are cancelled. All the completion callbacks
958 * are called with failure status to ensure cleanup.
961 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
963 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
966 /* Cancel current cmd */
967 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
968 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
969 adapter
->curr_cmd
->wait_q_enabled
= false;
970 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
971 adapter
->cmd_wait_q
.status
= -1;
972 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
974 /* Cancel all pending command */
975 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
976 list_for_each_entry_safe(cmd_node
, tmp_node
,
977 &adapter
->cmd_pending_q
, list
) {
978 list_del(&cmd_node
->list
);
979 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
981 if (cmd_node
->wait_q_enabled
) {
982 adapter
->cmd_wait_q
.status
= -1;
983 mwifiex_complete_cmd(adapter
, cmd_node
);
984 cmd_node
->wait_q_enabled
= false;
986 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
987 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
989 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
991 /* Cancel all pending scan command */
992 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
993 list_for_each_entry_safe(cmd_node
, tmp_node
,
994 &adapter
->scan_pending_q
, list
) {
995 list_del(&cmd_node
->list
);
996 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
998 cmd_node
->wait_q_enabled
= false;
999 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1000 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1002 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1004 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
1005 adapter
->scan_processing
= false;
1006 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
1010 * This function cancels all pending commands that matches with
1011 * the given IOCTL request.
1013 * Both the current command buffer and the pending command queue are
1014 * searched for matching IOCTL request. The completion callback of
1015 * the matched command is called with failure status to ensure cleanup.
1016 * In case of scan commands, all pending commands in scan pending queue
1020 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1022 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1023 unsigned long cmd_flags
;
1024 unsigned long scan_pending_q_flags
;
1025 uint16_t cancel_scan_cmd
= false;
1027 if ((adapter
->curr_cmd
) &&
1028 (adapter
->curr_cmd
->wait_q_enabled
)) {
1029 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1030 cmd_node
= adapter
->curr_cmd
;
1031 cmd_node
->wait_q_enabled
= false;
1032 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1033 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1034 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1035 adapter
->curr_cmd
= NULL
;
1036 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1039 /* Cancel all pending scan command */
1040 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1041 scan_pending_q_flags
);
1042 list_for_each_entry_safe(cmd_node
, tmp_node
,
1043 &adapter
->scan_pending_q
, list
) {
1044 list_del(&cmd_node
->list
);
1045 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1046 scan_pending_q_flags
);
1047 cmd_node
->wait_q_enabled
= false;
1048 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1049 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1050 scan_pending_q_flags
);
1051 cancel_scan_cmd
= true;
1053 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1054 scan_pending_q_flags
);
1056 if (cancel_scan_cmd
) {
1057 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1058 adapter
->scan_processing
= false;
1059 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1061 adapter
->cmd_wait_q
.status
= -1;
1065 * This function sends the sleep confirm command to firmware, if
1068 * The sleep confirm command cannot be issued if command response,
1069 * data response or event response is awaiting handling, or if we
1070 * are in the middle of sending a command, or expecting a command
1074 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1076 if (!adapter
->cmd_sent
&&
1077 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1078 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1080 dev_dbg(adapter
->dev
,
1081 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1082 (adapter
->cmd_sent
) ? "D" : "",
1083 (adapter
->curr_cmd
) ? "C" : "",
1084 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1088 * This function sends a Host Sleep activated event to applications.
1090 * This event is generated by the driver, with a blank event body.
1093 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1096 if (priv
->adapter
->is_hs_configured
) {
1097 priv
->adapter
->hs_activated
= true;
1098 mwifiex_update_rxreor_flags(priv
->adapter
,
1099 RXREOR_FORCE_NO_DROP
);
1100 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1101 priv
->adapter
->hs_activate_wait_q_woken
= true;
1102 wake_up_interruptible(
1103 &priv
->adapter
->hs_activate_wait_q
);
1105 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1108 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1109 priv
->adapter
->hs_activated
= false;
1114 * This function handles the command response of a Host Sleep configuration
1117 * Handling includes changing the header fields into CPU format
1118 * and setting the current host sleep activation status in driver.
1120 * In case host sleep status change, the function generates an event to
1121 * notify the applications.
1123 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1124 struct host_cmd_ds_command
*resp
)
1126 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1127 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1128 &resp
->params
.opt_hs_cfg
;
1129 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1131 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1132 adapter
->iface_type
== MWIFIEX_SDIO
) {
1133 mwifiex_hs_activated_event(priv
, true);
1136 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1137 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1138 resp
->result
, conditions
,
1139 phs_cfg
->params
.hs_config
.gpio
,
1140 phs_cfg
->params
.hs_config
.gap
);
1142 if (conditions
!= HOST_SLEEP_CFG_CANCEL
) {
1143 adapter
->is_hs_configured
= true;
1144 if (adapter
->iface_type
== MWIFIEX_USB
||
1145 adapter
->iface_type
== MWIFIEX_PCIE
)
1146 mwifiex_hs_activated_event(priv
, true);
1148 adapter
->is_hs_configured
= false;
1149 if (adapter
->hs_activated
)
1150 mwifiex_hs_activated_event(priv
, false);
1157 * This function wakes up the adapter and generates a Host Sleep
1158 * cancel event on receiving the power up interrupt.
1161 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1163 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1164 " since there is interrupt from the firmware\n", __func__
);
1166 adapter
->if_ops
.wakeup(adapter
);
1167 adapter
->hs_activated
= false;
1168 adapter
->is_hs_configured
= false;
1169 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1170 MWIFIEX_BSS_ROLE_ANY
),
1173 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1176 * This function handles the command response of a sleep confirm command.
1178 * The function sets the card state to SLEEP if the response indicates success.
1181 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1182 u8
*pbuf
, u32 upld_len
)
1184 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1185 struct mwifiex_private
*priv
=
1186 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1187 uint16_t result
= le16_to_cpu(cmd
->result
);
1188 uint16_t command
= le16_to_cpu(cmd
->command
);
1189 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1192 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1196 /* Get BSS number and corresponding priv */
1197 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1198 HostCmd_GET_BSS_TYPE(seq_num
));
1200 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1202 /* Update sequence number */
1203 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1204 /* Clear RET_BIT from HostCmd */
1205 command
&= HostCmd_CMD_ID_MASK
;
1207 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1208 dev_err(adapter
->dev
,
1209 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1210 __func__
, command
, result
);
1215 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1217 adapter
->pm_wakeup_card_req
= false;
1218 adapter
->ps_state
= PS_STATE_AWAKE
;
1221 adapter
->pm_wakeup_card_req
= true;
1222 if (adapter
->is_hs_configured
)
1223 mwifiex_hs_activated_event(mwifiex_get_priv
1224 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1226 adapter
->ps_state
= PS_STATE_SLEEP
;
1227 cmd
->command
= cpu_to_le16(command
);
1228 cmd
->seq_num
= cpu_to_le16(seq_num
);
1230 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1233 * This function prepares an enhanced power mode command.
1235 * This function can be used to disable power save or to configure
1236 * power save with auto PS or STA PS or auto deep sleep.
1238 * Preparation includes -
1239 * - Setting command ID, action and proper size
1240 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1241 * auto deep sleep TLV (as required)
1242 * - Ensuring correct endian-ness
1244 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1245 struct host_cmd_ds_command
*cmd
,
1246 u16 cmd_action
, uint16_t ps_bitmap
,
1247 struct mwifiex_ds_auto_ds
*auto_ds
)
1249 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1250 &cmd
->params
.psmode_enh
;
1254 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1255 if (cmd_action
== DIS_AUTO_PS
) {
1256 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1257 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1258 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1259 sizeof(psmode_enh
->params
.ps_bitmap
));
1260 } else if (cmd_action
== GET_PS
) {
1261 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1262 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1263 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1264 sizeof(psmode_enh
->params
.ps_bitmap
));
1265 } else if (cmd_action
== EN_AUTO_PS
) {
1266 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1267 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1268 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1269 sizeof(psmode_enh
->params
.ps_bitmap
);
1270 tlv
= (u8
*) cmd
+ cmd_size
;
1271 if (ps_bitmap
& BITMAP_STA_PS
) {
1272 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1273 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1274 (struct mwifiex_ie_types_ps_param
*) tlv
;
1275 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1276 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1277 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1278 sizeof(struct mwifiex_ie_types_header
));
1279 cmd_size
+= sizeof(*ps_tlv
);
1280 tlv
+= sizeof(*ps_tlv
);
1281 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1282 ps_mode
->null_pkt_interval
=
1283 cpu_to_le16(adapter
->null_pkt_interval
);
1284 ps_mode
->multiple_dtims
=
1285 cpu_to_le16(adapter
->multiple_dtim
);
1286 ps_mode
->bcn_miss_timeout
=
1287 cpu_to_le16(adapter
->bcn_miss_time_out
);
1288 ps_mode
->local_listen_interval
=
1289 cpu_to_le16(adapter
->local_listen_interval
);
1290 ps_mode
->adhoc_wake_period
=
1291 cpu_to_le16(adapter
->adhoc_awake_period
);
1292 ps_mode
->delay_to_ps
=
1293 cpu_to_le16(adapter
->delay_to_ps
);
1294 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1297 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1298 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1299 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1302 auto_ds_tlv
->header
.type
=
1303 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1304 auto_ds_tlv
->header
.len
=
1305 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1306 sizeof(struct mwifiex_ie_types_header
));
1307 cmd_size
+= sizeof(*auto_ds_tlv
);
1308 tlv
+= sizeof(*auto_ds_tlv
);
1310 idletime
= auto_ds
->idle_time
;
1311 dev_dbg(priv
->adapter
->dev
,
1312 "cmd: PS Command: Enter Auto Deep Sleep\n");
1313 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1315 cmd
->size
= cpu_to_le16(cmd_size
);
1321 * This function handles the command response of an enhanced power mode
1324 * Handling includes changing the header fields into CPU format
1325 * and setting the current enhanced power mode in driver.
1327 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1328 struct host_cmd_ds_command
*resp
,
1329 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1331 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1332 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1333 &resp
->params
.psmode_enh
;
1334 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1335 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1336 uint16_t auto_ps_bitmap
=
1337 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1339 dev_dbg(adapter
->dev
,
1340 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1341 __func__
, resp
->result
, action
);
1342 if (action
== EN_AUTO_PS
) {
1343 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1344 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1345 priv
->adapter
->is_deep_sleep
= true;
1347 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1348 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1349 if (adapter
->sleep_period
.period
)
1350 dev_dbg(adapter
->dev
,
1351 "cmd: set to uapsd/pps mode\n");
1353 } else if (action
== DIS_AUTO_PS
) {
1354 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1355 priv
->adapter
->is_deep_sleep
= false;
1356 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1358 if (ps_bitmap
& BITMAP_STA_PS
) {
1359 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1360 if (adapter
->sleep_period
.period
) {
1361 adapter
->delay_null_pkt
= false;
1362 adapter
->tx_lock_flag
= false;
1363 adapter
->pps_uapsd_mode
= false;
1366 } else if (action
== GET_PS
) {
1367 if (ps_bitmap
& BITMAP_STA_PS
)
1368 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1370 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1372 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1375 /* This section is for get power save mode */
1376 if (ps_bitmap
& BITMAP_STA_PS
)
1377 pm_cfg
->param
.ps_mode
= 1;
1379 pm_cfg
->param
.ps_mode
= 0;
1386 * This function prepares command to get hardware specifications.
1388 * Preparation includes -
1389 * - Setting command ID, action and proper size
1390 * - Setting permanent address parameter
1391 * - Ensuring correct endian-ness
1393 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1394 struct host_cmd_ds_command
*cmd
)
1396 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1398 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1400 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1401 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1407 * This function handles the command response of get hardware
1410 * Handling includes changing the header fields into CPU format
1411 * and saving/updating the following parameters in driver -
1412 * - Firmware capability information
1413 * - Firmware band settings
1414 * - Ad-hoc start band and channel
1415 * - Ad-hoc 11n activation status
1416 * - Firmware release number
1417 * - Number of antennas
1418 * - Hardware address
1419 * - Hardware interface version
1420 * - Firmware version
1422 * - 11n capabilities
1423 * - MCS support fields
1426 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1427 struct host_cmd_ds_command
*resp
)
1429 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1430 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1433 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1435 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1436 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1438 adapter
->fw_bands
= BAND_B
;
1440 adapter
->config_bands
= adapter
->fw_bands
;
1442 if (adapter
->fw_bands
& BAND_A
) {
1443 if (adapter
->fw_bands
& BAND_GN
) {
1444 adapter
->config_bands
|= BAND_AN
;
1445 adapter
->fw_bands
|= BAND_AN
;
1447 if (adapter
->fw_bands
& BAND_AN
) {
1448 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1449 adapter
->adhoc_11n_enabled
= true;
1451 adapter
->adhoc_start_band
= BAND_A
;
1453 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1454 } else if (adapter
->fw_bands
& BAND_GN
) {
1455 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1456 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1457 adapter
->adhoc_11n_enabled
= true;
1458 } else if (adapter
->fw_bands
& BAND_G
) {
1459 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1460 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1461 } else if (adapter
->fw_bands
& BAND_B
) {
1462 adapter
->adhoc_start_band
= BAND_B
;
1463 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1466 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1467 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1469 if (le32_to_cpu(hw_spec
->dot_11ac_dev_cap
)) {
1470 adapter
->is_hw_11ac_capable
= true;
1473 adapter
->hw_dot_11ac_dev_cap
=
1474 le32_to_cpu(hw_spec
->dot_11ac_dev_cap
);
1475 adapter
->usr_dot_11ac_dev_cap_bg
= adapter
->hw_dot_11ac_dev_cap
;
1476 adapter
->usr_dot_11ac_dev_cap_a
= adapter
->hw_dot_11ac_dev_cap
;
1479 adapter
->hw_dot_11ac_mcs_support
=
1480 le32_to_cpu(hw_spec
->dot_11ac_mcs_support
);
1481 adapter
->usr_dot_11ac_mcs_support
=
1482 adapter
->hw_dot_11ac_mcs_support
;
1484 adapter
->is_hw_11ac_capable
= false;
1487 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1488 adapter
->fw_release_number
);
1489 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1490 hw_spec
->permanent_addr
);
1491 dev_dbg(adapter
->dev
,
1492 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1493 le16_to_cpu(hw_spec
->hw_if_version
),
1494 le16_to_cpu(hw_spec
->version
));
1496 if (priv
->curr_addr
[0] == 0xff)
1497 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1499 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1501 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1502 /* Use the region code to search for the index */
1503 if (adapter
->region_code
== region_code_index
[i
])
1506 /* If it's unidentified region code, use the default (USA) */
1507 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1508 adapter
->region_code
= 0x10;
1509 dev_dbg(adapter
->dev
,
1510 "cmd: unknown region code, use default (USA)\n");
1513 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1514 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1516 if (adapter
->if_ops
.update_mp_end_port
)
1517 adapter
->if_ops
.update_mp_end_port(adapter
,
1518 le16_to_cpu(hw_spec
->mp_end_port
));