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