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