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; | |
5e6e3a92 BZ |
472 | } |
473 | ||
acebe8c1 | 474 | mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause); |
868093a9 | 475 | mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:", skb->data, skb->len); |
5e6e3a92 | 476 | |
3d99d987 AP |
477 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
478 | ret = mwifiex_process_uap_event(priv); | |
479 | else | |
480 | ret = mwifiex_process_sta_event(priv); | |
5e6e3a92 BZ |
481 | |
482 | adapter->event_cause = 0; | |
483 | adapter->event_skb = NULL; | |
d930faee | 484 | adapter->if_ops.event_complete(adapter, skb); |
5e6e3a92 BZ |
485 | |
486 | return ret; | |
487 | } | |
488 | ||
489 | /* | |
fa0ecbb9 | 490 | * This function prepares a command and send it to the firmware. |
5e6e3a92 BZ |
491 | * |
492 | * Preparation includes - | |
493 | * - Sanity tests to make sure the card is still present or the FW | |
494 | * is not reset | |
495 | * - Getting a new command node from the command free queue | |
496 | * - Initializing the command node for default parameters | |
497 | * - Fill up the non-default parameters and buffer pointers | |
498 | * - Add the command to pending queue | |
499 | */ | |
fa0ecbb9 BZ |
500 | int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no, |
501 | u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync) | |
5e6e3a92 | 502 | { |
270e58e8 | 503 | int ret; |
5e6e3a92 | 504 | struct mwifiex_adapter *adapter = priv->adapter; |
270e58e8 YAP |
505 | struct cmd_ctrl_node *cmd_node; |
506 | struct host_cmd_ds_command *cmd_ptr; | |
5e6e3a92 BZ |
507 | |
508 | if (!adapter) { | |
509 | pr_err("PREP_CMD: adapter is NULL\n"); | |
510 | return -1; | |
511 | } | |
512 | ||
513 | if (adapter->is_suspended) { | |
acebe8c1 ZL |
514 | mwifiex_dbg(adapter, ERROR, |
515 | "PREP_CMD: device in suspended state\n"); | |
5e6e3a92 BZ |
516 | return -1; |
517 | } | |
518 | ||
c0dbba66 | 519 | if (adapter->hs_enabling && cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) { |
acebe8c1 ZL |
520 | mwifiex_dbg(adapter, ERROR, |
521 | "PREP_CMD: host entering sleep state\n"); | |
c0dbba66 AK |
522 | return -1; |
523 | } | |
524 | ||
5e6e3a92 | 525 | if (adapter->surprise_removed) { |
acebe8c1 ZL |
526 | mwifiex_dbg(adapter, ERROR, |
527 | "PREP_CMD: card is removed\n"); | |
5e6e3a92 BZ |
528 | return -1; |
529 | } | |
530 | ||
0c9c4a09 | 531 | if (adapter->is_cmd_timedout) { |
acebe8c1 ZL |
532 | mwifiex_dbg(adapter, ERROR, |
533 | "PREP_CMD: FW is in bad state\n"); | |
38ec3f3f AK |
534 | return -1; |
535 | } | |
536 | ||
5e6e3a92 BZ |
537 | if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) { |
538 | if (cmd_no != HostCmd_CMD_FUNC_INIT) { | |
acebe8c1 ZL |
539 | mwifiex_dbg(adapter, ERROR, |
540 | "PREP_CMD: FW in reset state\n"); | |
5e6e3a92 BZ |
541 | return -1; |
542 | } | |
543 | } | |
544 | ||
545 | /* Get a new command node */ | |
546 | cmd_node = mwifiex_get_cmd_node(adapter); | |
547 | ||
548 | if (!cmd_node) { | |
acebe8c1 ZL |
549 | mwifiex_dbg(adapter, ERROR, |
550 | "PREP_CMD: no free cmd node\n"); | |
5e6e3a92 BZ |
551 | return -1; |
552 | } | |
553 | ||
554 | /* Initialize the command node */ | |
fa0ecbb9 | 555 | mwifiex_init_cmd_node(priv, cmd_node, cmd_oid, data_buf, sync); |
5e6e3a92 BZ |
556 | |
557 | if (!cmd_node->cmd_skb) { | |
acebe8c1 ZL |
558 | mwifiex_dbg(adapter, ERROR, |
559 | "PREP_CMD: no free cmd buf\n"); | |
5e6e3a92 BZ |
560 | return -1; |
561 | } | |
562 | ||
563 | memset(skb_put(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command)), | |
564 | 0, sizeof(struct host_cmd_ds_command)); | |
565 | ||
566 | cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); | |
567 | cmd_ptr->command = cpu_to_le16(cmd_no); | |
568 | cmd_ptr->result = 0; | |
569 | ||
570 | /* Prepare command */ | |
571 | if (cmd_no) { | |
40d07030 AP |
572 | switch (cmd_no) { |
573 | case HostCmd_CMD_UAP_SYS_CONFIG: | |
574 | case HostCmd_CMD_UAP_BSS_START: | |
575 | case HostCmd_CMD_UAP_BSS_STOP: | |
0f9e9b8b | 576 | case HostCmd_CMD_UAP_STA_DEAUTH: |
ed5cfbe6 | 577 | case HOST_CMD_APCMD_SYS_RESET: |
40d07030 AP |
578 | ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action, |
579 | cmd_oid, data_buf, | |
580 | cmd_ptr); | |
581 | break; | |
582 | default: | |
583 | ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action, | |
584 | cmd_oid, data_buf, | |
585 | cmd_ptr); | |
586 | break; | |
587 | } | |
5e6e3a92 BZ |
588 | } else { |
589 | ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf); | |
590 | cmd_node->cmd_flag |= CMD_F_HOSTCMD; | |
591 | } | |
592 | ||
593 | /* Return error, since the command preparation failed */ | |
594 | if (ret) { | |
acebe8c1 ZL |
595 | mwifiex_dbg(adapter, ERROR, |
596 | "PREP_CMD: cmd %#x preparation failed\n", | |
aea0701e | 597 | cmd_no); |
5e6e3a92 BZ |
598 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
599 | return -1; | |
600 | } | |
601 | ||
602 | /* Send command */ | |
21f58d20 AK |
603 | if (cmd_no == HostCmd_CMD_802_11_SCAN || |
604 | cmd_no == HostCmd_CMD_802_11_SCAN_EXT) { | |
5e6e3a92 | 605 | mwifiex_queue_scan_cmd(priv, cmd_node); |
efaaa8b8 | 606 | } else { |
5e6e3a92 | 607 | mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); |
1a1fb970 | 608 | queue_work(adapter->workqueue, &adapter->main_work); |
00d7ea11 AK |
609 | if (cmd_node->wait_q_enabled) |
610 | ret = mwifiex_wait_queue_complete(adapter, cmd_node); | |
efaaa8b8 | 611 | } |
5e6e3a92 BZ |
612 | |
613 | return ret; | |
614 | } | |
615 | ||
616 | /* | |
617 | * This function returns a command to the command free queue. | |
618 | * | |
619 | * The function also calls the completion callback if required, before | |
620 | * cleaning the command node and re-inserting it into the free queue. | |
621 | */ | |
622 | void | |
623 | mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter, | |
624 | struct cmd_ctrl_node *cmd_node) | |
625 | { | |
5e6e3a92 BZ |
626 | unsigned long flags; |
627 | ||
19a89860 | 628 | if (!cmd_node) |
5e6e3a92 | 629 | return; |
600f5d90 AK |
630 | |
631 | if (cmd_node->wait_q_enabled) | |
efaaa8b8 | 632 | mwifiex_complete_cmd(adapter, cmd_node); |
5e6e3a92 BZ |
633 | /* Clean the node */ |
634 | mwifiex_clean_cmd_node(adapter, cmd_node); | |
635 | ||
636 | /* Insert node into cmd_free_q */ | |
637 | spin_lock_irqsave(&adapter->cmd_free_q_lock, flags); | |
638 | list_add_tail(&cmd_node->list, &adapter->cmd_free_q); | |
639 | spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags); | |
5e6e3a92 BZ |
640 | } |
641 | ||
9908b074 BZ |
642 | /* This function reuses a command node. */ |
643 | void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter, | |
644 | struct cmd_ctrl_node *cmd_node) | |
645 | { | |
646 | struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data; | |
647 | ||
648 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); | |
649 | ||
650 | atomic_dec(&adapter->cmd_pending); | |
acebe8c1 ZL |
651 | mwifiex_dbg(adapter, CMD, |
652 | "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n", | |
9908b074 BZ |
653 | le16_to_cpu(host_cmd->command), |
654 | atomic_read(&adapter->cmd_pending)); | |
655 | } | |
656 | ||
5e6e3a92 BZ |
657 | /* |
658 | * This function queues a command to the command pending queue. | |
659 | * | |
660 | * This in effect adds the command to the command list to be executed. | |
661 | * Exit PS command is handled specially, by placing it always to the | |
662 | * front of the command queue. | |
663 | */ | |
664 | void | |
665 | mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter, | |
666 | struct cmd_ctrl_node *cmd_node, u32 add_tail) | |
667 | { | |
668 | struct host_cmd_ds_command *host_cmd = NULL; | |
669 | u16 command; | |
670 | unsigned long flags; | |
671 | ||
672 | host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); | |
673 | if (!host_cmd) { | |
acebe8c1 | 674 | mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n"); |
5e6e3a92 BZ |
675 | return; |
676 | } | |
677 | ||
678 | command = le16_to_cpu(host_cmd->command); | |
679 | ||
680 | /* Exit_PS command needs to be queued in the header always. */ | |
681 | if (command == HostCmd_CMD_802_11_PS_MODE_ENH) { | |
682 | struct host_cmd_ds_802_11_ps_mode_enh *pm = | |
aea0701e YAP |
683 | &host_cmd->params.psmode_enh; |
684 | if ((le16_to_cpu(pm->action) == DIS_PS) || | |
685 | (le16_to_cpu(pm->action) == DIS_AUTO_PS)) { | |
5e6e3a92 BZ |
686 | if (adapter->ps_state != PS_STATE_AWAKE) |
687 | add_tail = false; | |
688 | } | |
689 | } | |
690 | ||
691 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
692 | if (add_tail) | |
693 | list_add_tail(&cmd_node->list, &adapter->cmd_pending_q); | |
694 | else | |
695 | list_add(&cmd_node->list, &adapter->cmd_pending_q); | |
696 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
697 | ||
9908b074 | 698 | atomic_inc(&adapter->cmd_pending); |
acebe8c1 ZL |
699 | mwifiex_dbg(adapter, CMD, |
700 | "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n", | |
9908b074 | 701 | command, atomic_read(&adapter->cmd_pending)); |
5e6e3a92 BZ |
702 | } |
703 | ||
704 | /* | |
705 | * This function executes the next command in command pending queue. | |
706 | * | |
707 | * This function will fail if a command is already in processing stage, | |
708 | * otherwise it will dequeue the first command from the command pending | |
709 | * queue and send to the firmware. | |
710 | * | |
711 | * If the device is currently in host sleep mode, any commands, except the | |
712 | * host sleep configuration command will de-activate the host sleep. For PS | |
713 | * mode, the function will put the firmware back to sleep if applicable. | |
714 | */ | |
715 | int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter) | |
716 | { | |
270e58e8 YAP |
717 | struct mwifiex_private *priv; |
718 | struct cmd_ctrl_node *cmd_node; | |
5e6e3a92 BZ |
719 | int ret = 0; |
720 | struct host_cmd_ds_command *host_cmd; | |
721 | unsigned long cmd_flags; | |
722 | unsigned long cmd_pending_q_flags; | |
723 | ||
724 | /* Check if already in processing */ | |
725 | if (adapter->curr_cmd) { | |
acebe8c1 ZL |
726 | mwifiex_dbg(adapter, FATAL, |
727 | "EXEC_NEXT_CMD: cmd in processing\n"); | |
5e6e3a92 BZ |
728 | return -1; |
729 | } | |
730 | ||
731 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); | |
732 | /* Check if any command is pending */ | |
733 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags); | |
734 | if (list_empty(&adapter->cmd_pending_q)) { | |
735 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, | |
736 | cmd_pending_q_flags); | |
737 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); | |
738 | return 0; | |
739 | } | |
740 | cmd_node = list_first_entry(&adapter->cmd_pending_q, | |
741 | struct cmd_ctrl_node, list); | |
742 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, | |
743 | cmd_pending_q_flags); | |
744 | ||
745 | host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); | |
746 | priv = cmd_node->priv; | |
747 | ||
748 | if (adapter->ps_state != PS_STATE_AWAKE) { | |
acebe8c1 ZL |
749 | mwifiex_dbg(adapter, ERROR, |
750 | "%s: cannot send cmd in sleep state,\t" | |
751 | "this should not happen\n", __func__); | |
5e6e3a92 BZ |
752 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
753 | return ret; | |
754 | } | |
755 | ||
756 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags); | |
757 | list_del(&cmd_node->list); | |
758 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, | |
759 | cmd_pending_q_flags); | |
760 | ||
761 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); | |
762 | ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node); | |
763 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
764 | /* Any command sent to the firmware when host is in sleep | |
765 | * mode should de-configure host sleep. We should skip the | |
766 | * host sleep configuration command itself though | |
767 | */ | |
768 | if (priv && (host_cmd->command != | |
769 | cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) { | |
770 | if (adapter->hs_activated) { | |
771 | adapter->is_hs_configured = false; | |
772 | mwifiex_hs_activated_event(priv, false); | |
773 | } | |
774 | } | |
775 | ||
776 | return ret; | |
777 | } | |
778 | ||
779 | /* | |
780 | * This function handles the command response. | |
781 | * | |
782 | * After processing, the function cleans the command node and puts | |
783 | * it back to the command free queue. | |
784 | */ | |
785 | int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter) | |
786 | { | |
270e58e8 | 787 | struct host_cmd_ds_command *resp; |
5e6e3a92 BZ |
788 | struct mwifiex_private *priv = |
789 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
790 | int ret = 0; | |
791 | uint16_t orig_cmdresp_no; | |
792 | uint16_t cmdresp_no; | |
793 | uint16_t cmdresp_result; | |
5e6e3a92 BZ |
794 | unsigned long flags; |
795 | ||
796 | /* Now we got response from FW, cancel the command timer */ | |
629873f2 | 797 | del_timer_sync(&adapter->cmd_timer); |
5e6e3a92 BZ |
798 | |
799 | if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) { | |
800 | resp = (struct host_cmd_ds_command *) adapter->upld_buf; | |
acebe8c1 ZL |
801 | mwifiex_dbg(adapter, ERROR, |
802 | "CMD_RESP: NULL curr_cmd, %#x\n", | |
803 | le16_to_cpu(resp->command)); | |
5e6e3a92 BZ |
804 | return -1; |
805 | } | |
806 | ||
0c9c4a09 | 807 | adapter->is_cmd_timedout = 0; |
5e6e3a92 BZ |
808 | |
809 | resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data; | |
810 | if (adapter->curr_cmd->cmd_flag & CMD_F_CANCELED) { | |
acebe8c1 ZL |
811 | mwifiex_dbg(adapter, ERROR, |
812 | "CMD_RESP: %#x been canceled\n", | |
813 | le16_to_cpu(resp->command)); | |
9908b074 | 814 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
5e6e3a92 BZ |
815 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
816 | adapter->curr_cmd = NULL; | |
817 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); | |
818 | return -1; | |
819 | } | |
820 | ||
821 | if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) { | |
822 | /* Copy original response back to response buffer */ | |
a5ffddb7 | 823 | struct mwifiex_ds_misc_cmd *hostcmd; |
5e6e3a92 | 824 | uint16_t size = le16_to_cpu(resp->size); |
acebe8c1 ZL |
825 | mwifiex_dbg(adapter, INFO, |
826 | "info: host cmd resp size = %d\n", size); | |
5e6e3a92 BZ |
827 | size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER); |
828 | if (adapter->curr_cmd->data_buf) { | |
a5ffddb7 | 829 | hostcmd = adapter->curr_cmd->data_buf; |
5e6e3a92 | 830 | hostcmd->len = size; |
a5ffddb7 | 831 | memcpy(hostcmd->cmd, resp, size); |
5e6e3a92 BZ |
832 | } |
833 | } | |
834 | orig_cmdresp_no = le16_to_cpu(resp->command); | |
835 | ||
836 | /* Get BSS number and corresponding priv */ | |
837 | priv = mwifiex_get_priv_by_id(adapter, | |
aea0701e YAP |
838 | HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)), |
839 | HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num))); | |
5e6e3a92 BZ |
840 | if (!priv) |
841 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
842 | /* Clear RET_BIT from HostCmd */ | |
843 | resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK); | |
844 | ||
845 | cmdresp_no = le16_to_cpu(resp->command); | |
846 | cmdresp_result = le16_to_cpu(resp->result); | |
847 | ||
848 | /* Save the last command response to debug log */ | |
849 | adapter->dbg.last_cmd_resp_index = | |
aea0701e | 850 | (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM; |
5e6e3a92 | 851 | adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] = |
aea0701e | 852 | orig_cmdresp_no; |
5e6e3a92 | 853 | |
acebe8c1 ZL |
854 | mwifiex_dbg(adapter, CMD, |
855 | "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n", | |
856 | orig_cmdresp_no, cmdresp_result, | |
857 | le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num)); | |
868093a9 ZL |
858 | mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp, |
859 | le16_to_cpu(resp->size)); | |
5e6e3a92 BZ |
860 | |
861 | if (!(orig_cmdresp_no & HostCmd_RET_BIT)) { | |
acebe8c1 | 862 | mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n"); |
600f5d90 AK |
863 | if (adapter->curr_cmd->wait_q_enabled) |
864 | adapter->cmd_wait_q.status = -1; | |
5e6e3a92 | 865 | |
9908b074 | 866 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
5e6e3a92 BZ |
867 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
868 | adapter->curr_cmd = NULL; | |
869 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); | |
870 | return -1; | |
871 | } | |
872 | ||
873 | if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) { | |
874 | adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD; | |
aea0701e YAP |
875 | if ((cmdresp_result == HostCmd_RESULT_OK) && |
876 | (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH)) | |
5e6e3a92 BZ |
877 | ret = mwifiex_ret_802_11_hs_cfg(priv, resp); |
878 | } else { | |
879 | /* handle response */ | |
600f5d90 | 880 | ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp); |
5e6e3a92 BZ |
881 | } |
882 | ||
883 | /* Check init command response */ | |
884 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) { | |
a0f6d6ca | 885 | if (ret) { |
acebe8c1 ZL |
886 | mwifiex_dbg(adapter, ERROR, |
887 | "%s: cmd %#x failed during\t" | |
888 | "initialization\n", __func__, cmdresp_no); | |
5e6e3a92 BZ |
889 | mwifiex_init_fw_complete(adapter); |
890 | return -1; | |
891 | } else if (adapter->last_init_cmd == cmdresp_no) | |
892 | adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE; | |
893 | } | |
894 | ||
895 | if (adapter->curr_cmd) { | |
a0f6d6ca AK |
896 | if (adapter->curr_cmd->wait_q_enabled) |
897 | adapter->cmd_wait_q.status = ret; | |
5e6e3a92 | 898 | |
9908b074 | 899 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
5e6e3a92 BZ |
900 | |
901 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); | |
902 | adapter->curr_cmd = NULL; | |
903 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); | |
904 | } | |
905 | ||
906 | return ret; | |
907 | } | |
908 | ||
909 | /* | |
910 | * This function handles the timeout of command sending. | |
911 | * | |
912 | * It will re-send the same command again. | |
913 | */ | |
914 | void | |
915 | mwifiex_cmd_timeout_func(unsigned long function_context) | |
916 | { | |
917 | struct mwifiex_adapter *adapter = | |
918 | (struct mwifiex_adapter *) function_context; | |
270e58e8 | 919 | struct cmd_ctrl_node *cmd_node; |
5e6e3a92 | 920 | |
0c9c4a09 | 921 | adapter->is_cmd_timedout = 1; |
5e6e3a92 | 922 | if (!adapter->curr_cmd) { |
acebe8c1 ZL |
923 | mwifiex_dbg(adapter, ERROR, |
924 | "cmd: empty curr_cmd\n"); | |
5e6e3a92 BZ |
925 | return; |
926 | } | |
927 | cmd_node = adapter->curr_cmd; | |
5e6e3a92 BZ |
928 | if (cmd_node) { |
929 | adapter->dbg.timeout_cmd_id = | |
930 | adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index]; | |
931 | adapter->dbg.timeout_cmd_act = | |
932 | adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index]; | |
acebe8c1 ZL |
933 | mwifiex_dbg(adapter, MSG, |
934 | "%s: Timeout cmd id = %#x, act = %#x\n", __func__, | |
935 | adapter->dbg.timeout_cmd_id, | |
936 | adapter->dbg.timeout_cmd_act); | |
937 | ||
938 | mwifiex_dbg(adapter, MSG, | |
939 | "num_data_h2c_failure = %d\n", | |
940 | adapter->dbg.num_tx_host_to_card_failure); | |
941 | mwifiex_dbg(adapter, MSG, | |
942 | "num_cmd_h2c_failure = %d\n", | |
943 | adapter->dbg.num_cmd_host_to_card_failure); | |
944 | ||
945 | mwifiex_dbg(adapter, MSG, | |
946 | "is_cmd_timedout = %d\n", | |
947 | adapter->is_cmd_timedout); | |
948 | mwifiex_dbg(adapter, MSG, | |
949 | "num_tx_timeout = %d\n", | |
950 | adapter->dbg.num_tx_timeout); | |
951 | ||
952 | mwifiex_dbg(adapter, MSG, | |
953 | "last_cmd_index = %d\n", | |
954 | adapter->dbg.last_cmd_index); | |
955 | mwifiex_dbg(adapter, MSG, | |
956 | "last_cmd_id: %*ph\n", | |
957 | (int)sizeof(adapter->dbg.last_cmd_id), | |
958 | adapter->dbg.last_cmd_id); | |
959 | mwifiex_dbg(adapter, MSG, | |
960 | "last_cmd_act: %*ph\n", | |
961 | (int)sizeof(adapter->dbg.last_cmd_act), | |
962 | adapter->dbg.last_cmd_act); | |
963 | ||
964 | mwifiex_dbg(adapter, MSG, | |
965 | "last_cmd_resp_index = %d\n", | |
966 | adapter->dbg.last_cmd_resp_index); | |
967 | mwifiex_dbg(adapter, MSG, | |
968 | "last_cmd_resp_id: %*ph\n", | |
969 | (int)sizeof(adapter->dbg.last_cmd_resp_id), | |
970 | adapter->dbg.last_cmd_resp_id); | |
971 | ||
972 | mwifiex_dbg(adapter, MSG, | |
973 | "last_event_index = %d\n", | |
974 | adapter->dbg.last_event_index); | |
975 | mwifiex_dbg(adapter, MSG, | |
976 | "last_event: %*ph\n", | |
977 | (int)sizeof(adapter->dbg.last_event), | |
978 | adapter->dbg.last_event); | |
979 | ||
980 | mwifiex_dbg(adapter, MSG, | |
981 | "data_sent=%d cmd_sent=%d\n", | |
982 | adapter->data_sent, adapter->cmd_sent); | |
983 | ||
984 | mwifiex_dbg(adapter, MSG, | |
985 | "ps_mode=%d ps_state=%d\n", | |
986 | adapter->ps_mode, adapter->ps_state); | |
b1a47aa5 BZ |
987 | |
988 | if (cmd_node->wait_q_enabled) { | |
989 | adapter->cmd_wait_q.status = -ETIMEDOUT; | |
990 | wake_up_interruptible(&adapter->cmd_wait_q.wait); | |
991 | mwifiex_cancel_pending_ioctl(adapter); | |
b1a47aa5 | 992 | } |
5e6e3a92 BZ |
993 | } |
994 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) | |
995 | mwifiex_init_fw_complete(adapter); | |
d31ab357 | 996 | |
fc697159 AK |
997 | if (adapter->if_ops.device_dump) |
998 | adapter->if_ops.device_dump(adapter); | |
92c2538f | 999 | |
d31ab357 AK |
1000 | if (adapter->if_ops.card_reset) |
1001 | adapter->if_ops.card_reset(adapter); | |
5e6e3a92 BZ |
1002 | } |
1003 | ||
1004 | /* | |
1005 | * This function cancels all the pending commands. | |
1006 | * | |
1007 | * The current command, all commands in command pending queue and all scan | |
1008 | * commands in scan pending queue are cancelled. All the completion callbacks | |
1009 | * are called with failure status to ensure cleanup. | |
1010 | */ | |
1011 | void | |
1012 | mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter) | |
1013 | { | |
270e58e8 | 1014 | struct cmd_ctrl_node *cmd_node = NULL, *tmp_node; |
4af2bd49 AK |
1015 | unsigned long flags, cmd_flags; |
1016 | struct mwifiex_private *priv; | |
1017 | int i; | |
5e6e3a92 | 1018 | |
a7488c79 | 1019 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
5e6e3a92 | 1020 | /* Cancel current cmd */ |
600f5d90 | 1021 | if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) { |
600f5d90 | 1022 | adapter->curr_cmd->wait_q_enabled = false; |
600f5d90 | 1023 | adapter->cmd_wait_q.status = -1; |
efaaa8b8 | 1024 | mwifiex_complete_cmd(adapter, adapter->curr_cmd); |
5e6e3a92 BZ |
1025 | } |
1026 | /* Cancel all pending command */ | |
1027 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
1028 | list_for_each_entry_safe(cmd_node, tmp_node, | |
1029 | &adapter->cmd_pending_q, list) { | |
1030 | list_del(&cmd_node->list); | |
1031 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
1032 | ||
600f5d90 AK |
1033 | if (cmd_node->wait_q_enabled) { |
1034 | adapter->cmd_wait_q.status = -1; | |
efaaa8b8 | 1035 | mwifiex_complete_cmd(adapter, cmd_node); |
600f5d90 | 1036 | cmd_node->wait_q_enabled = false; |
5e6e3a92 | 1037 | } |
9908b074 | 1038 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
5e6e3a92 BZ |
1039 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
1040 | } | |
1041 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
a7488c79 | 1042 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
5e6e3a92 BZ |
1043 | |
1044 | /* Cancel all pending scan command */ | |
1045 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); | |
1046 | list_for_each_entry_safe(cmd_node, tmp_node, | |
1047 | &adapter->scan_pending_q, list) { | |
1048 | list_del(&cmd_node->list); | |
5e6e3a92 | 1049 | |
600f5d90 | 1050 | cmd_node->wait_q_enabled = false; |
5e6e3a92 | 1051 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
5e6e3a92 BZ |
1052 | } |
1053 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); | |
1054 | ||
4af2bd49 AK |
1055 | if (adapter->scan_processing) { |
1056 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); | |
1057 | adapter->scan_processing = false; | |
1058 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); | |
1059 | for (i = 0; i < adapter->priv_num; i++) { | |
1060 | priv = adapter->priv[i]; | |
1061 | if (!priv) | |
1062 | continue; | |
1063 | if (priv->scan_request) { | |
acebe8c1 | 1064 | mwifiex_dbg(adapter, WARN, "info: aborting scan\n"); |
4af2bd49 AK |
1065 | cfg80211_scan_done(priv->scan_request, 1); |
1066 | priv->scan_request = NULL; | |
1067 | } | |
1068 | } | |
1069 | } | |
5e6e3a92 BZ |
1070 | } |
1071 | ||
1072 | /* | |
1073 | * This function cancels all pending commands that matches with | |
1074 | * the given IOCTL request. | |
1075 | * | |
1076 | * Both the current command buffer and the pending command queue are | |
1077 | * searched for matching IOCTL request. The completion callback of | |
1078 | * the matched command is called with failure status to ensure cleanup. | |
1079 | * In case of scan commands, all pending commands in scan pending queue | |
1080 | * are cancelled. | |
1081 | */ | |
1082 | void | |
600f5d90 | 1083 | mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter) |
5e6e3a92 BZ |
1084 | { |
1085 | struct cmd_ctrl_node *cmd_node = NULL, *tmp_node = NULL; | |
1086 | unsigned long cmd_flags; | |
5e6e3a92 | 1087 | unsigned long scan_pending_q_flags; |
4af2bd49 AK |
1088 | struct mwifiex_private *priv; |
1089 | int i; | |
5e6e3a92 BZ |
1090 | |
1091 | if ((adapter->curr_cmd) && | |
aea0701e | 1092 | (adapter->curr_cmd->wait_q_enabled)) { |
5e6e3a92 BZ |
1093 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
1094 | cmd_node = adapter->curr_cmd; | |
600f5d90 | 1095 | cmd_node->wait_q_enabled = false; |
5e6e3a92 | 1096 | cmd_node->cmd_flag |= CMD_F_CANCELED; |
9908b074 | 1097 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
51e708c1 YAP |
1098 | mwifiex_complete_cmd(adapter, adapter->curr_cmd); |
1099 | adapter->curr_cmd = NULL; | |
600f5d90 | 1100 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
5e6e3a92 | 1101 | } |
600f5d90 | 1102 | |
5e6e3a92 BZ |
1103 | /* Cancel all pending scan command */ |
1104 | spin_lock_irqsave(&adapter->scan_pending_q_lock, | |
1105 | scan_pending_q_flags); | |
1106 | list_for_each_entry_safe(cmd_node, tmp_node, | |
1107 | &adapter->scan_pending_q, list) { | |
600f5d90 | 1108 | list_del(&cmd_node->list); |
600f5d90 AK |
1109 | cmd_node->wait_q_enabled = false; |
1110 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); | |
5e6e3a92 BZ |
1111 | } |
1112 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, | |
1113 | scan_pending_q_flags); | |
1114 | ||
4af2bd49 | 1115 | if (adapter->scan_processing) { |
5e6e3a92 BZ |
1116 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
1117 | adapter->scan_processing = false; | |
1118 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); | |
4af2bd49 AK |
1119 | for (i = 0; i < adapter->priv_num; i++) { |
1120 | priv = adapter->priv[i]; | |
1121 | if (!priv) | |
1122 | continue; | |
1123 | if (priv->scan_request) { | |
acebe8c1 | 1124 | mwifiex_dbg(adapter, WARN, "info: aborting scan\n"); |
4af2bd49 AK |
1125 | cfg80211_scan_done(priv->scan_request, 1); |
1126 | priv->scan_request = NULL; | |
1127 | } | |
1128 | } | |
5e6e3a92 | 1129 | } |
600f5d90 | 1130 | adapter->cmd_wait_q.status = -1; |
5e6e3a92 BZ |
1131 | } |
1132 | ||
1133 | /* | |
1134 | * This function sends the sleep confirm command to firmware, if | |
1135 | * possible. | |
1136 | * | |
1137 | * The sleep confirm command cannot be issued if command response, | |
1138 | * data response or event response is awaiting handling, or if we | |
1139 | * are in the middle of sending a command, or expecting a command | |
1140 | * response. | |
1141 | */ | |
1142 | void | |
1143 | mwifiex_check_ps_cond(struct mwifiex_adapter *adapter) | |
1144 | { | |
1145 | if (!adapter->cmd_sent && | |
1146 | !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter)) | |
1147 | mwifiex_dnld_sleep_confirm_cmd(adapter); | |
1148 | else | |
acebe8c1 ZL |
1149 | mwifiex_dbg(adapter, CMD, |
1150 | "cmd: Delay Sleep Confirm (%s%s%s)\n", | |
1151 | (adapter->cmd_sent) ? "D" : "", | |
1152 | (adapter->curr_cmd) ? "C" : "", | |
1153 | (IS_CARD_RX_RCVD(adapter)) ? "R" : ""); | |
5e6e3a92 BZ |
1154 | } |
1155 | ||
1156 | /* | |
1157 | * This function sends a Host Sleep activated event to applications. | |
1158 | * | |
1159 | * This event is generated by the driver, with a blank event body. | |
1160 | */ | |
1161 | void | |
1162 | mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated) | |
1163 | { | |
1164 | if (activated) { | |
1165 | if (priv->adapter->is_hs_configured) { | |
1166 | priv->adapter->hs_activated = true; | |
2db96c3d AP |
1167 | mwifiex_update_rxreor_flags(priv->adapter, |
1168 | RXREOR_FORCE_NO_DROP); | |
acebe8c1 ZL |
1169 | mwifiex_dbg(priv->adapter, EVENT, |
1170 | "event: hs_activated\n"); | |
5e6e3a92 BZ |
1171 | priv->adapter->hs_activate_wait_q_woken = true; |
1172 | wake_up_interruptible( | |
1173 | &priv->adapter->hs_activate_wait_q); | |
1174 | } else { | |
acebe8c1 ZL |
1175 | mwifiex_dbg(priv->adapter, EVENT, |
1176 | "event: HS not configured\n"); | |
5e6e3a92 BZ |
1177 | } |
1178 | } else { | |
acebe8c1 ZL |
1179 | mwifiex_dbg(priv->adapter, EVENT, |
1180 | "event: hs_deactivated\n"); | |
5e6e3a92 BZ |
1181 | priv->adapter->hs_activated = false; |
1182 | } | |
1183 | } | |
1184 | ||
1185 | /* | |
1186 | * This function handles the command response of a Host Sleep configuration | |
1187 | * command. | |
1188 | * | |
1189 | * Handling includes changing the header fields into CPU format | |
1190 | * and setting the current host sleep activation status in driver. | |
1191 | * | |
1192 | * In case host sleep status change, the function generates an event to | |
1193 | * notify the applications. | |
1194 | */ | |
1195 | int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv, | |
1196 | struct host_cmd_ds_command *resp) | |
1197 | { | |
1198 | struct mwifiex_adapter *adapter = priv->adapter; | |
1199 | struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg = | |
1200 | &resp->params.opt_hs_cfg; | |
1201 | uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions); | |
1202 | ||
a4186ea6 | 1203 | if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) && |
b7be1522 | 1204 | adapter->iface_type != MWIFIEX_USB) { |
5e6e3a92 BZ |
1205 | mwifiex_hs_activated_event(priv, true); |
1206 | return 0; | |
1207 | } else { | |
acebe8c1 ZL |
1208 | mwifiex_dbg(adapter, CMD, |
1209 | "cmd: CMD_RESP: HS_CFG cmd reply\t" | |
1210 | " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n", | |
1211 | resp->result, conditions, | |
1212 | phs_cfg->params.hs_config.gpio, | |
1213 | phs_cfg->params.hs_config.gap); | |
5e6e3a92 | 1214 | } |
cc0b5a64 | 1215 | if (conditions != HS_CFG_CANCEL) { |
5e6e3a92 | 1216 | adapter->is_hs_configured = true; |
b7be1522 | 1217 | if (adapter->iface_type == MWIFIEX_USB) |
a4186ea6 | 1218 | mwifiex_hs_activated_event(priv, true); |
5e6e3a92 BZ |
1219 | } else { |
1220 | adapter->is_hs_configured = false; | |
1221 | if (adapter->hs_activated) | |
1222 | mwifiex_hs_activated_event(priv, false); | |
1223 | } | |
1224 | ||
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | /* | |
1229 | * This function wakes up the adapter and generates a Host Sleep | |
1230 | * cancel event on receiving the power up interrupt. | |
1231 | */ | |
1232 | void | |
1233 | mwifiex_process_hs_config(struct mwifiex_adapter *adapter) | |
1234 | { | |
acebe8c1 ZL |
1235 | mwifiex_dbg(adapter, INFO, |
1236 | "info: %s: auto cancelling host sleep\t" | |
1237 | "since there is interrupt from the firmware\n", | |
1238 | __func__); | |
5e6e3a92 BZ |
1239 | |
1240 | adapter->if_ops.wakeup(adapter); | |
1241 | adapter->hs_activated = false; | |
1242 | adapter->is_hs_configured = false; | |
48795424 | 1243 | adapter->is_suspended = false; |
5e6e3a92 | 1244 | mwifiex_hs_activated_event(mwifiex_get_priv(adapter, |
aea0701e YAP |
1245 | MWIFIEX_BSS_ROLE_ANY), |
1246 | false); | |
5e6e3a92 | 1247 | } |
4daffe35 | 1248 | EXPORT_SYMBOL_GPL(mwifiex_process_hs_config); |
5e6e3a92 BZ |
1249 | |
1250 | /* | |
1251 | * This function handles the command response of a sleep confirm command. | |
1252 | * | |
1253 | * The function sets the card state to SLEEP if the response indicates success. | |
1254 | */ | |
1255 | void | |
1256 | mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter, | |
1257 | u8 *pbuf, u32 upld_len) | |
1258 | { | |
1259 | struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf; | |
1260 | struct mwifiex_private *priv = | |
1261 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
1262 | uint16_t result = le16_to_cpu(cmd->result); | |
1263 | uint16_t command = le16_to_cpu(cmd->command); | |
1264 | uint16_t seq_num = le16_to_cpu(cmd->seq_num); | |
1265 | ||
1266 | if (!upld_len) { | |
acebe8c1 ZL |
1267 | mwifiex_dbg(adapter, ERROR, |
1268 | "%s: cmd size is 0\n", __func__); | |
5e6e3a92 BZ |
1269 | return; |
1270 | } | |
1271 | ||
acebe8c1 ZL |
1272 | mwifiex_dbg(adapter, CMD, |
1273 | "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n", | |
1274 | command, result, le16_to_cpu(cmd->size), seq_num); | |
363c1b4f | 1275 | |
5e6e3a92 BZ |
1276 | /* Get BSS number and corresponding priv */ |
1277 | priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num), | |
1278 | HostCmd_GET_BSS_TYPE(seq_num)); | |
1279 | if (!priv) | |
1280 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
1281 | ||
1282 | /* Update sequence number */ | |
1283 | seq_num = HostCmd_GET_SEQ_NO(seq_num); | |
1284 | /* Clear RET_BIT from HostCmd */ | |
1285 | command &= HostCmd_CMD_ID_MASK; | |
1286 | ||
1287 | if (command != HostCmd_CMD_802_11_PS_MODE_ENH) { | |
acebe8c1 ZL |
1288 | mwifiex_dbg(adapter, ERROR, |
1289 | "%s: rcvd unexpected resp for cmd %#x, result = %x\n", | |
1290 | __func__, command, result); | |
5e6e3a92 BZ |
1291 | return; |
1292 | } | |
1293 | ||
1294 | if (result) { | |
acebe8c1 ZL |
1295 | mwifiex_dbg(adapter, ERROR, |
1296 | "%s: sleep confirm cmd failed\n", | |
1297 | __func__); | |
5e6e3a92 BZ |
1298 | adapter->pm_wakeup_card_req = false; |
1299 | adapter->ps_state = PS_STATE_AWAKE; | |
1300 | return; | |
1301 | } | |
1302 | adapter->pm_wakeup_card_req = true; | |
1303 | if (adapter->is_hs_configured) | |
aea0701e YAP |
1304 | mwifiex_hs_activated_event(mwifiex_get_priv |
1305 | (adapter, MWIFIEX_BSS_ROLE_ANY), | |
1306 | true); | |
5e6e3a92 BZ |
1307 | adapter->ps_state = PS_STATE_SLEEP; |
1308 | cmd->command = cpu_to_le16(command); | |
1309 | cmd->seq_num = cpu_to_le16(seq_num); | |
1310 | } | |
1311 | EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp); | |
1312 | ||
1313 | /* | |
1314 | * This function prepares an enhanced power mode command. | |
1315 | * | |
1316 | * This function can be used to disable power save or to configure | |
1317 | * power save with auto PS or STA PS or auto deep sleep. | |
1318 | * | |
1319 | * Preparation includes - | |
1320 | * - Setting command ID, action and proper size | |
1321 | * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV, | |
1322 | * auto deep sleep TLV (as required) | |
1323 | * - Ensuring correct endian-ness | |
1324 | */ | |
1325 | int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv, | |
1326 | struct host_cmd_ds_command *cmd, | |
1327 | u16 cmd_action, uint16_t ps_bitmap, | |
a5ffddb7 | 1328 | struct mwifiex_ds_auto_ds *auto_ds) |
5e6e3a92 BZ |
1329 | { |
1330 | struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh = | |
1331 | &cmd->params.psmode_enh; | |
270e58e8 | 1332 | u8 *tlv; |
5e6e3a92 BZ |
1333 | u16 cmd_size = 0; |
1334 | ||
1335 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH); | |
1336 | if (cmd_action == DIS_AUTO_PS) { | |
1337 | psmode_enh->action = cpu_to_le16(DIS_AUTO_PS); | |
1338 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); | |
2b06bdbe | 1339 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) + |
aea0701e | 1340 | sizeof(psmode_enh->params.ps_bitmap)); |
5e6e3a92 BZ |
1341 | } else if (cmd_action == GET_PS) { |
1342 | psmode_enh->action = cpu_to_le16(GET_PS); | |
1343 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); | |
2b06bdbe | 1344 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) + |
aea0701e | 1345 | sizeof(psmode_enh->params.ps_bitmap)); |
5e6e3a92 BZ |
1346 | } else if (cmd_action == EN_AUTO_PS) { |
1347 | psmode_enh->action = cpu_to_le16(EN_AUTO_PS); | |
2b06bdbe MY |
1348 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); |
1349 | cmd_size = S_DS_GEN + sizeof(psmode_enh->action) + | |
aea0701e | 1350 | sizeof(psmode_enh->params.ps_bitmap); |
5e6e3a92 BZ |
1351 | tlv = (u8 *) cmd + cmd_size; |
1352 | if (ps_bitmap & BITMAP_STA_PS) { | |
1353 | struct mwifiex_adapter *adapter = priv->adapter; | |
1354 | struct mwifiex_ie_types_ps_param *ps_tlv = | |
1355 | (struct mwifiex_ie_types_ps_param *) tlv; | |
1356 | struct mwifiex_ps_param *ps_mode = &ps_tlv->param; | |
1357 | ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM); | |
1358 | ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) - | |
1359 | sizeof(struct mwifiex_ie_types_header)); | |
1360 | cmd_size += sizeof(*ps_tlv); | |
1361 | tlv += sizeof(*ps_tlv); | |
acebe8c1 ZL |
1362 | mwifiex_dbg(priv->adapter, CMD, |
1363 | "cmd: PS Command: Enter PS\n"); | |
5e6e3a92 | 1364 | ps_mode->null_pkt_interval = |
aea0701e | 1365 | cpu_to_le16(adapter->null_pkt_interval); |
5e6e3a92 | 1366 | ps_mode->multiple_dtims = |
aea0701e | 1367 | cpu_to_le16(adapter->multiple_dtim); |
5e6e3a92 | 1368 | ps_mode->bcn_miss_timeout = |
aea0701e | 1369 | cpu_to_le16(adapter->bcn_miss_time_out); |
5e6e3a92 BZ |
1370 | ps_mode->local_listen_interval = |
1371 | cpu_to_le16(adapter->local_listen_interval); | |
1372 | ps_mode->adhoc_wake_period = | |
1373 | cpu_to_le16(adapter->adhoc_awake_period); | |
1374 | ps_mode->delay_to_ps = | |
aea0701e YAP |
1375 | cpu_to_le16(adapter->delay_to_ps); |
1376 | ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode); | |
5e6e3a92 BZ |
1377 | |
1378 | } | |
1379 | if (ps_bitmap & BITMAP_AUTO_DS) { | |
2b06bdbe | 1380 | struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv = |
5e6e3a92 | 1381 | (struct mwifiex_ie_types_auto_ds_param *) tlv; |
5e6e3a92 | 1382 | u16 idletime = 0; |
2b06bdbe MY |
1383 | |
1384 | auto_ds_tlv->header.type = | |
5e6e3a92 | 1385 | cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM); |
2b06bdbe MY |
1386 | auto_ds_tlv->header.len = |
1387 | cpu_to_le16(sizeof(*auto_ds_tlv) - | |
5e6e3a92 | 1388 | sizeof(struct mwifiex_ie_types_header)); |
2b06bdbe MY |
1389 | cmd_size += sizeof(*auto_ds_tlv); |
1390 | tlv += sizeof(*auto_ds_tlv); | |
a5ffddb7 AK |
1391 | if (auto_ds) |
1392 | idletime = auto_ds->idle_time; | |
acebe8c1 ZL |
1393 | mwifiex_dbg(priv->adapter, CMD, |
1394 | "cmd: PS Command: Enter Auto Deep Sleep\n"); | |
2b06bdbe | 1395 | auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime); |
5e6e3a92 BZ |
1396 | } |
1397 | cmd->size = cpu_to_le16(cmd_size); | |
1398 | } | |
1399 | return 0; | |
1400 | } | |
1401 | ||
1402 | /* | |
1403 | * This function handles the command response of an enhanced power mode | |
1404 | * command. | |
1405 | * | |
1406 | * Handling includes changing the header fields into CPU format | |
1407 | * and setting the current enhanced power mode in driver. | |
1408 | */ | |
1409 | int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv, | |
1410 | struct host_cmd_ds_command *resp, | |
a5ffddb7 | 1411 | struct mwifiex_ds_pm_cfg *pm_cfg) |
5e6e3a92 BZ |
1412 | { |
1413 | struct mwifiex_adapter *adapter = priv->adapter; | |
1414 | struct host_cmd_ds_802_11_ps_mode_enh *ps_mode = | |
1415 | &resp->params.psmode_enh; | |
1416 | uint16_t action = le16_to_cpu(ps_mode->action); | |
1417 | uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap); | |
1418 | uint16_t auto_ps_bitmap = | |
2b06bdbe | 1419 | le16_to_cpu(ps_mode->params.ps_bitmap); |
5e6e3a92 | 1420 | |
acebe8c1 ZL |
1421 | mwifiex_dbg(adapter, INFO, |
1422 | "info: %s: PS_MODE cmd reply result=%#x action=%#X\n", | |
1423 | __func__, resp->result, action); | |
5e6e3a92 BZ |
1424 | if (action == EN_AUTO_PS) { |
1425 | if (auto_ps_bitmap & BITMAP_AUTO_DS) { | |
acebe8c1 ZL |
1426 | mwifiex_dbg(adapter, CMD, |
1427 | "cmd: Enabled auto deep sleep\n"); | |
5e6e3a92 BZ |
1428 | priv->adapter->is_deep_sleep = true; |
1429 | } | |
1430 | if (auto_ps_bitmap & BITMAP_STA_PS) { | |
acebe8c1 ZL |
1431 | mwifiex_dbg(adapter, CMD, |
1432 | "cmd: Enabled STA power save\n"); | |
5e6e3a92 | 1433 | if (adapter->sleep_period.period) |
acebe8c1 ZL |
1434 | mwifiex_dbg(adapter, CMD, |
1435 | "cmd: set to uapsd/pps mode\n"); | |
5e6e3a92 BZ |
1436 | } |
1437 | } else if (action == DIS_AUTO_PS) { | |
1438 | if (ps_bitmap & BITMAP_AUTO_DS) { | |
1439 | priv->adapter->is_deep_sleep = false; | |
acebe8c1 ZL |
1440 | mwifiex_dbg(adapter, CMD, |
1441 | "cmd: Disabled auto deep sleep\n"); | |
5e6e3a92 BZ |
1442 | } |
1443 | if (ps_bitmap & BITMAP_STA_PS) { | |
acebe8c1 ZL |
1444 | mwifiex_dbg(adapter, CMD, |
1445 | "cmd: Disabled STA power save\n"); | |
5e6e3a92 BZ |
1446 | if (adapter->sleep_period.period) { |
1447 | adapter->delay_null_pkt = false; | |
1448 | adapter->tx_lock_flag = false; | |
1449 | adapter->pps_uapsd_mode = false; | |
1450 | } | |
1451 | } | |
1452 | } else if (action == GET_PS) { | |
2b06bdbe | 1453 | if (ps_bitmap & BITMAP_STA_PS) |
5e6e3a92 BZ |
1454 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; |
1455 | else | |
1456 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; | |
1457 | ||
acebe8c1 ZL |
1458 | mwifiex_dbg(adapter, CMD, |
1459 | "cmd: ps_bitmap=%#x\n", ps_bitmap); | |
5e6e3a92 | 1460 | |
a5ffddb7 | 1461 | if (pm_cfg) { |
5e6e3a92 | 1462 | /* This section is for get power save mode */ |
5e6e3a92 BZ |
1463 | if (ps_bitmap & BITMAP_STA_PS) |
1464 | pm_cfg->param.ps_mode = 1; | |
1465 | else | |
1466 | pm_cfg->param.ps_mode = 0; | |
1467 | } | |
1468 | } | |
1469 | return 0; | |
1470 | } | |
1471 | ||
1472 | /* | |
1473 | * This function prepares command to get hardware specifications. | |
1474 | * | |
1475 | * Preparation includes - | |
1476 | * - Setting command ID, action and proper size | |
1477 | * - Setting permanent address parameter | |
1478 | * - Ensuring correct endian-ness | |
1479 | */ | |
1480 | int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv, | |
1481 | struct host_cmd_ds_command *cmd) | |
1482 | { | |
1483 | struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec; | |
1484 | ||
1485 | cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC); | |
1486 | cmd->size = | |
1487 | cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN); | |
1488 | memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN); | |
1489 | ||
1490 | return 0; | |
1491 | } | |
1492 | ||
1493 | /* | |
1494 | * This function handles the command response of get hardware | |
1495 | * specifications. | |
1496 | * | |
1497 | * Handling includes changing the header fields into CPU format | |
1498 | * and saving/updating the following parameters in driver - | |
1499 | * - Firmware capability information | |
1500 | * - Firmware band settings | |
1501 | * - Ad-hoc start band and channel | |
1502 | * - Ad-hoc 11n activation status | |
1503 | * - Firmware release number | |
1504 | * - Number of antennas | |
1505 | * - Hardware address | |
1506 | * - Hardware interface version | |
1507 | * - Firmware version | |
1508 | * - Region code | |
1509 | * - 11n capabilities | |
1510 | * - MCS support fields | |
1511 | * - MP end port | |
1512 | */ | |
1513 | int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, | |
1514 | struct host_cmd_ds_command *resp) | |
1515 | { | |
1516 | struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec; | |
1517 | struct mwifiex_adapter *adapter = priv->adapter; | |
7f445d04 | 1518 | struct mwifiex_ie_types_header *tlv; |
4b9fede5 | 1519 | struct hw_spec_api_rev *api_rev; |
7f445d04 AP |
1520 | u16 resp_size, api_id; |
1521 | int i, left_len, parsed_len = 0; | |
5e6e3a92 BZ |
1522 | |
1523 | adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info); | |
1524 | ||
1525 | if (IS_SUPPORT_MULTI_BANDS(adapter)) | |
1526 | adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter); | |
1527 | else | |
1528 | adapter->fw_bands = BAND_B; | |
1529 | ||
1530 | adapter->config_bands = adapter->fw_bands; | |
1531 | ||
1532 | if (adapter->fw_bands & BAND_A) { | |
1533 | if (adapter->fw_bands & BAND_GN) { | |
1534 | adapter->config_bands |= BAND_AN; | |
1535 | adapter->fw_bands |= BAND_AN; | |
1536 | } | |
1537 | if (adapter->fw_bands & BAND_AN) { | |
1538 | adapter->adhoc_start_band = BAND_A | BAND_AN; | |
1539 | adapter->adhoc_11n_enabled = true; | |
1540 | } else { | |
1541 | adapter->adhoc_start_band = BAND_A; | |
1542 | } | |
1543 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A; | |
1544 | } else if (adapter->fw_bands & BAND_GN) { | |
1545 | adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN; | |
1546 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; | |
1547 | adapter->adhoc_11n_enabled = true; | |
1548 | } else if (adapter->fw_bands & BAND_G) { | |
1549 | adapter->adhoc_start_band = BAND_G | BAND_B; | |
1550 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; | |
1551 | } else if (adapter->fw_bands & BAND_B) { | |
1552 | adapter->adhoc_start_band = BAND_B; | |
1553 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; | |
1554 | } | |
1555 | ||
1556 | adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number); | |
4721c63b | 1557 | adapter->fw_api_ver = (adapter->fw_release_number >> 16) & 0xff; |
5e6e3a92 BZ |
1558 | adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna); |
1559 | ||
a5f39056 YAP |
1560 | if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) { |
1561 | adapter->is_hw_11ac_capable = true; | |
1562 | ||
1563 | /* Copy 11AC cap */ | |
1564 | adapter->hw_dot_11ac_dev_cap = | |
1565 | le32_to_cpu(hw_spec->dot_11ac_dev_cap); | |
79d9a54c AK |
1566 | adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap |
1567 | & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK; | |
1568 | adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap | |
1569 | & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK; | |
a5f39056 YAP |
1570 | |
1571 | /* Copy 11AC mcs */ | |
1572 | adapter->hw_dot_11ac_mcs_support = | |
1573 | le32_to_cpu(hw_spec->dot_11ac_mcs_support); | |
1574 | adapter->usr_dot_11ac_mcs_support = | |
1575 | adapter->hw_dot_11ac_mcs_support; | |
1576 | } else { | |
1577 | adapter->is_hw_11ac_capable = false; | |
1578 | } | |
1579 | ||
7f445d04 AP |
1580 | resp_size = le16_to_cpu(resp->size) - S_DS_GEN; |
1581 | if (resp_size > sizeof(struct host_cmd_ds_get_hw_spec)) { | |
1582 | /* we have variable HW SPEC information */ | |
1583 | left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec); | |
1584 | while (left_len > sizeof(struct mwifiex_ie_types_header)) { | |
1585 | tlv = (void *)&hw_spec->tlvs + parsed_len; | |
1586 | switch (le16_to_cpu(tlv->type)) { | |
4b9fede5 AK |
1587 | case TLV_TYPE_API_REV: |
1588 | api_rev = (struct hw_spec_api_rev *)tlv; | |
7f445d04 AP |
1589 | api_id = le16_to_cpu(api_rev->api_id); |
1590 | switch (api_id) { | |
1591 | case KEY_API_VER_ID: | |
4b9fede5 | 1592 | adapter->key_api_major_ver = |
7f445d04 | 1593 | api_rev->major_ver; |
4b9fede5 | 1594 | adapter->key_api_minor_ver = |
7f445d04 | 1595 | api_rev->minor_ver; |
acebe8c1 ZL |
1596 | mwifiex_dbg(adapter, INFO, |
1597 | "key_api v%d.%d\n", | |
1598 | adapter->key_api_major_ver, | |
1599 | adapter->key_api_minor_ver); | |
7f445d04 | 1600 | break; |
89be7ceb AK |
1601 | case FW_API_VER_ID: |
1602 | adapter->fw_api_ver = | |
1603 | api_rev->major_ver; | |
acebe8c1 ZL |
1604 | mwifiex_dbg(adapter, INFO, |
1605 | "Firmware api version %d\n", | |
1606 | adapter->fw_api_ver); | |
89be7ceb | 1607 | break; |
7f445d04 | 1608 | default: |
acebe8c1 ZL |
1609 | mwifiex_dbg(adapter, FATAL, |
1610 | "Unknown api_id: %d\n", | |
1611 | api_id); | |
7f445d04 AP |
1612 | break; |
1613 | } | |
1614 | break; | |
1615 | default: | |
acebe8c1 ZL |
1616 | mwifiex_dbg(adapter, FATAL, |
1617 | "Unknown GET_HW_SPEC TLV type: %#x\n", | |
1618 | le16_to_cpu(tlv->type)); | |
7f445d04 AP |
1619 | break; |
1620 | } | |
1621 | parsed_len += le16_to_cpu(tlv->len) + | |
1622 | sizeof(struct mwifiex_ie_types_header); | |
2618d4fb AK |
1623 | left_len -= le16_to_cpu(tlv->len) + |
1624 | sizeof(struct mwifiex_ie_types_header); | |
7f445d04 AP |
1625 | } |
1626 | } | |
1627 | ||
acebe8c1 ZL |
1628 | mwifiex_dbg(adapter, INFO, |
1629 | "info: GET_HW_SPEC: fw_release_number- %#x\n", | |
1630 | adapter->fw_release_number); | |
1631 | mwifiex_dbg(adapter, INFO, | |
1632 | "info: GET_HW_SPEC: permanent addr: %pM\n", | |
1633 | hw_spec->permanent_addr); | |
1634 | mwifiex_dbg(adapter, INFO, | |
1635 | "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n", | |
1636 | le16_to_cpu(hw_spec->hw_if_version), | |
1637 | le16_to_cpu(hw_spec->version)); | |
5e6e3a92 | 1638 | |
8d05eb22 | 1639 | ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr); |
5e6e3a92 BZ |
1640 | adapter->region_code = le16_to_cpu(hw_spec->region_code); |
1641 | ||
1642 | for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++) | |
1643 | /* Use the region code to search for the index */ | |
1644 | if (adapter->region_code == region_code_index[i]) | |
1645 | break; | |
1646 | ||
1647 | /* If it's unidentified region code, use the default (USA) */ | |
1648 | if (i >= MWIFIEX_MAX_REGION_CODE) { | |
1649 | adapter->region_code = 0x10; | |
acebe8c1 ZL |
1650 | mwifiex_dbg(adapter, WARN, |
1651 | "cmd: unknown region code, use default (USA)\n"); | |
5e6e3a92 BZ |
1652 | } |
1653 | ||
1654 | adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap); | |
5e6e3a92 | 1655 | adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support; |
a5333914 | 1656 | adapter->user_dev_mcs_support = adapter->hw_dev_mcs_support; |
5e6e3a92 BZ |
1657 | |
1658 | if (adapter->if_ops.update_mp_end_port) | |
1659 | adapter->if_ops.update_mp_end_port(adapter, | |
1660 | le16_to_cpu(hw_spec->mp_end_port)); | |
1661 | ||
cb91be87 AP |
1662 | if (adapter->fw_api_ver == MWIFIEX_FW_V15) |
1663 | adapter->scan_chan_gap_enabled = true; | |
1664 | ||
5e6e3a92 BZ |
1665 | return 0; |
1666 | } |