2 * Marvell Wireless LAN device driver: commands and events
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
29 * This function initializes a command node.
31 * The actual allocation of the node is not done by this function. It only
32 * initiates a node by filling it with default parameters. Similarly,
33 * allocation of the different buffers used (IOCTL buffer, data buffer) are
34 * not done by this function either.
37 mwifiex_init_cmd_node(struct mwifiex_private *priv,
38 struct cmd_ctrl_node *cmd_node,
39 u32 cmd_oid, void *wait_queue, void *data_buf)
41 cmd_node->priv = priv;
42 cmd_node->cmd_oid = cmd_oid;
43 cmd_node->wq_buf = wait_queue;
44 cmd_node->data_buf = data_buf;
45 cmd_node->cmd_skb = cmd_node->skb;
49 * This function returns a command node from the free queue depending upon
52 static struct cmd_ctrl_node *
53 mwifiex_get_cmd_node(struct mwifiex_adapter *adapter)
55 struct cmd_ctrl_node *cmd_node;
58 spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
59 if (list_empty(&adapter->cmd_free_q)) {
60 dev_err(adapter->dev, "GET_CMD_NODE: cmd node not available\n");
61 spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
64 cmd_node = list_first_entry(&adapter->cmd_free_q,
65 struct cmd_ctrl_node, list);
66 list_del(&cmd_node->list);
67 spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
73 * This function cleans up a command node.
75 * The function resets the fields including the buffer pointers.
76 * This function does not try to free the buffers. They must be
77 * freed before calling this function.
79 * This function will however call the receive completion callback
80 * in case a response buffer is still available before resetting
84 mwifiex_clean_cmd_node(struct mwifiex_adapter *adapter,
85 struct cmd_ctrl_node *cmd_node)
87 cmd_node->cmd_oid = 0;
88 cmd_node->cmd_flag = 0;
89 cmd_node->wq_buf = NULL;
90 cmd_node->data_buf = NULL;
92 if (cmd_node->resp_skb) {
93 mwifiex_recv_complete(adapter, cmd_node->resp_skb, 0);
94 cmd_node->resp_skb = NULL;
101 * This function returns a command node from the pending queue which
102 * matches the given IOCTL request.
104 static struct cmd_ctrl_node *
105 mwifiex_get_pending_ioctl_cmd(struct mwifiex_adapter *adapter,
106 struct mwifiex_wait_queue *wait_queue)
109 struct cmd_ctrl_node *cmd_node;
111 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
112 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
113 if (cmd_node->wq_buf == wait_queue) {
114 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
119 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
125 * This function sends a host command to the firmware.
127 * The function copies the host command into the driver command
128 * buffer, which will be transferred to the firmware later by the
131 static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv,
132 struct host_cmd_ds_command *cmd, void *data_buf)
134 struct mwifiex_ds_misc_cmd *pcmd_ptr =
135 (struct mwifiex_ds_misc_cmd *) data_buf;
137 /* Copy the HOST command to command buffer */
138 memcpy((void *) cmd, pcmd_ptr->cmd, pcmd_ptr->len);
139 dev_dbg(priv->adapter->dev, "cmd: host cmd size = %d\n", pcmd_ptr->len);
144 * This function downloads a command to the firmware.
146 * The function performs sanity tests, sets the command sequence
147 * number and size, converts the header fields to CPU format before
148 * sending. Afterwards, it logs the command ID and action for debugging
149 * and sets up the command timeout timer.
151 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
152 struct cmd_ctrl_node *cmd_node)
155 struct mwifiex_adapter *adapter = priv->adapter;
157 struct host_cmd_ds_command *host_cmd;
158 struct mwifiex_wait_queue *wait_queue = NULL;
161 struct timeval tstamp;
164 if (!adapter || !cmd_node)
167 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
168 if (cmd_node->wq_buf)
169 wait_queue = (struct mwifiex_wait_queue *) cmd_node->wq_buf;
172 if (host_cmd == NULL || host_cmd->size == 0) {
173 dev_err(adapter->dev, "DNLD_CMD: host_cmd is null"
174 " or cmd size is 0, not sending\n");
176 wait_queue->status = MWIFIEX_ERROR_CMD_DNLD_FAIL;
177 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
181 /* Set command sequence number */
183 host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
184 (adapter->seq_num, cmd_node->priv->bss_num,
185 cmd_node->priv->bss_type));
187 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
188 adapter->curr_cmd = cmd_node;
189 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
191 cmd_code = le16_to_cpu(host_cmd->command);
192 cmd_size = le16_to_cpu(host_cmd->size);
194 skb_trim(cmd_node->cmd_skb, cmd_size);
196 do_gettimeofday(&tstamp);
197 dev_dbg(adapter->dev, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
199 tstamp.tv_sec, tstamp.tv_usec, cmd_code,
200 le16_to_cpu(*(__le16 *) ((u8 *) host_cmd + S_DS_GEN)), cmd_size,
201 le16_to_cpu(host_cmd->seq_num));
203 skb_push(cmd_node->cmd_skb, INTF_HEADER_LEN);
205 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
206 cmd_node->cmd_skb->data,
207 cmd_node->cmd_skb->len, NULL);
210 dev_err(adapter->dev, "DNLD_CMD: host to card failed\n");
212 wait_queue->status = MWIFIEX_ERROR_CMD_DNLD_FAIL;
213 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
215 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
216 adapter->curr_cmd = NULL;
217 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
219 adapter->dbg.num_cmd_host_to_card_failure++;
223 /* Save the last command id and action to debug log */
224 adapter->dbg.last_cmd_index =
225 (adapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM;
226 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index] = cmd_code;
227 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] =
228 le16_to_cpu(*(__le16 *) ((u8 *) host_cmd + S_DS_GEN));
230 /* Clear BSS_NO_BITS from HostCmd */
231 cmd_code &= HostCmd_CMD_ID_MASK;
233 /* Setup the timer after transmit command */
234 mod_timer(&adapter->cmd_timer,
235 jiffies + (MWIFIEX_TIMER_10S * HZ) / 1000);
241 * This function downloads a sleep confirm command to the firmware.
243 * The function performs sanity tests, sets the command sequence
244 * number and size, converts the header fields to CPU format before
247 * No responses are needed for sleep confirm command.
249 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
253 struct mwifiex_private *priv;
254 struct mwifiex_opt_sleep_confirm_buffer *sleep_cfm_buf =
255 (struct mwifiex_opt_sleep_confirm_buffer *)
256 adapter->sleep_cfm->data;
257 cmd_len = sizeof(struct mwifiex_opt_sleep_confirm);
258 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
260 sleep_cfm_buf->ps_cfm_sleep.seq_num =
261 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
262 (adapter->seq_num, priv->bss_num,
266 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
267 adapter->sleep_cfm->data,
268 adapter->sleep_cfm->len +
269 INTF_HEADER_LEN, NULL);
272 dev_err(adapter->dev, "SLEEP_CFM: failed\n");
273 adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++;
276 if (GET_BSS_ROLE(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY))
277 == MWIFIEX_BSS_ROLE_STA) {
278 if (!sleep_cfm_buf->ps_cfm_sleep.resp_ctrl)
279 /* Response is not needed for sleep
281 adapter->ps_state = PS_STATE_SLEEP;
283 adapter->ps_state = PS_STATE_SLEEP_CFM;
285 if (!sleep_cfm_buf->ps_cfm_sleep.resp_ctrl
286 && (adapter->is_hs_configured
287 && !adapter->sleep_period.period)) {
288 adapter->pm_wakeup_card_req = true;
289 mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
290 MWIFIEX_BSS_ROLE_STA), true);
298 * This function allocates the command buffers and links them to
299 * the command free queue.
301 * The driver uses a pre allocated number of command buffers, which
302 * are created at driver initializations and freed at driver cleanup.
303 * Every command needs to obtain a command buffer from this pool before
304 * it can be issued. The command free queue lists the command buffers
305 * currently free to use, while the command pending queue lists the
306 * command buffers already in use and awaiting handling. Command buffers
307 * are returned to the free queue after use.
309 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
311 struct cmd_ctrl_node *cmd_array;
315 /* Allocate and initialize struct cmd_ctrl_node */
316 buf_size = sizeof(struct cmd_ctrl_node) * MWIFIEX_NUM_OF_CMD_BUFFER;
317 cmd_array = kzalloc(buf_size, GFP_KERNEL);
319 dev_err(adapter->dev, "%s: failed to alloc cmd_array\n",
324 adapter->cmd_pool = cmd_array;
325 memset(adapter->cmd_pool, 0, buf_size);
327 /* Allocate and initialize command buffers */
328 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
329 cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
330 if (!cmd_array[i].skb) {
331 dev_err(adapter->dev, "ALLOC_CMD_BUF: out of memory\n");
336 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++)
337 mwifiex_insert_cmd_to_free_q(adapter, &cmd_array[i]);
343 * This function frees the command buffers.
345 * The function calls the completion callback for all the command
346 * buffers that still have response buffers associated with them.
348 int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
350 struct cmd_ctrl_node *cmd_array;
353 /* Need to check if cmd pool is allocated or not */
354 if (!adapter->cmd_pool) {
355 dev_dbg(adapter->dev, "info: FREE_CMD_BUF: cmd_pool is null\n");
359 cmd_array = adapter->cmd_pool;
361 /* Release shared memory buffers */
362 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
363 if (cmd_array[i].skb) {
364 dev_dbg(adapter->dev, "cmd: free cmd buffer %d\n", i);
365 dev_kfree_skb_any(cmd_array[i].skb);
367 if (!cmd_array[i].resp_skb)
369 mwifiex_recv_complete(adapter, cmd_array[i].resp_skb, 0);
371 /* Release struct cmd_ctrl_node */
372 if (adapter->cmd_pool) {
373 dev_dbg(adapter->dev, "cmd: free cmd pool\n");
374 kfree(adapter->cmd_pool);
375 adapter->cmd_pool = NULL;
382 * This function handles events generated by firmware.
384 * Event body of events received from firmware are not used (though they are
385 * saved), only the event ID is used. Some events are re-invoked by
386 * the driver, with a new event body.
388 * After processing, the function calls the completion callback
391 int mwifiex_process_event(struct mwifiex_adapter *adapter)
394 struct mwifiex_private *priv =
395 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
396 struct sk_buff *skb = adapter->event_skb;
397 u32 eventcause = adapter->event_cause;
398 struct timeval tstamp;
399 struct mwifiex_rxinfo *rx_info = NULL;
401 /* Save the last event to debug log */
402 adapter->dbg.last_event_index =
403 (adapter->dbg.last_event_index + 1) % DBG_CMD_NUM;
404 adapter->dbg.last_event[adapter->dbg.last_event_index] =
407 /* Get BSS number and corresponding priv */
408 priv = mwifiex_get_priv_by_id(adapter, EVENT_GET_BSS_NUM(eventcause),
409 EVENT_GET_BSS_TYPE(eventcause));
411 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
412 /* Clear BSS_NO_BITS from event */
413 eventcause &= EVENT_ID_MASK;
414 adapter->event_cause = eventcause;
417 rx_info = MWIFIEX_SKB_RXCB(skb);
418 rx_info->bss_index = priv->bss_index;
421 if (eventcause != EVENT_PS_SLEEP && eventcause != EVENT_PS_AWAKE) {
422 do_gettimeofday(&tstamp);
423 dev_dbg(adapter->dev, "event: %lu.%lu: cause: %#x\n",
424 tstamp.tv_sec, tstamp.tv_usec, eventcause);
427 ret = mwifiex_process_sta_event(priv);
429 adapter->event_cause = 0;
430 adapter->event_skb = NULL;
432 mwifiex_recv_complete(adapter, skb, 0);
438 * This function prepares a command before sending it to the firmware.
440 * Preparation includes -
441 * - Sanity tests to make sure the card is still present or the FW
443 * - Getting a new command node from the command free queue
444 * - Initializing the command node for default parameters
445 * - Fill up the non-default parameters and buffer pointers
446 * - Add the command to pending queue
448 int mwifiex_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
449 u16 cmd_action, u32 cmd_oid,
450 void *wait_queue, void *data_buf)
453 struct mwifiex_adapter *adapter = priv->adapter;
454 struct cmd_ctrl_node *cmd_node = NULL;
455 struct host_cmd_ds_command *cmd_ptr = NULL;
458 pr_err("PREP_CMD: adapter is NULL\n");
462 if (adapter->is_suspended) {
463 dev_err(adapter->dev, "PREP_CMD: device in suspended state\n");
467 if (adapter->surprise_removed) {
468 dev_err(adapter->dev, "PREP_CMD: card is removed\n");
472 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) {
473 if (cmd_no != HostCmd_CMD_FUNC_INIT) {
474 dev_err(adapter->dev, "PREP_CMD: FW in reset state\n");
479 /* Get a new command node */
480 cmd_node = mwifiex_get_cmd_node(adapter);
483 dev_err(adapter->dev, "PREP_CMD: no free cmd node\n");
487 /* Initialize the command node */
488 mwifiex_init_cmd_node(priv, cmd_node, cmd_oid, wait_queue, data_buf);
490 if (!cmd_node->cmd_skb) {
491 dev_err(adapter->dev, "PREP_CMD: no free cmd buf\n");
495 memset(skb_put(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command)),
496 0, sizeof(struct host_cmd_ds_command));
498 cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
499 cmd_ptr->command = cpu_to_le16(cmd_no);
502 /* Prepare command */
504 ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action,
505 cmd_oid, data_buf, cmd_ptr);
507 ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf);
508 cmd_node->cmd_flag |= CMD_F_HOSTCMD;
511 /* Return error, since the command preparation failed */
513 dev_err(adapter->dev, "PREP_CMD: cmd %#x preparation failed\n",
515 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
520 if (cmd_no == HostCmd_CMD_802_11_SCAN)
521 mwifiex_queue_scan_cmd(priv, cmd_node);
523 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
529 * This function returns a command to the command free queue.
531 * The function also calls the completion callback if required, before
532 * cleaning the command node and re-inserting it into the free queue.
535 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
536 struct cmd_ctrl_node *cmd_node)
538 struct mwifiex_wait_queue *wait_queue = NULL;
541 if (cmd_node == NULL)
543 if (cmd_node->wq_buf) {
544 wait_queue = (struct mwifiex_wait_queue *) cmd_node->wq_buf;
545 if (wait_queue->status != MWIFIEX_ERROR_NO_ERROR)
546 mwifiex_ioctl_complete(adapter, wait_queue, -1);
548 mwifiex_ioctl_complete(adapter, wait_queue, 0);
551 mwifiex_clean_cmd_node(adapter, cmd_node);
553 /* Insert node into cmd_free_q */
554 spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
555 list_add_tail(&cmd_node->list, &adapter->cmd_free_q);
556 spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
562 * This function queues a command to the command pending queue.
564 * This in effect adds the command to the command list to be executed.
565 * Exit PS command is handled specially, by placing it always to the
566 * front of the command queue.
569 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
570 struct cmd_ctrl_node *cmd_node, u32 add_tail)
572 struct host_cmd_ds_command *host_cmd = NULL;
576 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
578 dev_err(adapter->dev, "QUEUE_CMD: host_cmd is NULL\n");
582 command = le16_to_cpu(host_cmd->command);
584 /* Exit_PS command needs to be queued in the header always. */
585 if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
586 struct host_cmd_ds_802_11_ps_mode_enh *pm =
587 &host_cmd->params.psmode_enh;
588 if ((le16_to_cpu(pm->action) == DIS_PS)
589 || (le16_to_cpu(pm->action) == DIS_AUTO_PS)) {
590 if (adapter->ps_state != PS_STATE_AWAKE)
595 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
597 list_add_tail(&cmd_node->list, &adapter->cmd_pending_q);
599 list_add(&cmd_node->list, &adapter->cmd_pending_q);
600 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
602 dev_dbg(adapter->dev, "cmd: QUEUE_CMD: cmd=%#x is queued\n", command);
608 * This function executes the next command in command pending queue.
610 * This function will fail if a command is already in processing stage,
611 * otherwise it will dequeue the first command from the command pending
612 * queue and send to the firmware.
614 * If the device is currently in host sleep mode, any commands, except the
615 * host sleep configuration command will de-activate the host sleep. For PS
616 * mode, the function will put the firmware back to sleep if applicable.
618 int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
620 struct mwifiex_private *priv = NULL;
621 struct cmd_ctrl_node *cmd_node = NULL;
623 struct host_cmd_ds_command *host_cmd;
624 unsigned long cmd_flags;
625 unsigned long cmd_pending_q_flags;
627 /* Check if already in processing */
628 if (adapter->curr_cmd) {
629 dev_err(adapter->dev, "EXEC_NEXT_CMD: cmd in processing\n");
633 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
634 /* Check if any command is pending */
635 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
636 if (list_empty(&adapter->cmd_pending_q)) {
637 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
638 cmd_pending_q_flags);
639 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
642 cmd_node = list_first_entry(&adapter->cmd_pending_q,
643 struct cmd_ctrl_node, list);
644 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
645 cmd_pending_q_flags);
647 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
648 priv = cmd_node->priv;
650 if (adapter->ps_state != PS_STATE_AWAKE) {
651 dev_err(adapter->dev, "%s: cannot send cmd in sleep state,"
652 " this should not happen\n", __func__);
653 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
657 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
658 list_del(&cmd_node->list);
659 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
660 cmd_pending_q_flags);
662 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
663 ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node);
664 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
665 /* Any command sent to the firmware when host is in sleep
666 * mode should de-configure host sleep. We should skip the
667 * host sleep configuration command itself though
669 if (priv && (host_cmd->command !=
670 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
671 if (adapter->hs_activated) {
672 adapter->is_hs_configured = false;
673 mwifiex_hs_activated_event(priv, false);
681 * This function handles the command response.
683 * After processing, the function cleans the command node and puts
684 * it back to the command free queue.
686 int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
688 struct host_cmd_ds_command *resp = NULL;
689 struct mwifiex_private *priv =
690 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
692 uint16_t orig_cmdresp_no;
694 uint16_t cmdresp_result;
695 struct mwifiex_wait_queue *wait_queue = NULL;
696 struct timeval tstamp;
699 /* Now we got response from FW, cancel the command timer */
700 del_timer(&adapter->cmd_timer);
702 if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
703 resp = (struct host_cmd_ds_command *) adapter->upld_buf;
704 dev_err(adapter->dev, "CMD_RESP: NULL curr_cmd, %#x\n",
705 le16_to_cpu(resp->command));
709 if (adapter->curr_cmd->wq_buf)
710 wait_queue = (struct mwifiex_wait_queue *)
711 adapter->curr_cmd->wq_buf;
713 adapter->num_cmd_timeout = 0;
715 resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data;
716 if (adapter->curr_cmd->cmd_flag & CMD_F_CANCELED) {
717 dev_err(adapter->dev, "CMD_RESP: %#x been canceled\n",
718 le16_to_cpu(resp->command));
719 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
720 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
721 adapter->curr_cmd = NULL;
722 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
726 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
727 /* Copy original response back to response buffer */
728 struct mwifiex_ds_misc_cmd *hostcmd = NULL;
729 uint16_t size = le16_to_cpu(resp->size);
730 dev_dbg(adapter->dev, "info: host cmd resp size = %d\n", size);
731 size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
732 if (adapter->curr_cmd->data_buf) {
733 hostcmd = (struct mwifiex_ds_misc_cmd *)
734 adapter->curr_cmd->data_buf;
736 memcpy(hostcmd->cmd, (void *) resp, size);
739 orig_cmdresp_no = le16_to_cpu(resp->command);
741 /* Get BSS number and corresponding priv */
742 priv = mwifiex_get_priv_by_id(adapter,
743 HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)),
744 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num)));
746 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
747 /* Clear RET_BIT from HostCmd */
748 resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK);
750 cmdresp_no = le16_to_cpu(resp->command);
751 cmdresp_result = le16_to_cpu(resp->result);
753 /* Save the last command response to debug log */
754 adapter->dbg.last_cmd_resp_index =
755 (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM;
756 adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
759 do_gettimeofday(&tstamp);
760 dev_dbg(adapter->dev, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
761 " len %d, seqno 0x%x\n",
762 tstamp.tv_sec, tstamp.tv_usec, orig_cmdresp_no, cmdresp_result,
763 le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
765 if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
766 dev_err(adapter->dev, "CMD_RESP: invalid cmd resp\n");
768 wait_queue->status = MWIFIEX_ERROR_FW_CMDRESP;
770 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
771 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
772 adapter->curr_cmd = NULL;
773 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
777 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
778 adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD;
779 if ((cmdresp_result == HostCmd_RESULT_OK)
780 && (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH))
781 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
783 /* handle response */
784 ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp,
788 /* Check init command response */
789 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
791 dev_err(adapter->dev, "%s: cmd %#x failed during "
792 "initialization\n", __func__, cmdresp_no);
793 mwifiex_init_fw_complete(adapter);
795 } else if (adapter->last_init_cmd == cmdresp_no)
796 adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE;
799 if (adapter->curr_cmd) {
800 if (wait_queue && (!ret))
801 wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
802 else if (wait_queue && (ret == -1))
803 wait_queue->status = MWIFIEX_ERROR_CMD_RESP_FAIL;
805 /* Clean up and put current command back to cmd_free_q */
806 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
808 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
809 adapter->curr_cmd = NULL;
810 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
817 * This function handles the timeout of command sending.
819 * It will re-send the same command again.
822 mwifiex_cmd_timeout_func(unsigned long function_context)
824 struct mwifiex_adapter *adapter =
825 (struct mwifiex_adapter *) function_context;
826 struct cmd_ctrl_node *cmd_node = NULL;
827 struct mwifiex_wait_queue *wait_queue = NULL;
828 struct timeval tstamp;
830 adapter->num_cmd_timeout++;
831 adapter->dbg.num_cmd_timeout++;
832 if (!adapter->curr_cmd) {
833 dev_dbg(adapter->dev, "cmd: empty curr_cmd\n");
836 cmd_node = adapter->curr_cmd;
837 if (cmd_node->wq_buf) {
838 wait_queue = (struct mwifiex_wait_queue *) cmd_node->wq_buf;
839 wait_queue->status = MWIFIEX_ERROR_CMD_TIMEOUT;
843 adapter->dbg.timeout_cmd_id =
844 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
845 adapter->dbg.timeout_cmd_act =
846 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
847 do_gettimeofday(&tstamp);
848 dev_err(adapter->dev, "%s: Timeout cmd id (%lu.%lu) = %#x,"
849 " act = %#x\n", __func__,
850 tstamp.tv_sec, tstamp.tv_usec,
851 adapter->dbg.timeout_cmd_id,
852 adapter->dbg.timeout_cmd_act);
854 dev_err(adapter->dev, "num_data_h2c_failure = %d\n",
855 adapter->dbg.num_tx_host_to_card_failure);
856 dev_err(adapter->dev, "num_cmd_h2c_failure = %d\n",
857 adapter->dbg.num_cmd_host_to_card_failure);
859 dev_err(adapter->dev, "num_cmd_timeout = %d\n",
860 adapter->dbg.num_cmd_timeout);
861 dev_err(adapter->dev, "num_tx_timeout = %d\n",
862 adapter->dbg.num_tx_timeout);
864 dev_err(adapter->dev, "last_cmd_index = %d\n",
865 adapter->dbg.last_cmd_index);
866 print_hex_dump_bytes("last_cmd_id: ", DUMP_PREFIX_OFFSET,
867 adapter->dbg.last_cmd_id, DBG_CMD_NUM);
868 print_hex_dump_bytes("last_cmd_act: ", DUMP_PREFIX_OFFSET,
869 adapter->dbg.last_cmd_act, DBG_CMD_NUM);
871 dev_err(adapter->dev, "last_cmd_resp_index = %d\n",
872 adapter->dbg.last_cmd_resp_index);
873 print_hex_dump_bytes("last_cmd_resp_id: ", DUMP_PREFIX_OFFSET,
874 adapter->dbg.last_cmd_resp_id, DBG_CMD_NUM);
876 dev_err(adapter->dev, "last_event_index = %d\n",
877 adapter->dbg.last_event_index);
878 print_hex_dump_bytes("last_event: ", DUMP_PREFIX_OFFSET,
879 adapter->dbg.last_event, DBG_CMD_NUM);
881 dev_err(adapter->dev, "data_sent=%d cmd_sent=%d\n",
882 adapter->data_sent, adapter->cmd_sent);
884 dev_err(adapter->dev, "ps_mode=%d ps_state=%d\n",
885 adapter->ps_mode, adapter->ps_state);
887 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
888 mwifiex_init_fw_complete(adapter);
894 * This function cancels all the pending commands.
896 * The current command, all commands in command pending queue and all scan
897 * commands in scan pending queue are cancelled. All the completion callbacks
898 * are called with failure status to ensure cleanup.
901 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
903 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node = NULL;
904 struct mwifiex_wait_queue *wait_queue = NULL;
907 /* Cancel current cmd */
908 if ((adapter->curr_cmd) && (adapter->curr_cmd->wq_buf)) {
910 (struct mwifiex_wait_queue *) adapter->curr_cmd->wq_buf;
911 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
912 adapter->curr_cmd->wq_buf = NULL;
913 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
914 wait_queue->status = MWIFIEX_ERROR_CMD_CANCEL;
915 mwifiex_ioctl_complete(adapter, wait_queue, -1);
917 /* Cancel all pending command */
918 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
919 list_for_each_entry_safe(cmd_node, tmp_node,
920 &adapter->cmd_pending_q, list) {
921 list_del(&cmd_node->list);
922 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
924 if (cmd_node->wq_buf) {
926 (struct mwifiex_wait_queue *) cmd_node->wq_buf;
927 wait_queue->status = MWIFIEX_ERROR_CMD_CANCEL;
928 mwifiex_ioctl_complete(adapter, wait_queue, -1);
929 cmd_node->wq_buf = NULL;
931 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
932 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
934 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
936 /* Cancel all pending scan command */
937 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
938 list_for_each_entry_safe(cmd_node, tmp_node,
939 &adapter->scan_pending_q, list) {
940 list_del(&cmd_node->list);
941 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
943 cmd_node->wq_buf = NULL;
944 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
945 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
947 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
949 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
950 adapter->scan_processing = false;
951 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
955 * This function cancels all pending commands that matches with
956 * the given IOCTL request.
958 * Both the current command buffer and the pending command queue are
959 * searched for matching IOCTL request. The completion callback of
960 * the matched command is called with failure status to ensure cleanup.
961 * In case of scan commands, all pending commands in scan pending queue
965 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter,
966 struct mwifiex_wait_queue *wait_queue)
968 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node = NULL;
969 unsigned long cmd_flags;
970 unsigned long cmd_pending_q_flags;
971 unsigned long scan_pending_q_flags;
972 uint16_t cancel_scan_cmd = false;
974 if ((adapter->curr_cmd) &&
975 (adapter->curr_cmd->wq_buf == wait_queue)) {
976 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
977 cmd_node = adapter->curr_cmd;
978 cmd_node->wq_buf = NULL;
979 cmd_node->cmd_flag |= CMD_F_CANCELED;
980 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
983 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
985 cmd_node = mwifiex_get_pending_ioctl_cmd(adapter, wait_queue);
989 spin_lock_irqsave(&adapter->cmd_pending_q_lock,
990 cmd_pending_q_flags);
991 list_del(&cmd_node->list);
992 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
993 cmd_pending_q_flags);
995 cmd_node->wq_buf = NULL;
996 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
998 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
999 /* Cancel all pending scan command */
1000 spin_lock_irqsave(&adapter->scan_pending_q_lock,
1001 scan_pending_q_flags);
1002 list_for_each_entry_safe(cmd_node, tmp_node,
1003 &adapter->scan_pending_q, list) {
1004 if (cmd_node->wq_buf == wait_queue) {
1005 list_del(&cmd_node->list);
1006 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1007 scan_pending_q_flags);
1008 cmd_node->wq_buf = NULL;
1009 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1010 spin_lock_irqsave(&adapter->scan_pending_q_lock,
1011 scan_pending_q_flags);
1012 cancel_scan_cmd = true;
1015 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1016 scan_pending_q_flags);
1018 if (cancel_scan_cmd) {
1019 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
1020 adapter->scan_processing = false;
1021 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
1023 wait_queue->status = MWIFIEX_ERROR_CMD_CANCEL;
1024 mwifiex_ioctl_complete(adapter, wait_queue, -1);
1030 * This function sends the sleep confirm command to firmware, if
1033 * The sleep confirm command cannot be issued if command response,
1034 * data response or event response is awaiting handling, or if we
1035 * are in the middle of sending a command, or expecting a command
1039 mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
1041 if (!adapter->cmd_sent &&
1042 !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
1043 mwifiex_dnld_sleep_confirm_cmd(adapter);
1045 dev_dbg(adapter->dev,
1046 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1047 (adapter->cmd_sent) ? "D" : "",
1048 (adapter->curr_cmd) ? "C" : "",
1049 (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
1053 * This function sends a Host Sleep activated event to applications.
1055 * This event is generated by the driver, with a blank event body.
1058 mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
1061 if (priv->adapter->is_hs_configured) {
1062 priv->adapter->hs_activated = true;
1063 dev_dbg(priv->adapter->dev, "event: hs_activated\n");
1064 priv->adapter->hs_activate_wait_q_woken = true;
1065 wake_up_interruptible(
1066 &priv->adapter->hs_activate_wait_q);
1068 dev_dbg(priv->adapter->dev, "event: HS not configured\n");
1071 dev_dbg(priv->adapter->dev, "event: hs_deactivated\n");
1072 priv->adapter->hs_activated = false;
1077 * This function handles the command response of a Host Sleep configuration
1080 * Handling includes changing the header fields into CPU format
1081 * and setting the current host sleep activation status in driver.
1083 * In case host sleep status change, the function generates an event to
1084 * notify the applications.
1086 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
1087 struct host_cmd_ds_command *resp)
1089 struct mwifiex_adapter *adapter = priv->adapter;
1090 struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg =
1091 &resp->params.opt_hs_cfg;
1092 uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions);
1094 if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE)) {
1095 mwifiex_hs_activated_event(priv, true);
1098 dev_dbg(adapter->dev, "cmd: CMD_RESP: HS_CFG cmd reply"
1099 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1100 resp->result, conditions,
1101 phs_cfg->params.hs_config.gpio,
1102 phs_cfg->params.hs_config.gap);
1104 if (conditions != HOST_SLEEP_CFG_CANCEL) {
1105 adapter->is_hs_configured = true;
1107 adapter->is_hs_configured = false;
1108 if (adapter->hs_activated)
1109 mwifiex_hs_activated_event(priv, false);
1116 * This function wakes up the adapter and generates a Host Sleep
1117 * cancel event on receiving the power up interrupt.
1120 mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
1122 dev_dbg(adapter->dev, "info: %s: auto cancelling host sleep"
1123 " since there is interrupt from the firmware\n", __func__);
1125 adapter->if_ops.wakeup(adapter);
1126 adapter->hs_activated = false;
1127 adapter->is_hs_configured = false;
1128 mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
1129 MWIFIEX_BSS_ROLE_ANY), false);
1134 * This function handles the command response of a sleep confirm command.
1136 * The function sets the card state to SLEEP if the response indicates success.
1139 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
1140 u8 *pbuf, u32 upld_len)
1142 struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf;
1143 struct mwifiex_private *priv =
1144 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1145 uint16_t result = le16_to_cpu(cmd->result);
1146 uint16_t command = le16_to_cpu(cmd->command);
1147 uint16_t seq_num = le16_to_cpu(cmd->seq_num);
1150 dev_err(adapter->dev, "%s: cmd size is 0\n", __func__);
1154 /* Get BSS number and corresponding priv */
1155 priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
1156 HostCmd_GET_BSS_TYPE(seq_num));
1158 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1160 /* Update sequence number */
1161 seq_num = HostCmd_GET_SEQ_NO(seq_num);
1162 /* Clear RET_BIT from HostCmd */
1163 command &= HostCmd_CMD_ID_MASK;
1165 if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
1166 dev_err(adapter->dev, "%s: received unexpected response for"
1167 " cmd %x, result = %x\n", __func__, command, result);
1172 dev_err(adapter->dev, "%s: sleep confirm cmd failed\n",
1174 adapter->pm_wakeup_card_req = false;
1175 adapter->ps_state = PS_STATE_AWAKE;
1178 adapter->pm_wakeup_card_req = true;
1179 if (adapter->is_hs_configured)
1180 mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
1181 MWIFIEX_BSS_ROLE_ANY), true);
1182 adapter->ps_state = PS_STATE_SLEEP;
1183 cmd->command = cpu_to_le16(command);
1184 cmd->seq_num = cpu_to_le16(seq_num);
1186 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp);
1189 * This function prepares an enhanced power mode command.
1191 * This function can be used to disable power save or to configure
1192 * power save with auto PS or STA PS or auto deep sleep.
1194 * Preparation includes -
1195 * - Setting command ID, action and proper size
1196 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1197 * auto deep sleep TLV (as required)
1198 * - Ensuring correct endian-ness
1200 int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
1201 struct host_cmd_ds_command *cmd,
1202 u16 cmd_action, uint16_t ps_bitmap,
1205 struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh =
1206 &cmd->params.psmode_enh;
1210 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
1211 if (cmd_action == DIS_AUTO_PS) {
1212 psmode_enh->action = cpu_to_le16(DIS_AUTO_PS);
1213 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1214 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1215 sizeof(psmode_enh->params.ps_bitmap));
1216 } else if (cmd_action == GET_PS) {
1217 psmode_enh->action = cpu_to_le16(GET_PS);
1218 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1219 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1220 sizeof(psmode_enh->params.ps_bitmap));
1221 } else if (cmd_action == EN_AUTO_PS) {
1222 psmode_enh->action = cpu_to_le16(EN_AUTO_PS);
1223 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1224 cmd_size = S_DS_GEN + sizeof(psmode_enh->action) +
1225 sizeof(psmode_enh->params.ps_bitmap);
1226 tlv = (u8 *) cmd + cmd_size;
1227 if (ps_bitmap & BITMAP_STA_PS) {
1228 struct mwifiex_adapter *adapter = priv->adapter;
1229 struct mwifiex_ie_types_ps_param *ps_tlv =
1230 (struct mwifiex_ie_types_ps_param *) tlv;
1231 struct mwifiex_ps_param *ps_mode = &ps_tlv->param;
1232 ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM);
1233 ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) -
1234 sizeof(struct mwifiex_ie_types_header));
1235 cmd_size += sizeof(*ps_tlv);
1236 tlv += sizeof(*ps_tlv);
1237 dev_dbg(adapter->dev, "cmd: PS Command: Enter PS\n");
1238 ps_mode->null_pkt_interval =
1239 cpu_to_le16(adapter->null_pkt_interval);
1240 ps_mode->multiple_dtims =
1241 cpu_to_le16(adapter->multiple_dtim);
1242 ps_mode->bcn_miss_timeout =
1243 cpu_to_le16(adapter->bcn_miss_time_out);
1244 ps_mode->local_listen_interval =
1245 cpu_to_le16(adapter->local_listen_interval);
1246 ps_mode->adhoc_wake_period =
1247 cpu_to_le16(adapter->adhoc_awake_period);
1248 ps_mode->delay_to_ps =
1249 cpu_to_le16(adapter->delay_to_ps);
1251 cpu_to_le16(adapter->enhanced_ps_mode);
1254 if (ps_bitmap & BITMAP_AUTO_DS) {
1255 struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv =
1256 (struct mwifiex_ie_types_auto_ds_param *) tlv;
1259 auto_ds_tlv->header.type =
1260 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM);
1261 auto_ds_tlv->header.len =
1262 cpu_to_le16(sizeof(*auto_ds_tlv) -
1263 sizeof(struct mwifiex_ie_types_header));
1264 cmd_size += sizeof(*auto_ds_tlv);
1265 tlv += sizeof(*auto_ds_tlv);
1267 idletime = ((struct mwifiex_ds_auto_ds *)
1268 data_buf)->idle_time;
1269 dev_dbg(priv->adapter->dev,
1270 "cmd: PS Command: Enter Auto Deep Sleep\n");
1271 auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
1273 cmd->size = cpu_to_le16(cmd_size);
1279 * This function handles the command response of an enhanced power mode
1282 * Handling includes changing the header fields into CPU format
1283 * and setting the current enhanced power mode in driver.
1285 int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
1286 struct host_cmd_ds_command *resp,
1289 struct mwifiex_adapter *adapter = priv->adapter;
1290 struct host_cmd_ds_802_11_ps_mode_enh *ps_mode =
1291 &resp->params.psmode_enh;
1292 uint16_t action = le16_to_cpu(ps_mode->action);
1293 uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap);
1294 uint16_t auto_ps_bitmap =
1295 le16_to_cpu(ps_mode->params.ps_bitmap);
1297 dev_dbg(adapter->dev, "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1298 __func__, resp->result, action);
1299 if (action == EN_AUTO_PS) {
1300 if (auto_ps_bitmap & BITMAP_AUTO_DS) {
1301 dev_dbg(adapter->dev, "cmd: Enabled auto deep sleep\n");
1302 priv->adapter->is_deep_sleep = true;
1304 if (auto_ps_bitmap & BITMAP_STA_PS) {
1305 dev_dbg(adapter->dev, "cmd: Enabled STA power save\n");
1306 if (adapter->sleep_period.period)
1307 dev_dbg(adapter->dev, "cmd: set to uapsd/pps mode\n");
1309 } else if (action == DIS_AUTO_PS) {
1310 if (ps_bitmap & BITMAP_AUTO_DS) {
1311 priv->adapter->is_deep_sleep = false;
1312 dev_dbg(adapter->dev, "cmd: Disabled auto deep sleep\n");
1314 if (ps_bitmap & BITMAP_STA_PS) {
1315 dev_dbg(adapter->dev, "cmd: Disabled STA power save\n");
1316 if (adapter->sleep_period.period) {
1317 adapter->delay_null_pkt = false;
1318 adapter->tx_lock_flag = false;
1319 adapter->pps_uapsd_mode = false;
1322 } else if (action == GET_PS) {
1323 if (ps_bitmap & BITMAP_STA_PS)
1324 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1326 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
1328 dev_dbg(adapter->dev, "cmd: ps_bitmap=%#x\n", ps_bitmap);
1331 /* This section is for get power save mode */
1332 struct mwifiex_ds_pm_cfg *pm_cfg =
1333 (struct mwifiex_ds_pm_cfg *)data_buf;
1334 if (ps_bitmap & BITMAP_STA_PS)
1335 pm_cfg->param.ps_mode = 1;
1337 pm_cfg->param.ps_mode = 0;
1344 * This function prepares command to get hardware specifications.
1346 * Preparation includes -
1347 * - Setting command ID, action and proper size
1348 * - Setting permanent address parameter
1349 * - Ensuring correct endian-ness
1351 int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
1352 struct host_cmd_ds_command *cmd)
1354 struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec;
1356 cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC);
1358 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN);
1359 memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN);
1365 * This function handles the command response of get hardware
1368 * Handling includes changing the header fields into CPU format
1369 * and saving/updating the following parameters in driver -
1370 * - Firmware capability information
1371 * - Firmware band settings
1372 * - Ad-hoc start band and channel
1373 * - Ad-hoc 11n activation status
1374 * - Firmware release number
1375 * - Number of antennas
1376 * - Hardware address
1377 * - Hardware interface version
1378 * - Firmware version
1380 * - 11n capabilities
1381 * - MCS support fields
1384 int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1385 struct host_cmd_ds_command *resp)
1387 struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec;
1388 struct mwifiex_adapter *adapter = priv->adapter;
1391 adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info);
1393 if (IS_SUPPORT_MULTI_BANDS(adapter))
1394 adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter);
1396 adapter->fw_bands = BAND_B;
1398 adapter->config_bands = adapter->fw_bands;
1400 if (adapter->fw_bands & BAND_A) {
1401 if (adapter->fw_bands & BAND_GN) {
1402 adapter->config_bands |= BAND_AN;
1403 adapter->fw_bands |= BAND_AN;
1405 if (adapter->fw_bands & BAND_AN) {
1406 adapter->adhoc_start_band = BAND_A | BAND_AN;
1407 adapter->adhoc_11n_enabled = true;
1409 adapter->adhoc_start_band = BAND_A;
1411 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A;
1412 } else if (adapter->fw_bands & BAND_GN) {
1413 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
1414 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1415 adapter->adhoc_11n_enabled = true;
1416 } else if (adapter->fw_bands & BAND_G) {
1417 adapter->adhoc_start_band = BAND_G | BAND_B;
1418 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1419 } else if (adapter->fw_bands & BAND_B) {
1420 adapter->adhoc_start_band = BAND_B;
1421 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1424 adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
1425 adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna);
1427 dev_dbg(adapter->dev, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1428 adapter->fw_release_number);
1429 dev_dbg(adapter->dev, "info: GET_HW_SPEC: permanent addr: %pM\n",
1430 hw_spec->permanent_addr);
1431 dev_dbg(adapter->dev, "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1432 le16_to_cpu(hw_spec->hw_if_version),
1433 le16_to_cpu(hw_spec->version));
1435 if (priv->curr_addr[0] == 0xff)
1436 memmove(priv->curr_addr, hw_spec->permanent_addr, ETH_ALEN);
1438 adapter->region_code = le16_to_cpu(hw_spec->region_code);
1440 for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++)
1441 /* Use the region code to search for the index */
1442 if (adapter->region_code == region_code_index[i])
1445 /* If it's unidentified region code, use the default (USA) */
1446 if (i >= MWIFIEX_MAX_REGION_CODE) {
1447 adapter->region_code = 0x10;
1448 dev_dbg(adapter->dev, "cmd: unknown region code, use default (USA)\n");
1451 adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);
1452 adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support;
1454 if (adapter->if_ops.update_mp_end_port)
1455 adapter->if_ops.update_mp_end_port(adapter,
1456 le16_to_cpu(hw_spec->mp_end_port));