mwifiex: minor changes in debug messages
[deliverable/linux.git] / drivers / net / wireless / mwifiex / cmdevt.c
... / ...
CommitLineData
1/*
2 * Marvell Wireless LAN device driver: commands and events
3 *
4 * Copyright (C) 2011-2014, Marvell International Ltd.
5 *
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.
13 *
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.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27#include "11ac.h"
28
29/*
30 * This function initializes a command node.
31 *
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.
36 */
37static void
38mwifiex_init_cmd_node(struct mwifiex_private *priv,
39 struct cmd_ctrl_node *cmd_node,
40 u32 cmd_oid, void *data_buf, bool sync)
41{
42 cmd_node->priv = priv;
43 cmd_node->cmd_oid = cmd_oid;
44 if (sync) {
45 cmd_node->wait_q_enabled = true;
46 cmd_node->cmd_wait_q_woken = false;
47 cmd_node->condition = &cmd_node->cmd_wait_q_woken;
48 }
49 cmd_node->data_buf = data_buf;
50 cmd_node->cmd_skb = cmd_node->skb;
51}
52
53/*
54 * This function returns a command node from the free queue depending upon
55 * availability.
56 */
57static struct cmd_ctrl_node *
58mwifiex_get_cmd_node(struct mwifiex_adapter *adapter)
59{
60 struct cmd_ctrl_node *cmd_node;
61 unsigned long flags;
62
63 spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
64 if (list_empty(&adapter->cmd_free_q)) {
65 mwifiex_dbg(adapter, ERROR,
66 "GET_CMD_NODE: cmd node not available\n");
67 spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
68 return NULL;
69 }
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);
74
75 return cmd_node;
76}
77
78/*
79 * This function cleans up a command node.
80 *
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.
84 *
85 * This function will however call the receive completion callback
86 * in case a response buffer is still available before resetting
87 * the pointer.
88 */
89static void
90mwifiex_clean_cmd_node(struct mwifiex_adapter *adapter,
91 struct cmd_ctrl_node *cmd_node)
92{
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;
97
98 if (cmd_node->cmd_skb)
99 skb_trim(cmd_node->cmd_skb, 0);
100
101 if (cmd_node->resp_skb) {
102 adapter->if_ops.cmdrsp_complete(adapter, cmd_node->resp_skb);
103 cmd_node->resp_skb = NULL;
104 }
105}
106
107/*
108 * This function sends a host command to the firmware.
109 *
110 * The function copies the host command into the driver command
111 * buffer, which will be transferred to the firmware later by the
112 * main thread.
113 */
114static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv,
115 struct host_cmd_ds_command *cmd,
116 struct mwifiex_ds_misc_cmd *pcmd_ptr)
117{
118 /* Copy the HOST command to command buffer */
119 memcpy(cmd, pcmd_ptr->cmd, pcmd_ptr->len);
120 mwifiex_dbg(priv->adapter, CMD,
121 "cmd: host cmd size = %d\n", pcmd_ptr->len);
122 return 0;
123}
124
125/*
126 * This function downloads a command to the firmware.
127 *
128 * The function performs sanity tests, sets the command sequence
129 * number and size, converts the header fields to CPU format before
130 * sending. Afterwards, it logs the command ID and action for debugging
131 * and sets up the command timeout timer.
132 */
133static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
134 struct cmd_ctrl_node *cmd_node)
135{
136
137 struct mwifiex_adapter *adapter = priv->adapter;
138 int ret;
139 struct host_cmd_ds_command *host_cmd;
140 uint16_t cmd_code;
141 uint16_t cmd_size;
142 unsigned long flags;
143 __le32 tmp;
144
145 if (!adapter || !cmd_node)
146 return -1;
147
148 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
149
150 /* Sanity test */
151 if (host_cmd == NULL || host_cmd->size == 0) {
152 mwifiex_dbg(adapter, ERROR,
153 "DNLD_CMD: host_cmd is null\t"
154 "or cmd size is 0, not sending\n");
155 if (cmd_node->wait_q_enabled)
156 adapter->cmd_wait_q.status = -1;
157 mwifiex_recycle_cmd_node(adapter, cmd_node);
158 return -1;
159 }
160
161 cmd_code = le16_to_cpu(host_cmd->command);
162 cmd_size = le16_to_cpu(host_cmd->size);
163
164 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET &&
165 cmd_code != HostCmd_CMD_FUNC_SHUTDOWN &&
166 cmd_code != HostCmd_CMD_FUNC_INIT) {
167 mwifiex_dbg(adapter, ERROR,
168 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
169 cmd_code);
170 if (cmd_node->wait_q_enabled)
171 mwifiex_complete_cmd(adapter, cmd_node);
172 mwifiex_recycle_cmd_node(adapter, cmd_node);
173 queue_work(adapter->workqueue, &adapter->main_work);
174 return -1;
175 }
176
177 /* Set command sequence number */
178 adapter->seq_num++;
179 host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
180 (adapter->seq_num,
181 cmd_node->priv->bss_num,
182 cmd_node->priv->bss_type));
183
184 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
185 adapter->curr_cmd = cmd_node;
186 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
187
188 /* Adjust skb length */
189 if (cmd_node->cmd_skb->len > cmd_size)
190 /*
191 * cmd_size is less than sizeof(struct host_cmd_ds_command).
192 * Trim off the unused portion.
193 */
194 skb_trim(cmd_node->cmd_skb, cmd_size);
195 else if (cmd_node->cmd_skb->len < cmd_size)
196 /*
197 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
198 * because we have appended custom IE TLV. Increase skb length
199 * accordingly.
200 */
201 skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len);
202
203 mwifiex_dbg(adapter, CMD,
204 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
205 cmd_code,
206 le16_to_cpu(*(__le16 *)((u8 *)host_cmd + S_DS_GEN)),
207 cmd_size, le16_to_cpu(host_cmd->seq_num));
208 mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
209
210 if (adapter->iface_type == MWIFIEX_USB) {
211 tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
212 skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
213 memcpy(cmd_node->cmd_skb->data, &tmp, MWIFIEX_TYPE_LEN);
214 adapter->cmd_sent = true;
215 ret = adapter->if_ops.host_to_card(adapter,
216 MWIFIEX_USB_EP_CMD_EVENT,
217 cmd_node->cmd_skb, NULL);
218 skb_pull(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
219 if (ret == -EBUSY)
220 cmd_node->cmd_skb = NULL;
221 } else {
222 skb_push(cmd_node->cmd_skb, INTF_HEADER_LEN);
223 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
224 cmd_node->cmd_skb, NULL);
225 skb_pull(cmd_node->cmd_skb, INTF_HEADER_LEN);
226 }
227
228 if (ret == -1) {
229 mwifiex_dbg(adapter, ERROR,
230 "DNLD_CMD: host to card failed\n");
231 if (adapter->iface_type == MWIFIEX_USB)
232 adapter->cmd_sent = false;
233 if (cmd_node->wait_q_enabled)
234 adapter->cmd_wait_q.status = -1;
235 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
236
237 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
238 adapter->curr_cmd = NULL;
239 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
240
241 adapter->dbg.num_cmd_host_to_card_failure++;
242 return -1;
243 }
244
245 /* Save the last command id and action to debug log */
246 adapter->dbg.last_cmd_index =
247 (adapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM;
248 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index] = cmd_code;
249 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] =
250 le16_to_cpu(*(__le16 *) ((u8 *) host_cmd + S_DS_GEN));
251
252 /* Clear BSS_NO_BITS from HostCmd */
253 cmd_code &= HostCmd_CMD_ID_MASK;
254
255 /* Setup the timer after transmit command */
256 mod_timer(&adapter->cmd_timer,
257 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
258
259 return 0;
260}
261
262/*
263 * This function downloads a sleep confirm command to the firmware.
264 *
265 * The function performs sanity tests, sets the command sequence
266 * number and size, converts the header fields to CPU format before
267 * sending.
268 *
269 * No responses are needed for sleep confirm command.
270 */
271static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
272{
273 int ret;
274 struct mwifiex_private *priv;
275 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf =
276 (struct mwifiex_opt_sleep_confirm *)
277 adapter->sleep_cfm->data;
278 struct sk_buff *sleep_cfm_tmp;
279 __le32 tmp;
280
281 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
282
283 adapter->seq_num++;
284 sleep_cfm_buf->seq_num =
285 cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO
286 (adapter->seq_num, priv->bss_num,
287 priv->bss_type)));
288
289 mwifiex_dbg(adapter, CMD,
290 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
291 le16_to_cpu(sleep_cfm_buf->command),
292 le16_to_cpu(sleep_cfm_buf->action),
293 le16_to_cpu(sleep_cfm_buf->size),
294 le16_to_cpu(sleep_cfm_buf->seq_num));
295 mwifiex_dbg_dump(adapter, CMD_D, "SLEEP_CFM buffer: ", sleep_cfm_buf,
296 le16_to_cpu(sleep_cfm_buf->size));
297
298 if (adapter->iface_type == MWIFIEX_USB) {
299 sleep_cfm_tmp =
300 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
301 + MWIFIEX_TYPE_LEN);
302 skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
303 + MWIFIEX_TYPE_LEN);
304 tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
305 memcpy(sleep_cfm_tmp->data, &tmp, MWIFIEX_TYPE_LEN);
306 memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN,
307 adapter->sleep_cfm->data,
308 sizeof(struct mwifiex_opt_sleep_confirm));
309 ret = adapter->if_ops.host_to_card(adapter,
310 MWIFIEX_USB_EP_CMD_EVENT,
311 sleep_cfm_tmp, NULL);
312 if (ret != -EBUSY)
313 dev_kfree_skb_any(sleep_cfm_tmp);
314 } else {
315 skb_push(adapter->sleep_cfm, INTF_HEADER_LEN);
316 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
317 adapter->sleep_cfm, NULL);
318 skb_pull(adapter->sleep_cfm, INTF_HEADER_LEN);
319 }
320
321 if (ret == -1) {
322 mwifiex_dbg(adapter, ERROR, "SLEEP_CFM: failed\n");
323 adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++;
324 return -1;
325 }
326
327 if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl))
328 /* Response is not needed for sleep confirm command */
329 adapter->ps_state = PS_STATE_SLEEP;
330 else
331 adapter->ps_state = PS_STATE_SLEEP_CFM;
332
333 if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl) &&
334 (adapter->is_hs_configured &&
335 !adapter->sleep_period.period)) {
336 adapter->pm_wakeup_card_req = true;
337 mwifiex_hs_activated_event(mwifiex_get_priv
338 (adapter, MWIFIEX_BSS_ROLE_ANY), true);
339 }
340
341 return ret;
342}
343
344/*
345 * This function allocates the command buffers and links them to
346 * the command free queue.
347 *
348 * The driver uses a pre allocated number of command buffers, which
349 * are created at driver initializations and freed at driver cleanup.
350 * Every command needs to obtain a command buffer from this pool before
351 * it can be issued. The command free queue lists the command buffers
352 * currently free to use, while the command pending queue lists the
353 * command buffers already in use and awaiting handling. Command buffers
354 * are returned to the free queue after use.
355 */
356int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
357{
358 struct cmd_ctrl_node *cmd_array;
359 u32 i;
360
361 /* Allocate and initialize struct cmd_ctrl_node */
362 cmd_array = kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER,
363 sizeof(struct cmd_ctrl_node), GFP_KERNEL);
364 if (!cmd_array)
365 return -ENOMEM;
366
367 adapter->cmd_pool = cmd_array;
368
369 /* Allocate and initialize command buffers */
370 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
371 cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
372 if (!cmd_array[i].skb) {
373 mwifiex_dbg(adapter, ERROR,
374 "unable to allocate command buffer\n");
375 return -ENOMEM;
376 }
377 }
378
379 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++)
380 mwifiex_insert_cmd_to_free_q(adapter, &cmd_array[i]);
381
382 return 0;
383}
384
385/*
386 * This function frees the command buffers.
387 *
388 * The function calls the completion callback for all the command
389 * buffers that still have response buffers associated with them.
390 */
391int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
392{
393 struct cmd_ctrl_node *cmd_array;
394 u32 i;
395
396 /* Need to check if cmd pool is allocated or not */
397 if (!adapter->cmd_pool) {
398 mwifiex_dbg(adapter, FATAL,
399 "info: FREE_CMD_BUF: cmd_pool is null\n");
400 return 0;
401 }
402
403 cmd_array = adapter->cmd_pool;
404
405 /* Release shared memory buffers */
406 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
407 if (cmd_array[i].skb) {
408 mwifiex_dbg(adapter, CMD,
409 "cmd: free cmd buffer %d\n", i);
410 dev_kfree_skb_any(cmd_array[i].skb);
411 }
412 if (!cmd_array[i].resp_skb)
413 continue;
414
415 if (adapter->iface_type == MWIFIEX_USB)
416 adapter->if_ops.cmdrsp_complete(adapter,
417 cmd_array[i].resp_skb);
418 else
419 dev_kfree_skb_any(cmd_array[i].resp_skb);
420 }
421 /* Release struct cmd_ctrl_node */
422 if (adapter->cmd_pool) {
423 mwifiex_dbg(adapter, CMD,
424 "cmd: free cmd pool\n");
425 kfree(adapter->cmd_pool);
426 adapter->cmd_pool = NULL;
427 }
428
429 return 0;
430}
431
432/*
433 * This function handles events generated by firmware.
434 *
435 * Event body of events received from firmware are not used (though they are
436 * saved), only the event ID is used. Some events are re-invoked by
437 * the driver, with a new event body.
438 *
439 * After processing, the function calls the completion callback
440 * for cleanup.
441 */
442int mwifiex_process_event(struct mwifiex_adapter *adapter)
443{
444 int ret;
445 struct mwifiex_private *priv =
446 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
447 struct sk_buff *skb = adapter->event_skb;
448 u32 eventcause = adapter->event_cause;
449 struct mwifiex_rxinfo *rx_info;
450
451 /* Save the last event to debug log */
452 adapter->dbg.last_event_index =
453 (adapter->dbg.last_event_index + 1) % DBG_CMD_NUM;
454 adapter->dbg.last_event[adapter->dbg.last_event_index] =
455 (u16) eventcause;
456
457 /* Get BSS number and corresponding priv */
458 priv = mwifiex_get_priv_by_id(adapter, EVENT_GET_BSS_NUM(eventcause),
459 EVENT_GET_BSS_TYPE(eventcause));
460 if (!priv)
461 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
462
463 /* Clear BSS_NO_BITS from event */
464 eventcause &= EVENT_ID_MASK;
465 adapter->event_cause = eventcause;
466
467 if (skb) {
468 rx_info = MWIFIEX_SKB_RXCB(skb);
469 memset(rx_info, 0, sizeof(*rx_info));
470 rx_info->bss_num = priv->bss_num;
471 rx_info->bss_type = priv->bss_type;
472 }
473
474 mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause);
475 mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:", skb->data, skb->len);
476
477 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
478 ret = mwifiex_process_uap_event(priv);
479 else
480 ret = mwifiex_process_sta_event(priv);
481
482 adapter->event_cause = 0;
483 adapter->event_skb = NULL;
484 adapter->if_ops.event_complete(adapter, skb);
485
486 return ret;
487}
488
489/*
490 * This function prepares a command and send it to the firmware.
491 *
492 * Preparation includes -
493 * - Sanity tests to make sure the card is still present or the FW
494 * is not reset
495 * - Getting a new command node from the command free queue
496 * - Initializing the command node for default parameters
497 * - Fill up the non-default parameters and buffer pointers
498 * - Add the command to pending queue
499 */
500int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
501 u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync)
502{
503 int ret;
504 struct mwifiex_adapter *adapter = priv->adapter;
505 struct cmd_ctrl_node *cmd_node;
506 struct host_cmd_ds_command *cmd_ptr;
507
508 if (!adapter) {
509 pr_err("PREP_CMD: adapter is NULL\n");
510 return -1;
511 }
512
513 if (adapter->is_suspended) {
514 mwifiex_dbg(adapter, ERROR,
515 "PREP_CMD: device in suspended state\n");
516 return -1;
517 }
518
519 if (adapter->hs_enabling && cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
520 mwifiex_dbg(adapter, ERROR,
521 "PREP_CMD: host entering sleep state\n");
522 return -1;
523 }
524
525 if (adapter->surprise_removed) {
526 mwifiex_dbg(adapter, ERROR,
527 "PREP_CMD: card is removed\n");
528 return -1;
529 }
530
531 if (adapter->is_cmd_timedout) {
532 mwifiex_dbg(adapter, ERROR,
533 "PREP_CMD: FW is in bad state\n");
534 return -1;
535 }
536
537 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) {
538 if (cmd_no != HostCmd_CMD_FUNC_INIT) {
539 mwifiex_dbg(adapter, ERROR,
540 "PREP_CMD: FW in reset state\n");
541 return -1;
542 }
543 }
544
545 /* Get a new command node */
546 cmd_node = mwifiex_get_cmd_node(adapter);
547
548 if (!cmd_node) {
549 mwifiex_dbg(adapter, ERROR,
550 "PREP_CMD: no free cmd node\n");
551 return -1;
552 }
553
554 /* Initialize the command node */
555 mwifiex_init_cmd_node(priv, cmd_node, cmd_oid, data_buf, sync);
556
557 if (!cmd_node->cmd_skb) {
558 mwifiex_dbg(adapter, ERROR,
559 "PREP_CMD: no free cmd buf\n");
560 return -1;
561 }
562
563 memset(skb_put(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command)),
564 0, sizeof(struct host_cmd_ds_command));
565
566 cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
567 cmd_ptr->command = cpu_to_le16(cmd_no);
568 cmd_ptr->result = 0;
569
570 /* Prepare command */
571 if (cmd_no) {
572 switch (cmd_no) {
573 case HostCmd_CMD_UAP_SYS_CONFIG:
574 case HostCmd_CMD_UAP_BSS_START:
575 case HostCmd_CMD_UAP_BSS_STOP:
576 case HostCmd_CMD_UAP_STA_DEAUTH:
577 ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action,
578 cmd_oid, data_buf,
579 cmd_ptr);
580 break;
581 default:
582 ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action,
583 cmd_oid, data_buf,
584 cmd_ptr);
585 break;
586 }
587 } else {
588 ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf);
589 cmd_node->cmd_flag |= CMD_F_HOSTCMD;
590 }
591
592 /* Return error, since the command preparation failed */
593 if (ret) {
594 mwifiex_dbg(adapter, ERROR,
595 "PREP_CMD: cmd %#x preparation failed\n",
596 cmd_no);
597 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
598 return -1;
599 }
600
601 /* Send command */
602 if (cmd_no == HostCmd_CMD_802_11_SCAN ||
603 cmd_no == HostCmd_CMD_802_11_SCAN_EXT) {
604 mwifiex_queue_scan_cmd(priv, cmd_node);
605 } else {
606 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
607 queue_work(adapter->workqueue, &adapter->main_work);
608 if (cmd_node->wait_q_enabled)
609 ret = mwifiex_wait_queue_complete(adapter, cmd_node);
610 }
611
612 return ret;
613}
614
615/*
616 * This function returns a command to the command free queue.
617 *
618 * The function also calls the completion callback if required, before
619 * cleaning the command node and re-inserting it into the free queue.
620 */
621void
622mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
623 struct cmd_ctrl_node *cmd_node)
624{
625 unsigned long flags;
626
627 if (!cmd_node)
628 return;
629
630 if (cmd_node->wait_q_enabled)
631 mwifiex_complete_cmd(adapter, cmd_node);
632 /* Clean the node */
633 mwifiex_clean_cmd_node(adapter, cmd_node);
634
635 /* Insert node into cmd_free_q */
636 spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
637 list_add_tail(&cmd_node->list, &adapter->cmd_free_q);
638 spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
639}
640
641/* This function reuses a command node. */
642void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
643 struct cmd_ctrl_node *cmd_node)
644{
645 struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data;
646
647 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
648
649 atomic_dec(&adapter->cmd_pending);
650 mwifiex_dbg(adapter, CMD,
651 "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
652 le16_to_cpu(host_cmd->command),
653 atomic_read(&adapter->cmd_pending));
654}
655
656/*
657 * This function queues a command to the command pending queue.
658 *
659 * This in effect adds the command to the command list to be executed.
660 * Exit PS command is handled specially, by placing it always to the
661 * front of the command queue.
662 */
663void
664mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
665 struct cmd_ctrl_node *cmd_node, u32 add_tail)
666{
667 struct host_cmd_ds_command *host_cmd = NULL;
668 u16 command;
669 unsigned long flags;
670
671 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
672 if (!host_cmd) {
673 mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n");
674 return;
675 }
676
677 command = le16_to_cpu(host_cmd->command);
678
679 /* Exit_PS command needs to be queued in the header always. */
680 if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
681 struct host_cmd_ds_802_11_ps_mode_enh *pm =
682 &host_cmd->params.psmode_enh;
683 if ((le16_to_cpu(pm->action) == DIS_PS) ||
684 (le16_to_cpu(pm->action) == DIS_AUTO_PS)) {
685 if (adapter->ps_state != PS_STATE_AWAKE)
686 add_tail = false;
687 }
688 }
689
690 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
691 if (add_tail)
692 list_add_tail(&cmd_node->list, &adapter->cmd_pending_q);
693 else
694 list_add(&cmd_node->list, &adapter->cmd_pending_q);
695 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
696
697 atomic_inc(&adapter->cmd_pending);
698 mwifiex_dbg(adapter, CMD,
699 "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
700 command, atomic_read(&adapter->cmd_pending));
701}
702
703/*
704 * This function executes the next command in command pending queue.
705 *
706 * This function will fail if a command is already in processing stage,
707 * otherwise it will dequeue the first command from the command pending
708 * queue and send to the firmware.
709 *
710 * If the device is currently in host sleep mode, any commands, except the
711 * host sleep configuration command will de-activate the host sleep. For PS
712 * mode, the function will put the firmware back to sleep if applicable.
713 */
714int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
715{
716 struct mwifiex_private *priv;
717 struct cmd_ctrl_node *cmd_node;
718 int ret = 0;
719 struct host_cmd_ds_command *host_cmd;
720 unsigned long cmd_flags;
721 unsigned long cmd_pending_q_flags;
722
723 /* Check if already in processing */
724 if (adapter->curr_cmd) {
725 mwifiex_dbg(adapter, FATAL,
726 "EXEC_NEXT_CMD: cmd in processing\n");
727 return -1;
728 }
729
730 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
731 /* Check if any command is pending */
732 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
733 if (list_empty(&adapter->cmd_pending_q)) {
734 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
735 cmd_pending_q_flags);
736 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
737 return 0;
738 }
739 cmd_node = list_first_entry(&adapter->cmd_pending_q,
740 struct cmd_ctrl_node, list);
741 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
742 cmd_pending_q_flags);
743
744 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
745 priv = cmd_node->priv;
746
747 if (adapter->ps_state != PS_STATE_AWAKE) {
748 mwifiex_dbg(adapter, ERROR,
749 "%s: cannot send cmd in sleep state,\t"
750 "this should not happen\n", __func__);
751 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
752 return ret;
753 }
754
755 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
756 list_del(&cmd_node->list);
757 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
758 cmd_pending_q_flags);
759
760 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
761 ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node);
762 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
763 /* Any command sent to the firmware when host is in sleep
764 * mode should de-configure host sleep. We should skip the
765 * host sleep configuration command itself though
766 */
767 if (priv && (host_cmd->command !=
768 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
769 if (adapter->hs_activated) {
770 adapter->is_hs_configured = false;
771 mwifiex_hs_activated_event(priv, false);
772 }
773 }
774
775 return ret;
776}
777
778/*
779 * This function handles the command response.
780 *
781 * After processing, the function cleans the command node and puts
782 * it back to the command free queue.
783 */
784int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
785{
786 struct host_cmd_ds_command *resp;
787 struct mwifiex_private *priv =
788 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
789 int ret = 0;
790 uint16_t orig_cmdresp_no;
791 uint16_t cmdresp_no;
792 uint16_t cmdresp_result;
793 unsigned long flags;
794
795 /* Now we got response from FW, cancel the command timer */
796 del_timer_sync(&adapter->cmd_timer);
797
798 if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
799 resp = (struct host_cmd_ds_command *) adapter->upld_buf;
800 mwifiex_dbg(adapter, ERROR,
801 "CMD_RESP: NULL curr_cmd, %#x\n",
802 le16_to_cpu(resp->command));
803 return -1;
804 }
805
806 adapter->is_cmd_timedout = 0;
807
808 resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data;
809 if (adapter->curr_cmd->cmd_flag & CMD_F_CANCELED) {
810 mwifiex_dbg(adapter, ERROR,
811 "CMD_RESP: %#x been canceled\n",
812 le16_to_cpu(resp->command));
813 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
814 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
815 adapter->curr_cmd = NULL;
816 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
817 return -1;
818 }
819
820 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
821 /* Copy original response back to response buffer */
822 struct mwifiex_ds_misc_cmd *hostcmd;
823 uint16_t size = le16_to_cpu(resp->size);
824 mwifiex_dbg(adapter, INFO,
825 "info: host cmd resp size = %d\n", size);
826 size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
827 if (adapter->curr_cmd->data_buf) {
828 hostcmd = adapter->curr_cmd->data_buf;
829 hostcmd->len = size;
830 memcpy(hostcmd->cmd, resp, size);
831 }
832 }
833 orig_cmdresp_no = le16_to_cpu(resp->command);
834
835 /* Get BSS number and corresponding priv */
836 priv = mwifiex_get_priv_by_id(adapter,
837 HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)),
838 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num)));
839 if (!priv)
840 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
841 /* Clear RET_BIT from HostCmd */
842 resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK);
843
844 cmdresp_no = le16_to_cpu(resp->command);
845 cmdresp_result = le16_to_cpu(resp->result);
846
847 /* Save the last command response to debug log */
848 adapter->dbg.last_cmd_resp_index =
849 (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM;
850 adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
851 orig_cmdresp_no;
852
853 mwifiex_dbg(adapter, CMD,
854 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
855 orig_cmdresp_no, cmdresp_result,
856 le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
857 mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp,
858 le16_to_cpu(resp->size));
859
860 if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
861 mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n");
862 if (adapter->curr_cmd->wait_q_enabled)
863 adapter->cmd_wait_q.status = -1;
864
865 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
866 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
867 adapter->curr_cmd = NULL;
868 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
869 return -1;
870 }
871
872 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
873 adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD;
874 if ((cmdresp_result == HostCmd_RESULT_OK) &&
875 (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH))
876 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
877 } else {
878 /* handle response */
879 ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp);
880 }
881
882 /* Check init command response */
883 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
884 if (ret) {
885 mwifiex_dbg(adapter, ERROR,
886 "%s: cmd %#x failed during\t"
887 "initialization\n", __func__, cmdresp_no);
888 mwifiex_init_fw_complete(adapter);
889 return -1;
890 } else if (adapter->last_init_cmd == cmdresp_no)
891 adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE;
892 }
893
894 if (adapter->curr_cmd) {
895 if (adapter->curr_cmd->wait_q_enabled)
896 adapter->cmd_wait_q.status = ret;
897
898 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
899
900 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
901 adapter->curr_cmd = NULL;
902 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
903 }
904
905 return ret;
906}
907
908/*
909 * This function handles the timeout of command sending.
910 *
911 * It will re-send the same command again.
912 */
913void
914mwifiex_cmd_timeout_func(unsigned long function_context)
915{
916 struct mwifiex_adapter *adapter =
917 (struct mwifiex_adapter *) function_context;
918 struct cmd_ctrl_node *cmd_node;
919
920 adapter->is_cmd_timedout = 1;
921 if (!adapter->curr_cmd) {
922 mwifiex_dbg(adapter, ERROR,
923 "cmd: empty curr_cmd\n");
924 return;
925 }
926 cmd_node = adapter->curr_cmd;
927 if (cmd_node) {
928 adapter->dbg.timeout_cmd_id =
929 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
930 adapter->dbg.timeout_cmd_act =
931 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
932 mwifiex_dbg(adapter, MSG,
933 "%s: Timeout cmd id = %#x, act = %#x\n", __func__,
934 adapter->dbg.timeout_cmd_id,
935 adapter->dbg.timeout_cmd_act);
936
937 mwifiex_dbg(adapter, MSG,
938 "num_data_h2c_failure = %d\n",
939 adapter->dbg.num_tx_host_to_card_failure);
940 mwifiex_dbg(adapter, MSG,
941 "num_cmd_h2c_failure = %d\n",
942 adapter->dbg.num_cmd_host_to_card_failure);
943
944 mwifiex_dbg(adapter, MSG,
945 "is_cmd_timedout = %d\n",
946 adapter->is_cmd_timedout);
947 mwifiex_dbg(adapter, MSG,
948 "num_tx_timeout = %d\n",
949 adapter->dbg.num_tx_timeout);
950
951 mwifiex_dbg(adapter, MSG,
952 "last_cmd_index = %d\n",
953 adapter->dbg.last_cmd_index);
954 mwifiex_dbg(adapter, MSG,
955 "last_cmd_id: %*ph\n",
956 (int)sizeof(adapter->dbg.last_cmd_id),
957 adapter->dbg.last_cmd_id);
958 mwifiex_dbg(adapter, MSG,
959 "last_cmd_act: %*ph\n",
960 (int)sizeof(adapter->dbg.last_cmd_act),
961 adapter->dbg.last_cmd_act);
962
963 mwifiex_dbg(adapter, MSG,
964 "last_cmd_resp_index = %d\n",
965 adapter->dbg.last_cmd_resp_index);
966 mwifiex_dbg(adapter, MSG,
967 "last_cmd_resp_id: %*ph\n",
968 (int)sizeof(adapter->dbg.last_cmd_resp_id),
969 adapter->dbg.last_cmd_resp_id);
970
971 mwifiex_dbg(adapter, MSG,
972 "last_event_index = %d\n",
973 adapter->dbg.last_event_index);
974 mwifiex_dbg(adapter, MSG,
975 "last_event: %*ph\n",
976 (int)sizeof(adapter->dbg.last_event),
977 adapter->dbg.last_event);
978
979 mwifiex_dbg(adapter, MSG,
980 "data_sent=%d cmd_sent=%d\n",
981 adapter->data_sent, adapter->cmd_sent);
982
983 mwifiex_dbg(adapter, MSG,
984 "ps_mode=%d ps_state=%d\n",
985 adapter->ps_mode, adapter->ps_state);
986
987 if (cmd_node->wait_q_enabled) {
988 adapter->cmd_wait_q.status = -ETIMEDOUT;
989 wake_up_interruptible(&adapter->cmd_wait_q.wait);
990 mwifiex_cancel_pending_ioctl(adapter);
991 }
992 }
993 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
994 mwifiex_init_fw_complete(adapter);
995
996 if (adapter->if_ops.fw_dump)
997 adapter->if_ops.fw_dump(adapter);
998
999 if (adapter->if_ops.card_reset)
1000 adapter->if_ops.card_reset(adapter);
1001}
1002
1003/*
1004 * This function cancels all the pending commands.
1005 *
1006 * The current command, all commands in command pending queue and all scan
1007 * commands in scan pending queue are cancelled. All the completion callbacks
1008 * are called with failure status to ensure cleanup.
1009 */
1010void
1011mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
1012{
1013 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
1014 unsigned long flags, cmd_flags;
1015 struct mwifiex_private *priv;
1016 int i;
1017
1018 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
1019 /* Cancel current cmd */
1020 if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) {
1021 adapter->curr_cmd->wait_q_enabled = false;
1022 adapter->cmd_wait_q.status = -1;
1023 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1024 }
1025 /* Cancel all pending command */
1026 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1027 list_for_each_entry_safe(cmd_node, tmp_node,
1028 &adapter->cmd_pending_q, list) {
1029 list_del(&cmd_node->list);
1030 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1031
1032 if (cmd_node->wait_q_enabled) {
1033 adapter->cmd_wait_q.status = -1;
1034 mwifiex_complete_cmd(adapter, cmd_node);
1035 cmd_node->wait_q_enabled = false;
1036 }
1037 mwifiex_recycle_cmd_node(adapter, cmd_node);
1038 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1039 }
1040 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1041 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
1042
1043 /* Cancel all pending scan command */
1044 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1045 list_for_each_entry_safe(cmd_node, tmp_node,
1046 &adapter->scan_pending_q, list) {
1047 list_del(&cmd_node->list);
1048
1049 cmd_node->wait_q_enabled = false;
1050 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1051 }
1052 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1053
1054 if (adapter->scan_processing) {
1055 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
1056 adapter->scan_processing = false;
1057 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
1058 for (i = 0; i < adapter->priv_num; i++) {
1059 priv = adapter->priv[i];
1060 if (!priv)
1061 continue;
1062 if (priv->scan_request) {
1063 mwifiex_dbg(adapter, WARN, "info: aborting scan\n");
1064 cfg80211_scan_done(priv->scan_request, 1);
1065 priv->scan_request = NULL;
1066 }
1067 }
1068 }
1069}
1070
1071/*
1072 * This function cancels all pending commands that matches with
1073 * the given IOCTL request.
1074 *
1075 * Both the current command buffer and the pending command queue are
1076 * searched for matching IOCTL request. The completion callback of
1077 * the matched command is called with failure status to ensure cleanup.
1078 * In case of scan commands, all pending commands in scan pending queue
1079 * are cancelled.
1080 */
1081void
1082mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
1083{
1084 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node = NULL;
1085 unsigned long cmd_flags;
1086 unsigned long scan_pending_q_flags;
1087 struct mwifiex_private *priv;
1088 int i;
1089
1090 if ((adapter->curr_cmd) &&
1091 (adapter->curr_cmd->wait_q_enabled)) {
1092 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
1093 cmd_node = adapter->curr_cmd;
1094 cmd_node->wait_q_enabled = false;
1095 cmd_node->cmd_flag |= CMD_F_CANCELED;
1096 mwifiex_recycle_cmd_node(adapter, cmd_node);
1097 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1098 adapter->curr_cmd = NULL;
1099 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
1100 }
1101
1102 /* Cancel all pending scan command */
1103 spin_lock_irqsave(&adapter->scan_pending_q_lock,
1104 scan_pending_q_flags);
1105 list_for_each_entry_safe(cmd_node, tmp_node,
1106 &adapter->scan_pending_q, list) {
1107 list_del(&cmd_node->list);
1108 cmd_node->wait_q_enabled = false;
1109 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1110 }
1111 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1112 scan_pending_q_flags);
1113
1114 if (adapter->scan_processing) {
1115 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
1116 adapter->scan_processing = false;
1117 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
1118 for (i = 0; i < adapter->priv_num; i++) {
1119 priv = adapter->priv[i];
1120 if (!priv)
1121 continue;
1122 if (priv->scan_request) {
1123 mwifiex_dbg(adapter, WARN, "info: aborting scan\n");
1124 cfg80211_scan_done(priv->scan_request, 1);
1125 priv->scan_request = NULL;
1126 }
1127 }
1128 }
1129 adapter->cmd_wait_q.status = -1;
1130}
1131
1132/*
1133 * This function sends the sleep confirm command to firmware, if
1134 * possible.
1135 *
1136 * The sleep confirm command cannot be issued if command response,
1137 * data response or event response is awaiting handling, or if we
1138 * are in the middle of sending a command, or expecting a command
1139 * response.
1140 */
1141void
1142mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
1143{
1144 if (!adapter->cmd_sent &&
1145 !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
1146 mwifiex_dnld_sleep_confirm_cmd(adapter);
1147 else
1148 mwifiex_dbg(adapter, CMD,
1149 "cmd: Delay Sleep Confirm (%s%s%s)\n",
1150 (adapter->cmd_sent) ? "D" : "",
1151 (adapter->curr_cmd) ? "C" : "",
1152 (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
1153}
1154
1155/*
1156 * This function sends a Host Sleep activated event to applications.
1157 *
1158 * This event is generated by the driver, with a blank event body.
1159 */
1160void
1161mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
1162{
1163 if (activated) {
1164 if (priv->adapter->is_hs_configured) {
1165 priv->adapter->hs_activated = true;
1166 mwifiex_update_rxreor_flags(priv->adapter,
1167 RXREOR_FORCE_NO_DROP);
1168 mwifiex_dbg(priv->adapter, EVENT,
1169 "event: hs_activated\n");
1170 priv->adapter->hs_activate_wait_q_woken = true;
1171 wake_up_interruptible(
1172 &priv->adapter->hs_activate_wait_q);
1173 } else {
1174 mwifiex_dbg(priv->adapter, EVENT,
1175 "event: HS not configured\n");
1176 }
1177 } else {
1178 mwifiex_dbg(priv->adapter, EVENT,
1179 "event: hs_deactivated\n");
1180 priv->adapter->hs_activated = false;
1181 }
1182}
1183
1184/*
1185 * This function handles the command response of a Host Sleep configuration
1186 * command.
1187 *
1188 * Handling includes changing the header fields into CPU format
1189 * and setting the current host sleep activation status in driver.
1190 *
1191 * In case host sleep status change, the function generates an event to
1192 * notify the applications.
1193 */
1194int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
1195 struct host_cmd_ds_command *resp)
1196{
1197 struct mwifiex_adapter *adapter = priv->adapter;
1198 struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg =
1199 &resp->params.opt_hs_cfg;
1200 uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions);
1201
1202 if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) &&
1203 adapter->iface_type != MWIFIEX_USB) {
1204 mwifiex_hs_activated_event(priv, true);
1205 return 0;
1206 } else {
1207 mwifiex_dbg(adapter, CMD,
1208 "cmd: CMD_RESP: HS_CFG cmd reply\t"
1209 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1210 resp->result, conditions,
1211 phs_cfg->params.hs_config.gpio,
1212 phs_cfg->params.hs_config.gap);
1213 }
1214 if (conditions != HS_CFG_CANCEL) {
1215 adapter->is_hs_configured = true;
1216 if (adapter->iface_type == MWIFIEX_USB)
1217 mwifiex_hs_activated_event(priv, true);
1218 } else {
1219 adapter->is_hs_configured = false;
1220 if (adapter->hs_activated)
1221 mwifiex_hs_activated_event(priv, false);
1222 }
1223
1224 return 0;
1225}
1226
1227/*
1228 * This function wakes up the adapter and generates a Host Sleep
1229 * cancel event on receiving the power up interrupt.
1230 */
1231void
1232mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
1233{
1234 mwifiex_dbg(adapter, INFO,
1235 "info: %s: auto cancelling host sleep\t"
1236 "since there is interrupt from the firmware\n",
1237 __func__);
1238
1239 adapter->if_ops.wakeup(adapter);
1240 adapter->hs_activated = false;
1241 adapter->is_hs_configured = false;
1242 adapter->is_suspended = false;
1243 mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
1244 MWIFIEX_BSS_ROLE_ANY),
1245 false);
1246}
1247EXPORT_SYMBOL_GPL(mwifiex_process_hs_config);
1248
1249/*
1250 * This function handles the command response of a sleep confirm command.
1251 *
1252 * The function sets the card state to SLEEP if the response indicates success.
1253 */
1254void
1255mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
1256 u8 *pbuf, u32 upld_len)
1257{
1258 struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf;
1259 struct mwifiex_private *priv =
1260 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1261 uint16_t result = le16_to_cpu(cmd->result);
1262 uint16_t command = le16_to_cpu(cmd->command);
1263 uint16_t seq_num = le16_to_cpu(cmd->seq_num);
1264
1265 if (!upld_len) {
1266 mwifiex_dbg(adapter, ERROR,
1267 "%s: cmd size is 0\n", __func__);
1268 return;
1269 }
1270
1271 mwifiex_dbg(adapter, CMD,
1272 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
1273 command, result, le16_to_cpu(cmd->size), seq_num);
1274
1275 /* Get BSS number and corresponding priv */
1276 priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
1277 HostCmd_GET_BSS_TYPE(seq_num));
1278 if (!priv)
1279 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1280
1281 /* Update sequence number */
1282 seq_num = HostCmd_GET_SEQ_NO(seq_num);
1283 /* Clear RET_BIT from HostCmd */
1284 command &= HostCmd_CMD_ID_MASK;
1285
1286 if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
1287 mwifiex_dbg(adapter, ERROR,
1288 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1289 __func__, command, result);
1290 return;
1291 }
1292
1293 if (result) {
1294 mwifiex_dbg(adapter, ERROR,
1295 "%s: sleep confirm cmd failed\n",
1296 __func__);
1297 adapter->pm_wakeup_card_req = false;
1298 adapter->ps_state = PS_STATE_AWAKE;
1299 return;
1300 }
1301 adapter->pm_wakeup_card_req = true;
1302 if (adapter->is_hs_configured)
1303 mwifiex_hs_activated_event(mwifiex_get_priv
1304 (adapter, MWIFIEX_BSS_ROLE_ANY),
1305 true);
1306 adapter->ps_state = PS_STATE_SLEEP;
1307 cmd->command = cpu_to_le16(command);
1308 cmd->seq_num = cpu_to_le16(seq_num);
1309}
1310EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp);
1311
1312/*
1313 * This function prepares an enhanced power mode command.
1314 *
1315 * This function can be used to disable power save or to configure
1316 * power save with auto PS or STA PS or auto deep sleep.
1317 *
1318 * Preparation includes -
1319 * - Setting command ID, action and proper size
1320 * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
1321 * auto deep sleep TLV (as required)
1322 * - Ensuring correct endian-ness
1323 */
1324int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
1325 struct host_cmd_ds_command *cmd,
1326 u16 cmd_action, uint16_t ps_bitmap,
1327 struct mwifiex_ds_auto_ds *auto_ds)
1328{
1329 struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh =
1330 &cmd->params.psmode_enh;
1331 u8 *tlv;
1332 u16 cmd_size = 0;
1333
1334 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
1335 if (cmd_action == DIS_AUTO_PS) {
1336 psmode_enh->action = cpu_to_le16(DIS_AUTO_PS);
1337 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1338 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1339 sizeof(psmode_enh->params.ps_bitmap));
1340 } else if (cmd_action == GET_PS) {
1341 psmode_enh->action = cpu_to_le16(GET_PS);
1342 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1343 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1344 sizeof(psmode_enh->params.ps_bitmap));
1345 } else if (cmd_action == EN_AUTO_PS) {
1346 psmode_enh->action = cpu_to_le16(EN_AUTO_PS);
1347 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1348 cmd_size = S_DS_GEN + sizeof(psmode_enh->action) +
1349 sizeof(psmode_enh->params.ps_bitmap);
1350 tlv = (u8 *) cmd + cmd_size;
1351 if (ps_bitmap & BITMAP_STA_PS) {
1352 struct mwifiex_adapter *adapter = priv->adapter;
1353 struct mwifiex_ie_types_ps_param *ps_tlv =
1354 (struct mwifiex_ie_types_ps_param *) tlv;
1355 struct mwifiex_ps_param *ps_mode = &ps_tlv->param;
1356 ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM);
1357 ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) -
1358 sizeof(struct mwifiex_ie_types_header));
1359 cmd_size += sizeof(*ps_tlv);
1360 tlv += sizeof(*ps_tlv);
1361 mwifiex_dbg(priv->adapter, CMD,
1362 "cmd: PS Command: Enter PS\n");
1363 ps_mode->null_pkt_interval =
1364 cpu_to_le16(adapter->null_pkt_interval);
1365 ps_mode->multiple_dtims =
1366 cpu_to_le16(adapter->multiple_dtim);
1367 ps_mode->bcn_miss_timeout =
1368 cpu_to_le16(adapter->bcn_miss_time_out);
1369 ps_mode->local_listen_interval =
1370 cpu_to_le16(adapter->local_listen_interval);
1371 ps_mode->adhoc_wake_period =
1372 cpu_to_le16(adapter->adhoc_awake_period);
1373 ps_mode->delay_to_ps =
1374 cpu_to_le16(adapter->delay_to_ps);
1375 ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode);
1376
1377 }
1378 if (ps_bitmap & BITMAP_AUTO_DS) {
1379 struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv =
1380 (struct mwifiex_ie_types_auto_ds_param *) tlv;
1381 u16 idletime = 0;
1382
1383 auto_ds_tlv->header.type =
1384 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM);
1385 auto_ds_tlv->header.len =
1386 cpu_to_le16(sizeof(*auto_ds_tlv) -
1387 sizeof(struct mwifiex_ie_types_header));
1388 cmd_size += sizeof(*auto_ds_tlv);
1389 tlv += sizeof(*auto_ds_tlv);
1390 if (auto_ds)
1391 idletime = auto_ds->idle_time;
1392 mwifiex_dbg(priv->adapter, CMD,
1393 "cmd: PS Command: Enter Auto Deep Sleep\n");
1394 auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
1395 }
1396 cmd->size = cpu_to_le16(cmd_size);
1397 }
1398 return 0;
1399}
1400
1401/*
1402 * This function handles the command response of an enhanced power mode
1403 * command.
1404 *
1405 * Handling includes changing the header fields into CPU format
1406 * and setting the current enhanced power mode in driver.
1407 */
1408int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
1409 struct host_cmd_ds_command *resp,
1410 struct mwifiex_ds_pm_cfg *pm_cfg)
1411{
1412 struct mwifiex_adapter *adapter = priv->adapter;
1413 struct host_cmd_ds_802_11_ps_mode_enh *ps_mode =
1414 &resp->params.psmode_enh;
1415 uint16_t action = le16_to_cpu(ps_mode->action);
1416 uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap);
1417 uint16_t auto_ps_bitmap =
1418 le16_to_cpu(ps_mode->params.ps_bitmap);
1419
1420 mwifiex_dbg(adapter, INFO,
1421 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1422 __func__, resp->result, action);
1423 if (action == EN_AUTO_PS) {
1424 if (auto_ps_bitmap & BITMAP_AUTO_DS) {
1425 mwifiex_dbg(adapter, CMD,
1426 "cmd: Enabled auto deep sleep\n");
1427 priv->adapter->is_deep_sleep = true;
1428 }
1429 if (auto_ps_bitmap & BITMAP_STA_PS) {
1430 mwifiex_dbg(adapter, CMD,
1431 "cmd: Enabled STA power save\n");
1432 if (adapter->sleep_period.period)
1433 mwifiex_dbg(adapter, CMD,
1434 "cmd: set to uapsd/pps mode\n");
1435 }
1436 } else if (action == DIS_AUTO_PS) {
1437 if (ps_bitmap & BITMAP_AUTO_DS) {
1438 priv->adapter->is_deep_sleep = false;
1439 mwifiex_dbg(adapter, CMD,
1440 "cmd: Disabled auto deep sleep\n");
1441 }
1442 if (ps_bitmap & BITMAP_STA_PS) {
1443 mwifiex_dbg(adapter, CMD,
1444 "cmd: Disabled STA power save\n");
1445 if (adapter->sleep_period.period) {
1446 adapter->delay_null_pkt = false;
1447 adapter->tx_lock_flag = false;
1448 adapter->pps_uapsd_mode = false;
1449 }
1450 }
1451 } else if (action == GET_PS) {
1452 if (ps_bitmap & BITMAP_STA_PS)
1453 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1454 else
1455 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
1456
1457 mwifiex_dbg(adapter, CMD,
1458 "cmd: ps_bitmap=%#x\n", ps_bitmap);
1459
1460 if (pm_cfg) {
1461 /* This section is for get power save mode */
1462 if (ps_bitmap & BITMAP_STA_PS)
1463 pm_cfg->param.ps_mode = 1;
1464 else
1465 pm_cfg->param.ps_mode = 0;
1466 }
1467 }
1468 return 0;
1469}
1470
1471/*
1472 * This function prepares command to get hardware specifications.
1473 *
1474 * Preparation includes -
1475 * - Setting command ID, action and proper size
1476 * - Setting permanent address parameter
1477 * - Ensuring correct endian-ness
1478 */
1479int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
1480 struct host_cmd_ds_command *cmd)
1481{
1482 struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec;
1483
1484 cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC);
1485 cmd->size =
1486 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN);
1487 memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN);
1488
1489 return 0;
1490}
1491
1492/*
1493 * This function handles the command response of get hardware
1494 * specifications.
1495 *
1496 * Handling includes changing the header fields into CPU format
1497 * and saving/updating the following parameters in driver -
1498 * - Firmware capability information
1499 * - Firmware band settings
1500 * - Ad-hoc start band and channel
1501 * - Ad-hoc 11n activation status
1502 * - Firmware release number
1503 * - Number of antennas
1504 * - Hardware address
1505 * - Hardware interface version
1506 * - Firmware version
1507 * - Region code
1508 * - 11n capabilities
1509 * - MCS support fields
1510 * - MP end port
1511 */
1512int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1513 struct host_cmd_ds_command *resp)
1514{
1515 struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec;
1516 struct mwifiex_adapter *adapter = priv->adapter;
1517 struct mwifiex_ie_types_header *tlv;
1518 struct hw_spec_api_rev *api_rev;
1519 u16 resp_size, api_id;
1520 int i, left_len, parsed_len = 0;
1521
1522 adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info);
1523
1524 if (IS_SUPPORT_MULTI_BANDS(adapter))
1525 adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter);
1526 else
1527 adapter->fw_bands = BAND_B;
1528
1529 adapter->config_bands = adapter->fw_bands;
1530
1531 if (adapter->fw_bands & BAND_A) {
1532 if (adapter->fw_bands & BAND_GN) {
1533 adapter->config_bands |= BAND_AN;
1534 adapter->fw_bands |= BAND_AN;
1535 }
1536 if (adapter->fw_bands & BAND_AN) {
1537 adapter->adhoc_start_band = BAND_A | BAND_AN;
1538 adapter->adhoc_11n_enabled = true;
1539 } else {
1540 adapter->adhoc_start_band = BAND_A;
1541 }
1542 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A;
1543 } else if (adapter->fw_bands & BAND_GN) {
1544 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
1545 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1546 adapter->adhoc_11n_enabled = true;
1547 } else if (adapter->fw_bands & BAND_G) {
1548 adapter->adhoc_start_band = BAND_G | BAND_B;
1549 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1550 } else if (adapter->fw_bands & BAND_B) {
1551 adapter->adhoc_start_band = BAND_B;
1552 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1553 }
1554
1555 adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
1556 adapter->fw_api_ver = (adapter->fw_release_number >> 16) & 0xff;
1557 adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna);
1558
1559 if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) {
1560 adapter->is_hw_11ac_capable = true;
1561
1562 /* Copy 11AC cap */
1563 adapter->hw_dot_11ac_dev_cap =
1564 le32_to_cpu(hw_spec->dot_11ac_dev_cap);
1565 adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap
1566 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
1567 adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap
1568 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
1569
1570 /* Copy 11AC mcs */
1571 adapter->hw_dot_11ac_mcs_support =
1572 le32_to_cpu(hw_spec->dot_11ac_mcs_support);
1573 adapter->usr_dot_11ac_mcs_support =
1574 adapter->hw_dot_11ac_mcs_support;
1575 } else {
1576 adapter->is_hw_11ac_capable = false;
1577 }
1578
1579 resp_size = le16_to_cpu(resp->size) - S_DS_GEN;
1580 if (resp_size > sizeof(struct host_cmd_ds_get_hw_spec)) {
1581 /* we have variable HW SPEC information */
1582 left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec);
1583 while (left_len > sizeof(struct mwifiex_ie_types_header)) {
1584 tlv = (void *)&hw_spec->tlvs + parsed_len;
1585 switch (le16_to_cpu(tlv->type)) {
1586 case TLV_TYPE_API_REV:
1587 api_rev = (struct hw_spec_api_rev *)tlv;
1588 api_id = le16_to_cpu(api_rev->api_id);
1589 switch (api_id) {
1590 case KEY_API_VER_ID:
1591 adapter->key_api_major_ver =
1592 api_rev->major_ver;
1593 adapter->key_api_minor_ver =
1594 api_rev->minor_ver;
1595 mwifiex_dbg(adapter, INFO,
1596 "key_api v%d.%d\n",
1597 adapter->key_api_major_ver,
1598 adapter->key_api_minor_ver);
1599 break;
1600 case FW_API_VER_ID:
1601 adapter->fw_api_ver =
1602 api_rev->major_ver;
1603 mwifiex_dbg(adapter, INFO,
1604 "Firmware api version %d\n",
1605 adapter->fw_api_ver);
1606 break;
1607 default:
1608 mwifiex_dbg(adapter, FATAL,
1609 "Unknown api_id: %d\n",
1610 api_id);
1611 break;
1612 }
1613 break;
1614 default:
1615 mwifiex_dbg(adapter, FATAL,
1616 "Unknown GET_HW_SPEC TLV type: %#x\n",
1617 le16_to_cpu(tlv->type));
1618 break;
1619 }
1620 parsed_len += le16_to_cpu(tlv->len) +
1621 sizeof(struct mwifiex_ie_types_header);
1622 left_len -= le16_to_cpu(tlv->len) +
1623 sizeof(struct mwifiex_ie_types_header);
1624 }
1625 }
1626
1627 mwifiex_dbg(adapter, INFO,
1628 "info: GET_HW_SPEC: fw_release_number- %#x\n",
1629 adapter->fw_release_number);
1630 mwifiex_dbg(adapter, INFO,
1631 "info: GET_HW_SPEC: permanent addr: %pM\n",
1632 hw_spec->permanent_addr);
1633 mwifiex_dbg(adapter, INFO,
1634 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1635 le16_to_cpu(hw_spec->hw_if_version),
1636 le16_to_cpu(hw_spec->version));
1637
1638 ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr);
1639 adapter->region_code = le16_to_cpu(hw_spec->region_code);
1640
1641 for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++)
1642 /* Use the region code to search for the index */
1643 if (adapter->region_code == region_code_index[i])
1644 break;
1645
1646 /* If it's unidentified region code, use the default (USA) */
1647 if (i >= MWIFIEX_MAX_REGION_CODE) {
1648 adapter->region_code = 0x10;
1649 mwifiex_dbg(adapter, WARN,
1650 "cmd: unknown region code, use default (USA)\n");
1651 }
1652
1653 adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);
1654 adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support;
1655 adapter->user_dev_mcs_support = adapter->hw_dev_mcs_support;
1656
1657 if (adapter->if_ops.update_mp_end_port)
1658 adapter->if_ops.update_mp_end_port(adapter,
1659 le16_to_cpu(hw_spec->mp_end_port));
1660
1661 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
1662 adapter->scan_chan_gap_enabled = true;
1663
1664 return 0;
1665}
This page took 0.030062 seconds and 5 git commands to generate.