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