2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
29 * This function initializes a command node.
31 * The actual allocation of the node is not done by this function. It only
32 * initiates a node by filling it with default parameters. Similarly,
33 * allocation of the different buffers used (IOCTL buffer, data buffer) are
34 * not done by this function either.
37 mwifiex_init_cmd_node(struct mwifiex_private
*priv
,
38 struct cmd_ctrl_node
*cmd_node
,
39 u32 cmd_oid
, void *data_buf
)
41 cmd_node
->priv
= priv
;
42 cmd_node
->cmd_oid
= cmd_oid
;
43 if (priv
->adapter
->cmd_wait_q_required
) {
44 cmd_node
->wait_q_enabled
= priv
->adapter
->cmd_wait_q_required
;
45 priv
->adapter
->cmd_wait_q_required
= false;
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
;
140 struct timeval tstamp
;
144 if (!adapter
|| !cmd_node
)
147 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
150 if (host_cmd
== NULL
|| host_cmd
->size
== 0) {
151 dev_err(adapter
->dev
, "DNLD_CMD: host_cmd is null"
152 " or cmd size is 0, not sending\n");
153 if (cmd_node
->wait_q_enabled
)
154 adapter
->cmd_wait_q
.status
= -1;
155 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
159 /* Set command sequence number */
161 host_cmd
->seq_num
= cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
163 cmd_node
->priv
->bss_num
,
164 cmd_node
->priv
->bss_type
));
166 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
167 adapter
->curr_cmd
= cmd_node
;
168 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
170 cmd_code
= le16_to_cpu(host_cmd
->command
);
171 cmd_size
= le16_to_cpu(host_cmd
->size
);
173 /* Adjust skb length */
174 if (cmd_node
->cmd_skb
->len
> cmd_size
)
176 * cmd_size is less than sizeof(struct host_cmd_ds_command).
177 * Trim off the unused portion.
179 skb_trim(cmd_node
->cmd_skb
, cmd_size
);
180 else if (cmd_node
->cmd_skb
->len
< cmd_size
)
182 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
183 * because we have appended custom IE TLV. Increase skb length
186 skb_put(cmd_node
->cmd_skb
, cmd_size
- cmd_node
->cmd_skb
->len
);
188 do_gettimeofday(&tstamp
);
189 dev_dbg(adapter
->dev
, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
191 tstamp
.tv_sec
, tstamp
.tv_usec
, cmd_code
,
192 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
)), cmd_size
,
193 le16_to_cpu(host_cmd
->seq_num
));
195 if (adapter
->iface_type
== MWIFIEX_USB
) {
196 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
197 skb_push(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
198 memcpy(cmd_node
->cmd_skb
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
199 adapter
->cmd_sent
= true;
200 ret
= adapter
->if_ops
.host_to_card(adapter
,
201 MWIFIEX_USB_EP_CMD_EVENT
,
202 cmd_node
->cmd_skb
, NULL
);
203 skb_pull(cmd_node
->cmd_skb
, MWIFIEX_TYPE_LEN
);
205 cmd_node
->cmd_skb
= NULL
;
207 skb_push(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
208 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
209 cmd_node
->cmd_skb
, NULL
);
210 skb_pull(cmd_node
->cmd_skb
, INTF_HEADER_LEN
);
214 dev_err(adapter
->dev
, "DNLD_CMD: host to card failed\n");
215 if (adapter
->iface_type
== MWIFIEX_USB
)
216 adapter
->cmd_sent
= false;
217 if (cmd_node
->wait_q_enabled
)
218 adapter
->cmd_wait_q
.status
= -1;
219 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
221 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
222 adapter
->curr_cmd
= NULL
;
223 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
225 adapter
->dbg
.num_cmd_host_to_card_failure
++;
229 /* Save the last command id and action to debug log */
230 adapter
->dbg
.last_cmd_index
=
231 (adapter
->dbg
.last_cmd_index
+ 1) % DBG_CMD_NUM
;
232 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
] = cmd_code
;
233 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
] =
234 le16_to_cpu(*(__le16
*) ((u8
*) host_cmd
+ S_DS_GEN
));
236 /* Clear BSS_NO_BITS from HostCmd */
237 cmd_code
&= HostCmd_CMD_ID_MASK
;
239 /* Setup the timer after transmit command */
240 mod_timer(&adapter
->cmd_timer
,
241 jiffies
+ (MWIFIEX_TIMER_10S
* HZ
) / 1000);
247 * This function downloads a sleep confirm command to the firmware.
249 * The function performs sanity tests, sets the command sequence
250 * number and size, converts the header fields to CPU format before
253 * No responses are needed for sleep confirm command.
255 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter
*adapter
)
258 struct mwifiex_private
*priv
;
259 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
=
260 (struct mwifiex_opt_sleep_confirm
*)
261 adapter
->sleep_cfm
->data
;
262 struct sk_buff
*sleep_cfm_tmp
;
265 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
267 sleep_cfm_buf
->seq_num
=
268 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
269 (adapter
->seq_num
, priv
->bss_num
,
273 if (adapter
->iface_type
== MWIFIEX_USB
) {
275 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
277 skb_put(sleep_cfm_tmp
, sizeof(struct mwifiex_opt_sleep_confirm
)
279 tmp
= cpu_to_le32(MWIFIEX_USB_TYPE_CMD
);
280 memcpy(sleep_cfm_tmp
->data
, &tmp
, MWIFIEX_TYPE_LEN
);
281 memcpy(sleep_cfm_tmp
->data
+ MWIFIEX_TYPE_LEN
,
282 adapter
->sleep_cfm
->data
,
283 sizeof(struct mwifiex_opt_sleep_confirm
));
284 ret
= adapter
->if_ops
.host_to_card(adapter
,
285 MWIFIEX_USB_EP_CMD_EVENT
,
286 sleep_cfm_tmp
, NULL
);
288 dev_kfree_skb_any(sleep_cfm_tmp
);
290 skb_push(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
291 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_CMD
,
292 adapter
->sleep_cfm
, NULL
);
293 skb_pull(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
297 dev_err(adapter
->dev
, "SLEEP_CFM: failed\n");
298 adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
++;
301 if (GET_BSS_ROLE(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
))
302 == MWIFIEX_BSS_ROLE_STA
) {
303 if (!sleep_cfm_buf
->resp_ctrl
)
304 /* Response is not needed for sleep
306 adapter
->ps_state
= PS_STATE_SLEEP
;
308 adapter
->ps_state
= PS_STATE_SLEEP_CFM
;
310 if (!sleep_cfm_buf
->resp_ctrl
&&
311 (adapter
->is_hs_configured
&&
312 !adapter
->sleep_period
.period
)) {
313 adapter
->pm_wakeup_card_req
= true;
314 mwifiex_hs_activated_event(mwifiex_get_priv
315 (adapter
, MWIFIEX_BSS_ROLE_STA
), true);
323 * This function allocates the command buffers and links them to
324 * the command free queue.
326 * The driver uses a pre allocated number of command buffers, which
327 * are created at driver initializations and freed at driver cleanup.
328 * Every command needs to obtain a command buffer from this pool before
329 * it can be issued. The command free queue lists the command buffers
330 * currently free to use, while the command pending queue lists the
331 * command buffers already in use and awaiting handling. Command buffers
332 * are returned to the free queue after use.
334 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter
*adapter
)
336 struct cmd_ctrl_node
*cmd_array
;
340 /* Allocate and initialize struct cmd_ctrl_node */
341 buf_size
= sizeof(struct cmd_ctrl_node
) * MWIFIEX_NUM_OF_CMD_BUFFER
;
342 cmd_array
= kzalloc(buf_size
, GFP_KERNEL
);
344 dev_err(adapter
->dev
, "%s: failed to alloc cmd_array\n",
349 adapter
->cmd_pool
= cmd_array
;
350 memset(adapter
->cmd_pool
, 0, buf_size
);
352 /* Allocate and initialize command buffers */
353 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
354 cmd_array
[i
].skb
= dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER
);
355 if (!cmd_array
[i
].skb
) {
356 dev_err(adapter
->dev
, "ALLOC_CMD_BUF: out of memory\n");
361 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++)
362 mwifiex_insert_cmd_to_free_q(adapter
, &cmd_array
[i
]);
368 * This function frees the command buffers.
370 * The function calls the completion callback for all the command
371 * buffers that still have response buffers associated with them.
373 int mwifiex_free_cmd_buffer(struct mwifiex_adapter
*adapter
)
375 struct cmd_ctrl_node
*cmd_array
;
378 /* Need to check if cmd pool is allocated or not */
379 if (!adapter
->cmd_pool
) {
380 dev_dbg(adapter
->dev
, "info: FREE_CMD_BUF: cmd_pool is null\n");
384 cmd_array
= adapter
->cmd_pool
;
386 /* Release shared memory buffers */
387 for (i
= 0; i
< MWIFIEX_NUM_OF_CMD_BUFFER
; i
++) {
388 if (cmd_array
[i
].skb
) {
389 dev_dbg(adapter
->dev
, "cmd: free cmd buffer %d\n", i
);
390 dev_kfree_skb_any(cmd_array
[i
].skb
);
392 if (!cmd_array
[i
].resp_skb
)
395 if (adapter
->iface_type
== MWIFIEX_USB
)
396 adapter
->if_ops
.cmdrsp_complete(adapter
,
397 cmd_array
[i
].resp_skb
);
399 dev_kfree_skb_any(cmd_array
[i
].resp_skb
);
401 /* Release struct cmd_ctrl_node */
402 if (adapter
->cmd_pool
) {
403 dev_dbg(adapter
->dev
, "cmd: free cmd pool\n");
404 kfree(adapter
->cmd_pool
);
405 adapter
->cmd_pool
= NULL
;
412 * This function handles events generated by firmware.
414 * Event body of events received from firmware are not used (though they are
415 * saved), only the event ID is used. Some events are re-invoked by
416 * the driver, with a new event body.
418 * After processing, the function calls the completion callback
421 int mwifiex_process_event(struct mwifiex_adapter
*adapter
)
424 struct mwifiex_private
*priv
=
425 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
426 struct sk_buff
*skb
= adapter
->event_skb
;
427 u32 eventcause
= adapter
->event_cause
;
428 struct timeval tstamp
;
429 struct mwifiex_rxinfo
*rx_info
;
431 /* Save the last event to debug log */
432 adapter
->dbg
.last_event_index
=
433 (adapter
->dbg
.last_event_index
+ 1) % DBG_CMD_NUM
;
434 adapter
->dbg
.last_event
[adapter
->dbg
.last_event_index
] =
437 /* Get BSS number and corresponding priv */
438 priv
= mwifiex_get_priv_by_id(adapter
, EVENT_GET_BSS_NUM(eventcause
),
439 EVENT_GET_BSS_TYPE(eventcause
));
441 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
442 /* Clear BSS_NO_BITS from event */
443 eventcause
&= EVENT_ID_MASK
;
444 adapter
->event_cause
= eventcause
;
447 rx_info
= MWIFIEX_SKB_RXCB(skb
);
448 rx_info
->bss_num
= priv
->bss_num
;
449 rx_info
->bss_type
= priv
->bss_type
;
452 if (eventcause
!= EVENT_PS_SLEEP
&& eventcause
!= EVENT_PS_AWAKE
) {
453 do_gettimeofday(&tstamp
);
454 dev_dbg(adapter
->dev
, "event: %lu.%lu: cause: %#x\n",
455 tstamp
.tv_sec
, tstamp
.tv_usec
, eventcause
);
457 /* Handle PS_SLEEP/AWAKE events on STA */
458 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
460 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
463 if (priv
->bss_role
== MWIFIEX_BSS_ROLE_UAP
)
464 ret
= mwifiex_process_uap_event(priv
);
466 ret
= mwifiex_process_sta_event(priv
);
468 adapter
->event_cause
= 0;
469 adapter
->event_skb
= NULL
;
470 adapter
->if_ops
.event_complete(adapter
, skb
);
476 * This function is used to send synchronous command to the firmware.
478 * it allocates a wait queue for the command and wait for the command
481 int mwifiex_send_cmd_sync(struct mwifiex_private
*priv
, uint16_t cmd_no
,
482 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
485 struct mwifiex_adapter
*adapter
= priv
->adapter
;
487 adapter
->cmd_wait_q_required
= true;
489 ret
= mwifiex_send_cmd_async(priv
, cmd_no
, cmd_action
, cmd_oid
,
492 ret
= mwifiex_wait_queue_complete(adapter
);
499 * This function prepares a command and asynchronously send it to the firmware.
501 * Preparation includes -
502 * - Sanity tests to make sure the card is still present or the FW
504 * - Getting a new command node from the command free queue
505 * - Initializing the command node for default parameters
506 * - Fill up the non-default parameters and buffer pointers
507 * - Add the command to pending queue
509 int mwifiex_send_cmd_async(struct mwifiex_private
*priv
, uint16_t cmd_no
,
510 u16 cmd_action
, u32 cmd_oid
, void *data_buf
)
513 struct mwifiex_adapter
*adapter
= priv
->adapter
;
514 struct cmd_ctrl_node
*cmd_node
;
515 struct host_cmd_ds_command
*cmd_ptr
;
518 pr_err("PREP_CMD: adapter is NULL\n");
522 if (adapter
->is_suspended
) {
523 dev_err(adapter
->dev
, "PREP_CMD: device in suspended state\n");
527 if (adapter
->surprise_removed
) {
528 dev_err(adapter
->dev
, "PREP_CMD: card is removed\n");
532 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_RESET
) {
533 if (cmd_no
!= HostCmd_CMD_FUNC_INIT
) {
534 dev_err(adapter
->dev
, "PREP_CMD: FW in reset state\n");
539 /* Get a new command node */
540 cmd_node
= mwifiex_get_cmd_node(adapter
);
543 dev_err(adapter
->dev
, "PREP_CMD: no free cmd node\n");
547 /* Initialize the command node */
548 mwifiex_init_cmd_node(priv
, cmd_node
, cmd_oid
, data_buf
);
550 if (!cmd_node
->cmd_skb
) {
551 dev_err(adapter
->dev
, "PREP_CMD: no free cmd buf\n");
555 memset(skb_put(cmd_node
->cmd_skb
, sizeof(struct host_cmd_ds_command
)),
556 0, sizeof(struct host_cmd_ds_command
));
558 cmd_ptr
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
559 cmd_ptr
->command
= cpu_to_le16(cmd_no
);
562 /* Prepare command */
565 case HostCmd_CMD_UAP_SYS_CONFIG
:
566 case HostCmd_CMD_UAP_BSS_START
:
567 case HostCmd_CMD_UAP_BSS_STOP
:
568 ret
= mwifiex_uap_prepare_cmd(priv
, cmd_no
, cmd_action
,
573 ret
= mwifiex_sta_prepare_cmd(priv
, cmd_no
, cmd_action
,
579 ret
= mwifiex_cmd_host_cmd(priv
, cmd_ptr
, data_buf
);
580 cmd_node
->cmd_flag
|= CMD_F_HOSTCMD
;
583 /* Return error, since the command preparation failed */
585 dev_err(adapter
->dev
, "PREP_CMD: cmd %#x preparation failed\n",
587 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
592 if (cmd_no
== HostCmd_CMD_802_11_SCAN
) {
593 mwifiex_queue_scan_cmd(priv
, cmd_node
);
595 adapter
->cmd_queued
= cmd_node
;
596 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
, true);
597 queue_work(adapter
->workqueue
, &adapter
->main_work
);
604 * This function returns a command to the command free queue.
606 * The function also calls the completion callback if required, before
607 * cleaning the command node and re-inserting it into the free queue.
610 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter
*adapter
,
611 struct cmd_ctrl_node
*cmd_node
)
618 if (cmd_node
->wait_q_enabled
)
619 mwifiex_complete_cmd(adapter
, cmd_node
);
621 mwifiex_clean_cmd_node(adapter
, cmd_node
);
623 /* Insert node into cmd_free_q */
624 spin_lock_irqsave(&adapter
->cmd_free_q_lock
, flags
);
625 list_add_tail(&cmd_node
->list
, &adapter
->cmd_free_q
);
626 spin_unlock_irqrestore(&adapter
->cmd_free_q_lock
, flags
);
630 * This function queues a command to the command pending queue.
632 * This in effect adds the command to the command list to be executed.
633 * Exit PS command is handled specially, by placing it always to the
634 * front of the command queue.
637 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter
*adapter
,
638 struct cmd_ctrl_node
*cmd_node
, u32 add_tail
)
640 struct host_cmd_ds_command
*host_cmd
= NULL
;
644 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
646 dev_err(adapter
->dev
, "QUEUE_CMD: host_cmd is NULL\n");
650 command
= le16_to_cpu(host_cmd
->command
);
652 /* Exit_PS command needs to be queued in the header always. */
653 if (command
== HostCmd_CMD_802_11_PS_MODE_ENH
) {
654 struct host_cmd_ds_802_11_ps_mode_enh
*pm
=
655 &host_cmd
->params
.psmode_enh
;
656 if ((le16_to_cpu(pm
->action
) == DIS_PS
) ||
657 (le16_to_cpu(pm
->action
) == DIS_AUTO_PS
)) {
658 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
663 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
665 list_add_tail(&cmd_node
->list
, &adapter
->cmd_pending_q
);
667 list_add(&cmd_node
->list
, &adapter
->cmd_pending_q
);
668 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
670 dev_dbg(adapter
->dev
, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command
);
674 * This function executes the next command in command pending queue.
676 * This function will fail if a command is already in processing stage,
677 * otherwise it will dequeue the first command from the command pending
678 * queue and send to the firmware.
680 * If the device is currently in host sleep mode, any commands, except the
681 * host sleep configuration command will de-activate the host sleep. For PS
682 * mode, the function will put the firmware back to sleep if applicable.
684 int mwifiex_exec_next_cmd(struct mwifiex_adapter
*adapter
)
686 struct mwifiex_private
*priv
;
687 struct cmd_ctrl_node
*cmd_node
;
689 struct host_cmd_ds_command
*host_cmd
;
690 unsigned long cmd_flags
;
691 unsigned long cmd_pending_q_flags
;
693 /* Check if already in processing */
694 if (adapter
->curr_cmd
) {
695 dev_err(adapter
->dev
, "EXEC_NEXT_CMD: cmd in processing\n");
699 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
700 /* Check if any command is pending */
701 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
702 if (list_empty(&adapter
->cmd_pending_q
)) {
703 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
704 cmd_pending_q_flags
);
705 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
708 cmd_node
= list_first_entry(&adapter
->cmd_pending_q
,
709 struct cmd_ctrl_node
, list
);
710 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
711 cmd_pending_q_flags
);
713 host_cmd
= (struct host_cmd_ds_command
*) (cmd_node
->cmd_skb
->data
);
714 priv
= cmd_node
->priv
;
716 if (adapter
->ps_state
!= PS_STATE_AWAKE
) {
717 dev_err(adapter
->dev
, "%s: cannot send cmd in sleep state,"
718 " this should not happen\n", __func__
);
719 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
723 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, cmd_pending_q_flags
);
724 list_del(&cmd_node
->list
);
725 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
,
726 cmd_pending_q_flags
);
728 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
729 ret
= mwifiex_dnld_cmd_to_fw(priv
, cmd_node
);
730 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
731 /* Any command sent to the firmware when host is in sleep
732 * mode should de-configure host sleep. We should skip the
733 * host sleep configuration command itself though
735 if (priv
&& (host_cmd
->command
!=
736 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH
))) {
737 if (adapter
->hs_activated
) {
738 adapter
->is_hs_configured
= false;
739 mwifiex_hs_activated_event(priv
, false);
747 * This function handles the command response.
749 * After processing, the function cleans the command node and puts
750 * it back to the command free queue.
752 int mwifiex_process_cmdresp(struct mwifiex_adapter
*adapter
)
754 struct host_cmd_ds_command
*resp
;
755 struct mwifiex_private
*priv
=
756 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
758 uint16_t orig_cmdresp_no
;
760 uint16_t cmdresp_result
;
761 struct timeval tstamp
;
764 /* Now we got response from FW, cancel the command timer */
765 del_timer(&adapter
->cmd_timer
);
767 if (!adapter
->curr_cmd
|| !adapter
->curr_cmd
->resp_skb
) {
768 resp
= (struct host_cmd_ds_command
*) adapter
->upld_buf
;
769 dev_err(adapter
->dev
, "CMD_RESP: NULL curr_cmd, %#x\n",
770 le16_to_cpu(resp
->command
));
774 adapter
->num_cmd_timeout
= 0;
776 resp
= (struct host_cmd_ds_command
*) adapter
->curr_cmd
->resp_skb
->data
;
777 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_CANCELED
) {
778 dev_err(adapter
->dev
, "CMD_RESP: %#x been canceled\n",
779 le16_to_cpu(resp
->command
));
780 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
781 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
782 adapter
->curr_cmd
= NULL
;
783 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
787 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
788 /* Copy original response back to response buffer */
789 struct mwifiex_ds_misc_cmd
*hostcmd
;
790 uint16_t size
= le16_to_cpu(resp
->size
);
791 dev_dbg(adapter
->dev
, "info: host cmd resp size = %d\n", size
);
792 size
= min_t(u16
, size
, MWIFIEX_SIZE_OF_CMD_BUFFER
);
793 if (adapter
->curr_cmd
->data_buf
) {
794 hostcmd
= adapter
->curr_cmd
->data_buf
;
796 memcpy(hostcmd
->cmd
, resp
, size
);
799 orig_cmdresp_no
= le16_to_cpu(resp
->command
);
801 /* Get BSS number and corresponding priv */
802 priv
= mwifiex_get_priv_by_id(adapter
,
803 HostCmd_GET_BSS_NO(le16_to_cpu(resp
->seq_num
)),
804 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp
->seq_num
)));
806 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
807 /* Clear RET_BIT from HostCmd */
808 resp
->command
= cpu_to_le16(orig_cmdresp_no
& HostCmd_CMD_ID_MASK
);
810 cmdresp_no
= le16_to_cpu(resp
->command
);
811 cmdresp_result
= le16_to_cpu(resp
->result
);
813 /* Save the last command response to debug log */
814 adapter
->dbg
.last_cmd_resp_index
=
815 (adapter
->dbg
.last_cmd_resp_index
+ 1) % DBG_CMD_NUM
;
816 adapter
->dbg
.last_cmd_resp_id
[adapter
->dbg
.last_cmd_resp_index
] =
819 do_gettimeofday(&tstamp
);
820 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
821 " len %d, seqno 0x%x\n",
822 tstamp
.tv_sec
, tstamp
.tv_usec
, orig_cmdresp_no
, cmdresp_result
,
823 le16_to_cpu(resp
->size
), le16_to_cpu(resp
->seq_num
));
825 if (!(orig_cmdresp_no
& HostCmd_RET_BIT
)) {
826 dev_err(adapter
->dev
, "CMD_RESP: invalid cmd resp\n");
827 if (adapter
->curr_cmd
->wait_q_enabled
)
828 adapter
->cmd_wait_q
.status
= -1;
830 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
831 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
832 adapter
->curr_cmd
= NULL
;
833 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
837 if (adapter
->curr_cmd
->cmd_flag
& CMD_F_HOSTCMD
) {
838 adapter
->curr_cmd
->cmd_flag
&= ~CMD_F_HOSTCMD
;
839 if ((cmdresp_result
== HostCmd_RESULT_OK
) &&
840 (cmdresp_no
== HostCmd_CMD_802_11_HS_CFG_ENH
))
841 ret
= mwifiex_ret_802_11_hs_cfg(priv
, resp
);
843 /* handle response */
844 ret
= mwifiex_process_sta_cmdresp(priv
, cmdresp_no
, resp
);
847 /* Check init command response */
848 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
) {
850 dev_err(adapter
->dev
, "%s: cmd %#x failed during "
851 "initialization\n", __func__
, cmdresp_no
);
852 mwifiex_init_fw_complete(adapter
);
854 } else if (adapter
->last_init_cmd
== cmdresp_no
)
855 adapter
->hw_status
= MWIFIEX_HW_STATUS_INIT_DONE
;
858 if (adapter
->curr_cmd
) {
859 if (adapter
->curr_cmd
->wait_q_enabled
)
860 adapter
->cmd_wait_q
.status
= ret
;
862 /* Clean up and put current command back to cmd_free_q */
863 mwifiex_insert_cmd_to_free_q(adapter
, adapter
->curr_cmd
);
865 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
866 adapter
->curr_cmd
= NULL
;
867 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
874 * This function handles the timeout of command sending.
876 * It will re-send the same command again.
879 mwifiex_cmd_timeout_func(unsigned long function_context
)
881 struct mwifiex_adapter
*adapter
=
882 (struct mwifiex_adapter
*) function_context
;
883 struct cmd_ctrl_node
*cmd_node
;
884 struct timeval tstamp
;
886 adapter
->num_cmd_timeout
++;
887 adapter
->dbg
.num_cmd_timeout
++;
888 if (!adapter
->curr_cmd
) {
889 dev_dbg(adapter
->dev
, "cmd: empty curr_cmd\n");
892 cmd_node
= adapter
->curr_cmd
;
894 adapter
->dbg
.timeout_cmd_id
=
895 adapter
->dbg
.last_cmd_id
[adapter
->dbg
.last_cmd_index
];
896 adapter
->dbg
.timeout_cmd_act
=
897 adapter
->dbg
.last_cmd_act
[adapter
->dbg
.last_cmd_index
];
898 do_gettimeofday(&tstamp
);
899 dev_err(adapter
->dev
,
900 "%s: Timeout cmd id (%lu.%lu) = %#x, act = %#x\n",
901 __func__
, tstamp
.tv_sec
, tstamp
.tv_usec
,
902 adapter
->dbg
.timeout_cmd_id
,
903 adapter
->dbg
.timeout_cmd_act
);
905 dev_err(adapter
->dev
, "num_data_h2c_failure = %d\n",
906 adapter
->dbg
.num_tx_host_to_card_failure
);
907 dev_err(adapter
->dev
, "num_cmd_h2c_failure = %d\n",
908 adapter
->dbg
.num_cmd_host_to_card_failure
);
910 dev_err(adapter
->dev
, "num_cmd_timeout = %d\n",
911 adapter
->dbg
.num_cmd_timeout
);
912 dev_err(adapter
->dev
, "num_tx_timeout = %d\n",
913 adapter
->dbg
.num_tx_timeout
);
915 dev_err(adapter
->dev
, "last_cmd_index = %d\n",
916 adapter
->dbg
.last_cmd_index
);
917 dev_err(adapter
->dev
, "last_cmd_id: %*ph\n",
918 (int)sizeof(adapter
->dbg
.last_cmd_id
),
919 adapter
->dbg
.last_cmd_id
);
920 dev_err(adapter
->dev
, "last_cmd_act: %*ph\n",
921 (int)sizeof(adapter
->dbg
.last_cmd_act
),
922 adapter
->dbg
.last_cmd_act
);
924 dev_err(adapter
->dev
, "last_cmd_resp_index = %d\n",
925 adapter
->dbg
.last_cmd_resp_index
);
926 dev_err(adapter
->dev
, "last_cmd_resp_id: %*ph\n",
927 (int)sizeof(adapter
->dbg
.last_cmd_resp_id
),
928 adapter
->dbg
.last_cmd_resp_id
);
930 dev_err(adapter
->dev
, "last_event_index = %d\n",
931 adapter
->dbg
.last_event_index
);
932 dev_err(adapter
->dev
, "last_event: %*ph\n",
933 (int)sizeof(adapter
->dbg
.last_event
),
934 adapter
->dbg
.last_event
);
936 dev_err(adapter
->dev
, "data_sent=%d cmd_sent=%d\n",
937 adapter
->data_sent
, adapter
->cmd_sent
);
939 dev_err(adapter
->dev
, "ps_mode=%d ps_state=%d\n",
940 adapter
->ps_mode
, adapter
->ps_state
);
942 if (cmd_node
->wait_q_enabled
) {
943 adapter
->cmd_wait_q
.status
= -ETIMEDOUT
;
944 wake_up_interruptible(&adapter
->cmd_wait_q
.wait
);
945 mwifiex_cancel_pending_ioctl(adapter
);
946 /* reset cmd_sent flag to unblock new commands */
947 adapter
->cmd_sent
= false;
950 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INITIALIZING
)
951 mwifiex_init_fw_complete(adapter
);
953 if (adapter
->if_ops
.card_reset
)
954 adapter
->if_ops
.card_reset(adapter
);
958 * This function cancels all the pending commands.
960 * The current command, all commands in command pending queue and all scan
961 * commands in scan pending queue are cancelled. All the completion callbacks
962 * are called with failure status to ensure cleanup.
965 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter
*adapter
)
967 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
;
970 /* Cancel current cmd */
971 if ((adapter
->curr_cmd
) && (adapter
->curr_cmd
->wait_q_enabled
)) {
972 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
973 adapter
->curr_cmd
->wait_q_enabled
= false;
974 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
975 adapter
->cmd_wait_q
.status
= -1;
976 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
978 /* Cancel all pending command */
979 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
980 list_for_each_entry_safe(cmd_node
, tmp_node
,
981 &adapter
->cmd_pending_q
, list
) {
982 list_del(&cmd_node
->list
);
983 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
985 if (cmd_node
->wait_q_enabled
) {
986 adapter
->cmd_wait_q
.status
= -1;
987 mwifiex_complete_cmd(adapter
, cmd_node
);
988 cmd_node
->wait_q_enabled
= false;
990 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
991 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
993 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
995 /* Cancel all pending scan command */
996 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
997 list_for_each_entry_safe(cmd_node
, tmp_node
,
998 &adapter
->scan_pending_q
, list
) {
999 list_del(&cmd_node
->list
);
1000 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1002 cmd_node
->wait_q_enabled
= false;
1003 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1004 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
1006 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
1008 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
1009 adapter
->scan_processing
= false;
1010 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
1014 * This function cancels all pending commands that matches with
1015 * the given IOCTL request.
1017 * Both the current command buffer and the pending command queue are
1018 * searched for matching IOCTL request. The completion callback of
1019 * the matched command is called with failure status to ensure cleanup.
1020 * In case of scan commands, all pending commands in scan pending queue
1024 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter
*adapter
)
1026 struct cmd_ctrl_node
*cmd_node
= NULL
, *tmp_node
= NULL
;
1027 unsigned long cmd_flags
;
1028 unsigned long scan_pending_q_flags
;
1029 uint16_t cancel_scan_cmd
= false;
1031 if ((adapter
->curr_cmd
) &&
1032 (adapter
->curr_cmd
->wait_q_enabled
)) {
1033 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1034 cmd_node
= adapter
->curr_cmd
;
1035 cmd_node
->wait_q_enabled
= false;
1036 cmd_node
->cmd_flag
|= CMD_F_CANCELED
;
1037 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1038 mwifiex_complete_cmd(adapter
, adapter
->curr_cmd
);
1039 adapter
->curr_cmd
= NULL
;
1040 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1043 /* Cancel all pending scan command */
1044 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1045 scan_pending_q_flags
);
1046 list_for_each_entry_safe(cmd_node
, tmp_node
,
1047 &adapter
->scan_pending_q
, list
) {
1048 list_del(&cmd_node
->list
);
1049 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1050 scan_pending_q_flags
);
1051 cmd_node
->wait_q_enabled
= false;
1052 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
1053 spin_lock_irqsave(&adapter
->scan_pending_q_lock
,
1054 scan_pending_q_flags
);
1055 cancel_scan_cmd
= true;
1057 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
1058 scan_pending_q_flags
);
1060 if (cancel_scan_cmd
) {
1061 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1062 adapter
->scan_processing
= false;
1063 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, cmd_flags
);
1065 adapter
->cmd_wait_q
.status
= -1;
1069 * This function sends the sleep confirm command to firmware, if
1072 * The sleep confirm command cannot be issued if command response,
1073 * data response or event response is awaiting handling, or if we
1074 * are in the middle of sending a command, or expecting a command
1078 mwifiex_check_ps_cond(struct mwifiex_adapter
*adapter
)
1080 if (!adapter
->cmd_sent
&&
1081 !adapter
->curr_cmd
&& !IS_CARD_RX_RCVD(adapter
))
1082 mwifiex_dnld_sleep_confirm_cmd(adapter
);
1084 dev_dbg(adapter
->dev
,
1085 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1086 (adapter
->cmd_sent
) ? "D" : "",
1087 (adapter
->curr_cmd
) ? "C" : "",
1088 (IS_CARD_RX_RCVD(adapter
)) ? "R" : "");
1092 * This function sends a Host Sleep activated event to applications.
1094 * This event is generated by the driver, with a blank event body.
1097 mwifiex_hs_activated_event(struct mwifiex_private
*priv
, u8 activated
)
1100 if (priv
->adapter
->is_hs_configured
) {
1101 priv
->adapter
->hs_activated
= true;
1102 mwifiex_update_rxreor_flags(priv
->adapter
,
1103 RXREOR_FORCE_NO_DROP
);
1104 dev_dbg(priv
->adapter
->dev
, "event: hs_activated\n");
1105 priv
->adapter
->hs_activate_wait_q_woken
= true;
1106 wake_up_interruptible(
1107 &priv
->adapter
->hs_activate_wait_q
);
1109 dev_dbg(priv
->adapter
->dev
, "event: HS not configured\n");
1112 dev_dbg(priv
->adapter
->dev
, "event: hs_deactivated\n");
1113 priv
->adapter
->hs_activated
= false;
1118 * This function handles the command response of a Host Sleep configuration
1121 * Handling includes changing the header fields into CPU format
1122 * and setting the current host sleep activation status in driver.
1124 * In case host sleep status change, the function generates an event to
1125 * notify the applications.
1127 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private
*priv
,
1128 struct host_cmd_ds_command
*resp
)
1130 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1131 struct host_cmd_ds_802_11_hs_cfg_enh
*phs_cfg
=
1132 &resp
->params
.opt_hs_cfg
;
1133 uint32_t conditions
= le32_to_cpu(phs_cfg
->params
.hs_config
.conditions
);
1135 if (phs_cfg
->action
== cpu_to_le16(HS_ACTIVATE
) &&
1136 adapter
->iface_type
== MWIFIEX_SDIO
) {
1137 mwifiex_hs_activated_event(priv
, true);
1140 dev_dbg(adapter
->dev
, "cmd: CMD_RESP: HS_CFG cmd reply"
1141 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1142 resp
->result
, conditions
,
1143 phs_cfg
->params
.hs_config
.gpio
,
1144 phs_cfg
->params
.hs_config
.gap
);
1146 if (conditions
!= HOST_SLEEP_CFG_CANCEL
) {
1147 adapter
->is_hs_configured
= true;
1148 if (adapter
->iface_type
== MWIFIEX_USB
||
1149 adapter
->iface_type
== MWIFIEX_PCIE
)
1150 mwifiex_hs_activated_event(priv
, true);
1152 adapter
->is_hs_configured
= false;
1153 if (adapter
->hs_activated
)
1154 mwifiex_hs_activated_event(priv
, false);
1161 * This function wakes up the adapter and generates a Host Sleep
1162 * cancel event on receiving the power up interrupt.
1165 mwifiex_process_hs_config(struct mwifiex_adapter
*adapter
)
1167 dev_dbg(adapter
->dev
, "info: %s: auto cancelling host sleep"
1168 " since there is interrupt from the firmware\n", __func__
);
1170 adapter
->if_ops
.wakeup(adapter
);
1171 adapter
->hs_activated
= false;
1172 adapter
->is_hs_configured
= false;
1173 mwifiex_hs_activated_event(mwifiex_get_priv(adapter
,
1174 MWIFIEX_BSS_ROLE_ANY
),
1177 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config
);
1180 * This function handles the command response of a sleep confirm command.
1182 * The function sets the card state to SLEEP if the response indicates success.
1185 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter
*adapter
,
1186 u8
*pbuf
, u32 upld_len
)
1188 struct host_cmd_ds_command
*cmd
= (struct host_cmd_ds_command
*) pbuf
;
1189 struct mwifiex_private
*priv
=
1190 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1191 uint16_t result
= le16_to_cpu(cmd
->result
);
1192 uint16_t command
= le16_to_cpu(cmd
->command
);
1193 uint16_t seq_num
= le16_to_cpu(cmd
->seq_num
);
1196 dev_err(adapter
->dev
, "%s: cmd size is 0\n", __func__
);
1200 /* Get BSS number and corresponding priv */
1201 priv
= mwifiex_get_priv_by_id(adapter
, HostCmd_GET_BSS_NO(seq_num
),
1202 HostCmd_GET_BSS_TYPE(seq_num
));
1204 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1206 /* Update sequence number */
1207 seq_num
= HostCmd_GET_SEQ_NO(seq_num
);
1208 /* Clear RET_BIT from HostCmd */
1209 command
&= HostCmd_CMD_ID_MASK
;
1211 if (command
!= HostCmd_CMD_802_11_PS_MODE_ENH
) {
1212 dev_err(adapter
->dev
,
1213 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1214 __func__
, command
, result
);
1219 dev_err(adapter
->dev
, "%s: sleep confirm cmd failed\n",
1221 adapter
->pm_wakeup_card_req
= false;
1222 adapter
->ps_state
= PS_STATE_AWAKE
;
1225 adapter
->pm_wakeup_card_req
= true;
1226 if (adapter
->is_hs_configured
)
1227 mwifiex_hs_activated_event(mwifiex_get_priv
1228 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
1230 adapter
->ps_state
= PS_STATE_SLEEP
;
1231 cmd
->command
= cpu_to_le16(command
);
1232 cmd
->seq_num
= cpu_to_le16(seq_num
);
1234 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp
);
1237 * This function prepares an enhanced power mode command.
1239 * This function can be used to disable power save or to configure
1240 * power save with auto PS or STA PS or auto deep sleep.
1242 * Preparation includes -
1243 * - Setting command ID, action and proper size
1244 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1245 * auto deep sleep TLV (as required)
1246 * - Ensuring correct endian-ness
1248 int mwifiex_cmd_enh_power_mode(struct mwifiex_private
*priv
,
1249 struct host_cmd_ds_command
*cmd
,
1250 u16 cmd_action
, uint16_t ps_bitmap
,
1251 struct mwifiex_ds_auto_ds
*auto_ds
)
1253 struct host_cmd_ds_802_11_ps_mode_enh
*psmode_enh
=
1254 &cmd
->params
.psmode_enh
;
1258 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
1259 if (cmd_action
== DIS_AUTO_PS
) {
1260 psmode_enh
->action
= cpu_to_le16(DIS_AUTO_PS
);
1261 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1262 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1263 sizeof(psmode_enh
->params
.ps_bitmap
));
1264 } else if (cmd_action
== GET_PS
) {
1265 psmode_enh
->action
= cpu_to_le16(GET_PS
);
1266 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1267 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1268 sizeof(psmode_enh
->params
.ps_bitmap
));
1269 } else if (cmd_action
== EN_AUTO_PS
) {
1270 psmode_enh
->action
= cpu_to_le16(EN_AUTO_PS
);
1271 psmode_enh
->params
.ps_bitmap
= cpu_to_le16(ps_bitmap
);
1272 cmd_size
= S_DS_GEN
+ sizeof(psmode_enh
->action
) +
1273 sizeof(psmode_enh
->params
.ps_bitmap
);
1274 tlv
= (u8
*) cmd
+ cmd_size
;
1275 if (ps_bitmap
& BITMAP_STA_PS
) {
1276 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1277 struct mwifiex_ie_types_ps_param
*ps_tlv
=
1278 (struct mwifiex_ie_types_ps_param
*) tlv
;
1279 struct mwifiex_ps_param
*ps_mode
= &ps_tlv
->param
;
1280 ps_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_PS_PARAM
);
1281 ps_tlv
->header
.len
= cpu_to_le16(sizeof(*ps_tlv
) -
1282 sizeof(struct mwifiex_ie_types_header
));
1283 cmd_size
+= sizeof(*ps_tlv
);
1284 tlv
+= sizeof(*ps_tlv
);
1285 dev_dbg(adapter
->dev
, "cmd: PS Command: Enter PS\n");
1286 ps_mode
->null_pkt_interval
=
1287 cpu_to_le16(adapter
->null_pkt_interval
);
1288 ps_mode
->multiple_dtims
=
1289 cpu_to_le16(adapter
->multiple_dtim
);
1290 ps_mode
->bcn_miss_timeout
=
1291 cpu_to_le16(adapter
->bcn_miss_time_out
);
1292 ps_mode
->local_listen_interval
=
1293 cpu_to_le16(adapter
->local_listen_interval
);
1294 ps_mode
->adhoc_wake_period
=
1295 cpu_to_le16(adapter
->adhoc_awake_period
);
1296 ps_mode
->delay_to_ps
=
1297 cpu_to_le16(adapter
->delay_to_ps
);
1298 ps_mode
->mode
= cpu_to_le16(adapter
->enhanced_ps_mode
);
1301 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1302 struct mwifiex_ie_types_auto_ds_param
*auto_ds_tlv
=
1303 (struct mwifiex_ie_types_auto_ds_param
*) tlv
;
1306 auto_ds_tlv
->header
.type
=
1307 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM
);
1308 auto_ds_tlv
->header
.len
=
1309 cpu_to_le16(sizeof(*auto_ds_tlv
) -
1310 sizeof(struct mwifiex_ie_types_header
));
1311 cmd_size
+= sizeof(*auto_ds_tlv
);
1312 tlv
+= sizeof(*auto_ds_tlv
);
1314 idletime
= auto_ds
->idle_time
;
1315 dev_dbg(priv
->adapter
->dev
,
1316 "cmd: PS Command: Enter Auto Deep Sleep\n");
1317 auto_ds_tlv
->deep_sleep_timeout
= cpu_to_le16(idletime
);
1319 cmd
->size
= cpu_to_le16(cmd_size
);
1325 * This function handles the command response of an enhanced power mode
1328 * Handling includes changing the header fields into CPU format
1329 * and setting the current enhanced power mode in driver.
1331 int mwifiex_ret_enh_power_mode(struct mwifiex_private
*priv
,
1332 struct host_cmd_ds_command
*resp
,
1333 struct mwifiex_ds_pm_cfg
*pm_cfg
)
1335 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1336 struct host_cmd_ds_802_11_ps_mode_enh
*ps_mode
=
1337 &resp
->params
.psmode_enh
;
1338 uint16_t action
= le16_to_cpu(ps_mode
->action
);
1339 uint16_t ps_bitmap
= le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1340 uint16_t auto_ps_bitmap
=
1341 le16_to_cpu(ps_mode
->params
.ps_bitmap
);
1343 dev_dbg(adapter
->dev
,
1344 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1345 __func__
, resp
->result
, action
);
1346 if (action
== EN_AUTO_PS
) {
1347 if (auto_ps_bitmap
& BITMAP_AUTO_DS
) {
1348 dev_dbg(adapter
->dev
, "cmd: Enabled auto deep sleep\n");
1349 priv
->adapter
->is_deep_sleep
= true;
1351 if (auto_ps_bitmap
& BITMAP_STA_PS
) {
1352 dev_dbg(adapter
->dev
, "cmd: Enabled STA power save\n");
1353 if (adapter
->sleep_period
.period
)
1354 dev_dbg(adapter
->dev
,
1355 "cmd: set to uapsd/pps mode\n");
1357 } else if (action
== DIS_AUTO_PS
) {
1358 if (ps_bitmap
& BITMAP_AUTO_DS
) {
1359 priv
->adapter
->is_deep_sleep
= false;
1360 dev_dbg(adapter
->dev
, "cmd: Disabled auto deep sleep\n");
1362 if (ps_bitmap
& BITMAP_STA_PS
) {
1363 dev_dbg(adapter
->dev
, "cmd: Disabled STA power save\n");
1364 if (adapter
->sleep_period
.period
) {
1365 adapter
->delay_null_pkt
= false;
1366 adapter
->tx_lock_flag
= false;
1367 adapter
->pps_uapsd_mode
= false;
1370 } else if (action
== GET_PS
) {
1371 if (ps_bitmap
& BITMAP_STA_PS
)
1372 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
1374 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
1376 dev_dbg(adapter
->dev
, "cmd: ps_bitmap=%#x\n", ps_bitmap
);
1379 /* This section is for get power save mode */
1380 if (ps_bitmap
& BITMAP_STA_PS
)
1381 pm_cfg
->param
.ps_mode
= 1;
1383 pm_cfg
->param
.ps_mode
= 0;
1390 * This function prepares command to get hardware specifications.
1392 * Preparation includes -
1393 * - Setting command ID, action and proper size
1394 * - Setting permanent address parameter
1395 * - Ensuring correct endian-ness
1397 int mwifiex_cmd_get_hw_spec(struct mwifiex_private
*priv
,
1398 struct host_cmd_ds_command
*cmd
)
1400 struct host_cmd_ds_get_hw_spec
*hw_spec
= &cmd
->params
.hw_spec
;
1402 cmd
->command
= cpu_to_le16(HostCmd_CMD_GET_HW_SPEC
);
1404 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec
) + S_DS_GEN
);
1405 memcpy(hw_spec
->permanent_addr
, priv
->curr_addr
, ETH_ALEN
);
1411 * This function handles the command response of get hardware
1414 * Handling includes changing the header fields into CPU format
1415 * and saving/updating the following parameters in driver -
1416 * - Firmware capability information
1417 * - Firmware band settings
1418 * - Ad-hoc start band and channel
1419 * - Ad-hoc 11n activation status
1420 * - Firmware release number
1421 * - Number of antennas
1422 * - Hardware address
1423 * - Hardware interface version
1424 * - Firmware version
1426 * - 11n capabilities
1427 * - MCS support fields
1430 int mwifiex_ret_get_hw_spec(struct mwifiex_private
*priv
,
1431 struct host_cmd_ds_command
*resp
)
1433 struct host_cmd_ds_get_hw_spec
*hw_spec
= &resp
->params
.hw_spec
;
1434 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1437 adapter
->fw_cap_info
= le32_to_cpu(hw_spec
->fw_cap_info
);
1439 if (IS_SUPPORT_MULTI_BANDS(adapter
))
1440 adapter
->fw_bands
= (u8
) GET_FW_DEFAULT_BANDS(adapter
);
1442 adapter
->fw_bands
= BAND_B
;
1444 adapter
->config_bands
= adapter
->fw_bands
;
1446 if (adapter
->fw_bands
& BAND_A
) {
1447 if (adapter
->fw_bands
& BAND_GN
) {
1448 adapter
->config_bands
|= BAND_AN
;
1449 adapter
->fw_bands
|= BAND_AN
;
1451 if (adapter
->fw_bands
& BAND_AN
) {
1452 adapter
->adhoc_start_band
= BAND_A
| BAND_AN
;
1453 adapter
->adhoc_11n_enabled
= true;
1455 adapter
->adhoc_start_band
= BAND_A
;
1457 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL_A
;
1458 } else if (adapter
->fw_bands
& BAND_GN
) {
1459 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
1460 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1461 adapter
->adhoc_11n_enabled
= true;
1462 } else if (adapter
->fw_bands
& BAND_G
) {
1463 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
1464 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1465 } else if (adapter
->fw_bands
& BAND_B
) {
1466 adapter
->adhoc_start_band
= BAND_B
;
1467 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
1470 adapter
->fw_release_number
= le32_to_cpu(hw_spec
->fw_release_number
);
1471 adapter
->number_of_antenna
= le16_to_cpu(hw_spec
->number_of_antenna
);
1473 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1474 adapter
->fw_release_number
);
1475 dev_dbg(adapter
->dev
, "info: GET_HW_SPEC: permanent addr: %pM\n",
1476 hw_spec
->permanent_addr
);
1477 dev_dbg(adapter
->dev
,
1478 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1479 le16_to_cpu(hw_spec
->hw_if_version
),
1480 le16_to_cpu(hw_spec
->version
));
1482 if (priv
->curr_addr
[0] == 0xff)
1483 memmove(priv
->curr_addr
, hw_spec
->permanent_addr
, ETH_ALEN
);
1485 adapter
->region_code
= le16_to_cpu(hw_spec
->region_code
);
1487 for (i
= 0; i
< MWIFIEX_MAX_REGION_CODE
; i
++)
1488 /* Use the region code to search for the index */
1489 if (adapter
->region_code
== region_code_index
[i
])
1492 /* If it's unidentified region code, use the default (USA) */
1493 if (i
>= MWIFIEX_MAX_REGION_CODE
) {
1494 adapter
->region_code
= 0x10;
1495 dev_dbg(adapter
->dev
,
1496 "cmd: unknown region code, use default (USA)\n");
1499 adapter
->hw_dot_11n_dev_cap
= le32_to_cpu(hw_spec
->dot_11n_dev_cap
);
1500 adapter
->hw_dev_mcs_support
= hw_spec
->dev_mcs_support
;
1502 if (adapter
->if_ops
.update_mp_end_port
)
1503 adapter
->if_ops
.update_mp_end_port(adapter
,
1504 le16_to_cpu(hw_spec
->mp_end_port
));