2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
30 * This function initializes a command node.
32 * The actual allocation of the node is not done by this function. It only
33 * initiates a node by filling it with default parameters. Similarly,
34 * allocation of the different buffers used (IOCTL buffer, data buffer) are
35 * not done by this function either.
38 mwifiex_init_cmd_node(struct mwifiex_private
*priv
,
39 struct cmd_ctrl_node
*cmd_node
,
40 u32 cmd_oid
, void *data_buf
)
42 cmd_node
->priv
= priv
;
43 cmd_node
->cmd_oid
= cmd_oid
;
44 if (priv
->adapter
->cmd_wait_q_required
) {
45 cmd_node
->wait_q_enabled
= priv
->adapter
->cmd_wait_q_required
;
46 priv
->adapter
->cmd_wait_q_required
= false;
47 cmd_node
->cmd_wait_q_woken
= false;
48 cmd_node
->condition
= &cmd_node
->cmd_wait_q_woken
;
50 cmd_node
->data_buf
= data_buf
;
51 cmd_node
->cmd_skb
= cmd_node
->skb
;
55 * This function returns a command node from the free queue depending upon
58 static struct cmd_ctrl_node
*
59 mwifiex_get_cmd_node(struct mwifiex_adapter
*adapter
)
61 struct cmd_ctrl_node
*cmd_node
;
64 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
65 if (list_empty(&adapter
->cmd_free_q
)) {
66 dev_err(adapter
->dev
, "GET_CMD_NODE: cmd node not available\n");
67 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
70 cmd_node
= list_first_entry(&adapter
->cmd_free_q
,
71 struct cmd_ctrl_node
, list
);
72 list_del(&cmd_node
->list
);
73 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
79 * This function cleans up a command node.
81 * The function resets the fields including the buffer pointers.
82 * This function does not try to free the buffers. They must be
83 * freed before calling this function.
85 * This function will however call the receive completion callback
86 * in case a response buffer is still available before resetting
90 mwifiex_clean_cmd_node(struct mwifiex_adapter
*adapter
,
91 struct cmd_ctrl_node
*cmd_node
)
93 cmd_node
->cmd_oid
= 0;
94 cmd_node
->cmd_flag
= 0;
95 cmd_node
->data_buf
= NULL
;
96 cmd_node
->wait_q_enabled
= false;
98 if (cmd_node
->cmd_skb
)
99 skb_trim(cmd_node
->cmd_skb
, 0);
101 if (cmd_node
->resp_skb
) {
102 adapter
->if_ops
.cmdrsp_complete(adapter
, cmd_node
->resp_skb
);
103 cmd_node
->resp_skb
= NULL
;
108 * This function sends a host command to the firmware.
110 * The function copies the host command into the driver command
111 * buffer, which will be transferred to the firmware later by the
114 static int mwifiex_cmd_host_cmd(struct mwifiex_private
*priv
,
115 struct host_cmd_ds_command
*cmd
,
116 struct mwifiex_ds_misc_cmd
*pcmd_ptr
)
118 /* Copy the HOST command to command buffer */
119 memcpy(cmd
, pcmd_ptr
->cmd
, pcmd_ptr
->len
);
120 dev_dbg(priv
->adapter
->dev
, "cmd: host cmd size = %d\n", pcmd_ptr
->len
);
125 * This function downloads a command to the firmware.
127 * The function performs sanity tests, sets the command sequence
128 * number and size, converts the header fields to CPU format before
129 * sending. Afterwards, it logs the command ID and action for debugging
130 * and sets up the command timeout timer.
132 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private
*priv
,
133 struct cmd_ctrl_node
*cmd_node
)
136 struct mwifiex_adapter
*adapter
= priv
->adapter
;
138 struct host_cmd_ds_command
*host_cmd
;
141 struct timeval tstamp
;
145 if (!adapter
|| !cmd_node
)
148 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
151 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
152 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
153 " or cmd size is 0, not sending\n");
154 if (cmd_node
->wait_q_enabled
)
155 adapter
->cmd_wait_q
.status
= -1;
156 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
160 cmd_code
= le16_to_cpu(host_cmd
->command
);
161 cmd_size
= le16_to_cpu(host_cmd
->size
);
163 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
&&
164 cmd_code
!= HostCmd_CMD_FUNC_SHUTDOWN
&&
165 cmd_code
!= HostCmd_CMD_FUNC_INIT
) {
166 dev_err(adapter
->dev
,
167 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
169 mwifiex_complete_cmd(adapter
, cmd_node
);
170 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
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 do_gettimeofday(&tstamp
);
201 dev_dbg(adapter
->dev
, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
203 tstamp
.tv_sec
, tstamp
.tv_usec
, cmd_code
,
204 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
205 le16_to_cpu(host_cmd
->seq_num
));
207 if (adapter
->iface_type
== MWIFIEX_USB
) {
208 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
209 skb_push(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
210 memcpy(cmd_node
->cmd_skb
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
211 adapter
->cmd_sent
= true;
212 ret
= adapter
->if_ops
.host_to_card(adapter
,
213 MWIFIEX_USB_EP_CMD_EVENT
,
214 cmd_node
->cmd_skb
, NULL
);
215 skb_pull(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
217 cmd_node
->cmd_skb
= NULL
;
219 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
220 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
221 cmd_node
->cmd_skb
, NULL
);
222 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
226 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
227 if (adapter
->iface_type
== MWIFIEX_USB
)
228 adapter
->cmd_sent
= false;
229 if (cmd_node
->wait_q_enabled
)
230 adapter
->cmd_wait_q
.status
= -1;
231 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
233 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
234 adapter
->curr_cmd
= NULL
;
235 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
237 adapter
->dbg
.num_cmd_host_to_card_failure
++;
241 /* Save the last command id and action to debug log */
242 adapter
->dbg
.last_cmd_index
=
243 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
244 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
245 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
246 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
248 /* Clear BSS_NO_BITS from HostCmd */
249 cmd_code
&= HostCmd_CMD_ID_MASK
;
251 /* Setup the timer after transmit command */
252 mod_timer(&adapter
->cmd_timer
,
253 jiffies
+ (MWIFIEX_TIMER_10S
* HZ
) / 1000);
259 * This function downloads a sleep confirm command to the firmware.
261 * The function performs sanity tests, sets the command sequence
262 * number and size, converts the header fields to CPU format before
265 * No responses are needed for sleep confirm command.
267 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
270 struct mwifiex_private
*priv
;
271 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
=
272 (struct mwifiex_opt_sleep_confirm
*)
273 adapter
->sleep_cfm
->data
;
274 struct sk_buff
*sleep_cfm_tmp
;
277 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
279 sleep_cfm_buf
->seq_num
=
280 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
281 (adapter
->seq_num
, priv
->bss_num
,
285 if (adapter
->iface_type
== MWIFIEX_USB
) {
287 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
289 skb_put(sleep_cfm_tmp
, sizeof(struct mwifiex_opt_sleep_confirm
)
291 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
292 memcpy(sleep_cfm_tmp
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
293 memcpy(sleep_cfm_tmp
->data
+ MWIFIEX_TYPE_LEN
,
294 adapter
->sleep_cfm
->data
,
295 sizeof(struct mwifiex_opt_sleep_confirm
));
296 ret
= adapter
->if_ops
.host_to_card(adapter
,
297 MWIFIEX_USB_EP_CMD_EVENT
,
298 sleep_cfm_tmp
, NULL
);
300 dev_kfree_skb_any(sleep_cfm_tmp
);
302 skb_push(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
303 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
304 adapter
->sleep_cfm
, NULL
);
305 skb_pull(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
309 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
310 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
313 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
314 == MWIFIEX_BSS_ROLE_STA
) {
315 if (!sleep_cfm_buf
->resp_ctrl
)
316 /* Response is not needed for sleep
318 adapter
->ps_state
= PS_STATE_SLEEP
;
320 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
322 if (!sleep_cfm_buf
->resp_ctrl
&&
323 (adapter
->is_hs_configured
&&
324 !adapter
->sleep_period
.period
)) {
325 adapter
->pm_wakeup_card_req
= true;
326 mwifiex_hs_activated_event(mwifiex_get_priv
327 (adapter
, MWIFIEX_BSS_ROLE_STA
), true);
335 * This function allocates the command buffers and links them to
336 * the command free queue.
338 * The driver uses a pre allocated number of command buffers, which
339 * are created at driver initializations and freed at driver cleanup.
340 * Every command needs to obtain a command buffer from this pool before
341 * it can be issued. The command free queue lists the command buffers
342 * currently free to use, while the command pending queue lists the
343 * command buffers already in use and awaiting handling. Command buffers
344 * are returned to the free queue after use.
346 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
348 struct cmd_ctrl_node
*cmd_array
;
351 /* Allocate and initialize struct cmd_ctrl_node */
352 cmd_array
= kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER
,
353 sizeof(struct cmd_ctrl_node
), GFP_KERNEL
);
357 adapter
->cmd_pool
= cmd_array
;
359 /* Allocate and initialize command buffers */
360 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
361 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
362 if (!cmd_array
[i
].skb
) {
363 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
368 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
369 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
375 * This function frees the command buffers.
377 * The function calls the completion callback for all the command
378 * buffers that still have response buffers associated with them.
380 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
382 struct cmd_ctrl_node
*cmd_array
;
385 /* Need to check if cmd pool is allocated or not */
386 if (!adapter
->cmd_pool
) {
387 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
391 cmd_array
= adapter
->cmd_pool
;
393 /* Release shared memory buffers */
394 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
395 if (cmd_array
[i
].skb
) {
396 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
397 dev_kfree_skb_any(cmd_array
[i
].skb
);
399 if (!cmd_array
[i
].resp_skb
)
402 if (adapter
->iface_type
== MWIFIEX_USB
)
403 adapter
->if_ops
.cmdrsp_complete(adapter
,
404 cmd_array
[i
].resp_skb
);
406 dev_kfree_skb_any(cmd_array
[i
].resp_skb
);
408 /* Release struct cmd_ctrl_node */
409 if (adapter
->cmd_pool
) {
410 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
411 kfree(adapter
->cmd_pool
);
412 adapter
->cmd_pool
= NULL
;
419 * This function handles events generated by firmware.
421 * Event body of events received from firmware are not used (though they are
422 * saved), only the event ID is used. Some events are re-invoked by
423 * the driver, with a new event body.
425 * After processing, the function calls the completion callback
428 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
431 struct mwifiex_private
*priv
=
432 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
433 struct sk_buff
*skb
= adapter
->event_skb
;
434 u32 eventcause
= adapter
->event_cause
;
435 struct timeval tstamp
;
436 struct mwifiex_rxinfo
*rx_info
;
438 /* Save the last event to debug log */
439 adapter
->dbg
.last_event_index
=
440 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
441 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
444 /* Get BSS number and corresponding priv */
445 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
446 EVENT_GET_BSS_TYPE(eventcause
));
448 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
449 /* Clear BSS_NO_BITS from event */
450 eventcause
&= EVENT_ID_MASK
;
451 adapter
->event_cause
= eventcause
;
454 rx_info
= MWIFIEX_SKB_RXCB(skb
);
455 rx_info
->bss_num
= priv
->bss_num
;
456 rx_info
->bss_type
= priv
->bss_type
;
459 if (eventcause
!= EVENT_PS_SLEEP
&& eventcause
!= EVENT_PS_AWAKE
) {
460 do_gettimeofday(&tstamp
);
461 dev_dbg(adapter
->dev
, "event: %lu.%lu: cause: %#x\n",
462 tstamp
.tv_sec
, tstamp
.tv_usec
, eventcause
);
464 /* Handle PS_SLEEP/AWAKE events on STA */
465 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
467 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
470 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
471 ret
= mwifiex_process_uap_event(priv
);
473 ret
= mwifiex_process_sta_event(priv
);
475 adapter
->event_cause
= 0;
476 adapter
->event_skb
= NULL
;
477 adapter
->if_ops
.event_complete(adapter
, skb
);
483 * This function is used to send synchronous command to the firmware.
485 * it allocates a wait queue for the command and wait for the command
488 int mwifiex_send_cmd_sync(struct mwifiex_private
*priv
, uint16_t cmd_no
,
489 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
492 struct mwifiex_adapter
*adapter
= priv
->adapter
;
494 adapter
->cmd_wait_q_required
= true;
496 ret
= mwifiex_send_cmd_async(priv
, cmd_no
, cmd_action
, cmd_oid
,
504 * This function prepares a command and asynchronously send it to the firmware.
506 * Preparation includes -
507 * - Sanity tests to make sure the card is still present or the FW
509 * - Getting a new command node from the command free queue
510 * - Initializing the command node for default parameters
511 * - Fill up the non-default parameters and buffer pointers
512 * - Add the command to pending queue
514 int mwifiex_send_cmd_async(struct mwifiex_private
*priv
, uint16_t cmd_no
,
515 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
518 struct mwifiex_adapter
*adapter
= priv
->adapter
;
519 struct cmd_ctrl_node
*cmd_node
;
520 struct host_cmd_ds_command
*cmd_ptr
;
523 pr_err("PREP_CMD: adapter is NULL\n");
527 if (adapter
->is_suspended
) {
528 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
532 if (adapter
->surprise_removed
) {
533 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
537 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
538 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
539 dev_err(adapter
->dev
, "PREP_CMD: FW in reset state\n");
544 /* Get a new command node */
545 cmd_node
= mwifiex_get_cmd_node(adapter
);
548 dev_err(adapter
->dev
, "PREP_CMD: no free cmd node\n");
552 /* Initialize the command node */
553 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
);
555 if (!cmd_node
->cmd_skb
) {
556 dev_err(adapter
->dev
, "PREP_CMD: no free cmd buf\n");
560 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
561 0, sizeof(struct host_cmd_ds_command
));
563 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
564 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
567 /* Prepare command */
570 case HostCmd_CMD_UAP_SYS_CONFIG
:
571 case HostCmd_CMD_UAP_BSS_START
:
572 case HostCmd_CMD_UAP_BSS_STOP
:
573 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
578 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
584 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
585 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
588 /* Return error, since the command preparation failed */
590 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
592 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
597 if (cmd_no
== HostCmd_CMD_802_11_SCAN
) {
598 mwifiex_queue_scan_cmd(priv
, cmd_node
);
600 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
601 queue_work(adapter
->workqueue
, &adapter
->main_work
);
602 if (cmd_node
->wait_q_enabled
)
603 ret
= mwifiex_wait_queue_complete(adapter
, cmd_node
);
610 * This function returns a command to the command free queue.
612 * The function also calls the completion callback if required, before
613 * cleaning the command node and re-inserting it into the free queue.
616 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
617 struct cmd_ctrl_node
*cmd_node
)
624 if (cmd_node
->wait_q_enabled
)
625 mwifiex_complete_cmd(adapter
, cmd_node
);
627 mwifiex_clean_cmd_node(adapter
, cmd_node
);
629 /* Insert node into cmd_free_q */
630 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
631 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
632 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
636 * This function queues a command to the command pending queue.
638 * This in effect adds the command to the command list to be executed.
639 * Exit PS command is handled specially, by placing it always to the
640 * front of the command queue.
643 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
644 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
646 struct host_cmd_ds_command
*host_cmd
= NULL
;
650 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
652 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
656 command
= le16_to_cpu(host_cmd
->command
);
658 /* Exit_PS command needs to be queued in the header always. */
659 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
660 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
661 &host_cmd
->params
.psmode_enh
;
662 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
663 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
664 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
669 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
671 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
673 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
674 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
676 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command
);
680 * This function executes the next command in command pending queue.
682 * This function will fail if a command is already in processing stage,
683 * otherwise it will dequeue the first command from the command pending
684 * queue and send to the firmware.
686 * If the device is currently in host sleep mode, any commands, except the
687 * host sleep configuration command will de-activate the host sleep. For PS
688 * mode, the function will put the firmware back to sleep if applicable.
690 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
692 struct mwifiex_private
*priv
;
693 struct cmd_ctrl_node
*cmd_node
;
695 struct host_cmd_ds_command
*host_cmd
;
696 unsigned long cmd_flags
;
697 unsigned long cmd_pending_q_flags
;
699 /* Check if already in processing */
700 if (adapter
->curr_cmd
) {
701 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
705 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
706 /* Check if any command is pending */
707 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
708 if (list_empty(&adapter
->cmd_pending_q
)) {
709 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
710 cmd_pending_q_flags
);
711 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
714 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
715 struct cmd_ctrl_node
, list
);
716 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
717 cmd_pending_q_flags
);
719 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
720 priv
= cmd_node
->priv
;
722 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
723 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
724 " this should not happen\n", __func__
);
725 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
729 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
730 list_del(&cmd_node
->list
);
731 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
732 cmd_pending_q_flags
);
734 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
735 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
736 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
737 /* Any command sent to the firmware when host is in sleep
738 * mode should de-configure host sleep. We should skip the
739 * host sleep configuration command itself though
741 if (priv
&& (host_cmd
->command
!=
742 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
743 if (adapter
->hs_activated
) {
744 adapter
->is_hs_configured
= false;
745 mwifiex_hs_activated_event(priv
, false);
753 * This function handles the command response.
755 * After processing, the function cleans the command node and puts
756 * it back to the command free queue.
758 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
760 struct host_cmd_ds_command
*resp
;
761 struct mwifiex_private
*priv
=
762 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
764 uint16_t orig_cmdresp_no
;
766 uint16_t cmdresp_result
;
767 struct timeval tstamp
;
770 /* Now we got response from FW, cancel the command timer */
771 del_timer(&adapter
->cmd_timer
);
773 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
774 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
775 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
776 le16_to_cpu(resp
->command
));
780 adapter
->num_cmd_timeout
= 0;
782 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
783 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
784 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
785 le16_to_cpu(resp
->command
));
786 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
787 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
788 adapter
->curr_cmd
= NULL
;
789 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
793 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
794 /* Copy original response back to response buffer */
795 struct mwifiex_ds_misc_cmd
*hostcmd
;
796 uint16_t size
= le16_to_cpu(resp
->size
);
797 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
798 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
799 if (adapter
->curr_cmd
->data_buf
) {
800 hostcmd
= adapter
->curr_cmd
->data_buf
;
802 memcpy(hostcmd
->cmd
, resp
, size
);
805 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
807 /* Get BSS number and corresponding priv */
808 priv
= mwifiex_get_priv_by_id(adapter
,
809 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
810 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
812 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
813 /* Clear RET_BIT from HostCmd */
814 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
816 cmdresp_no
= le16_to_cpu(resp
->command
);
817 cmdresp_result
= le16_to_cpu(resp
->result
);
819 /* Save the last command response to debug log */
820 adapter
->dbg
.last_cmd_resp_index
=
821 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
822 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
825 do_gettimeofday(&tstamp
);
826 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
827 " len %d, seqno 0x%x\n",
828 tstamp
.tv_sec
, tstamp
.tv_usec
, orig_cmdresp_no
, cmdresp_result
,
829 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
831 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
832 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
833 if (adapter
->curr_cmd
->wait_q_enabled
)
834 adapter
->cmd_wait_q
.status
= -1;
836 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
837 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
838 adapter
->curr_cmd
= NULL
;
839 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
843 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
844 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
845 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
846 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
847 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
849 /* handle response */
850 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
853 /* Check init command response */
854 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
856 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
857 "initialization\n", __func__
, cmdresp_no
);
858 mwifiex_init_fw_complete(adapter
);
860 } else if (adapter
->last_init_cmd
== cmdresp_no
)
861 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
864 if (adapter
->curr_cmd
) {
865 if (adapter
->curr_cmd
->wait_q_enabled
)
866 adapter
->cmd_wait_q
.status
= ret
;
868 /* Clean up and put current command back to cmd_free_q */
869 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
871 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
872 adapter
->curr_cmd
= NULL
;
873 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
880 * This function handles the timeout of command sending.
882 * It will re-send the same command again.
885 mwifiex_cmd_timeout_func(unsigned long function_context
)
887 struct mwifiex_adapter
*adapter
=
888 (struct mwifiex_adapter
*) function_context
;
889 struct cmd_ctrl_node
*cmd_node
;
890 struct timeval tstamp
;
892 adapter
->num_cmd_timeout
++;
893 adapter
->dbg
.num_cmd_timeout
++;
894 if (!adapter
->curr_cmd
) {
895 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
898 cmd_node
= adapter
->curr_cmd
;
900 adapter
->dbg
.timeout_cmd_id
=
901 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
902 adapter
->dbg
.timeout_cmd_act
=
903 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
904 do_gettimeofday(&tstamp
);
905 dev_err(adapter
->dev
,
906 "%s: Timeout cmd id (%lu.%lu) = %#x, act = %#x\n",
907 __func__
, tstamp
.tv_sec
, tstamp
.tv_usec
,
908 adapter
->dbg
.timeout_cmd_id
,
909 adapter
->dbg
.timeout_cmd_act
);
911 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
912 adapter
->dbg
.num_tx_host_to_card_failure
);
913 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
914 adapter
->dbg
.num_cmd_host_to_card_failure
);
916 dev_err(adapter
->dev
, "num_cmd_timeout = %d\n",
917 adapter
->dbg
.num_cmd_timeout
);
918 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
919 adapter
->dbg
.num_tx_timeout
);
921 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
922 adapter
->dbg
.last_cmd_index
);
923 dev_err(adapter
->dev
, "last_cmd_id: %*ph\n",
924 (int)sizeof(adapter
->dbg
.last_cmd_id
),
925 adapter
->dbg
.last_cmd_id
);
926 dev_err(adapter
->dev
, "last_cmd_act: %*ph\n",
927 (int)sizeof(adapter
->dbg
.last_cmd_act
),
928 adapter
->dbg
.last_cmd_act
);
930 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
931 adapter
->dbg
.last_cmd_resp_index
);
932 dev_err(adapter
->dev
, "last_cmd_resp_id: %*ph\n",
933 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
934 adapter
->dbg
.last_cmd_resp_id
);
936 dev_err(adapter
->dev
, "last_event_index = %d\n",
937 adapter
->dbg
.last_event_index
);
938 dev_err(adapter
->dev
, "last_event: %*ph\n",
939 (int)sizeof(adapter
->dbg
.last_event
),
940 adapter
->dbg
.last_event
);
942 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
943 adapter
->data_sent
, adapter
->cmd_sent
);
945 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
946 adapter
->ps_mode
, adapter
->ps_state
);
948 if (cmd_node
->wait_q_enabled
) {
949 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
950 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
951 mwifiex_cancel_pending_ioctl(adapter
);
952 /* reset cmd_sent flag to unblock new commands */
953 adapter
->cmd_sent
= false;
956 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
957 mwifiex_init_fw_complete(adapter
);
959 if (adapter
->if_ops
.card_reset
)
960 adapter
->if_ops
.card_reset(adapter
);
964 * This function cancels all the pending commands.
966 * The current command, all commands in command pending queue and all scan
967 * commands in scan pending queue are cancelled. All the completion callbacks
968 * are called with failure status to ensure cleanup.
971 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
973 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
976 /* Cancel current cmd */
977 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
978 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
979 adapter
->curr_cmd
->wait_q_enabled
= false;
980 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
981 adapter
->cmd_wait_q
.status
= -1;
982 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
984 /* Cancel all pending command */
985 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
986 list_for_each_entry_safe(cmd_node
, tmp_node
,
987 &adapter
->cmd_pending_q
, list
) {
988 list_del(&cmd_node
->list
);
989 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
991 if (cmd_node
->wait_q_enabled
) {
992 adapter
->cmd_wait_q
.status
= -1;
993 mwifiex_complete_cmd(adapter
, cmd_node
);
994 cmd_node
->wait_q_enabled
= false;
996 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
997 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
999 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1001 /* Cancel all pending scan command */
1002 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1003 list_for_each_entry_safe(cmd_node
, tmp_node
,
1004 &adapter
->scan_pending_q
, list
) {
1005 list_del(&cmd_node
->list
);
1006 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1008 cmd_node
->wait_q_enabled
= false;
1009 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1010 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1012 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1014 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
1015 adapter
->scan_processing
= false;
1016 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
1020 * This function cancels all pending commands that matches with
1021 * the given IOCTL request.
1023 * Both the current command buffer and the pending command queue are
1024 * searched for matching IOCTL request. The completion callback of
1025 * the matched command is called with failure status to ensure cleanup.
1026 * In case of scan commands, all pending commands in scan pending queue
1030 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1032 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1033 unsigned long cmd_flags
;
1034 unsigned long scan_pending_q_flags
;
1035 uint16_t cancel_scan_cmd
= false;
1037 if ((adapter
->curr_cmd
) &&
1038 (adapter
->curr_cmd
->wait_q_enabled
)) {
1039 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1040 cmd_node
= adapter
->curr_cmd
;
1041 cmd_node
->wait_q_enabled
= false;
1042 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1043 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1044 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1045 adapter
->curr_cmd
= NULL
;
1046 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1049 /* Cancel all pending scan command */
1050 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1051 scan_pending_q_flags
);
1052 list_for_each_entry_safe(cmd_node
, tmp_node
,
1053 &adapter
->scan_pending_q
, list
) {
1054 list_del(&cmd_node
->list
);
1055 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1056 scan_pending_q_flags
);
1057 cmd_node
->wait_q_enabled
= false;
1058 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1059 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1060 scan_pending_q_flags
);
1061 cancel_scan_cmd
= true;
1063 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1064 scan_pending_q_flags
);
1066 if (cancel_scan_cmd
) {
1067 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1068 adapter
->scan_processing
= false;
1069 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1071 adapter
->cmd_wait_q
.status
= -1;
1075 * This function sends the sleep confirm command to firmware, if
1078 * The sleep confirm command cannot be issued if command response,
1079 * data response or event response is awaiting handling, or if we
1080 * are in the middle of sending a command, or expecting a command
1084 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1086 if (!adapter
->cmd_sent
&&
1087 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1088 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1090 dev_dbg(adapter
->dev
,
1091 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1092 (adapter
->cmd_sent
) ? "D" : "",
1093 (adapter
->curr_cmd
) ? "C" : "",
1094 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1098 * This function sends a Host Sleep activated event to applications.
1100 * This event is generated by the driver, with a blank event body.
1103 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1106 if (priv
->adapter
->is_hs_configured
) {
1107 priv
->adapter
->hs_activated
= true;
1108 mwifiex_update_rxreor_flags(priv
->adapter
,
1109 RXREOR_FORCE_NO_DROP
);
1110 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1111 priv
->adapter
->hs_activate_wait_q_woken
= true;
1112 wake_up_interruptible(
1113 &priv
->adapter
->hs_activate_wait_q
);
1115 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1118 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1119 priv
->adapter
->hs_activated
= false;
1124 * This function handles the command response of a Host Sleep configuration
1127 * Handling includes changing the header fields into CPU format
1128 * and setting the current host sleep activation status in driver.
1130 * In case host sleep status change, the function generates an event to
1131 * notify the applications.
1133 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1134 struct host_cmd_ds_command
*resp
)
1136 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1137 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1138 &resp
->params
.opt_hs_cfg
;
1139 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1141 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1142 adapter
->iface_type
== MWIFIEX_SDIO
) {
1143 mwifiex_hs_activated_event(priv
, true);
1146 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1147 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1148 resp
->result
, conditions
,
1149 phs_cfg
->params
.hs_config
.gpio
,
1150 phs_cfg
->params
.hs_config
.gap
);
1152 if (conditions
!= HOST_SLEEP_CFG_CANCEL
) {
1153 adapter
->is_hs_configured
= true;
1154 if (adapter
->iface_type
== MWIFIEX_USB
||
1155 adapter
->iface_type
== MWIFIEX_PCIE
)
1156 mwifiex_hs_activated_event(priv
, true);
1158 adapter
->is_hs_configured
= false;
1159 if (adapter
->hs_activated
)
1160 mwifiex_hs_activated_event(priv
, false);
1167 * This function wakes up the adapter and generates a Host Sleep
1168 * cancel event on receiving the power up interrupt.
1171 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1173 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1174 " since there is interrupt from the firmware\n", __func__
);
1176 adapter
->if_ops
.wakeup(adapter
);
1177 adapter
->hs_activated
= false;
1178 adapter
->is_hs_configured
= false;
1179 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1180 MWIFIEX_BSS_ROLE_ANY
),
1183 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1186 * This function handles the command response of a sleep confirm command.
1188 * The function sets the card state to SLEEP if the response indicates success.
1191 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1192 u8
*pbuf
, u32 upld_len
)
1194 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1195 struct mwifiex_private
*priv
=
1196 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1197 uint16_t result
= le16_to_cpu(cmd
->result
);
1198 uint16_t command
= le16_to_cpu(cmd
->command
);
1199 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1202 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1206 /* Get BSS number and corresponding priv */
1207 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1208 HostCmd_GET_BSS_TYPE(seq_num
));
1210 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1212 /* Update sequence number */
1213 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1214 /* Clear RET_BIT from HostCmd */
1215 command
&= HostCmd_CMD_ID_MASK
;
1217 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1218 dev_err(adapter
->dev
,
1219 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1220 __func__
, command
, result
);
1225 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1227 adapter
->pm_wakeup_card_req
= false;
1228 adapter
->ps_state
= PS_STATE_AWAKE
;
1231 adapter
->pm_wakeup_card_req
= true;
1232 if (adapter
->is_hs_configured
)
1233 mwifiex_hs_activated_event(mwifiex_get_priv
1234 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1236 adapter
->ps_state
= PS_STATE_SLEEP
;
1237 cmd
->command
= cpu_to_le16(command
);
1238 cmd
->seq_num
= cpu_to_le16(seq_num
);
1240 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1243 * This function prepares an enhanced power mode command.
1245 * This function can be used to disable power save or to configure
1246 * power save with auto PS or STA PS or auto deep sleep.
1248 * Preparation includes -
1249 * - Setting command ID, action and proper size
1250 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1251 * auto deep sleep TLV (as required)
1252 * - Ensuring correct endian-ness
1254 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1255 struct host_cmd_ds_command
*cmd
,
1256 u16 cmd_action
, uint16_t ps_bitmap
,
1257 struct mwifiex_ds_auto_ds
*auto_ds
)
1259 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1260 &cmd
->params
.psmode_enh
;
1264 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1265 if (cmd_action
== DIS_AUTO_PS
) {
1266 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1267 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1268 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1269 sizeof(psmode_enh
->params
.ps_bitmap
));
1270 } else if (cmd_action
== GET_PS
) {
1271 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1272 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1273 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1274 sizeof(psmode_enh
->params
.ps_bitmap
));
1275 } else if (cmd_action
== EN_AUTO_PS
) {
1276 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1277 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1278 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1279 sizeof(psmode_enh
->params
.ps_bitmap
);
1280 tlv
= (u8
*) cmd
+ cmd_size
;
1281 if (ps_bitmap
& BITMAP_STA_PS
) {
1282 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1283 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1284 (struct mwifiex_ie_types_ps_param
*) tlv
;
1285 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1286 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1287 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1288 sizeof(struct mwifiex_ie_types_header
));
1289 cmd_size
+= sizeof(*ps_tlv
);
1290 tlv
+= sizeof(*ps_tlv
);
1291 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1292 ps_mode
->null_pkt_interval
=
1293 cpu_to_le16(adapter
->null_pkt_interval
);
1294 ps_mode
->multiple_dtims
=
1295 cpu_to_le16(adapter
->multiple_dtim
);
1296 ps_mode
->bcn_miss_timeout
=
1297 cpu_to_le16(adapter
->bcn_miss_time_out
);
1298 ps_mode
->local_listen_interval
=
1299 cpu_to_le16(adapter
->local_listen_interval
);
1300 ps_mode
->adhoc_wake_period
=
1301 cpu_to_le16(adapter
->adhoc_awake_period
);
1302 ps_mode
->delay_to_ps
=
1303 cpu_to_le16(adapter
->delay_to_ps
);
1304 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1307 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1308 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1309 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1312 auto_ds_tlv
->header
.type
=
1313 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1314 auto_ds_tlv
->header
.len
=
1315 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1316 sizeof(struct mwifiex_ie_types_header
));
1317 cmd_size
+= sizeof(*auto_ds_tlv
);
1318 tlv
+= sizeof(*auto_ds_tlv
);
1320 idletime
= auto_ds
->idle_time
;
1321 dev_dbg(priv
->adapter
->dev
,
1322 "cmd: PS Command: Enter Auto Deep Sleep\n");
1323 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1325 cmd
->size
= cpu_to_le16(cmd_size
);
1331 * This function handles the command response of an enhanced power mode
1334 * Handling includes changing the header fields into CPU format
1335 * and setting the current enhanced power mode in driver.
1337 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1338 struct host_cmd_ds_command
*resp
,
1339 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1341 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1342 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1343 &resp
->params
.psmode_enh
;
1344 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1345 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1346 uint16_t auto_ps_bitmap
=
1347 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1349 dev_dbg(adapter
->dev
,
1350 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1351 __func__
, resp
->result
, action
);
1352 if (action
== EN_AUTO_PS
) {
1353 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1354 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1355 priv
->adapter
->is_deep_sleep
= true;
1357 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1358 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1359 if (adapter
->sleep_period
.period
)
1360 dev_dbg(adapter
->dev
,
1361 "cmd: set to uapsd/pps mode\n");
1363 } else if (action
== DIS_AUTO_PS
) {
1364 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1365 priv
->adapter
->is_deep_sleep
= false;
1366 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1368 if (ps_bitmap
& BITMAP_STA_PS
) {
1369 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1370 if (adapter
->sleep_period
.period
) {
1371 adapter
->delay_null_pkt
= false;
1372 adapter
->tx_lock_flag
= false;
1373 adapter
->pps_uapsd_mode
= false;
1376 } else if (action
== GET_PS
) {
1377 if (ps_bitmap
& BITMAP_STA_PS
)
1378 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1380 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1382 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1385 /* This section is for get power save mode */
1386 if (ps_bitmap
& BITMAP_STA_PS
)
1387 pm_cfg
->param
.ps_mode
= 1;
1389 pm_cfg
->param
.ps_mode
= 0;
1396 * This function prepares command to get hardware specifications.
1398 * Preparation includes -
1399 * - Setting command ID, action and proper size
1400 * - Setting permanent address parameter
1401 * - Ensuring correct endian-ness
1403 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1404 struct host_cmd_ds_command
*cmd
)
1406 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1408 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1410 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1411 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1417 * This function handles the command response of get hardware
1420 * Handling includes changing the header fields into CPU format
1421 * and saving/updating the following parameters in driver -
1422 * - Firmware capability information
1423 * - Firmware band settings
1424 * - Ad-hoc start band and channel
1425 * - Ad-hoc 11n activation status
1426 * - Firmware release number
1427 * - Number of antennas
1428 * - Hardware address
1429 * - Hardware interface version
1430 * - Firmware version
1432 * - 11n capabilities
1433 * - MCS support fields
1436 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1437 struct host_cmd_ds_command
*resp
)
1439 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1440 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1443 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1445 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1446 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1448 adapter
->fw_bands
= BAND_B
;
1450 adapter
->config_bands
= adapter
->fw_bands
;
1452 if (adapter
->fw_bands
& BAND_A
) {
1453 if (adapter
->fw_bands
& BAND_GN
) {
1454 adapter
->config_bands
|= BAND_AN
;
1455 adapter
->fw_bands
|= BAND_AN
;
1457 if (adapter
->fw_bands
& BAND_AN
) {
1458 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1459 adapter
->adhoc_11n_enabled
= true;
1461 adapter
->adhoc_start_band
= BAND_A
;
1463 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1464 } else if (adapter
->fw_bands
& BAND_GN
) {
1465 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1466 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1467 adapter
->adhoc_11n_enabled
= true;
1468 } else if (adapter
->fw_bands
& BAND_G
) {
1469 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1470 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1471 } else if (adapter
->fw_bands
& BAND_B
) {
1472 adapter
->adhoc_start_band
= BAND_B
;
1473 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1476 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1477 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1479 if (le32_to_cpu(hw_spec
->dot_11ac_dev_cap
)) {
1480 adapter
->is_hw_11ac_capable
= true;
1483 adapter
->hw_dot_11ac_dev_cap
=
1484 le32_to_cpu(hw_spec
->dot_11ac_dev_cap
);
1485 adapter
->usr_dot_11ac_dev_cap_bg
= adapter
->hw_dot_11ac_dev_cap
;
1486 adapter
->usr_dot_11ac_dev_cap_a
= adapter
->hw_dot_11ac_dev_cap
;
1489 adapter
->hw_dot_11ac_mcs_support
=
1490 le32_to_cpu(hw_spec
->dot_11ac_mcs_support
);
1491 adapter
->usr_dot_11ac_mcs_support
=
1492 adapter
->hw_dot_11ac_mcs_support
;
1494 adapter
->is_hw_11ac_capable
= false;
1497 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1498 adapter
->fw_release_number
);
1499 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1500 hw_spec
->permanent_addr
);
1501 dev_dbg(adapter
->dev
,
1502 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1503 le16_to_cpu(hw_spec
->hw_if_version
),
1504 le16_to_cpu(hw_spec
->version
));
1506 if (priv
->curr_addr
[0] == 0xff)
1507 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1509 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1511 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1512 /* Use the region code to search for the index */
1513 if (adapter
->region_code
== region_code_index
[i
])
1516 /* If it's unidentified region code, use the default (USA) */
1517 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1518 adapter
->region_code
= 0x10;
1519 dev_dbg(adapter
->dev
,
1520 "cmd: unknown region code, use default (USA)\n");
1523 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1524 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1526 if (adapter
->if_ops
.update_mp_end_port
)
1527 adapter
->if_ops
.update_mp_end_port(adapter
,
1528 le16_to_cpu(hw_spec
->mp_end_port
));