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