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.
29 * This function initializes a command node.
31 * The actual allocation of the node is not done by this function. It only
32 * initiates a node by filling it with default parameters. Similarly,
33 * allocation of the different buffers used (IOCTL buffer, data buffer) are
34 * not done by this function either.
37 mwifiex_init_cmd_node(struct mwifiex_private
*priv
,
38 struct cmd_ctrl_node
*cmd_node
,
39 u32 cmd_oid
, void *wait_queue
, void *data_buf
)
41 cmd_node
->priv
= priv
;
42 cmd_node
->cmd_oid
= cmd_oid
;
43 cmd_node
->wq_buf
= wait_queue
;
44 cmd_node
->data_buf
= data_buf
;
45 cmd_node
->cmd_skb
= cmd_node
->skb
;
49 * This function returns a command node from the free queue depending upon
52 static struct cmd_ctrl_node
*
53 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
55 struct cmd_ctrl_node
*cmd_node
;
58 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
59 if (list_empty(&adapter
->cmd_free_q
)) {
60 dev_err(adapter
->dev
, "GET_CMD_NODE: cmd node not available\n");
61 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
64 cmd_node
= list_first_entry(&adapter
->cmd_free_q
,
65 struct cmd_ctrl_node
, list
);
66 list_del(&cmd_node
->list
);
67 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
73 * This function cleans up a command node.
75 * The function resets the fields including the buffer pointers.
76 * This function does not try to free the buffers. They must be
77 * freed before calling this function.
79 * This function will however call the receive completion callback
80 * in case a response buffer is still available before resetting
84 mwifiex_clean_cmd_node(struct mwifiex_adapter
*adapter
,
85 struct cmd_ctrl_node
*cmd_node
)
87 cmd_node
->cmd_oid
= 0;
88 cmd_node
->cmd_flag
= 0;
89 cmd_node
->wq_buf
= NULL
;
90 cmd_node
->data_buf
= NULL
;
92 if (cmd_node
->resp_skb
) {
93 mwifiex_recv_complete(adapter
, cmd_node
->resp_skb
, 0);
94 cmd_node
->resp_skb
= NULL
;
101 * This function returns a command node from the pending queue which
102 * matches the given IOCTL request.
104 static struct cmd_ctrl_node
*
105 mwifiex_get_pending_ioctl_cmd(struct mwifiex_adapter
*adapter
,
106 struct mwifiex_wait_queue
*wait_queue
)
109 struct cmd_ctrl_node
*cmd_node
;
111 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
112 list_for_each_entry(cmd_node
, &adapter
->cmd_pending_q
, list
) {
113 if (cmd_node
->wq_buf
== wait_queue
) {
114 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
119 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
125 * This function sends a host command to the firmware.
127 * The function copies the host command into the driver command
128 * buffer, which will be transferred to the firmware later by the
131 static int mwifiex_cmd_host_cmd(struct mwifiex_private
*priv
,
132 struct host_cmd_ds_command
*cmd
, void *data_buf
)
134 struct mwifiex_ds_misc_cmd
*pcmd_ptr
=
135 (struct mwifiex_ds_misc_cmd
*) data_buf
;
137 /* Copy the HOST command to command buffer */
138 memcpy((void *) cmd
, pcmd_ptr
->cmd
, pcmd_ptr
->len
);
139 dev_dbg(priv
->adapter
->dev
, "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
144 * This function downloads a command to the firmware.
146 * The function performs sanity tests, sets the command sequence
147 * number and size, converts the header fields to CPU format before
148 * sending. Afterwards, it logs the command ID and action for debugging
149 * and sets up the command timeout timer.
151 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
152 struct cmd_ctrl_node
*cmd_node
)
155 struct mwifiex_adapter
*adapter
= priv
->adapter
;
157 struct host_cmd_ds_command
*host_cmd
;
158 struct mwifiex_wait_queue
*wait_queue
= NULL
;
161 struct timeval tstamp
;
164 if (!adapter
|| !cmd_node
)
167 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
168 if (cmd_node
->wq_buf
)
169 wait_queue
= (struct mwifiex_wait_queue
*) cmd_node
->wq_buf
;
172 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
173 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
174 " or cmd size is 0, not sending\n");
176 wait_queue
->status
= MWIFIEX_ERROR_CMD_DNLD_FAIL
;
177 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
181 /* Set command sequence number */
183 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
184 (adapter
->seq_num
, cmd_node
->priv
->bss_num
,
185 cmd_node
->priv
->bss_type
));
187 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
188 adapter
->curr_cmd
= cmd_node
;
189 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
191 cmd_code
= le16_to_cpu(host_cmd
->command
);
192 cmd_size
= le16_to_cpu(host_cmd
->size
);
194 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
196 do_gettimeofday(&tstamp
);
197 dev_dbg(adapter
->dev
, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
199 tstamp
.tv_sec
, tstamp
.tv_usec
, cmd_code
,
200 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
201 le16_to_cpu(host_cmd
->seq_num
));
203 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
205 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
206 cmd_node
->cmd_skb
->data
,
207 cmd_node
->cmd_skb
->len
, NULL
);
209 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
212 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
214 wait_queue
->status
= MWIFIEX_ERROR_CMD_DNLD_FAIL
;
215 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
217 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
218 adapter
->curr_cmd
= NULL
;
219 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
221 adapter
->dbg
.num_cmd_host_to_card_failure
++;
225 /* Save the last command id and action to debug log */
226 adapter
->dbg
.last_cmd_index
=
227 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
228 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
229 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
230 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
232 /* Clear BSS_NO_BITS from HostCmd */
233 cmd_code
&= HostCmd_CMD_ID_MASK
;
235 /* Setup the timer after transmit command */
236 mod_timer(&adapter
->cmd_timer
,
237 jiffies
+ (MWIFIEX_TIMER_10S
* HZ
) / 1000);
243 * This function downloads a sleep confirm command to the firmware.
245 * The function performs sanity tests, sets the command sequence
246 * number and size, converts the header fields to CPU format before
249 * No responses are needed for sleep confirm command.
251 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
255 struct mwifiex_private
*priv
;
256 struct mwifiex_opt_sleep_confirm_buffer
*sleep_cfm_buf
=
257 (struct mwifiex_opt_sleep_confirm_buffer
*)
258 adapter
->sleep_cfm
->data
;
259 cmd_len
= sizeof(struct mwifiex_opt_sleep_confirm
);
260 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
262 sleep_cfm_buf
->ps_cfm_sleep
.seq_num
=
263 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
264 (adapter
->seq_num
, priv
->bss_num
,
268 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
269 adapter
->sleep_cfm
->data
,
270 adapter
->sleep_cfm
->len
+
271 INTF_HEADER_LEN
, NULL
);
274 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
275 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
278 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
279 == MWIFIEX_BSS_ROLE_STA
) {
280 if (!sleep_cfm_buf
->ps_cfm_sleep
.resp_ctrl
)
281 /* Response is not needed for sleep
283 adapter
->ps_state
= PS_STATE_SLEEP
;
285 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
287 if (!sleep_cfm_buf
->ps_cfm_sleep
.resp_ctrl
288 && (adapter
->is_hs_configured
289 && !adapter
->sleep_period
.period
)) {
290 adapter
->pm_wakeup_card_req
= true;
291 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
292 MWIFIEX_BSS_ROLE_STA
), true);
300 * This function allocates the command buffers and links them to
301 * the command free queue.
303 * The driver uses a pre allocated number of command buffers, which
304 * are created at driver initializations and freed at driver cleanup.
305 * Every command needs to obtain a command buffer from this pool before
306 * it can be issued. The command free queue lists the command buffers
307 * currently free to use, while the command pending queue lists the
308 * command buffers already in use and awaiting handling. Command buffers
309 * are returned to the free queue after use.
311 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
313 struct cmd_ctrl_node
*cmd_array
;
317 /* Allocate and initialize struct cmd_ctrl_node */
318 buf_size
= sizeof(struct cmd_ctrl_node
) * MWIFIEX_NUM_OF_CMD_BUFFER
;
319 cmd_array
= kzalloc(buf_size
, GFP_KERNEL
);
321 dev_err(adapter
->dev
, "%s: failed to alloc cmd_array\n",
326 adapter
->cmd_pool
= cmd_array
;
327 memset(adapter
->cmd_pool
, 0, buf_size
);
329 /* Allocate and initialize command buffers */
330 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
331 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
332 if (!cmd_array
[i
].skb
) {
333 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
338 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
339 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
345 * This function frees the command buffers.
347 * The function calls the completion callback for all the command
348 * buffers that still have response buffers associated with them.
350 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
352 struct cmd_ctrl_node
*cmd_array
;
355 /* Need to check if cmd pool is allocated or not */
356 if (!adapter
->cmd_pool
) {
357 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
361 cmd_array
= adapter
->cmd_pool
;
363 /* Release shared memory buffers */
364 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
365 if (cmd_array
[i
].skb
) {
366 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
367 dev_kfree_skb_any(cmd_array
[i
].skb
);
369 if (!cmd_array
[i
].resp_skb
)
371 mwifiex_recv_complete(adapter
, cmd_array
[i
].resp_skb
, 0);
373 /* Release struct cmd_ctrl_node */
374 if (adapter
->cmd_pool
) {
375 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
376 kfree(adapter
->cmd_pool
);
377 adapter
->cmd_pool
= NULL
;
384 * This function handles events generated by firmware.
386 * Event body of events received from firmware are not used (though they are
387 * saved), only the event ID is used. Some events are re-invoked by
388 * the driver, with a new event body.
390 * After processing, the function calls the completion callback
393 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
396 struct mwifiex_private
*priv
=
397 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
398 struct sk_buff
*skb
= adapter
->event_skb
;
399 u32 eventcause
= adapter
->event_cause
;
400 struct timeval tstamp
;
401 struct mwifiex_rxinfo
*rx_info
= NULL
;
403 /* Save the last event to debug log */
404 adapter
->dbg
.last_event_index
=
405 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
406 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
409 /* Get BSS number and corresponding priv */
410 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
411 EVENT_GET_BSS_TYPE(eventcause
));
413 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
414 /* Clear BSS_NO_BITS from event */
415 eventcause
&= EVENT_ID_MASK
;
416 adapter
->event_cause
= eventcause
;
419 rx_info
= MWIFIEX_SKB_RXCB(skb
);
420 rx_info
->bss_index
= priv
->bss_index
;
423 if (eventcause
!= EVENT_PS_SLEEP
&& eventcause
!= EVENT_PS_AWAKE
) {
424 do_gettimeofday(&tstamp
);
425 dev_dbg(adapter
->dev
, "event: %lu.%lu: cause: %#x\n",
426 tstamp
.tv_sec
, tstamp
.tv_usec
, eventcause
);
429 ret
= mwifiex_process_sta_event(priv
);
431 adapter
->event_cause
= 0;
432 adapter
->event_skb
= NULL
;
434 mwifiex_recv_complete(adapter
, skb
, 0);
440 * This function prepares a command before sending it to the firmware.
442 * Preparation includes -
443 * - Sanity tests to make sure the card is still present or the FW
445 * - Getting a new command node from the command free queue
446 * - Initializing the command node for default parameters
447 * - Fill up the non-default parameters and buffer pointers
448 * - Add the command to pending queue
450 int mwifiex_prepare_cmd(struct mwifiex_private
*priv
, uint16_t cmd_no
,
451 u16 cmd_action
, u32 cmd_oid
,
452 void *wait_queue
, void *data_buf
)
455 struct mwifiex_adapter
*adapter
= priv
->adapter
;
456 struct cmd_ctrl_node
*cmd_node
= NULL
;
457 struct host_cmd_ds_command
*cmd_ptr
= NULL
;
460 pr_err("PREP_CMD: adapter is NULL\n");
464 if (adapter
->is_suspended
) {
465 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
469 if (adapter
->surprise_removed
) {
470 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
474 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
475 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
476 dev_err(adapter
->dev
, "PREP_CMD: FW in reset state\n");
481 /* Get a new command node */
482 cmd_node
= mwifiex_get_cmd_node(adapter
);
485 dev_err(adapter
->dev
, "PREP_CMD: no free cmd node\n");
489 /* Initialize the command node */
490 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, wait_queue
, data_buf
);
492 if (!cmd_node
->cmd_skb
) {
493 dev_err(adapter
->dev
, "PREP_CMD: no free cmd buf\n");
497 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
498 0, sizeof(struct host_cmd_ds_command
));
500 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
501 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
504 /* Prepare command */
506 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
507 cmd_oid
, data_buf
, cmd_ptr
);
509 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
510 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
513 /* Return error, since the command preparation failed */
515 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
517 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
522 if (cmd_no
== HostCmd_CMD_802_11_SCAN
)
523 mwifiex_queue_scan_cmd(priv
, cmd_node
);
525 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
531 * This function returns a command to the command free queue.
533 * The function also calls the completion callback if required, before
534 * cleaning the command node and re-inserting it into the free queue.
537 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
538 struct cmd_ctrl_node
*cmd_node
)
540 struct mwifiex_wait_queue
*wait_queue
= NULL
;
543 if (cmd_node
== NULL
)
545 if (cmd_node
->wq_buf
) {
546 wait_queue
= (struct mwifiex_wait_queue
*) cmd_node
->wq_buf
;
547 if (wait_queue
->status
!= MWIFIEX_ERROR_NO_ERROR
)
548 mwifiex_ioctl_complete(adapter
, wait_queue
, -1);
550 mwifiex_ioctl_complete(adapter
, wait_queue
, 0);
553 mwifiex_clean_cmd_node(adapter
, cmd_node
);
555 /* Insert node into cmd_free_q */
556 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
557 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
558 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
564 * This function queues a command to the command pending queue.
566 * This in effect adds the command to the command list to be executed.
567 * Exit PS command is handled specially, by placing it always to the
568 * front of the command queue.
571 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
572 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
574 struct host_cmd_ds_command
*host_cmd
= NULL
;
578 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
580 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
584 command
= le16_to_cpu(host_cmd
->command
);
586 /* Exit_PS command needs to be queued in the header always. */
587 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
588 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
589 &host_cmd
->params
.psmode_enh
;
590 if ((le16_to_cpu(pm
->action
) == DIS_PS
)
591 || (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
592 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
597 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
599 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
601 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
602 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
604 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command
);
610 * This function executes the next command in command pending queue.
612 * This function will fail if a command is already in processing stage,
613 * otherwise it will dequeue the first command from the command pending
614 * queue and send to the firmware.
616 * If the device is currently in host sleep mode, any commands, except the
617 * host sleep configuration command will de-activate the host sleep. For PS
618 * mode, the function will put the firmware back to sleep if applicable.
620 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
622 struct mwifiex_private
*priv
= NULL
;
623 struct cmd_ctrl_node
*cmd_node
= NULL
;
625 struct host_cmd_ds_command
*host_cmd
;
626 unsigned long cmd_flags
;
627 unsigned long cmd_pending_q_flags
;
629 /* Check if already in processing */
630 if (adapter
->curr_cmd
) {
631 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
635 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
636 /* Check if any command is pending */
637 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
638 if (list_empty(&adapter
->cmd_pending_q
)) {
639 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
640 cmd_pending_q_flags
);
641 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
644 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
645 struct cmd_ctrl_node
, list
);
646 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
647 cmd_pending_q_flags
);
649 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
650 priv
= cmd_node
->priv
;
652 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
653 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
654 " this should not happen\n", __func__
);
655 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
659 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
660 list_del(&cmd_node
->list
);
661 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
662 cmd_pending_q_flags
);
664 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
665 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
666 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
667 /* Any command sent to the firmware when host is in sleep
668 * mode should de-configure host sleep. We should skip the
669 * host sleep configuration command itself though
671 if (priv
&& (host_cmd
->command
!=
672 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
673 if (adapter
->hs_activated
) {
674 adapter
->is_hs_configured
= false;
675 mwifiex_hs_activated_event(priv
, false);
683 * This function handles the command response.
685 * After processing, the function cleans the command node and puts
686 * it back to the command free queue.
688 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
690 struct host_cmd_ds_command
*resp
= NULL
;
691 struct mwifiex_private
*priv
=
692 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
694 uint16_t orig_cmdresp_no
;
696 uint16_t cmdresp_result
;
697 struct mwifiex_wait_queue
*wait_queue
= NULL
;
698 struct timeval tstamp
;
701 /* Now we got response from FW, cancel the command timer */
702 del_timer(&adapter
->cmd_timer
);
704 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
705 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
706 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
707 le16_to_cpu(resp
->command
));
711 if (adapter
->curr_cmd
->wq_buf
)
712 wait_queue
= (struct mwifiex_wait_queue
*)
713 adapter
->curr_cmd
->wq_buf
;
715 adapter
->num_cmd_timeout
= 0;
717 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
718 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
719 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
720 le16_to_cpu(resp
->command
));
721 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
722 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
723 adapter
->curr_cmd
= NULL
;
724 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
728 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
729 /* Copy original response back to response buffer */
730 struct mwifiex_ds_misc_cmd
*hostcmd
= NULL
;
731 uint16_t size
= le16_to_cpu(resp
->size
);
732 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
733 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
734 if (adapter
->curr_cmd
->data_buf
) {
735 hostcmd
= (struct mwifiex_ds_misc_cmd
*)
736 adapter
->curr_cmd
->data_buf
;
738 memcpy(hostcmd
->cmd
, (void *) resp
, size
);
741 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
743 /* Get BSS number and corresponding priv */
744 priv
= mwifiex_get_priv_by_id(adapter
,
745 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
746 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
748 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
749 /* Clear RET_BIT from HostCmd */
750 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
752 cmdresp_no
= le16_to_cpu(resp
->command
);
753 cmdresp_result
= le16_to_cpu(resp
->result
);
755 /* Save the last command response to debug log */
756 adapter
->dbg
.last_cmd_resp_index
=
757 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
758 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
761 do_gettimeofday(&tstamp
);
762 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
763 " len %d, seqno 0x%x\n",
764 tstamp
.tv_sec
, tstamp
.tv_usec
, orig_cmdresp_no
, cmdresp_result
,
765 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
767 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
768 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
770 wait_queue
->status
= MWIFIEX_ERROR_FW_CMDRESP
;
772 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
773 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
774 adapter
->curr_cmd
= NULL
;
775 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
779 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
780 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
781 if ((cmdresp_result
== HostCmd_RESULT_OK
)
782 && (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
783 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
785 /* handle response */
786 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
,
790 /* Check init command response */
791 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
793 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
794 "initialization\n", __func__
, cmdresp_no
);
795 mwifiex_init_fw_complete(adapter
);
797 } else if (adapter
->last_init_cmd
== cmdresp_no
)
798 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
801 if (adapter
->curr_cmd
) {
802 if (wait_queue
&& (!ret
))
803 wait_queue
->status
= MWIFIEX_ERROR_NO_ERROR
;
804 else if (wait_queue
&& (ret
== -1))
805 wait_queue
->status
= MWIFIEX_ERROR_CMD_RESP_FAIL
;
807 /* Clean up and put current command back to cmd_free_q */
808 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
810 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
811 adapter
->curr_cmd
= NULL
;
812 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
819 * This function handles the timeout of command sending.
821 * It will re-send the same command again.
824 mwifiex_cmd_timeout_func(unsigned long function_context
)
826 struct mwifiex_adapter
*adapter
=
827 (struct mwifiex_adapter
*) function_context
;
828 struct cmd_ctrl_node
*cmd_node
= NULL
;
829 struct mwifiex_wait_queue
*wait_queue
= NULL
;
830 struct timeval tstamp
;
832 adapter
->num_cmd_timeout
++;
833 adapter
->dbg
.num_cmd_timeout
++;
834 if (!adapter
->curr_cmd
) {
835 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
838 cmd_node
= adapter
->curr_cmd
;
839 if (cmd_node
->wq_buf
) {
840 wait_queue
= (struct mwifiex_wait_queue
*) cmd_node
->wq_buf
;
841 wait_queue
->status
= MWIFIEX_ERROR_CMD_TIMEOUT
;
845 adapter
->dbg
.timeout_cmd_id
=
846 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
847 adapter
->dbg
.timeout_cmd_act
=
848 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
849 do_gettimeofday(&tstamp
);
850 dev_err(adapter
->dev
, "%s: Timeout cmd id (%lu.%lu) = %#x,"
851 " act = %#x\n", __func__
,
852 tstamp
.tv_sec
, tstamp
.tv_usec
,
853 adapter
->dbg
.timeout_cmd_id
,
854 adapter
->dbg
.timeout_cmd_act
);
856 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
857 adapter
->dbg
.num_tx_host_to_card_failure
);
858 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
859 adapter
->dbg
.num_cmd_host_to_card_failure
);
861 dev_err(adapter
->dev
, "num_cmd_timeout = %d\n",
862 adapter
->dbg
.num_cmd_timeout
);
863 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
864 adapter
->dbg
.num_tx_timeout
);
866 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
867 adapter
->dbg
.last_cmd_index
);
868 print_hex_dump_bytes("last_cmd_id: ", DUMP_PREFIX_OFFSET
,
869 adapter
->dbg
.last_cmd_id
, DBG_CMD_NUM
);
870 print_hex_dump_bytes("last_cmd_act: ", DUMP_PREFIX_OFFSET
,
871 adapter
->dbg
.last_cmd_act
, DBG_CMD_NUM
);
873 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
874 adapter
->dbg
.last_cmd_resp_index
);
875 print_hex_dump_bytes("last_cmd_resp_id: ", DUMP_PREFIX_OFFSET
,
876 adapter
->dbg
.last_cmd_resp_id
, DBG_CMD_NUM
);
878 dev_err(adapter
->dev
, "last_event_index = %d\n",
879 adapter
->dbg
.last_event_index
);
880 print_hex_dump_bytes("last_event: ", DUMP_PREFIX_OFFSET
,
881 adapter
->dbg
.last_event
, DBG_CMD_NUM
);
883 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
884 adapter
->data_sent
, adapter
->cmd_sent
);
886 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
887 adapter
->ps_mode
, adapter
->ps_state
);
889 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
890 mwifiex_init_fw_complete(adapter
);
896 * This function cancels all the pending commands.
898 * The current command, all commands in command pending queue and all scan
899 * commands in scan pending queue are cancelled. All the completion callbacks
900 * are called with failure status to ensure cleanup.
903 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
905 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
906 struct mwifiex_wait_queue
*wait_queue
= NULL
;
909 /* Cancel current cmd */
910 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wq_buf
)) {
912 (struct mwifiex_wait_queue
*) adapter
->curr_cmd
->wq_buf
;
913 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
914 adapter
->curr_cmd
->wq_buf
= NULL
;
915 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
916 wait_queue
->status
= MWIFIEX_ERROR_CMD_CANCEL
;
917 mwifiex_ioctl_complete(adapter
, wait_queue
, -1);
919 /* Cancel all pending command */
920 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
921 list_for_each_entry_safe(cmd_node
, tmp_node
,
922 &adapter
->cmd_pending_q
, list
) {
923 list_del(&cmd_node
->list
);
924 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
926 if (cmd_node
->wq_buf
) {
928 (struct mwifiex_wait_queue
*) cmd_node
->wq_buf
;
929 wait_queue
->status
= MWIFIEX_ERROR_CMD_CANCEL
;
930 mwifiex_ioctl_complete(adapter
, wait_queue
, -1);
931 cmd_node
->wq_buf
= NULL
;
933 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
934 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
936 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
938 /* Cancel all pending scan command */
939 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
940 list_for_each_entry_safe(cmd_node
, tmp_node
,
941 &adapter
->scan_pending_q
, list
) {
942 list_del(&cmd_node
->list
);
943 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
945 cmd_node
->wq_buf
= NULL
;
946 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
947 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
949 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
951 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
952 adapter
->scan_processing
= false;
953 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
957 * This function cancels all pending commands that matches with
958 * the given IOCTL request.
960 * Both the current command buffer and the pending command queue are
961 * searched for matching IOCTL request. The completion callback of
962 * the matched command is called with failure status to ensure cleanup.
963 * In case of scan commands, all pending commands in scan pending queue
967 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
,
968 struct mwifiex_wait_queue
*wait_queue
)
970 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
971 unsigned long cmd_flags
;
972 unsigned long cmd_pending_q_flags
;
973 unsigned long scan_pending_q_flags
;
974 uint16_t cancel_scan_cmd
= false;
976 if ((adapter
->curr_cmd
) &&
977 (adapter
->curr_cmd
->wq_buf
== wait_queue
)) {
978 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
979 cmd_node
= adapter
->curr_cmd
;
980 cmd_node
->wq_buf
= NULL
;
981 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
982 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
985 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
987 cmd_node
= mwifiex_get_pending_ioctl_cmd(adapter
, wait_queue
);
991 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
,
992 cmd_pending_q_flags
);
993 list_del(&cmd_node
->list
);
994 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
995 cmd_pending_q_flags
);
997 cmd_node
->wq_buf
= NULL
;
998 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1000 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1001 /* Cancel all pending scan command */
1002 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1003 scan_pending_q_flags
);
1004 list_for_each_entry_safe(cmd_node
, tmp_node
,
1005 &adapter
->scan_pending_q
, list
) {
1006 if (cmd_node
->wq_buf
== wait_queue
) {
1007 list_del(&cmd_node
->list
);
1008 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1009 scan_pending_q_flags
);
1010 cmd_node
->wq_buf
= NULL
;
1011 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1012 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1013 scan_pending_q_flags
);
1014 cancel_scan_cmd
= true;
1017 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1018 scan_pending_q_flags
);
1020 if (cancel_scan_cmd
) {
1021 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1022 adapter
->scan_processing
= false;
1023 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1025 wait_queue
->status
= MWIFIEX_ERROR_CMD_CANCEL
;
1026 mwifiex_ioctl_complete(adapter
, wait_queue
, -1);
1032 * This function sends the sleep confirm command to firmware, if
1035 * The sleep confirm command cannot be issued if command response,
1036 * data response or event response is awaiting handling, or if we
1037 * are in the middle of sending a command, or expecting a command
1041 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1043 if (!adapter
->cmd_sent
&&
1044 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1045 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1047 dev_dbg(adapter
->dev
,
1048 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1049 (adapter
->cmd_sent
) ? "D" : "",
1050 (adapter
->curr_cmd
) ? "C" : "",
1051 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1055 * This function sends a Host Sleep activated event to applications.
1057 * This event is generated by the driver, with a blank event body.
1060 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1063 if (priv
->adapter
->is_hs_configured
) {
1064 priv
->adapter
->hs_activated
= true;
1065 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1066 priv
->adapter
->hs_activate_wait_q_woken
= true;
1067 wake_up_interruptible(
1068 &priv
->adapter
->hs_activate_wait_q
);
1070 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1073 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1074 priv
->adapter
->hs_activated
= false;
1079 * This function handles the command response of a Host Sleep configuration
1082 * Handling includes changing the header fields into CPU format
1083 * and setting the current host sleep activation status in driver.
1085 * In case host sleep status change, the function generates an event to
1086 * notify the applications.
1088 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1089 struct host_cmd_ds_command
*resp
)
1091 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1092 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1093 &resp
->params
.opt_hs_cfg
;
1094 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1096 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
)) {
1097 mwifiex_hs_activated_event(priv
, true);
1100 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1101 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1102 resp
->result
, conditions
,
1103 phs_cfg
->params
.hs_config
.gpio
,
1104 phs_cfg
->params
.hs_config
.gap
);
1106 if (conditions
!= HOST_SLEEP_CFG_CANCEL
) {
1107 adapter
->is_hs_configured
= true;
1109 adapter
->is_hs_configured
= false;
1110 if (adapter
->hs_activated
)
1111 mwifiex_hs_activated_event(priv
, false);
1118 * This function wakes up the adapter and generates a Host Sleep
1119 * cancel event on receiving the power up interrupt.
1122 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1124 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1125 " since there is interrupt from the firmware\n", __func__
);
1127 adapter
->if_ops
.wakeup(adapter
);
1128 adapter
->hs_activated
= false;
1129 adapter
->is_hs_configured
= false;
1130 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1131 MWIFIEX_BSS_ROLE_ANY
), false);
1136 * This function handles the command response of a sleep confirm command.
1138 * The function sets the card state to SLEEP if the response indicates success.
1141 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1142 u8
*pbuf
, u32 upld_len
)
1144 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1145 struct mwifiex_private
*priv
=
1146 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1147 uint16_t result
= le16_to_cpu(cmd
->result
);
1148 uint16_t command
= le16_to_cpu(cmd
->command
);
1149 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1152 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1156 /* Get BSS number and corresponding priv */
1157 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1158 HostCmd_GET_BSS_TYPE(seq_num
));
1160 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1162 /* Update sequence number */
1163 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1164 /* Clear RET_BIT from HostCmd */
1165 command
&= HostCmd_CMD_ID_MASK
;
1167 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1168 dev_err(adapter
->dev
, "%s: received unexpected response for"
1169 " cmd %x, result = %x\n", __func__
, command
, result
);
1174 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1176 adapter
->pm_wakeup_card_req
= false;
1177 adapter
->ps_state
= PS_STATE_AWAKE
;
1180 adapter
->pm_wakeup_card_req
= true;
1181 if (adapter
->is_hs_configured
)
1182 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1183 MWIFIEX_BSS_ROLE_ANY
), true);
1184 adapter
->ps_state
= PS_STATE_SLEEP
;
1185 cmd
->command
= cpu_to_le16(command
);
1186 cmd
->seq_num
= cpu_to_le16(seq_num
);
1188 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1191 * This function prepares an enhanced power mode command.
1193 * This function can be used to disable power save or to configure
1194 * power save with auto PS or STA PS or auto deep sleep.
1196 * Preparation includes -
1197 * - Setting command ID, action and proper size
1198 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1199 * auto deep sleep TLV (as required)
1200 * - Ensuring correct endian-ness
1202 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1203 struct host_cmd_ds_command
*cmd
,
1204 u16 cmd_action
, uint16_t ps_bitmap
,
1207 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1208 &cmd
->params
.psmode_enh
;
1212 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1213 if (cmd_action
== DIS_AUTO_PS
) {
1214 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1215 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1216 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1217 sizeof(psmode_enh
->params
.ps_bitmap
));
1218 } else if (cmd_action
== GET_PS
) {
1219 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1220 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1221 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1222 sizeof(psmode_enh
->params
.ps_bitmap
));
1223 } else if (cmd_action
== EN_AUTO_PS
) {
1224 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1225 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1226 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1227 sizeof(psmode_enh
->params
.ps_bitmap
);
1228 tlv
= (u8
*) cmd
+ cmd_size
;
1229 if (ps_bitmap
& BITMAP_STA_PS
) {
1230 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1231 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1232 (struct mwifiex_ie_types_ps_param
*) tlv
;
1233 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1234 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1235 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1236 sizeof(struct mwifiex_ie_types_header
));
1237 cmd_size
+= sizeof(*ps_tlv
);
1238 tlv
+= sizeof(*ps_tlv
);
1239 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1240 ps_mode
->null_pkt_interval
=
1241 cpu_to_le16(adapter
->null_pkt_interval
);
1242 ps_mode
->multiple_dtims
=
1243 cpu_to_le16(adapter
->multiple_dtim
);
1244 ps_mode
->bcn_miss_timeout
=
1245 cpu_to_le16(adapter
->bcn_miss_time_out
);
1246 ps_mode
->local_listen_interval
=
1247 cpu_to_le16(adapter
->local_listen_interval
);
1248 ps_mode
->adhoc_wake_period
=
1249 cpu_to_le16(adapter
->adhoc_awake_period
);
1250 ps_mode
->delay_to_ps
=
1251 cpu_to_le16(adapter
->delay_to_ps
);
1253 cpu_to_le16(adapter
->enhanced_ps_mode
);
1256 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1257 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1258 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1261 auto_ds_tlv
->header
.type
=
1262 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1263 auto_ds_tlv
->header
.len
=
1264 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1265 sizeof(struct mwifiex_ie_types_header
));
1266 cmd_size
+= sizeof(*auto_ds_tlv
);
1267 tlv
+= sizeof(*auto_ds_tlv
);
1269 idletime
= ((struct mwifiex_ds_auto_ds
*)
1270 data_buf
)->idle_time
;
1271 dev_dbg(priv
->adapter
->dev
,
1272 "cmd: PS Command: Enter Auto Deep Sleep\n");
1273 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1275 cmd
->size
= cpu_to_le16(cmd_size
);
1281 * This function handles the command response of an enhanced power mode
1284 * Handling includes changing the header fields into CPU format
1285 * and setting the current enhanced power mode in driver.
1287 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1288 struct host_cmd_ds_command
*resp
,
1291 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1292 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1293 &resp
->params
.psmode_enh
;
1294 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1295 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1296 uint16_t auto_ps_bitmap
=
1297 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1299 dev_dbg(adapter
->dev
, "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1300 __func__
, resp
->result
, action
);
1301 if (action
== EN_AUTO_PS
) {
1302 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1303 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1304 priv
->adapter
->is_deep_sleep
= true;
1306 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1307 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1308 if (adapter
->sleep_period
.period
)
1309 dev_dbg(adapter
->dev
, "cmd: set to uapsd/pps mode\n");
1311 } else if (action
== DIS_AUTO_PS
) {
1312 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1313 priv
->adapter
->is_deep_sleep
= false;
1314 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1316 if (ps_bitmap
& BITMAP_STA_PS
) {
1317 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1318 if (adapter
->sleep_period
.period
) {
1319 adapter
->delay_null_pkt
= false;
1320 adapter
->tx_lock_flag
= false;
1321 adapter
->pps_uapsd_mode
= false;
1324 } else if (action
== GET_PS
) {
1325 if (ps_bitmap
& BITMAP_STA_PS
)
1326 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1328 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1330 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1333 /* This section is for get power save mode */
1334 struct mwifiex_ds_pm_cfg
*pm_cfg
=
1335 (struct mwifiex_ds_pm_cfg
*)data_buf
;
1336 if (ps_bitmap
& BITMAP_STA_PS
)
1337 pm_cfg
->param
.ps_mode
= 1;
1339 pm_cfg
->param
.ps_mode
= 0;
1346 * This function prepares command to get hardware specifications.
1348 * Preparation includes -
1349 * - Setting command ID, action and proper size
1350 * - Setting permanent address parameter
1351 * - Ensuring correct endian-ness
1353 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1354 struct host_cmd_ds_command
*cmd
)
1356 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1358 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1360 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1361 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1367 * This function handles the command response of get hardware
1370 * Handling includes changing the header fields into CPU format
1371 * and saving/updating the following parameters in driver -
1372 * - Firmware capability information
1373 * - Firmware band settings
1374 * - Ad-hoc start band and channel
1375 * - Ad-hoc 11n activation status
1376 * - Firmware release number
1377 * - Number of antennas
1378 * - Hardware address
1379 * - Hardware interface version
1380 * - Firmware version
1382 * - 11n capabilities
1383 * - MCS support fields
1386 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1387 struct host_cmd_ds_command
*resp
)
1389 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1390 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1393 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1395 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1396 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1398 adapter
->fw_bands
= BAND_B
;
1400 adapter
->config_bands
= adapter
->fw_bands
;
1402 if (adapter
->fw_bands
& BAND_A
) {
1403 if (adapter
->fw_bands
& BAND_GN
) {
1404 adapter
->config_bands
|= BAND_AN
;
1405 adapter
->fw_bands
|= BAND_AN
;
1407 if (adapter
->fw_bands
& BAND_AN
) {
1408 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1409 adapter
->adhoc_11n_enabled
= true;
1411 adapter
->adhoc_start_band
= BAND_A
;
1413 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1414 } else if (adapter
->fw_bands
& BAND_GN
) {
1415 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1416 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1417 adapter
->adhoc_11n_enabled
= true;
1418 } else if (adapter
->fw_bands
& BAND_G
) {
1419 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1420 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1421 } else if (adapter
->fw_bands
& BAND_B
) {
1422 adapter
->adhoc_start_band
= BAND_B
;
1423 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1426 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1427 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1429 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1430 adapter
->fw_release_number
);
1431 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1432 hw_spec
->permanent_addr
);
1433 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1434 le16_to_cpu(hw_spec
->hw_if_version
),
1435 le16_to_cpu(hw_spec
->version
));
1437 if (priv
->curr_addr
[0] == 0xff)
1438 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1440 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1442 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1443 /* Use the region code to search for the index */
1444 if (adapter
->region_code
== region_code_index
[i
])
1447 /* If it's unidentified region code, use the default (USA) */
1448 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1449 adapter
->region_code
= 0x10;
1450 dev_dbg(adapter
->dev
, "cmd: unknown region code, use default (USA)\n");
1453 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1454 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1456 if (adapter
->if_ops
.update_mp_end_port
)
1457 adapter
->if_ops
.update_mp_end_port(adapter
,
1458 le16_to_cpu(hw_spec
->mp_end_port
));