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