2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
30 * This function initializes a command node.
32 * The actual allocation of the node is not done by this function. It only
33 * initiates a node by filling it with default parameters. Similarly,
34 * allocation of the different buffers used (IOCTL buffer, data buffer) are
35 * not done by this function either.
38 mwifiex_init_cmd_node(struct mwifiex_private
*priv
,
39 struct cmd_ctrl_node
*cmd_node
,
40 u32 cmd_oid
, void *data_buf
, bool sync
)
42 cmd_node
->priv
= priv
;
43 cmd_node
->cmd_oid
= cmd_oid
;
45 cmd_node
->wait_q_enabled
= true;
46 cmd_node
->cmd_wait_q_woken
= false;
47 cmd_node
->condition
= &cmd_node
->cmd_wait_q_woken
;
49 cmd_node
->data_buf
= data_buf
;
50 cmd_node
->cmd_skb
= cmd_node
->skb
;
54 * This function returns a command node from the free queue depending upon
57 static struct cmd_ctrl_node
*
58 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
60 struct cmd_ctrl_node
*cmd_node
;
63 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
64 if (list_empty(&adapter
->cmd_free_q
)) {
65 dev_err(adapter
->dev
, "GET_CMD_NODE: cmd node not available\n");
66 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
69 cmd_node
= list_first_entry(&adapter
->cmd_free_q
,
70 struct cmd_ctrl_node
, list
);
71 list_del(&cmd_node
->list
);
72 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
78 * This function cleans up a command node.
80 * The function resets the fields including the buffer pointers.
81 * This function does not try to free the buffers. They must be
82 * freed before calling this function.
84 * This function will however call the receive completion callback
85 * in case a response buffer is still available before resetting
89 mwifiex_clean_cmd_node(struct mwifiex_adapter
*adapter
,
90 struct cmd_ctrl_node
*cmd_node
)
92 cmd_node
->cmd_oid
= 0;
93 cmd_node
->cmd_flag
= 0;
94 cmd_node
->data_buf
= NULL
;
95 cmd_node
->wait_q_enabled
= false;
97 if (cmd_node
->cmd_skb
)
98 skb_trim(cmd_node
->cmd_skb
, 0);
100 if (cmd_node
->resp_skb
) {
101 adapter
->if_ops
.cmdrsp_complete(adapter
, cmd_node
->resp_skb
);
102 cmd_node
->resp_skb
= NULL
;
107 * This function sends a host command to the firmware.
109 * The function copies the host command into the driver command
110 * buffer, which will be transferred to the firmware later by the
113 static int mwifiex_cmd_host_cmd(struct mwifiex_private
*priv
,
114 struct host_cmd_ds_command
*cmd
,
115 struct mwifiex_ds_misc_cmd
*pcmd_ptr
)
117 /* Copy the HOST command to command buffer */
118 memcpy(cmd
, pcmd_ptr
->cmd
, pcmd_ptr
->len
);
119 dev_dbg(priv
->adapter
->dev
, "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
124 * This function downloads a command to the firmware.
126 * The function performs sanity tests, sets the command sequence
127 * number and size, converts the header fields to CPU format before
128 * sending. Afterwards, it logs the command ID and action for debugging
129 * and sets up the command timeout timer.
131 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
132 struct cmd_ctrl_node
*cmd_node
)
135 struct mwifiex_adapter
*adapter
= priv
->adapter
;
137 struct host_cmd_ds_command
*host_cmd
;
143 if (!adapter
|| !cmd_node
)
146 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
149 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
150 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
151 " or cmd size is 0, not sending\n");
152 if (cmd_node
->wait_q_enabled
)
153 adapter
->cmd_wait_q
.status
= -1;
154 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
158 cmd_code
= le16_to_cpu(host_cmd
->command
);
159 cmd_size
= le16_to_cpu(host_cmd
->size
);
161 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
&&
162 cmd_code
!= HostCmd_CMD_FUNC_SHUTDOWN
&&
163 cmd_code
!= HostCmd_CMD_FUNC_INIT
) {
164 dev_err(adapter
->dev
,
165 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
167 if (cmd_node
->wait_q_enabled
)
168 mwifiex_complete_cmd(adapter
, cmd_node
);
169 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
170 queue_work(adapter
->workqueue
, &adapter
->main_work
);
174 /* Set command sequence number */
176 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
178 cmd_node
->priv
->bss_num
,
179 cmd_node
->priv
->bss_type
));
181 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
182 adapter
->curr_cmd
= cmd_node
;
183 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
185 /* Adjust skb length */
186 if (cmd_node
->cmd_skb
->len
> cmd_size
)
188 * cmd_size is less than sizeof(struct host_cmd_ds_command).
189 * Trim off the unused portion.
191 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
192 else if (cmd_node
->cmd_skb
->len
< cmd_size
)
194 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
195 * because we have appended custom IE TLV. Increase skb length
198 skb_put(cmd_node
->cmd_skb
, cmd_size
- cmd_node
->cmd_skb
->len
);
200 dev_dbg(adapter
->dev
,
201 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n", cmd_code
,
202 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
203 le16_to_cpu(host_cmd
->seq_num
));
205 if (adapter
->iface_type
== MWIFIEX_USB
) {
206 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
207 skb_push(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
208 memcpy(cmd_node
->cmd_skb
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
209 adapter
->cmd_sent
= true;
210 ret
= adapter
->if_ops
.host_to_card(adapter
,
211 MWIFIEX_USB_EP_CMD_EVENT
,
212 cmd_node
->cmd_skb
, NULL
);
213 skb_pull(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
215 cmd_node
->cmd_skb
= NULL
;
217 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
218 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
219 cmd_node
->cmd_skb
, NULL
);
220 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
224 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
225 if (adapter
->iface_type
== MWIFIEX_USB
)
226 adapter
->cmd_sent
= false;
227 if (cmd_node
->wait_q_enabled
)
228 adapter
->cmd_wait_q
.status
= -1;
229 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
231 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
232 adapter
->curr_cmd
= NULL
;
233 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
235 adapter
->dbg
.num_cmd_host_to_card_failure
++;
239 /* Save the last command id and action to debug log */
240 adapter
->dbg
.last_cmd_index
=
241 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
242 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
243 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
244 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
246 /* Clear BSS_NO_BITS from HostCmd */
247 cmd_code
&= HostCmd_CMD_ID_MASK
;
249 /* Setup the timer after transmit command */
250 mod_timer(&adapter
->cmd_timer
,
251 jiffies
+ msecs_to_jiffies(MWIFIEX_TIMER_10S
));
257 * This function downloads a sleep confirm command to the firmware.
259 * The function performs sanity tests, sets the command sequence
260 * number and size, converts the header fields to CPU format before
263 * No responses are needed for sleep confirm command.
265 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
268 struct mwifiex_private
*priv
;
269 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
=
270 (struct mwifiex_opt_sleep_confirm
*)
271 adapter
->sleep_cfm
->data
;
272 struct sk_buff
*sleep_cfm_tmp
;
275 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
278 sleep_cfm_buf
->seq_num
=
279 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
280 (adapter
->seq_num
, priv
->bss_num
,
283 dev_dbg(adapter
->dev
,
284 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
285 le16_to_cpu(sleep_cfm_buf
->command
),
286 le16_to_cpu(sleep_cfm_buf
->action
),
287 le16_to_cpu(sleep_cfm_buf
->size
),
288 le16_to_cpu(sleep_cfm_buf
->seq_num
));
290 if (adapter
->iface_type
== MWIFIEX_USB
) {
292 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
294 skb_put(sleep_cfm_tmp
, sizeof(struct mwifiex_opt_sleep_confirm
)
296 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
297 memcpy(sleep_cfm_tmp
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
298 memcpy(sleep_cfm_tmp
->data
+ MWIFIEX_TYPE_LEN
,
299 adapter
->sleep_cfm
->data
,
300 sizeof(struct mwifiex_opt_sleep_confirm
));
301 ret
= adapter
->if_ops
.host_to_card(adapter
,
302 MWIFIEX_USB_EP_CMD_EVENT
,
303 sleep_cfm_tmp
, NULL
);
305 dev_kfree_skb_any(sleep_cfm_tmp
);
307 skb_push(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
308 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
309 adapter
->sleep_cfm
, NULL
);
310 skb_pull(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
314 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
315 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
318 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
319 == MWIFIEX_BSS_ROLE_STA
) {
320 if (!le16_to_cpu(sleep_cfm_buf
->resp_ctrl
))
321 /* Response is not needed for sleep
323 adapter
->ps_state
= PS_STATE_SLEEP
;
325 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
327 if (!le16_to_cpu(sleep_cfm_buf
->resp_ctrl
) &&
328 (adapter
->is_hs_configured
&&
329 !adapter
->sleep_period
.period
)) {
330 adapter
->pm_wakeup_card_req
= true;
331 mwifiex_hs_activated_event(mwifiex_get_priv
332 (adapter
, MWIFIEX_BSS_ROLE_STA
), true);
340 * This function allocates the command buffers and links them to
341 * the command free queue.
343 * The driver uses a pre allocated number of command buffers, which
344 * are created at driver initializations and freed at driver cleanup.
345 * Every command needs to obtain a command buffer from this pool before
346 * it can be issued. The command free queue lists the command buffers
347 * currently free to use, while the command pending queue lists the
348 * command buffers already in use and awaiting handling. Command buffers
349 * are returned to the free queue after use.
351 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
353 struct cmd_ctrl_node
*cmd_array
;
356 /* Allocate and initialize struct cmd_ctrl_node */
357 cmd_array
= kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER
,
358 sizeof(struct cmd_ctrl_node
), GFP_KERNEL
);
362 adapter
->cmd_pool
= cmd_array
;
364 /* Allocate and initialize command buffers */
365 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
366 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
367 if (!cmd_array
[i
].skb
) {
368 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
373 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
374 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
380 * This function frees the command buffers.
382 * The function calls the completion callback for all the command
383 * buffers that still have response buffers associated with them.
385 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
387 struct cmd_ctrl_node
*cmd_array
;
390 /* Need to check if cmd pool is allocated or not */
391 if (!adapter
->cmd_pool
) {
392 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
396 cmd_array
= adapter
->cmd_pool
;
398 /* Release shared memory buffers */
399 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
400 if (cmd_array
[i
].skb
) {
401 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
402 dev_kfree_skb_any(cmd_array
[i
].skb
);
404 if (!cmd_array
[i
].resp_skb
)
407 if (adapter
->iface_type
== MWIFIEX_USB
)
408 adapter
->if_ops
.cmdrsp_complete(adapter
,
409 cmd_array
[i
].resp_skb
);
411 dev_kfree_skb_any(cmd_array
[i
].resp_skb
);
413 /* Release struct cmd_ctrl_node */
414 if (adapter
->cmd_pool
) {
415 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
416 kfree(adapter
->cmd_pool
);
417 adapter
->cmd_pool
= NULL
;
424 * This function handles events generated by firmware.
426 * Event body of events received from firmware are not used (though they are
427 * saved), only the event ID is used. Some events are re-invoked by
428 * the driver, with a new event body.
430 * After processing, the function calls the completion callback
433 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
436 struct mwifiex_private
*priv
=
437 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
438 struct sk_buff
*skb
= adapter
->event_skb
;
439 u32 eventcause
= adapter
->event_cause
;
440 struct mwifiex_rxinfo
*rx_info
;
442 /* Save the last event to debug log */
443 adapter
->dbg
.last_event_index
=
444 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
445 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
448 /* Get BSS number and corresponding priv */
449 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
450 EVENT_GET_BSS_TYPE(eventcause
));
452 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
453 /* Clear BSS_NO_BITS from event */
454 eventcause
&= EVENT_ID_MASK
;
455 adapter
->event_cause
= eventcause
;
458 rx_info
= MWIFIEX_SKB_RXCB(skb
);
459 memset(rx_info
, 0, sizeof(*rx_info
));
460 rx_info
->bss_num
= priv
->bss_num
;
461 rx_info
->bss_type
= priv
->bss_type
;
464 dev_dbg(adapter
->dev
, "EVENT: cause: %#x\n", eventcause
);
465 if (eventcause
== EVENT_PS_SLEEP
|| eventcause
== EVENT_PS_AWAKE
) {
466 /* Handle PS_SLEEP/AWAKE events on STA */
467 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
469 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
472 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
473 ret
= mwifiex_process_uap_event(priv
);
475 ret
= mwifiex_process_sta_event(priv
);
477 adapter
->event_cause
= 0;
478 adapter
->event_skb
= NULL
;
479 adapter
->if_ops
.event_complete(adapter
, skb
);
485 * This function prepares a command and send it to the firmware.
487 * Preparation includes -
488 * - Sanity tests to make sure the card is still present or the FW
490 * - Getting a new command node from the command free queue
491 * - Initializing the command node for default parameters
492 * - Fill up the non-default parameters and buffer pointers
493 * - Add the command to pending queue
495 int mwifiex_send_cmd(struct mwifiex_private
*priv
, u16 cmd_no
,
496 u16 cmd_action
, u32 cmd_oid
, void *data_buf
, bool sync
)
499 struct mwifiex_adapter
*adapter
= priv
->adapter
;
500 struct cmd_ctrl_node
*cmd_node
;
501 struct host_cmd_ds_command
*cmd_ptr
;
504 pr_err("PREP_CMD: adapter is NULL\n");
508 if (adapter
->is_suspended
) {
509 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
513 if (adapter
->hs_enabling
&& cmd_no
!= HostCmd_CMD_802_11_HS_CFG_ENH
) {
514 dev_err(adapter
->dev
, "PREP_CMD: host entering sleep state\n");
518 if (adapter
->surprise_removed
) {
519 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
523 if (adapter
->is_cmd_timedout
) {
524 dev_err(adapter
->dev
, "PREP_CMD: FW is in bad state\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
, sync
);
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 case HostCmd_CMD_UAP_STA_DEAUTH
:
565 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
570 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
576 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
577 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
580 /* Return error, since the command preparation failed */
582 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
584 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
589 if (cmd_no
== HostCmd_CMD_802_11_SCAN
||
590 cmd_no
== HostCmd_CMD_802_11_SCAN_EXT
) {
591 mwifiex_queue_scan_cmd(priv
, cmd_node
);
593 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
594 queue_work(adapter
->workqueue
, &adapter
->main_work
);
595 if (cmd_node
->wait_q_enabled
)
596 ret
= mwifiex_wait_queue_complete(adapter
, cmd_node
);
603 * This function returns a command to the command free queue.
605 * The function also calls the completion callback if required, before
606 * cleaning the command node and re-inserting it into the free queue.
609 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
610 struct cmd_ctrl_node
*cmd_node
)
617 if (cmd_node
->wait_q_enabled
)
618 mwifiex_complete_cmd(adapter
, cmd_node
);
620 mwifiex_clean_cmd_node(adapter
, cmd_node
);
622 /* Insert node into cmd_free_q */
623 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
624 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
625 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
628 /* This function reuses a command node. */
629 void mwifiex_recycle_cmd_node(struct mwifiex_adapter
*adapter
,
630 struct cmd_ctrl_node
*cmd_node
)
632 struct host_cmd_ds_command
*host_cmd
= (void *)cmd_node
->cmd_skb
->data
;
634 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
636 atomic_dec(&adapter
->cmd_pending
);
637 dev_dbg(adapter
->dev
, "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
638 le16_to_cpu(host_cmd
->command
),
639 atomic_read(&adapter
->cmd_pending
));
643 * This function queues a command to the command pending queue.
645 * This in effect adds the command to the command list to be executed.
646 * Exit PS command is handled specially, by placing it always to the
647 * front of the command queue.
650 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
651 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
653 struct host_cmd_ds_command
*host_cmd
= NULL
;
657 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
659 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
663 command
= le16_to_cpu(host_cmd
->command
);
665 /* Exit_PS command needs to be queued in the header always. */
666 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
667 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
668 &host_cmd
->params
.psmode_enh
;
669 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
670 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
671 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
676 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
678 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
680 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
681 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
683 atomic_inc(&adapter
->cmd_pending
);
684 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
685 command
, atomic_read(&adapter
->cmd_pending
));
689 * This function executes the next command in command pending queue.
691 * This function will fail if a command is already in processing stage,
692 * otherwise it will dequeue the first command from the command pending
693 * queue and send to the firmware.
695 * If the device is currently in host sleep mode, any commands, except the
696 * host sleep configuration command will de-activate the host sleep. For PS
697 * mode, the function will put the firmware back to sleep if applicable.
699 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
701 struct mwifiex_private
*priv
;
702 struct cmd_ctrl_node
*cmd_node
;
704 struct host_cmd_ds_command
*host_cmd
;
705 unsigned long cmd_flags
;
706 unsigned long cmd_pending_q_flags
;
708 /* Check if already in processing */
709 if (adapter
->curr_cmd
) {
710 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
714 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
715 /* Check if any command is pending */
716 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
717 if (list_empty(&adapter
->cmd_pending_q
)) {
718 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
719 cmd_pending_q_flags
);
720 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
723 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
724 struct cmd_ctrl_node
, list
);
725 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
726 cmd_pending_q_flags
);
728 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
729 priv
= cmd_node
->priv
;
731 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
732 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
733 " this should not happen\n", __func__
);
734 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
738 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
739 list_del(&cmd_node
->list
);
740 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
741 cmd_pending_q_flags
);
743 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
744 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
745 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
746 /* Any command sent to the firmware when host is in sleep
747 * mode should de-configure host sleep. We should skip the
748 * host sleep configuration command itself though
750 if (priv
&& (host_cmd
->command
!=
751 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
752 if (adapter
->hs_activated
) {
753 adapter
->is_hs_configured
= false;
754 mwifiex_hs_activated_event(priv
, false);
762 * This function handles the command response.
764 * After processing, the function cleans the command node and puts
765 * it back to the command free queue.
767 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
769 struct host_cmd_ds_command
*resp
;
770 struct mwifiex_private
*priv
=
771 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
773 uint16_t orig_cmdresp_no
;
775 uint16_t cmdresp_result
;
778 /* Now we got response from FW, cancel the command timer */
779 del_timer_sync(&adapter
->cmd_timer
);
781 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
782 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
783 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
784 le16_to_cpu(resp
->command
));
788 adapter
->is_cmd_timedout
= 0;
790 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
791 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
792 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
793 le16_to_cpu(resp
->command
));
794 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
795 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
796 adapter
->curr_cmd
= NULL
;
797 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
801 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
802 /* Copy original response back to response buffer */
803 struct mwifiex_ds_misc_cmd
*hostcmd
;
804 uint16_t size
= le16_to_cpu(resp
->size
);
805 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
806 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
807 if (adapter
->curr_cmd
->data_buf
) {
808 hostcmd
= adapter
->curr_cmd
->data_buf
;
810 memcpy(hostcmd
->cmd
, resp
, size
);
813 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
815 /* Get BSS number and corresponding priv */
816 priv
= mwifiex_get_priv_by_id(adapter
,
817 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
818 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
820 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
821 /* Clear RET_BIT from HostCmd */
822 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
824 cmdresp_no
= le16_to_cpu(resp
->command
);
825 cmdresp_result
= le16_to_cpu(resp
->result
);
827 /* Save the last command response to debug log */
828 adapter
->dbg
.last_cmd_resp_index
=
829 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
830 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
833 dev_dbg(adapter
->dev
,
834 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
835 orig_cmdresp_no
, cmdresp_result
,
836 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
838 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
839 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
840 if (adapter
->curr_cmd
->wait_q_enabled
)
841 adapter
->cmd_wait_q
.status
= -1;
843 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
844 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
845 adapter
->curr_cmd
= NULL
;
846 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
850 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
851 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
852 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
853 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
854 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
856 /* handle response */
857 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
860 /* Check init command response */
861 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
863 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
864 "initialization\n", __func__
, cmdresp_no
);
865 mwifiex_init_fw_complete(adapter
);
867 } else if (adapter
->last_init_cmd
== cmdresp_no
)
868 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
871 if (adapter
->curr_cmd
) {
872 if (adapter
->curr_cmd
->wait_q_enabled
)
873 adapter
->cmd_wait_q
.status
= ret
;
875 mwifiex_recycle_cmd_node(adapter
, adapter
->curr_cmd
);
877 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
878 adapter
->curr_cmd
= NULL
;
879 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
886 * This function handles the timeout of command sending.
888 * It will re-send the same command again.
891 mwifiex_cmd_timeout_func(unsigned long function_context
)
893 struct mwifiex_adapter
*adapter
=
894 (struct mwifiex_adapter
*) function_context
;
895 struct cmd_ctrl_node
*cmd_node
;
897 adapter
->is_cmd_timedout
= 1;
898 if (!adapter
->curr_cmd
) {
899 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
902 cmd_node
= adapter
->curr_cmd
;
904 adapter
->dbg
.timeout_cmd_id
=
905 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
906 adapter
->dbg
.timeout_cmd_act
=
907 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
908 dev_err(adapter
->dev
,
909 "%s: Timeout cmd id = %#x, act = %#x\n", __func__
,
910 adapter
->dbg
.timeout_cmd_id
,
911 adapter
->dbg
.timeout_cmd_act
);
913 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
914 adapter
->dbg
.num_tx_host_to_card_failure
);
915 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
916 adapter
->dbg
.num_cmd_host_to_card_failure
);
918 dev_err(adapter
->dev
, "is_cmd_timedout = %d\n",
919 adapter
->is_cmd_timedout
);
920 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
921 adapter
->dbg
.num_tx_timeout
);
923 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
924 adapter
->dbg
.last_cmd_index
);
925 dev_err(adapter
->dev
, "last_cmd_id: %*ph\n",
926 (int)sizeof(adapter
->dbg
.last_cmd_id
),
927 adapter
->dbg
.last_cmd_id
);
928 dev_err(adapter
->dev
, "last_cmd_act: %*ph\n",
929 (int)sizeof(adapter
->dbg
.last_cmd_act
),
930 adapter
->dbg
.last_cmd_act
);
932 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
933 adapter
->dbg
.last_cmd_resp_index
);
934 dev_err(adapter
->dev
, "last_cmd_resp_id: %*ph\n",
935 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
936 adapter
->dbg
.last_cmd_resp_id
);
938 dev_err(adapter
->dev
, "last_event_index = %d\n",
939 adapter
->dbg
.last_event_index
);
940 dev_err(adapter
->dev
, "last_event: %*ph\n",
941 (int)sizeof(adapter
->dbg
.last_event
),
942 adapter
->dbg
.last_event
);
944 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
945 adapter
->data_sent
, adapter
->cmd_sent
);
947 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
948 adapter
->ps_mode
, adapter
->ps_state
);
950 if (cmd_node
->wait_q_enabled
) {
951 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
952 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
953 mwifiex_cancel_pending_ioctl(adapter
);
956 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
957 mwifiex_init_fw_complete(adapter
);
959 if (adapter
->if_ops
.fw_dump
)
960 adapter
->if_ops
.fw_dump(adapter
);
962 if (adapter
->if_ops
.card_reset
)
963 adapter
->if_ops
.card_reset(adapter
);
967 * This function cancels all the pending commands.
969 * The current command, all commands in command pending queue and all scan
970 * commands in scan pending queue are cancelled. All the completion callbacks
971 * are called with failure status to ensure cleanup.
974 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
976 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
977 unsigned long flags
, cmd_flags
;
978 struct mwifiex_private
*priv
;
981 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
982 /* Cancel current cmd */
983 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
984 adapter
->curr_cmd
->wait_q_enabled
= false;
985 adapter
->cmd_wait_q
.status
= -1;
986 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
988 /* Cancel all pending command */
989 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
990 list_for_each_entry_safe(cmd_node
, tmp_node
,
991 &adapter
->cmd_pending_q
, list
) {
992 list_del(&cmd_node
->list
);
993 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
995 if (cmd_node
->wait_q_enabled
) {
996 adapter
->cmd_wait_q
.status
= -1;
997 mwifiex_complete_cmd(adapter
, cmd_node
);
998 cmd_node
->wait_q_enabled
= false;
1000 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1001 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1003 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1004 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1006 /* Cancel all pending scan command */
1007 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1008 list_for_each_entry_safe(cmd_node
, tmp_node
,
1009 &adapter
->scan_pending_q
, list
) {
1010 list_del(&cmd_node
->list
);
1011 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1013 cmd_node
->wait_q_enabled
= false;
1014 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1015 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1017 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1019 if (adapter
->scan_processing
) {
1020 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1021 adapter
->scan_processing
= false;
1022 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1023 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1024 priv
= adapter
->priv
[i
];
1027 if (priv
->scan_request
) {
1028 dev_dbg(adapter
->dev
, "info: aborting scan\n");
1029 cfg80211_scan_done(priv
->scan_request
, 1);
1030 priv
->scan_request
= NULL
;
1037 * This function cancels all pending commands that matches with
1038 * the given IOCTL request.
1040 * Both the current command buffer and the pending command queue are
1041 * searched for matching IOCTL request. The completion callback of
1042 * the matched command is called with failure status to ensure cleanup.
1043 * In case of scan commands, all pending commands in scan pending queue
1047 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1049 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1050 unsigned long cmd_flags
;
1051 unsigned long scan_pending_q_flags
;
1052 struct mwifiex_private
*priv
;
1055 if ((adapter
->curr_cmd
) &&
1056 (adapter
->curr_cmd
->wait_q_enabled
)) {
1057 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1058 cmd_node
= adapter
->curr_cmd
;
1059 cmd_node
->wait_q_enabled
= false;
1060 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1061 mwifiex_recycle_cmd_node(adapter
, cmd_node
);
1062 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1063 adapter
->curr_cmd
= NULL
;
1064 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1067 /* Cancel all pending scan command */
1068 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1069 scan_pending_q_flags
);
1070 list_for_each_entry_safe(cmd_node
, tmp_node
,
1071 &adapter
->scan_pending_q
, list
) {
1072 list_del(&cmd_node
->list
);
1073 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1074 scan_pending_q_flags
);
1075 cmd_node
->wait_q_enabled
= false;
1076 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1077 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1078 scan_pending_q_flags
);
1080 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1081 scan_pending_q_flags
);
1083 if (adapter
->scan_processing
) {
1084 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1085 adapter
->scan_processing
= false;
1086 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1087 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1088 priv
= adapter
->priv
[i
];
1091 if (priv
->scan_request
) {
1092 dev_dbg(adapter
->dev
, "info: aborting scan\n");
1093 cfg80211_scan_done(priv
->scan_request
, 1);
1094 priv
->scan_request
= NULL
;
1098 adapter
->cmd_wait_q
.status
= -1;
1102 * This function sends the sleep confirm command to firmware, if
1105 * The sleep confirm command cannot be issued if command response,
1106 * data response or event response is awaiting handling, or if we
1107 * are in the middle of sending a command, or expecting a command
1111 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1113 if (!adapter
->cmd_sent
&&
1114 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1115 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1117 dev_dbg(adapter
->dev
,
1118 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1119 (adapter
->cmd_sent
) ? "D" : "",
1120 (adapter
->curr_cmd
) ? "C" : "",
1121 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1125 * This function sends a Host Sleep activated event to applications.
1127 * This event is generated by the driver, with a blank event body.
1130 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1133 if (priv
->adapter
->is_hs_configured
) {
1134 priv
->adapter
->hs_activated
= true;
1135 mwifiex_update_rxreor_flags(priv
->adapter
,
1136 RXREOR_FORCE_NO_DROP
);
1137 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1138 priv
->adapter
->hs_activate_wait_q_woken
= true;
1139 wake_up_interruptible(
1140 &priv
->adapter
->hs_activate_wait_q
);
1142 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1145 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1146 priv
->adapter
->hs_activated
= false;
1151 * This function handles the command response of a Host Sleep configuration
1154 * Handling includes changing the header fields into CPU format
1155 * and setting the current host sleep activation status in driver.
1157 * In case host sleep status change, the function generates an event to
1158 * notify the applications.
1160 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1161 struct host_cmd_ds_command
*resp
)
1163 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1164 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1165 &resp
->params
.opt_hs_cfg
;
1166 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1168 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1169 adapter
->iface_type
!= MWIFIEX_USB
) {
1170 mwifiex_hs_activated_event(priv
, true);
1173 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1174 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1175 resp
->result
, conditions
,
1176 phs_cfg
->params
.hs_config
.gpio
,
1177 phs_cfg
->params
.hs_config
.gap
);
1179 if (conditions
!= HS_CFG_CANCEL
) {
1180 adapter
->is_hs_configured
= true;
1181 if (adapter
->iface_type
== MWIFIEX_USB
)
1182 mwifiex_hs_activated_event(priv
, true);
1184 adapter
->is_hs_configured
= false;
1185 if (adapter
->hs_activated
)
1186 mwifiex_hs_activated_event(priv
, false);
1193 * This function wakes up the adapter and generates a Host Sleep
1194 * cancel event on receiving the power up interrupt.
1197 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1199 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1200 " since there is interrupt from the firmware\n", __func__
);
1202 adapter
->if_ops
.wakeup(adapter
);
1203 adapter
->hs_activated
= false;
1204 adapter
->is_hs_configured
= false;
1205 adapter
->is_suspended
= false;
1206 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1207 MWIFIEX_BSS_ROLE_ANY
),
1210 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1213 * This function handles the command response of a sleep confirm command.
1215 * The function sets the card state to SLEEP if the response indicates success.
1218 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1219 u8
*pbuf
, u32 upld_len
)
1221 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1222 struct mwifiex_private
*priv
=
1223 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1224 uint16_t result
= le16_to_cpu(cmd
->result
);
1225 uint16_t command
= le16_to_cpu(cmd
->command
);
1226 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1229 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1233 dev_dbg(adapter
->dev
,
1234 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
1235 command
, result
, le16_to_cpu(cmd
->size
), seq_num
);
1237 /* Get BSS number and corresponding priv */
1238 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1239 HostCmd_GET_BSS_TYPE(seq_num
));
1241 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1243 /* Update sequence number */
1244 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1245 /* Clear RET_BIT from HostCmd */
1246 command
&= HostCmd_CMD_ID_MASK
;
1248 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1249 dev_err(adapter
->dev
,
1250 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1251 __func__
, command
, result
);
1256 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1258 adapter
->pm_wakeup_card_req
= false;
1259 adapter
->ps_state
= PS_STATE_AWAKE
;
1262 adapter
->pm_wakeup_card_req
= true;
1263 if (adapter
->is_hs_configured
)
1264 mwifiex_hs_activated_event(mwifiex_get_priv
1265 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1267 adapter
->ps_state
= PS_STATE_SLEEP
;
1268 cmd
->command
= cpu_to_le16(command
);
1269 cmd
->seq_num
= cpu_to_le16(seq_num
);
1271 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1274 * This function prepares an enhanced power mode command.
1276 * This function can be used to disable power save or to configure
1277 * power save with auto PS or STA PS or auto deep sleep.
1279 * Preparation includes -
1280 * - Setting command ID, action and proper size
1281 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1282 * auto deep sleep TLV (as required)
1283 * - Ensuring correct endian-ness
1285 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1286 struct host_cmd_ds_command
*cmd
,
1287 u16 cmd_action
, uint16_t ps_bitmap
,
1288 struct mwifiex_ds_auto_ds
*auto_ds
)
1290 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1291 &cmd
->params
.psmode_enh
;
1295 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1296 if (cmd_action
== DIS_AUTO_PS
) {
1297 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1298 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1299 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1300 sizeof(psmode_enh
->params
.ps_bitmap
));
1301 } else if (cmd_action
== GET_PS
) {
1302 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1303 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1304 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1305 sizeof(psmode_enh
->params
.ps_bitmap
));
1306 } else if (cmd_action
== EN_AUTO_PS
) {
1307 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1308 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1309 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1310 sizeof(psmode_enh
->params
.ps_bitmap
);
1311 tlv
= (u8
*) cmd
+ cmd_size
;
1312 if (ps_bitmap
& BITMAP_STA_PS
) {
1313 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1314 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1315 (struct mwifiex_ie_types_ps_param
*) tlv
;
1316 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1317 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1318 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1319 sizeof(struct mwifiex_ie_types_header
));
1320 cmd_size
+= sizeof(*ps_tlv
);
1321 tlv
+= sizeof(*ps_tlv
);
1322 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1323 ps_mode
->null_pkt_interval
=
1324 cpu_to_le16(adapter
->null_pkt_interval
);
1325 ps_mode
->multiple_dtims
=
1326 cpu_to_le16(adapter
->multiple_dtim
);
1327 ps_mode
->bcn_miss_timeout
=
1328 cpu_to_le16(adapter
->bcn_miss_time_out
);
1329 ps_mode
->local_listen_interval
=
1330 cpu_to_le16(adapter
->local_listen_interval
);
1331 ps_mode
->adhoc_wake_period
=
1332 cpu_to_le16(adapter
->adhoc_awake_period
);
1333 ps_mode
->delay_to_ps
=
1334 cpu_to_le16(adapter
->delay_to_ps
);
1335 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1338 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1339 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1340 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1343 auto_ds_tlv
->header
.type
=
1344 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1345 auto_ds_tlv
->header
.len
=
1346 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1347 sizeof(struct mwifiex_ie_types_header
));
1348 cmd_size
+= sizeof(*auto_ds_tlv
);
1349 tlv
+= sizeof(*auto_ds_tlv
);
1351 idletime
= auto_ds
->idle_time
;
1352 dev_dbg(priv
->adapter
->dev
,
1353 "cmd: PS Command: Enter Auto Deep Sleep\n");
1354 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1356 cmd
->size
= cpu_to_le16(cmd_size
);
1362 * This function handles the command response of an enhanced power mode
1365 * Handling includes changing the header fields into CPU format
1366 * and setting the current enhanced power mode in driver.
1368 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1369 struct host_cmd_ds_command
*resp
,
1370 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1372 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1373 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1374 &resp
->params
.psmode_enh
;
1375 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1376 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1377 uint16_t auto_ps_bitmap
=
1378 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1380 dev_dbg(adapter
->dev
,
1381 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1382 __func__
, resp
->result
, action
);
1383 if (action
== EN_AUTO_PS
) {
1384 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1385 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1386 priv
->adapter
->is_deep_sleep
= true;
1388 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1389 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1390 if (adapter
->sleep_period
.period
)
1391 dev_dbg(adapter
->dev
,
1392 "cmd: set to uapsd/pps mode\n");
1394 } else if (action
== DIS_AUTO_PS
) {
1395 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1396 priv
->adapter
->is_deep_sleep
= false;
1397 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1399 if (ps_bitmap
& BITMAP_STA_PS
) {
1400 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1401 if (adapter
->sleep_period
.period
) {
1402 adapter
->delay_null_pkt
= false;
1403 adapter
->tx_lock_flag
= false;
1404 adapter
->pps_uapsd_mode
= false;
1407 } else if (action
== GET_PS
) {
1408 if (ps_bitmap
& BITMAP_STA_PS
)
1409 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1411 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1413 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1416 /* This section is for get power save mode */
1417 if (ps_bitmap
& BITMAP_STA_PS
)
1418 pm_cfg
->param
.ps_mode
= 1;
1420 pm_cfg
->param
.ps_mode
= 0;
1427 * This function prepares command to get hardware specifications.
1429 * Preparation includes -
1430 * - Setting command ID, action and proper size
1431 * - Setting permanent address parameter
1432 * - Ensuring correct endian-ness
1434 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1435 struct host_cmd_ds_command
*cmd
)
1437 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1439 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1441 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1442 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1448 * This function handles the command response of get hardware
1451 * Handling includes changing the header fields into CPU format
1452 * and saving/updating the following parameters in driver -
1453 * - Firmware capability information
1454 * - Firmware band settings
1455 * - Ad-hoc start band and channel
1456 * - Ad-hoc 11n activation status
1457 * - Firmware release number
1458 * - Number of antennas
1459 * - Hardware address
1460 * - Hardware interface version
1461 * - Firmware version
1463 * - 11n capabilities
1464 * - MCS support fields
1467 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1468 struct host_cmd_ds_command
*resp
)
1470 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1471 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1472 struct mwifiex_ie_types_header
*tlv
;
1473 struct hw_spec_api_rev
*api_rev
;
1474 u16 resp_size
, api_id
;
1475 int i
, left_len
, parsed_len
= 0;
1477 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1479 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1480 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1482 adapter
->fw_bands
= BAND_B
;
1484 adapter
->config_bands
= adapter
->fw_bands
;
1486 if (adapter
->fw_bands
& BAND_A
) {
1487 if (adapter
->fw_bands
& BAND_GN
) {
1488 adapter
->config_bands
|= BAND_AN
;
1489 adapter
->fw_bands
|= BAND_AN
;
1491 if (adapter
->fw_bands
& BAND_AN
) {
1492 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1493 adapter
->adhoc_11n_enabled
= true;
1495 adapter
->adhoc_start_band
= BAND_A
;
1497 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1498 } else if (adapter
->fw_bands
& BAND_GN
) {
1499 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1500 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1501 adapter
->adhoc_11n_enabled
= true;
1502 } else if (adapter
->fw_bands
& BAND_G
) {
1503 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1504 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1505 } else if (adapter
->fw_bands
& BAND_B
) {
1506 adapter
->adhoc_start_band
= BAND_B
;
1507 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1510 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1511 adapter
->fw_api_ver
= (adapter
->fw_release_number
>> 16) & 0xff;
1512 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1514 if (le32_to_cpu(hw_spec
->dot_11ac_dev_cap
)) {
1515 adapter
->is_hw_11ac_capable
= true;
1518 adapter
->hw_dot_11ac_dev_cap
=
1519 le32_to_cpu(hw_spec
->dot_11ac_dev_cap
);
1520 adapter
->usr_dot_11ac_dev_cap_bg
= adapter
->hw_dot_11ac_dev_cap
1521 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1522 adapter
->usr_dot_11ac_dev_cap_a
= adapter
->hw_dot_11ac_dev_cap
1523 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK
;
1526 adapter
->hw_dot_11ac_mcs_support
=
1527 le32_to_cpu(hw_spec
->dot_11ac_mcs_support
);
1528 adapter
->usr_dot_11ac_mcs_support
=
1529 adapter
->hw_dot_11ac_mcs_support
;
1531 adapter
->is_hw_11ac_capable
= false;
1534 resp_size
= le16_to_cpu(resp
->size
) - S_DS_GEN
;
1535 if (resp_size
> sizeof(struct host_cmd_ds_get_hw_spec
)) {
1536 /* we have variable HW SPEC information */
1537 left_len
= resp_size
- sizeof(struct host_cmd_ds_get_hw_spec
);
1538 while (left_len
> sizeof(struct mwifiex_ie_types_header
)) {
1539 tlv
= (void *)&hw_spec
->tlvs
+ parsed_len
;
1540 switch (le16_to_cpu(tlv
->type
)) {
1541 case TLV_TYPE_API_REV
:
1542 api_rev
= (struct hw_spec_api_rev
*)tlv
;
1543 api_id
= le16_to_cpu(api_rev
->api_id
);
1545 case KEY_API_VER_ID
:
1546 adapter
->key_api_major_ver
=
1548 adapter
->key_api_minor_ver
=
1550 dev_dbg(adapter
->dev
,
1552 adapter
->key_api_major_ver
,
1553 adapter
->key_api_minor_ver
);
1556 adapter
->fw_api_ver
=
1558 dev_dbg(adapter
->dev
,
1559 "Firmware api version %d\n",
1560 adapter
->fw_api_ver
);
1563 dev_warn(adapter
->dev
,
1564 "Unknown api_id: %d\n",
1570 dev_warn(adapter
->dev
,
1571 "Unknown GET_HW_SPEC TLV type: %#x\n",
1572 le16_to_cpu(tlv
->type
));
1575 parsed_len
+= le16_to_cpu(tlv
->len
) +
1576 sizeof(struct mwifiex_ie_types_header
);
1577 left_len
-= le16_to_cpu(tlv
->len
) +
1578 sizeof(struct mwifiex_ie_types_header
);
1582 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1583 adapter
->fw_release_number
);
1584 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1585 hw_spec
->permanent_addr
);
1586 dev_dbg(adapter
->dev
,
1587 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1588 le16_to_cpu(hw_spec
->hw_if_version
),
1589 le16_to_cpu(hw_spec
->version
));
1591 if (priv
->curr_addr
[0] == 0xff)
1592 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1594 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1596 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1597 /* Use the region code to search for the index */
1598 if (adapter
->region_code
== region_code_index
[i
])
1601 /* If it's unidentified region code, use the default (USA) */
1602 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1603 adapter
->region_code
= 0x10;
1604 dev_dbg(adapter
->dev
,
1605 "cmd: unknown region code, use default (USA)\n");
1608 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1609 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1610 adapter
->user_dev_mcs_support
= adapter
->hw_dev_mcs_support
;
1612 if (adapter
->if_ops
.update_mp_end_port
)
1613 adapter
->if_ops
.update_mp_end_port(adapter
,
1614 le16_to_cpu(hw_spec
->mp_end_port
));
1616 if (adapter
->fw_api_ver
== MWIFIEX_FW_V15
)
1617 adapter
->scan_chan_gap_enabled
= true;