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 *data_buf
)
41 cmd_node
->priv
= priv
;
42 cmd_node
->cmd_oid
= cmd_oid
;
43 cmd_node
->wait_q_enabled
= priv
->adapter
->cmd_wait_q_required
;
44 priv
->adapter
->cmd_wait_q_required
= false;
45 cmd_node
->data_buf
= data_buf
;
46 cmd_node
->cmd_skb
= cmd_node
->skb
;
50 * This function returns a command node from the free queue depending upon
53 static struct cmd_ctrl_node
*
54 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
56 struct cmd_ctrl_node
*cmd_node
;
59 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
60 if (list_empty(&adapter
->cmd_free_q
)) {
61 dev_err(adapter
->dev
, "GET_CMD_NODE: cmd node not available\n");
62 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
65 cmd_node
= list_first_entry(&adapter
->cmd_free_q
,
66 struct cmd_ctrl_node
, list
);
67 list_del(&cmd_node
->list
);
68 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
74 * This function cleans up a command node.
76 * The function resets the fields including the buffer pointers.
77 * This function does not try to free the buffers. They must be
78 * freed before calling this function.
80 * This function will however call the receive completion callback
81 * in case a response buffer is still available before resetting
85 mwifiex_clean_cmd_node(struct mwifiex_adapter
*adapter
,
86 struct cmd_ctrl_node
*cmd_node
)
88 cmd_node
->cmd_oid
= 0;
89 cmd_node
->cmd_flag
= 0;
90 cmd_node
->data_buf
= NULL
;
91 cmd_node
->wait_q_enabled
= false;
93 if (cmd_node
->resp_skb
) {
94 mwifiex_recv_complete(adapter
, cmd_node
->resp_skb
, 0);
95 cmd_node
->resp_skb
= NULL
;
100 * This function sends a host command to the firmware.
102 * The function copies the host command into the driver command
103 * buffer, which will be transferred to the firmware later by the
106 static int mwifiex_cmd_host_cmd(struct mwifiex_private
*priv
,
107 struct host_cmd_ds_command
*cmd
, void *data_buf
)
109 struct mwifiex_ds_misc_cmd
*pcmd_ptr
=
110 (struct mwifiex_ds_misc_cmd
*) data_buf
;
112 /* Copy the HOST command to command buffer */
113 memcpy((void *) cmd
, pcmd_ptr
->cmd
, pcmd_ptr
->len
);
114 dev_dbg(priv
->adapter
->dev
, "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
119 * This function downloads a command to the firmware.
121 * The function performs sanity tests, sets the command sequence
122 * number and size, converts the header fields to CPU format before
123 * sending. Afterwards, it logs the command ID and action for debugging
124 * and sets up the command timeout timer.
126 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
127 struct cmd_ctrl_node
*cmd_node
)
130 struct mwifiex_adapter
*adapter
= priv
->adapter
;
132 struct host_cmd_ds_command
*host_cmd
;
135 struct timeval tstamp
;
138 if (!adapter
|| !cmd_node
)
141 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
144 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
145 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
146 " or cmd size is 0, not sending\n");
147 if (cmd_node
->wait_q_enabled
)
148 adapter
->cmd_wait_q
.status
= -1;
149 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
153 /* Set command sequence number */
155 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
156 (adapter
->seq_num
, cmd_node
->priv
->bss_num
,
157 cmd_node
->priv
->bss_type
));
159 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
160 adapter
->curr_cmd
= cmd_node
;
161 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
163 cmd_code
= le16_to_cpu(host_cmd
->command
);
164 cmd_size
= le16_to_cpu(host_cmd
->size
);
166 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
168 do_gettimeofday(&tstamp
);
169 dev_dbg(adapter
->dev
, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
171 tstamp
.tv_sec
, tstamp
.tv_usec
, cmd_code
,
172 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
173 le16_to_cpu(host_cmd
->seq_num
));
175 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
177 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
178 cmd_node
->cmd_skb
->data
,
179 cmd_node
->cmd_skb
->len
, NULL
);
181 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
184 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
185 if (cmd_node
->wait_q_enabled
)
186 adapter
->cmd_wait_q
.status
= -1;
187 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
189 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
190 adapter
->curr_cmd
= NULL
;
191 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
193 adapter
->dbg
.num_cmd_host_to_card_failure
++;
197 /* Save the last command id and action to debug log */
198 adapter
->dbg
.last_cmd_index
=
199 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
200 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
201 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
202 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
204 /* Clear BSS_NO_BITS from HostCmd */
205 cmd_code
&= HostCmd_CMD_ID_MASK
;
207 /* Setup the timer after transmit command */
208 mod_timer(&adapter
->cmd_timer
,
209 jiffies
+ (MWIFIEX_TIMER_10S
* HZ
) / 1000);
215 * This function downloads a sleep confirm command to the firmware.
217 * The function performs sanity tests, sets the command sequence
218 * number and size, converts the header fields to CPU format before
221 * No responses are needed for sleep confirm command.
223 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
227 struct mwifiex_private
*priv
;
228 struct mwifiex_opt_sleep_confirm_buffer
*sleep_cfm_buf
=
229 (struct mwifiex_opt_sleep_confirm_buffer
*)
230 adapter
->sleep_cfm
->data
;
231 cmd_len
= sizeof(struct mwifiex_opt_sleep_confirm
);
232 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
234 sleep_cfm_buf
->ps_cfm_sleep
.seq_num
=
235 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
236 (adapter
->seq_num
, priv
->bss_num
,
240 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
241 adapter
->sleep_cfm
->data
,
242 adapter
->sleep_cfm
->len
+
243 INTF_HEADER_LEN
, NULL
);
246 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
247 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
250 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
251 == MWIFIEX_BSS_ROLE_STA
) {
252 if (!sleep_cfm_buf
->ps_cfm_sleep
.resp_ctrl
)
253 /* Response is not needed for sleep
255 adapter
->ps_state
= PS_STATE_SLEEP
;
257 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
259 if (!sleep_cfm_buf
->ps_cfm_sleep
.resp_ctrl
260 && (adapter
->is_hs_configured
261 && !adapter
->sleep_period
.period
)) {
262 adapter
->pm_wakeup_card_req
= true;
263 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
264 MWIFIEX_BSS_ROLE_STA
), true);
272 * This function allocates the command buffers and links them to
273 * the command free queue.
275 * The driver uses a pre allocated number of command buffers, which
276 * are created at driver initializations and freed at driver cleanup.
277 * Every command needs to obtain a command buffer from this pool before
278 * it can be issued. The command free queue lists the command buffers
279 * currently free to use, while the command pending queue lists the
280 * command buffers already in use and awaiting handling. Command buffers
281 * are returned to the free queue after use.
283 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
285 struct cmd_ctrl_node
*cmd_array
;
289 /* Allocate and initialize struct cmd_ctrl_node */
290 buf_size
= sizeof(struct cmd_ctrl_node
) * MWIFIEX_NUM_OF_CMD_BUFFER
;
291 cmd_array
= kzalloc(buf_size
, GFP_KERNEL
);
293 dev_err(adapter
->dev
, "%s: failed to alloc cmd_array\n",
298 adapter
->cmd_pool
= cmd_array
;
299 memset(adapter
->cmd_pool
, 0, buf_size
);
301 /* Allocate and initialize command buffers */
302 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
303 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
304 if (!cmd_array
[i
].skb
) {
305 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
310 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
311 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
317 * This function frees the command buffers.
319 * The function calls the completion callback for all the command
320 * buffers that still have response buffers associated with them.
322 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
324 struct cmd_ctrl_node
*cmd_array
;
327 /* Need to check if cmd pool is allocated or not */
328 if (!adapter
->cmd_pool
) {
329 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
333 cmd_array
= adapter
->cmd_pool
;
335 /* Release shared memory buffers */
336 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
337 if (cmd_array
[i
].skb
) {
338 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
339 dev_kfree_skb_any(cmd_array
[i
].skb
);
341 if (!cmd_array
[i
].resp_skb
)
343 mwifiex_recv_complete(adapter
, cmd_array
[i
].resp_skb
, 0);
345 /* Release struct cmd_ctrl_node */
346 if (adapter
->cmd_pool
) {
347 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
348 kfree(adapter
->cmd_pool
);
349 adapter
->cmd_pool
= NULL
;
356 * This function handles events generated by firmware.
358 * Event body of events received from firmware are not used (though they are
359 * saved), only the event ID is used. Some events are re-invoked by
360 * the driver, with a new event body.
362 * After processing, the function calls the completion callback
365 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
368 struct mwifiex_private
*priv
=
369 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
370 struct sk_buff
*skb
= adapter
->event_skb
;
371 u32 eventcause
= adapter
->event_cause
;
372 struct timeval tstamp
;
373 struct mwifiex_rxinfo
*rx_info
;
375 /* Save the last event to debug log */
376 adapter
->dbg
.last_event_index
=
377 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
378 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
381 /* Get BSS number and corresponding priv */
382 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
383 EVENT_GET_BSS_TYPE(eventcause
));
385 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
386 /* Clear BSS_NO_BITS from event */
387 eventcause
&= EVENT_ID_MASK
;
388 adapter
->event_cause
= eventcause
;
391 rx_info
= MWIFIEX_SKB_RXCB(skb
);
392 rx_info
->bss_index
= priv
->bss_index
;
395 if (eventcause
!= EVENT_PS_SLEEP
&& eventcause
!= EVENT_PS_AWAKE
) {
396 do_gettimeofday(&tstamp
);
397 dev_dbg(adapter
->dev
, "event: %lu.%lu: cause: %#x\n",
398 tstamp
.tv_sec
, tstamp
.tv_usec
, eventcause
);
401 ret
= mwifiex_process_sta_event(priv
);
403 adapter
->event_cause
= 0;
404 adapter
->event_skb
= NULL
;
406 mwifiex_recv_complete(adapter
, skb
, 0);
412 * This function is used to send synchronous command to the firmware.
414 * it allocates a wait queue for the command and wait for the command
417 int mwifiex_send_cmd_sync(struct mwifiex_private
*priv
, uint16_t cmd_no
,
418 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
421 struct mwifiex_adapter
*adapter
= priv
->adapter
;
423 adapter
->cmd_wait_q_required
= true;
424 adapter
->cmd_wait_q
.condition
= false;
426 ret
= mwifiex_send_cmd_async(priv
, cmd_no
, cmd_action
, cmd_oid
,
429 ret
= mwifiex_wait_queue_complete(adapter
);
436 * This function prepares a command and asynchronously send it to the firmware.
438 * Preparation includes -
439 * - Sanity tests to make sure the card is still present or the FW
441 * - Getting a new command node from the command free queue
442 * - Initializing the command node for default parameters
443 * - Fill up the non-default parameters and buffer pointers
444 * - Add the command to pending queue
446 int mwifiex_send_cmd_async(struct mwifiex_private
*priv
, uint16_t cmd_no
,
447 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
450 struct mwifiex_adapter
*adapter
= priv
->adapter
;
451 struct cmd_ctrl_node
*cmd_node
;
452 struct host_cmd_ds_command
*cmd_ptr
;
455 pr_err("PREP_CMD: adapter is NULL\n");
459 if (adapter
->is_suspended
) {
460 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
464 if (adapter
->surprise_removed
) {
465 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
469 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
470 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
471 dev_err(adapter
->dev
, "PREP_CMD: FW in reset state\n");
476 /* Get a new command node */
477 cmd_node
= mwifiex_get_cmd_node(adapter
);
480 dev_err(adapter
->dev
, "PREP_CMD: no free cmd node\n");
484 /* Initialize the command node */
485 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
);
487 if (!cmd_node
->cmd_skb
) {
488 dev_err(adapter
->dev
, "PREP_CMD: no free cmd buf\n");
492 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
493 0, sizeof(struct host_cmd_ds_command
));
495 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
496 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
499 /* Prepare command */
501 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
502 cmd_oid
, data_buf
, cmd_ptr
);
504 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
505 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
508 /* Return error, since the command preparation failed */
510 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
512 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
517 if (cmd_no
== HostCmd_CMD_802_11_SCAN
)
518 mwifiex_queue_scan_cmd(priv
, cmd_node
);
520 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
526 * This function returns a command to the command free queue.
528 * The function also calls the completion callback if required, before
529 * cleaning the command node and re-inserting it into the free queue.
532 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
533 struct cmd_ctrl_node
*cmd_node
)
540 if (cmd_node
->wait_q_enabled
)
541 mwifiex_complete_cmd(adapter
);
543 mwifiex_clean_cmd_node(adapter
, cmd_node
);
545 /* Insert node into cmd_free_q */
546 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
547 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
548 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
552 * This function queues a command to the command pending queue.
554 * This in effect adds the command to the command list to be executed.
555 * Exit PS command is handled specially, by placing it always to the
556 * front of the command queue.
559 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
560 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
562 struct host_cmd_ds_command
*host_cmd
= NULL
;
566 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
568 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
572 command
= le16_to_cpu(host_cmd
->command
);
574 /* Exit_PS command needs to be queued in the header always. */
575 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
576 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
577 &host_cmd
->params
.psmode_enh
;
578 if ((le16_to_cpu(pm
->action
) == DIS_PS
)
579 || (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
580 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
585 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
587 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
589 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
590 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
592 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command
);
596 * This function executes the next command in command pending queue.
598 * This function will fail if a command is already in processing stage,
599 * otherwise it will dequeue the first command from the command pending
600 * queue and send to the firmware.
602 * If the device is currently in host sleep mode, any commands, except the
603 * host sleep configuration command will de-activate the host sleep. For PS
604 * mode, the function will put the firmware back to sleep if applicable.
606 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
608 struct mwifiex_private
*priv
;
609 struct cmd_ctrl_node
*cmd_node
;
611 struct host_cmd_ds_command
*host_cmd
;
612 unsigned long cmd_flags
;
613 unsigned long cmd_pending_q_flags
;
615 /* Check if already in processing */
616 if (adapter
->curr_cmd
) {
617 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
621 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
622 /* Check if any command is pending */
623 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
624 if (list_empty(&adapter
->cmd_pending_q
)) {
625 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
626 cmd_pending_q_flags
);
627 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
630 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
631 struct cmd_ctrl_node
, list
);
632 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
633 cmd_pending_q_flags
);
635 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
636 priv
= cmd_node
->priv
;
638 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
639 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
640 " this should not happen\n", __func__
);
641 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
645 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
646 list_del(&cmd_node
->list
);
647 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
648 cmd_pending_q_flags
);
650 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
651 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
652 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
653 /* Any command sent to the firmware when host is in sleep
654 * mode should de-configure host sleep. We should skip the
655 * host sleep configuration command itself though
657 if (priv
&& (host_cmd
->command
!=
658 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
659 if (adapter
->hs_activated
) {
660 adapter
->is_hs_configured
= false;
661 mwifiex_hs_activated_event(priv
, false);
669 * This function handles the command response.
671 * After processing, the function cleans the command node and puts
672 * it back to the command free queue.
674 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
676 struct host_cmd_ds_command
*resp
;
677 struct mwifiex_private
*priv
=
678 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
680 uint16_t orig_cmdresp_no
;
682 uint16_t cmdresp_result
;
683 struct timeval tstamp
;
686 /* Now we got response from FW, cancel the command timer */
687 del_timer(&adapter
->cmd_timer
);
689 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
690 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
691 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
692 le16_to_cpu(resp
->command
));
696 adapter
->num_cmd_timeout
= 0;
698 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
699 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
700 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
701 le16_to_cpu(resp
->command
));
702 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
703 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
704 adapter
->curr_cmd
= NULL
;
705 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
709 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
710 /* Copy original response back to response buffer */
711 struct mwifiex_ds_misc_cmd
*hostcmd
= NULL
;
712 uint16_t size
= le16_to_cpu(resp
->size
);
713 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
714 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
715 if (adapter
->curr_cmd
->data_buf
) {
716 hostcmd
= (struct mwifiex_ds_misc_cmd
*)
717 adapter
->curr_cmd
->data_buf
;
719 memcpy(hostcmd
->cmd
, (void *) resp
, size
);
722 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
724 /* Get BSS number and corresponding priv */
725 priv
= mwifiex_get_priv_by_id(adapter
,
726 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
727 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
729 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
730 /* Clear RET_BIT from HostCmd */
731 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
733 cmdresp_no
= le16_to_cpu(resp
->command
);
734 cmdresp_result
= le16_to_cpu(resp
->result
);
736 /* Save the last command response to debug log */
737 adapter
->dbg
.last_cmd_resp_index
=
738 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
739 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
742 do_gettimeofday(&tstamp
);
743 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
744 " len %d, seqno 0x%x\n",
745 tstamp
.tv_sec
, tstamp
.tv_usec
, orig_cmdresp_no
, cmdresp_result
,
746 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
748 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
749 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
750 if (adapter
->curr_cmd
->wait_q_enabled
)
751 adapter
->cmd_wait_q
.status
= -1;
753 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
754 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
755 adapter
->curr_cmd
= NULL
;
756 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
760 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
761 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
762 if ((cmdresp_result
== HostCmd_RESULT_OK
)
763 && (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
764 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
766 /* handle response */
767 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
770 /* Check init command response */
771 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
773 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
774 "initialization\n", __func__
, cmdresp_no
);
775 mwifiex_init_fw_complete(adapter
);
777 } else if (adapter
->last_init_cmd
== cmdresp_no
)
778 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
781 if (adapter
->curr_cmd
) {
782 if (adapter
->curr_cmd
->wait_q_enabled
&& (!ret
))
783 adapter
->cmd_wait_q
.status
= 0;
784 else if (adapter
->curr_cmd
->wait_q_enabled
&& (ret
== -1))
785 adapter
->cmd_wait_q
.status
= -1;
787 /* Clean up and put current command back to cmd_free_q */
788 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
790 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
791 adapter
->curr_cmd
= NULL
;
792 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
799 * This function handles the timeout of command sending.
801 * It will re-send the same command again.
804 mwifiex_cmd_timeout_func(unsigned long function_context
)
806 struct mwifiex_adapter
*adapter
=
807 (struct mwifiex_adapter
*) function_context
;
808 struct cmd_ctrl_node
*cmd_node
;
809 struct timeval tstamp
;
811 adapter
->num_cmd_timeout
++;
812 adapter
->dbg
.num_cmd_timeout
++;
813 if (!adapter
->curr_cmd
) {
814 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
817 cmd_node
= adapter
->curr_cmd
;
818 if (cmd_node
->wait_q_enabled
)
819 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
822 adapter
->dbg
.timeout_cmd_id
=
823 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
824 adapter
->dbg
.timeout_cmd_act
=
825 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
826 do_gettimeofday(&tstamp
);
827 dev_err(adapter
->dev
, "%s: Timeout cmd id (%lu.%lu) = %#x,"
828 " act = %#x\n", __func__
,
829 tstamp
.tv_sec
, tstamp
.tv_usec
,
830 adapter
->dbg
.timeout_cmd_id
,
831 adapter
->dbg
.timeout_cmd_act
);
833 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
834 adapter
->dbg
.num_tx_host_to_card_failure
);
835 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
836 adapter
->dbg
.num_cmd_host_to_card_failure
);
838 dev_err(adapter
->dev
, "num_cmd_timeout = %d\n",
839 adapter
->dbg
.num_cmd_timeout
);
840 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
841 adapter
->dbg
.num_tx_timeout
);
843 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
844 adapter
->dbg
.last_cmd_index
);
845 print_hex_dump_bytes("last_cmd_id: ", DUMP_PREFIX_OFFSET
,
846 adapter
->dbg
.last_cmd_id
, DBG_CMD_NUM
);
847 print_hex_dump_bytes("last_cmd_act: ", DUMP_PREFIX_OFFSET
,
848 adapter
->dbg
.last_cmd_act
, DBG_CMD_NUM
);
850 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
851 adapter
->dbg
.last_cmd_resp_index
);
852 print_hex_dump_bytes("last_cmd_resp_id: ", DUMP_PREFIX_OFFSET
,
853 adapter
->dbg
.last_cmd_resp_id
, DBG_CMD_NUM
);
855 dev_err(adapter
->dev
, "last_event_index = %d\n",
856 adapter
->dbg
.last_event_index
);
857 print_hex_dump_bytes("last_event: ", DUMP_PREFIX_OFFSET
,
858 adapter
->dbg
.last_event
, DBG_CMD_NUM
);
860 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
861 adapter
->data_sent
, adapter
->cmd_sent
);
863 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
864 adapter
->ps_mode
, adapter
->ps_state
);
866 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
867 mwifiex_init_fw_complete(adapter
);
871 * This function cancels all the pending commands.
873 * The current command, all commands in command pending queue and all scan
874 * commands in scan pending queue are cancelled. All the completion callbacks
875 * are called with failure status to ensure cleanup.
878 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
880 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
883 /* Cancel current cmd */
884 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
885 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
886 adapter
->curr_cmd
->wait_q_enabled
= false;
887 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
888 adapter
->cmd_wait_q
.status
= -1;
889 mwifiex_complete_cmd(adapter
);
891 /* Cancel all pending command */
892 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
893 list_for_each_entry_safe(cmd_node
, tmp_node
,
894 &adapter
->cmd_pending_q
, list
) {
895 list_del(&cmd_node
->list
);
896 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
898 if (cmd_node
->wait_q_enabled
) {
899 adapter
->cmd_wait_q
.status
= -1;
900 mwifiex_complete_cmd(adapter
);
901 cmd_node
->wait_q_enabled
= false;
903 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
904 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
906 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
908 /* Cancel all pending scan command */
909 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
910 list_for_each_entry_safe(cmd_node
, tmp_node
,
911 &adapter
->scan_pending_q
, list
) {
912 list_del(&cmd_node
->list
);
913 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
915 cmd_node
->wait_q_enabled
= false;
916 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
917 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
919 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
921 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
922 adapter
->scan_processing
= false;
923 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
927 * This function cancels all pending commands that matches with
928 * the given IOCTL request.
930 * Both the current command buffer and the pending command queue are
931 * searched for matching IOCTL request. The completion callback of
932 * the matched command is called with failure status to ensure cleanup.
933 * In case of scan commands, all pending commands in scan pending queue
937 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
939 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
940 unsigned long cmd_flags
;
941 unsigned long cmd_pending_q_flags
;
942 unsigned long scan_pending_q_flags
;
943 uint16_t cancel_scan_cmd
= false;
945 if ((adapter
->curr_cmd
) &&
946 (adapter
->curr_cmd
->wait_q_enabled
)) {
947 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
948 cmd_node
= adapter
->curr_cmd
;
949 cmd_node
->wait_q_enabled
= false;
950 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
951 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
,
952 cmd_pending_q_flags
);
953 list_del(&cmd_node
->list
);
954 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
955 cmd_pending_q_flags
);
956 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
957 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
960 /* Cancel all pending scan command */
961 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
962 scan_pending_q_flags
);
963 list_for_each_entry_safe(cmd_node
, tmp_node
,
964 &adapter
->scan_pending_q
, list
) {
965 list_del(&cmd_node
->list
);
966 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
967 scan_pending_q_flags
);
968 cmd_node
->wait_q_enabled
= false;
969 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
970 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
971 scan_pending_q_flags
);
972 cancel_scan_cmd
= true;
974 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
975 scan_pending_q_flags
);
977 if (cancel_scan_cmd
) {
978 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
979 adapter
->scan_processing
= false;
980 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
982 adapter
->cmd_wait_q
.status
= -1;
983 mwifiex_complete_cmd(adapter
);
987 * This function sends the sleep confirm command to firmware, if
990 * The sleep confirm command cannot be issued if command response,
991 * data response or event response is awaiting handling, or if we
992 * are in the middle of sending a command, or expecting a command
996 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
998 if (!adapter
->cmd_sent
&&
999 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1000 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1002 dev_dbg(adapter
->dev
,
1003 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1004 (adapter
->cmd_sent
) ? "D" : "",
1005 (adapter
->curr_cmd
) ? "C" : "",
1006 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1010 * This function sends a Host Sleep activated event to applications.
1012 * This event is generated by the driver, with a blank event body.
1015 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1018 if (priv
->adapter
->is_hs_configured
) {
1019 priv
->adapter
->hs_activated
= true;
1020 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1021 priv
->adapter
->hs_activate_wait_q_woken
= true;
1022 wake_up_interruptible(
1023 &priv
->adapter
->hs_activate_wait_q
);
1025 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1028 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1029 priv
->adapter
->hs_activated
= false;
1034 * This function handles the command response of a Host Sleep configuration
1037 * Handling includes changing the header fields into CPU format
1038 * and setting the current host sleep activation status in driver.
1040 * In case host sleep status change, the function generates an event to
1041 * notify the applications.
1043 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1044 struct host_cmd_ds_command
*resp
)
1046 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1047 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1048 &resp
->params
.opt_hs_cfg
;
1049 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1051 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
)) {
1052 mwifiex_hs_activated_event(priv
, true);
1055 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1056 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1057 resp
->result
, conditions
,
1058 phs_cfg
->params
.hs_config
.gpio
,
1059 phs_cfg
->params
.hs_config
.gap
);
1061 if (conditions
!= HOST_SLEEP_CFG_CANCEL
) {
1062 adapter
->is_hs_configured
= true;
1064 adapter
->is_hs_configured
= false;
1065 if (adapter
->hs_activated
)
1066 mwifiex_hs_activated_event(priv
, false);
1073 * This function wakes up the adapter and generates a Host Sleep
1074 * cancel event on receiving the power up interrupt.
1077 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1079 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1080 " since there is interrupt from the firmware\n", __func__
);
1082 adapter
->if_ops
.wakeup(adapter
);
1083 adapter
->hs_activated
= false;
1084 adapter
->is_hs_configured
= false;
1085 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1086 MWIFIEX_BSS_ROLE_ANY
), false);
1090 * This function handles the command response of a sleep confirm command.
1092 * The function sets the card state to SLEEP if the response indicates success.
1095 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1096 u8
*pbuf
, u32 upld_len
)
1098 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1099 struct mwifiex_private
*priv
=
1100 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1101 uint16_t result
= le16_to_cpu(cmd
->result
);
1102 uint16_t command
= le16_to_cpu(cmd
->command
);
1103 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1106 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1110 /* Get BSS number and corresponding priv */
1111 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1112 HostCmd_GET_BSS_TYPE(seq_num
));
1114 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1116 /* Update sequence number */
1117 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1118 /* Clear RET_BIT from HostCmd */
1119 command
&= HostCmd_CMD_ID_MASK
;
1121 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1122 dev_err(adapter
->dev
, "%s: received unexpected response for"
1123 " cmd %x, result = %x\n", __func__
, command
, result
);
1128 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1130 adapter
->pm_wakeup_card_req
= false;
1131 adapter
->ps_state
= PS_STATE_AWAKE
;
1134 adapter
->pm_wakeup_card_req
= true;
1135 if (adapter
->is_hs_configured
)
1136 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1137 MWIFIEX_BSS_ROLE_ANY
), true);
1138 adapter
->ps_state
= PS_STATE_SLEEP
;
1139 cmd
->command
= cpu_to_le16(command
);
1140 cmd
->seq_num
= cpu_to_le16(seq_num
);
1142 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1145 * This function prepares an enhanced power mode command.
1147 * This function can be used to disable power save or to configure
1148 * power save with auto PS or STA PS or auto deep sleep.
1150 * Preparation includes -
1151 * - Setting command ID, action and proper size
1152 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1153 * auto deep sleep TLV (as required)
1154 * - Ensuring correct endian-ness
1156 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1157 struct host_cmd_ds_command
*cmd
,
1158 u16 cmd_action
, uint16_t ps_bitmap
,
1161 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1162 &cmd
->params
.psmode_enh
;
1166 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1167 if (cmd_action
== DIS_AUTO_PS
) {
1168 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1169 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1170 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1171 sizeof(psmode_enh
->params
.ps_bitmap
));
1172 } else if (cmd_action
== GET_PS
) {
1173 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1174 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1175 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1176 sizeof(psmode_enh
->params
.ps_bitmap
));
1177 } else if (cmd_action
== EN_AUTO_PS
) {
1178 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1179 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1180 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1181 sizeof(psmode_enh
->params
.ps_bitmap
);
1182 tlv
= (u8
*) cmd
+ cmd_size
;
1183 if (ps_bitmap
& BITMAP_STA_PS
) {
1184 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1185 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1186 (struct mwifiex_ie_types_ps_param
*) tlv
;
1187 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1188 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1189 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1190 sizeof(struct mwifiex_ie_types_header
));
1191 cmd_size
+= sizeof(*ps_tlv
);
1192 tlv
+= sizeof(*ps_tlv
);
1193 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1194 ps_mode
->null_pkt_interval
=
1195 cpu_to_le16(adapter
->null_pkt_interval
);
1196 ps_mode
->multiple_dtims
=
1197 cpu_to_le16(adapter
->multiple_dtim
);
1198 ps_mode
->bcn_miss_timeout
=
1199 cpu_to_le16(adapter
->bcn_miss_time_out
);
1200 ps_mode
->local_listen_interval
=
1201 cpu_to_le16(adapter
->local_listen_interval
);
1202 ps_mode
->adhoc_wake_period
=
1203 cpu_to_le16(adapter
->adhoc_awake_period
);
1204 ps_mode
->delay_to_ps
=
1205 cpu_to_le16(adapter
->delay_to_ps
);
1207 cpu_to_le16(adapter
->enhanced_ps_mode
);
1210 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1211 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1212 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1215 auto_ds_tlv
->header
.type
=
1216 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1217 auto_ds_tlv
->header
.len
=
1218 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1219 sizeof(struct mwifiex_ie_types_header
));
1220 cmd_size
+= sizeof(*auto_ds_tlv
);
1221 tlv
+= sizeof(*auto_ds_tlv
);
1223 idletime
= ((struct mwifiex_ds_auto_ds
*)
1224 data_buf
)->idle_time
;
1225 dev_dbg(priv
->adapter
->dev
,
1226 "cmd: PS Command: Enter Auto Deep Sleep\n");
1227 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1229 cmd
->size
= cpu_to_le16(cmd_size
);
1235 * This function handles the command response of an enhanced power mode
1238 * Handling includes changing the header fields into CPU format
1239 * and setting the current enhanced power mode in driver.
1241 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1242 struct host_cmd_ds_command
*resp
,
1245 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1246 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1247 &resp
->params
.psmode_enh
;
1248 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1249 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1250 uint16_t auto_ps_bitmap
=
1251 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1253 dev_dbg(adapter
->dev
, "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1254 __func__
, resp
->result
, action
);
1255 if (action
== EN_AUTO_PS
) {
1256 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1257 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1258 priv
->adapter
->is_deep_sleep
= true;
1260 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1261 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1262 if (adapter
->sleep_period
.period
)
1263 dev_dbg(adapter
->dev
, "cmd: set to uapsd/pps mode\n");
1265 } else if (action
== DIS_AUTO_PS
) {
1266 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1267 priv
->adapter
->is_deep_sleep
= false;
1268 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1270 if (ps_bitmap
& BITMAP_STA_PS
) {
1271 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1272 if (adapter
->sleep_period
.period
) {
1273 adapter
->delay_null_pkt
= false;
1274 adapter
->tx_lock_flag
= false;
1275 adapter
->pps_uapsd_mode
= false;
1278 } else if (action
== GET_PS
) {
1279 if (ps_bitmap
& BITMAP_STA_PS
)
1280 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1282 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1284 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1287 /* This section is for get power save mode */
1288 struct mwifiex_ds_pm_cfg
*pm_cfg
=
1289 (struct mwifiex_ds_pm_cfg
*)data_buf
;
1290 if (ps_bitmap
& BITMAP_STA_PS
)
1291 pm_cfg
->param
.ps_mode
= 1;
1293 pm_cfg
->param
.ps_mode
= 0;
1300 * This function prepares command to get hardware specifications.
1302 * Preparation includes -
1303 * - Setting command ID, action and proper size
1304 * - Setting permanent address parameter
1305 * - Ensuring correct endian-ness
1307 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1308 struct host_cmd_ds_command
*cmd
)
1310 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1312 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1314 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1315 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1321 * This function handles the command response of get hardware
1324 * Handling includes changing the header fields into CPU format
1325 * and saving/updating the following parameters in driver -
1326 * - Firmware capability information
1327 * - Firmware band settings
1328 * - Ad-hoc start band and channel
1329 * - Ad-hoc 11n activation status
1330 * - Firmware release number
1331 * - Number of antennas
1332 * - Hardware address
1333 * - Hardware interface version
1334 * - Firmware version
1336 * - 11n capabilities
1337 * - MCS support fields
1340 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1341 struct host_cmd_ds_command
*resp
)
1343 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1344 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1347 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1349 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1350 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1352 adapter
->fw_bands
= BAND_B
;
1354 adapter
->config_bands
= adapter
->fw_bands
;
1356 if (adapter
->fw_bands
& BAND_A
) {
1357 if (adapter
->fw_bands
& BAND_GN
) {
1358 adapter
->config_bands
|= BAND_AN
;
1359 adapter
->fw_bands
|= BAND_AN
;
1361 if (adapter
->fw_bands
& BAND_AN
) {
1362 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1363 adapter
->adhoc_11n_enabled
= true;
1365 adapter
->adhoc_start_band
= BAND_A
;
1367 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1368 } else if (adapter
->fw_bands
& BAND_GN
) {
1369 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1370 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1371 adapter
->adhoc_11n_enabled
= true;
1372 } else if (adapter
->fw_bands
& BAND_G
) {
1373 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1374 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1375 } else if (adapter
->fw_bands
& BAND_B
) {
1376 adapter
->adhoc_start_band
= BAND_B
;
1377 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1380 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1381 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1383 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1384 adapter
->fw_release_number
);
1385 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1386 hw_spec
->permanent_addr
);
1387 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1388 le16_to_cpu(hw_spec
->hw_if_version
),
1389 le16_to_cpu(hw_spec
->version
));
1391 if (priv
->curr_addr
[0] == 0xff)
1392 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1394 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1396 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1397 /* Use the region code to search for the index */
1398 if (adapter
->region_code
== region_code_index
[i
])
1401 /* If it's unidentified region code, use the default (USA) */
1402 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1403 adapter
->region_code
= 0x10;
1404 dev_dbg(adapter
->dev
, "cmd: unknown region code, use default (USA)\n");
1407 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1408 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1410 if (adapter
->if_ops
.update_mp_end_port
)
1411 adapter
->if_ops
.update_mp_end_port(adapter
,
1412 le16_to_cpu(hw_spec
->mp_end_port
));