]>
Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: major functions | |
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 | ||
ef7e0714 JC |
20 | #include <linux/suspend.h> |
21 | ||
5e6e3a92 BZ |
22 | #include "main.h" |
23 | #include "wmm.h" | |
24 | #include "cfg80211.h" | |
25 | #include "11n.h" | |
26 | ||
27 | #define VERSION "1.0" | |
cf5383b0 | 28 | #define MFG_FIRMWARE "mwifiex_mfg.bin" |
5e6e3a92 | 29 | |
c687a007 ZL |
30 | static unsigned int debug_mask = MWIFIEX_DEFAULT_DEBUG_MASK; |
31 | module_param(debug_mask, uint, 0); | |
32 | MODULE_PARM_DESC(debug_mask, "bitmap for debug flags"); | |
33 | ||
5e6e3a92 | 34 | const char driver_version[] = "mwifiex " VERSION " (%s) "; |
388ec385 AK |
35 | static char *cal_data_cfg; |
36 | module_param(cal_data_cfg, charp, 0); | |
5e6e3a92 | 37 | |
0013c7ce AP |
38 | static unsigned short driver_mode; |
39 | module_param(driver_mode, ushort, 0); | |
40 | MODULE_PARM_DESC(driver_mode, | |
41 | "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7"); | |
42 | ||
cf5383b0 XH |
43 | bool mfg_mode; |
44 | module_param(mfg_mode, bool, 0); | |
45 | MODULE_PARM_DESC(mfg_mode, "manufacturing mode enable:1, disable:0"); | |
46 | ||
c5994293 XH |
47 | bool aggr_ctrl; |
48 | module_param(aggr_ctrl, bool, 0000); | |
c5597172 | 49 | MODULE_PARM_DESC(aggr_ctrl, "usb tx aggregation enable:1, disable:0"); |
c5994293 | 50 | |
5e6e3a92 BZ |
51 | /* |
52 | * This function registers the device and performs all the necessary | |
53 | * initializations. | |
54 | * | |
55 | * The following initialization operations are performed - | |
56 | * - Allocate adapter structure | |
57 | * - Save interface specific operations table in adapter | |
58 | * - Call interface specific initialization routine | |
59 | * - Allocate private structures | |
60 | * - Set default adapter structure parameters | |
61 | * - Initialize locks | |
62 | * | |
63 | * In case of any errors during inittialization, this function also ensures | |
64 | * proper cleanup before exiting. | |
65 | */ | |
ba1c7e45 BN |
66 | static int mwifiex_register(void *card, struct device *dev, |
67 | struct mwifiex_if_ops *if_ops, void **padapter) | |
5e6e3a92 | 68 | { |
2be7859f AK |
69 | struct mwifiex_adapter *adapter; |
70 | int i; | |
5e6e3a92 BZ |
71 | |
72 | adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); | |
5e6e3a92 | 73 | if (!adapter) |
b53575ec | 74 | return -ENOMEM; |
5e6e3a92 | 75 | |
287546df | 76 | *padapter = adapter; |
ba1c7e45 | 77 | adapter->dev = dev; |
5e6e3a92 BZ |
78 | adapter->card = card; |
79 | ||
80 | /* Save interface specific operations in adapter */ | |
81 | memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); | |
c687a007 | 82 | adapter->debug_mask = debug_mask; |
5e6e3a92 BZ |
83 | |
84 | /* card specific initialization has been deferred until now .. */ | |
4daffe35 AK |
85 | if (adapter->if_ops.init_if) |
86 | if (adapter->if_ops.init_if(adapter)) | |
87 | goto error; | |
5e6e3a92 BZ |
88 | |
89 | adapter->priv_num = 0; | |
5e6e3a92 | 90 | |
64b05e2f AP |
91 | for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { |
92 | /* Allocate memory for private structure */ | |
93 | adapter->priv[i] = | |
94 | kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL); | |
95 | if (!adapter->priv[i]) | |
96 | goto error; | |
93a1df48 | 97 | |
64b05e2f | 98 | adapter->priv[i]->adapter = adapter; |
64b05e2f AP |
99 | adapter->priv_num++; |
100 | } | |
44b815c6 | 101 | mwifiex_init_lock_list(adapter); |
5e6e3a92 | 102 | |
08c2eb8e | 103 | timer_setup(&adapter->cmd_timer, mwifiex_cmd_timeout_func, 0); |
5e6e3a92 | 104 | |
5e6e3a92 BZ |
105 | return 0; |
106 | ||
107 | error: | |
acebe8c1 ZL |
108 | mwifiex_dbg(adapter, ERROR, |
109 | "info: leave mwifiex_register with error\n"); | |
5e6e3a92 | 110 | |
93a1df48 | 111 | for (i = 0; i < adapter->priv_num; i++) |
5e6e3a92 | 112 | kfree(adapter->priv[i]); |
93a1df48 | 113 | |
5e6e3a92 BZ |
114 | kfree(adapter); |
115 | ||
116 | return -1; | |
117 | } | |
118 | ||
119 | /* | |
120 | * This function unregisters the device and performs all the necessary | |
121 | * cleanups. | |
122 | * | |
123 | * The following cleanup operations are performed - | |
124 | * - Free the timers | |
125 | * - Free beacon buffers | |
126 | * - Free private structures | |
127 | * - Free adapter structure | |
128 | */ | |
129 | static int mwifiex_unregister(struct mwifiex_adapter *adapter) | |
130 | { | |
270e58e8 | 131 | s32 i; |
5e6e3a92 | 132 | |
4cfda67d AK |
133 | if (adapter->if_ops.cleanup_if) |
134 | adapter->if_ops.cleanup_if(adapter); | |
135 | ||
629873f2 | 136 | del_timer_sync(&adapter->cmd_timer); |
5e6e3a92 BZ |
137 | |
138 | /* Free private structures */ | |
139 | for (i = 0; i < adapter->priv_num; i++) { | |
140 | if (adapter->priv[i]) { | |
141 | mwifiex_free_curr_bcn(adapter->priv[i]); | |
142 | kfree(adapter->priv[i]); | |
143 | } | |
144 | } | |
145 | ||
7d7f07d8 | 146 | if (adapter->nd_info) { |
147 | for (i = 0 ; i < adapter->nd_info->n_matches ; i++) | |
148 | kfree(adapter->nd_info->matches[i]); | |
149 | kfree(adapter->nd_info); | |
150 | adapter->nd_info = NULL; | |
151 | } | |
152 | ||
72539799 AK |
153 | kfree(adapter->regd); |
154 | ||
5e6e3a92 BZ |
155 | kfree(adapter); |
156 | return 0; | |
157 | } | |
158 | ||
b2713f67 SL |
159 | void mwifiex_queue_main_work(struct mwifiex_adapter *adapter) |
160 | { | |
161 | unsigned long flags; | |
162 | ||
163 | spin_lock_irqsave(&adapter->main_proc_lock, flags); | |
164 | if (adapter->mwifiex_processing) { | |
165 | adapter->more_task_flag = true; | |
166 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
167 | } else { | |
168 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
169 | queue_work(adapter->workqueue, &adapter->main_work); | |
170 | } | |
171 | } | |
172 | EXPORT_SYMBOL_GPL(mwifiex_queue_main_work); | |
173 | ||
174 | static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter) | |
175 | { | |
176 | unsigned long flags; | |
177 | ||
178 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); | |
179 | if (adapter->rx_processing) { | |
180 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
181 | } else { | |
182 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
183 | queue_work(adapter->rx_workqueue, &adapter->rx_work); | |
184 | } | |
185 | } | |
186 | ||
6e251174 AP |
187 | static int mwifiex_process_rx(struct mwifiex_adapter *adapter) |
188 | { | |
189 | unsigned long flags; | |
190 | struct sk_buff *skb; | |
92263a84 | 191 | struct mwifiex_rxinfo *rx_info; |
6e251174 AP |
192 | |
193 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); | |
194 | if (adapter->rx_processing || adapter->rx_locked) { | |
195 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
196 | goto exit_rx_proc; | |
197 | } else { | |
198 | adapter->rx_processing = true; | |
199 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
200 | } | |
201 | ||
202 | /* Check for Rx data */ | |
203 | while ((skb = skb_dequeue(&adapter->rx_data_q))) { | |
204 | atomic_dec(&adapter->rx_pending); | |
381e9fff AK |
205 | if ((adapter->delay_main_work || |
206 | adapter->iface_type == MWIFIEX_USB) && | |
b43a0d9d | 207 | (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) { |
cf6a64fd AK |
208 | if (adapter->if_ops.submit_rem_rx_urbs) |
209 | adapter->if_ops.submit_rem_rx_urbs(adapter); | |
6e251174 | 210 | adapter->delay_main_work = false; |
b2713f67 | 211 | mwifiex_queue_main_work(adapter); |
6e251174 | 212 | } |
92263a84 ZL |
213 | rx_info = MWIFIEX_SKB_RXCB(skb); |
214 | if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) { | |
215 | if (adapter->if_ops.deaggr_pkt) | |
216 | adapter->if_ops.deaggr_pkt(adapter, skb); | |
217 | dev_kfree_skb_any(skb); | |
218 | } else { | |
219 | mwifiex_handle_rx_packet(adapter, skb); | |
6e251174 | 220 | } |
6e251174 AP |
221 | } |
222 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); | |
223 | adapter->rx_processing = false; | |
224 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
225 | ||
6e251174 AP |
226 | exit_rx_proc: |
227 | return 0; | |
228 | } | |
229 | ||
5e6e3a92 BZ |
230 | /* |
231 | * The main process. | |
232 | * | |
233 | * This function is the main procedure of the driver and handles various driver | |
234 | * operations. It runs in a loop and provides the core functionalities. | |
235 | * | |
236 | * The main responsibilities of this function are - | |
237 | * - Ensure concurrency control | |
238 | * - Handle pending interrupts and call interrupt handlers | |
239 | * - Wake up the card if required | |
240 | * - Handle command responses and call response handlers | |
241 | * - Handle events and call event handlers | |
242 | * - Execute pending commands | |
243 | * - Transmit pending data packets | |
244 | */ | |
245 | int mwifiex_main_process(struct mwifiex_adapter *adapter) | |
246 | { | |
247 | int ret = 0; | |
248 | unsigned long flags; | |
249 | ||
250 | spin_lock_irqsave(&adapter->main_proc_lock, flags); | |
251 | ||
252 | /* Check if already processing */ | |
a9adbcb3 | 253 | if (adapter->mwifiex_processing || adapter->main_locked) { |
04c7b363 | 254 | adapter->more_task_flag = true; |
5e6e3a92 | 255 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
5bf15e3f | 256 | return 0; |
5e6e3a92 BZ |
257 | } else { |
258 | adapter->mwifiex_processing = true; | |
91457eaa | 259 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
5e6e3a92 BZ |
260 | } |
261 | process_start: | |
262 | do { | |
5bf15e3f | 263 | if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) |
5e6e3a92 BZ |
264 | break; |
265 | ||
381e9fff AK |
266 | /* For non-USB interfaces, If we process interrupts first, it |
267 | * would increase RX pending even further. Avoid this by | |
268 | * checking if rx_pending has crossed high threshold and | |
269 | * schedule rx work queue and then process interrupts. | |
270 | * For USB interface, there are no interrupts. We already have | |
271 | * HIGH_RX_PENDING check in usb.c | |
6e251174 | 272 | */ |
381e9fff AK |
273 | if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING && |
274 | adapter->iface_type != MWIFIEX_USB) { | |
6e251174 | 275 | adapter->delay_main_work = true; |
b2713f67 | 276 | mwifiex_queue_rx_work(adapter); |
6e251174 AP |
277 | break; |
278 | } | |
279 | ||
5e6e3a92 BZ |
280 | /* Handle pending interrupt if any */ |
281 | if (adapter->int_status) { | |
282 | if (adapter->hs_activated) | |
283 | mwifiex_process_hs_config(adapter); | |
4daffe35 AK |
284 | if (adapter->if_ops.process_int_status) |
285 | adapter->if_ops.process_int_status(adapter); | |
5e6e3a92 BZ |
286 | } |
287 | ||
6e251174 | 288 | if (adapter->rx_work_enabled && adapter->data_received) |
b2713f67 | 289 | mwifiex_queue_rx_work(adapter); |
6e251174 | 290 | |
5e6e3a92 BZ |
291 | /* Need to wake up the card ? */ |
292 | if ((adapter->ps_state == PS_STATE_SLEEP) && | |
293 | (adapter->pm_wakeup_card_req && | |
294 | !adapter->pm_wakeup_fw_try) && | |
f57c1edc | 295 | (is_command_pending(adapter) || |
e35000ea | 296 | !skb_queue_empty(&adapter->tx_data_q) || |
a1777327 | 297 | !mwifiex_bypass_txlist_empty(adapter) || |
f57c1edc | 298 | !mwifiex_wmm_lists_empty(adapter))) { |
5e6e3a92 | 299 | adapter->pm_wakeup_fw_try = true; |
4636187d | 300 | mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3)); |
5e6e3a92 BZ |
301 | adapter->if_ops.wakeup(adapter); |
302 | continue; | |
303 | } | |
4daffe35 | 304 | |
5e6e3a92 | 305 | if (IS_CARD_RX_RCVD(adapter)) { |
6e251174 | 306 | adapter->data_received = false; |
5e6e3a92 | 307 | adapter->pm_wakeup_fw_try = false; |
6e9344fd | 308 | del_timer(&adapter->wakeup_timer); |
5e6e3a92 BZ |
309 | if (adapter->ps_state == PS_STATE_SLEEP) |
310 | adapter->ps_state = PS_STATE_AWAKE; | |
311 | } else { | |
312 | /* We have tried to wakeup the card already */ | |
313 | if (adapter->pm_wakeup_fw_try) | |
314 | break; | |
67120768 SL |
315 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) |
316 | mwifiex_check_ps_cond(adapter); | |
317 | ||
7e4e5d2c | 318 | if (adapter->ps_state != PS_STATE_AWAKE) |
5e6e3a92 | 319 | break; |
7e4e5d2c ZL |
320 | if (adapter->tx_lock_flag) { |
321 | if (adapter->iface_type == MWIFIEX_USB) { | |
322 | if (!adapter->usb_mc_setup) | |
323 | break; | |
324 | } else | |
325 | break; | |
326 | } | |
5e6e3a92 | 327 | |
5ec39efa | 328 | if ((!adapter->scan_chan_gap_enabled && |
5ec39efa | 329 | adapter->scan_processing) || adapter->data_sent || |
ba101ad5 XH |
330 | mwifiex_is_tdls_chan_switching |
331 | (mwifiex_get_priv(adapter, | |
332 | MWIFIEX_BSS_ROLE_STA)) || | |
e35000ea | 333 | (mwifiex_wmm_lists_empty(adapter) && |
a1777327 | 334 | mwifiex_bypass_txlist_empty(adapter) && |
e35000ea | 335 | skb_queue_empty(&adapter->tx_data_q))) { |
f57c1edc | 336 | if (adapter->cmd_sent || adapter->curr_cmd || |
ba101ad5 XH |
337 | !mwifiex_is_send_cmd_allowed |
338 | (mwifiex_get_priv(adapter, | |
339 | MWIFIEX_BSS_ROLE_STA)) || | |
f57c1edc | 340 | (!is_command_pending(adapter))) |
5e6e3a92 BZ |
341 | break; |
342 | } | |
343 | } | |
344 | ||
20474129 AK |
345 | /* Check for event */ |
346 | if (adapter->event_received) { | |
347 | adapter->event_received = false; | |
348 | mwifiex_process_event(adapter); | |
349 | } | |
350 | ||
5e6e3a92 BZ |
351 | /* Check for Cmd Resp */ |
352 | if (adapter->cmd_resp_received) { | |
353 | adapter->cmd_resp_received = false; | |
354 | mwifiex_process_cmdresp(adapter); | |
355 | ||
356 | /* call mwifiex back when init_fw is done */ | |
357 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) { | |
358 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
359 | mwifiex_init_fw_complete(adapter); | |
360 | } | |
361 | } | |
362 | ||
5e6e3a92 BZ |
363 | /* Check if we need to confirm Sleep Request |
364 | received previously */ | |
67120768 SL |
365 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) |
366 | mwifiex_check_ps_cond(adapter); | |
5e6e3a92 BZ |
367 | |
368 | /* * The ps_state may have been changed during processing of | |
369 | * Sleep Request event. | |
370 | */ | |
f57c1edc YAP |
371 | if ((adapter->ps_state == PS_STATE_SLEEP) || |
372 | (adapter->ps_state == PS_STATE_PRE_SLEEP) || | |
7e4e5d2c | 373 | (adapter->ps_state == PS_STATE_SLEEP_CFM)) { |
5e6e3a92 | 374 | continue; |
04c7b363 | 375 | } |
5e6e3a92 | 376 | |
7e4e5d2c ZL |
377 | if (adapter->tx_lock_flag) { |
378 | if (adapter->iface_type == MWIFIEX_USB) { | |
379 | if (!adapter->usb_mc_setup) | |
380 | continue; | |
381 | } else | |
382 | continue; | |
383 | } | |
384 | ||
ba101ad5 XH |
385 | if (!adapter->cmd_sent && !adapter->curr_cmd && |
386 | mwifiex_is_send_cmd_allowed | |
387 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) { | |
5e6e3a92 BZ |
388 | if (mwifiex_exec_next_cmd(adapter) == -1) { |
389 | ret = -1; | |
390 | break; | |
391 | } | |
392 | } | |
393 | ||
7e4e5d2c ZL |
394 | /** If USB Multi channel setup ongoing, |
395 | * wait for ready to tx data. | |
396 | */ | |
397 | if (adapter->iface_type == MWIFIEX_USB && | |
398 | adapter->usb_mc_setup) | |
399 | continue; | |
400 | ||
e35000ea ZL |
401 | if ((adapter->scan_chan_gap_enabled || |
402 | !adapter->scan_processing) && | |
403 | !adapter->data_sent && | |
404 | !skb_queue_empty(&adapter->tx_data_q)) { | |
405 | mwifiex_process_tx_queue(adapter); | |
406 | if (adapter->hs_activated) { | |
407 | adapter->is_hs_configured = false; | |
408 | mwifiex_hs_activated_event | |
409 | (mwifiex_get_priv | |
410 | (adapter, MWIFIEX_BSS_ROLE_ANY), | |
411 | false); | |
412 | } | |
413 | } | |
414 | ||
a1777327 AP |
415 | if ((adapter->scan_chan_gap_enabled || |
416 | !adapter->scan_processing) && | |
417 | !adapter->data_sent && | |
418 | !mwifiex_bypass_txlist_empty(adapter) && | |
419 | !mwifiex_is_tdls_chan_switching | |
420 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) { | |
421 | mwifiex_process_bypass_tx(adapter); | |
422 | if (adapter->hs_activated) { | |
423 | adapter->is_hs_configured = false; | |
424 | mwifiex_hs_activated_event | |
425 | (mwifiex_get_priv | |
426 | (adapter, MWIFIEX_BSS_ROLE_ANY), | |
427 | false); | |
428 | } | |
429 | } | |
430 | ||
5ec39efa | 431 | if ((adapter->scan_chan_gap_enabled || |
d8d91253 | 432 | !adapter->scan_processing) && |
ba101ad5 XH |
433 | !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) && |
434 | !mwifiex_is_tdls_chan_switching | |
435 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) { | |
5e6e3a92 BZ |
436 | mwifiex_wmm_process_tx(adapter); |
437 | if (adapter->hs_activated) { | |
438 | adapter->is_hs_configured = false; | |
439 | mwifiex_hs_activated_event | |
440 | (mwifiex_get_priv | |
441 | (adapter, MWIFIEX_BSS_ROLE_ANY), | |
442 | false); | |
443 | } | |
444 | } | |
445 | ||
446 | if (adapter->delay_null_pkt && !adapter->cmd_sent && | |
f57c1edc | 447 | !adapter->curr_cmd && !is_command_pending(adapter) && |
e35000ea | 448 | (mwifiex_wmm_lists_empty(adapter) && |
a1777327 | 449 | mwifiex_bypass_txlist_empty(adapter) && |
e35000ea | 450 | skb_queue_empty(&adapter->tx_data_q))) { |
5e6e3a92 BZ |
451 | if (!mwifiex_send_null_packet |
452 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), | |
453 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET | | |
454 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) { | |
455 | adapter->delay_null_pkt = false; | |
456 | adapter->ps_state = PS_STATE_SLEEP; | |
457 | } | |
458 | break; | |
459 | } | |
460 | } while (true); | |
461 | ||
453b0c3f | 462 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
91457eaa CL |
463 | if (adapter->more_task_flag) { |
464 | adapter->more_task_flag = false; | |
465 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
5e6e3a92 | 466 | goto process_start; |
91457eaa | 467 | } |
5e6e3a92 BZ |
468 | adapter->mwifiex_processing = false; |
469 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
470 | ||
5e6e3a92 BZ |
471 | return ret; |
472 | } | |
601216e1 | 473 | EXPORT_SYMBOL_GPL(mwifiex_main_process); |
5e6e3a92 | 474 | |
5e6e3a92 BZ |
475 | /* |
476 | * This function frees the adapter structure. | |
477 | * | |
478 | * Additionally, this closes the netlink socket, frees the timers | |
479 | * and private structures. | |
480 | */ | |
481 | static void mwifiex_free_adapter(struct mwifiex_adapter *adapter) | |
482 | { | |
483 | if (!adapter) { | |
484 | pr_err("%s: adapter is NULL\n", __func__); | |
485 | return; | |
486 | } | |
487 | ||
488 | mwifiex_unregister(adapter); | |
489 | pr_debug("info: %s: free adapter\n", __func__); | |
490 | } | |
491 | ||
6b41f941 AK |
492 | /* |
493 | * This function cancels all works in the queue and destroys | |
494 | * the main workqueue. | |
495 | */ | |
496 | static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter) | |
497 | { | |
4c5dae59 AK |
498 | if (adapter->workqueue) { |
499 | flush_workqueue(adapter->workqueue); | |
500 | destroy_workqueue(adapter->workqueue); | |
501 | adapter->workqueue = NULL; | |
502 | } | |
6e251174 AP |
503 | |
504 | if (adapter->rx_workqueue) { | |
505 | flush_workqueue(adapter->rx_workqueue); | |
506 | destroy_workqueue(adapter->rx_workqueue); | |
507 | adapter->rx_workqueue = NULL; | |
508 | } | |
6b41f941 AK |
509 | } |
510 | ||
5e6e3a92 | 511 | /* |
59a4cc25 | 512 | * This function gets firmware and initializes it. |
5e6e3a92 BZ |
513 | * |
514 | * The main initialization steps followed are - | |
515 | * - Download the correct firmware to card | |
5e6e3a92 BZ |
516 | * - Issue the init commands to firmware |
517 | */ | |
755b37c9 | 518 | static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context) |
5e6e3a92 | 519 | { |
bec568ff | 520 | int ret; |
59a4cc25 | 521 | char fmt[64]; |
59a4cc25 | 522 | struct mwifiex_adapter *adapter = context; |
5e6e3a92 | 523 | struct mwifiex_fw_image fw; |
c3afd99f | 524 | bool init_failed = false; |
68b76e99 | 525 | struct wireless_dev *wdev; |
4a79aa17 | 526 | struct completion *fw_done = adapter->fw_done; |
5e6e3a92 | 527 | |
59a4cc25 | 528 | if (!firmware) { |
acebe8c1 ZL |
529 | mwifiex_dbg(adapter, ERROR, |
530 | "Failed to get firmware %s\n", adapter->fw_name); | |
6b41f941 | 531 | goto err_dnld_fw; |
5e6e3a92 | 532 | } |
59a4cc25 AK |
533 | |
534 | memset(&fw, 0, sizeof(struct mwifiex_fw_image)); | |
535 | adapter->firmware = firmware; | |
5e6e3a92 BZ |
536 | fw.fw_buf = (u8 *) adapter->firmware->data; |
537 | fw.fw_len = adapter->firmware->size; | |
538 | ||
65c71efe | 539 | if (adapter->if_ops.dnld_fw) { |
4daffe35 | 540 | ret = adapter->if_ops.dnld_fw(adapter, &fw); |
65c71efe | 541 | } else { |
4daffe35 | 542 | ret = mwifiex_dnld_fw(adapter, &fw); |
65c71efe WNH |
543 | } |
544 | ||
5e6e3a92 | 545 | if (ret == -1) |
6b41f941 | 546 | goto err_dnld_fw; |
5e6e3a92 | 547 | |
acebe8c1 | 548 | mwifiex_dbg(adapter, MSG, "WLAN FW is active\n"); |
5e6e3a92 | 549 | |
388ec385 AK |
550 | if (cal_data_cfg) { |
551 | if ((request_firmware(&adapter->cal_data, cal_data_cfg, | |
552 | adapter->dev)) < 0) | |
acebe8c1 ZL |
553 | mwifiex_dbg(adapter, ERROR, |
554 | "Cal data request_firmware() failed\n"); | |
388ec385 AK |
555 | } |
556 | ||
232fde06 | 557 | /* enable host interrupt after fw dnld is successful */ |
6b41f941 AK |
558 | if (adapter->if_ops.enable_int) { |
559 | if (adapter->if_ops.enable_int(adapter)) | |
560 | goto err_dnld_fw; | |
561 | } | |
232fde06 | 562 | |
5e6e3a92 BZ |
563 | adapter->init_wait_q_woken = false; |
564 | ret = mwifiex_init_fw(adapter); | |
565 | if (ret == -1) { | |
6b41f941 | 566 | goto err_init_fw; |
5e6e3a92 BZ |
567 | } else if (!ret) { |
568 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
569 | goto done; | |
570 | } | |
571 | /* Wait for mwifiex_init to complete */ | |
cf5383b0 XH |
572 | if (!adapter->mfg_mode) { |
573 | wait_event_interruptible(adapter->init_wait_q, | |
574 | adapter->init_wait_q_woken); | |
575 | if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) | |
576 | goto err_init_fw; | |
577 | } | |
59a4cc25 | 578 | |
4c5dae59 AK |
579 | if (!adapter->wiphy) { |
580 | if (mwifiex_register_cfg80211(adapter)) { | |
581 | mwifiex_dbg(adapter, ERROR, | |
582 | "cannot register with cfg80211\n"); | |
583 | goto err_init_fw; | |
584 | } | |
59a4cc25 AK |
585 | } |
586 | ||
bf354433 | 587 | if (mwifiex_init_channel_scan_gap(adapter)) { |
acebe8c1 ZL |
588 | mwifiex_dbg(adapter, ERROR, |
589 | "could not init channel stats table\n"); | |
c253a62d | 590 | goto err_init_chan_scan; |
bf354433 AP |
591 | } |
592 | ||
0013c7ce AP |
593 | if (driver_mode) { |
594 | driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK; | |
595 | driver_mode |= MWIFIEX_DRIVER_MODE_STA; | |
596 | } | |
597 | ||
59a4cc25 AK |
598 | rtnl_lock(); |
599 | /* Create station interface by default */ | |
6bab2e19 | 600 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM, |
818a986e | 601 | NL80211_IFTYPE_STATION, NULL); |
68b76e99 | 602 | if (IS_ERR(wdev)) { |
acebe8c1 ZL |
603 | mwifiex_dbg(adapter, ERROR, |
604 | "cannot create default STA interface\n"); | |
bec568ff | 605 | rtnl_unlock(); |
59a4cc25 | 606 | goto err_add_intf; |
5e6e3a92 | 607 | } |
0013c7ce AP |
608 | |
609 | if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) { | |
6bab2e19 | 610 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM, |
818a986e | 611 | NL80211_IFTYPE_AP, NULL); |
0013c7ce | 612 | if (IS_ERR(wdev)) { |
acebe8c1 ZL |
613 | mwifiex_dbg(adapter, ERROR, |
614 | "cannot create AP interface\n"); | |
0013c7ce AP |
615 | rtnl_unlock(); |
616 | goto err_add_intf; | |
617 | } | |
618 | } | |
619 | ||
620 | if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) { | |
6bab2e19 | 621 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM, |
818a986e | 622 | NL80211_IFTYPE_P2P_CLIENT, NULL); |
0013c7ce | 623 | if (IS_ERR(wdev)) { |
acebe8c1 ZL |
624 | mwifiex_dbg(adapter, ERROR, |
625 | "cannot create p2p client interface\n"); | |
0013c7ce AP |
626 | rtnl_unlock(); |
627 | goto err_add_intf; | |
628 | } | |
629 | } | |
59a4cc25 AK |
630 | rtnl_unlock(); |
631 | ||
632 | mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); | |
acebe8c1 | 633 | mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt); |
59a4cc25 | 634 | goto done; |
5e6e3a92 | 635 | |
59a4cc25 | 636 | err_add_intf: |
fb9e67be | 637 | vfree(adapter->chan_stats); |
c253a62d | 638 | err_init_chan_scan: |
6b41f941 AK |
639 | wiphy_unregister(adapter->wiphy); |
640 | wiphy_free(adapter->wiphy); | |
59a4cc25 | 641 | err_init_fw: |
232fde06 DD |
642 | if (adapter->if_ops.disable_int) |
643 | adapter->if_ops.disable_int(adapter); | |
6b41f941 | 644 | err_dnld_fw: |
acebe8c1 ZL |
645 | mwifiex_dbg(adapter, ERROR, |
646 | "info: %s: unregister device\n", __func__); | |
6b41f941 AK |
647 | if (adapter->if_ops.unregister_dev) |
648 | adapter->if_ops.unregister_dev(adapter); | |
649 | ||
5bf15e3f XH |
650 | adapter->surprise_removed = true; |
651 | mwifiex_terminate_workqueue(adapter); | |
652 | ||
7197325b | 653 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) { |
6b41f941 | 654 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
5bf15e3f | 655 | mwifiex_shutdown_drv(adapter); |
ce32d1d8 | 656 | mwifiex_free_cmd_buffers(adapter); |
6b41f941 | 657 | } |
5bf15e3f | 658 | |
c3afd99f | 659 | init_failed = true; |
5e6e3a92 | 660 | done: |
388ec385 AK |
661 | if (adapter->cal_data) { |
662 | release_firmware(adapter->cal_data); | |
663 | adapter->cal_data = NULL; | |
664 | } | |
c3afd99f AK |
665 | if (adapter->firmware) { |
666 | release_firmware(adapter->firmware); | |
667 | adapter->firmware = NULL; | |
668 | } | |
f101d964 JC |
669 | if (init_failed) { |
670 | if (adapter->irq_wakeup >= 0) | |
671 | device_init_wakeup(adapter->dev, false); | |
c3afd99f | 672 | mwifiex_free_adapter(adapter); |
f101d964 | 673 | } |
4a79aa17 BN |
674 | /* Tell all current and future waiters we're finished */ |
675 | complete_all(fw_done); | |
755b37c9 BN |
676 | |
677 | return init_failed ? -EIO : 0; | |
678 | } | |
679 | ||
680 | static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) | |
681 | { | |
682 | _mwifiex_fw_dpc(firmware, context); | |
59a4cc25 AK |
683 | } |
684 | ||
685 | /* | |
755b37c9 BN |
686 | * This function gets the firmware and (if called asynchronously) kicks off the |
687 | * HW init when done. | |
59a4cc25 | 688 | */ |
4c5dae59 AK |
689 | static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter, |
690 | bool req_fw_nowait) | |
59a4cc25 AK |
691 | { |
692 | int ret; | |
693 | ||
cf5383b0 XH |
694 | /* Override default firmware with manufacturing one if |
695 | * manufacturing mode is enabled | |
696 | */ | |
697 | if (mfg_mode) { | |
698 | if (strlcpy(adapter->fw_name, MFG_FIRMWARE, | |
699 | sizeof(adapter->fw_name)) >= | |
700 | sizeof(adapter->fw_name)) { | |
701 | pr_err("%s: fw_name too long!\n", __func__); | |
702 | return -1; | |
703 | } | |
704 | } | |
4c5dae59 AK |
705 | |
706 | if (req_fw_nowait) { | |
707 | ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, | |
708 | adapter->dev, GFP_KERNEL, adapter, | |
709 | mwifiex_fw_dpc); | |
4c5dae59 AK |
710 | } else { |
711 | ret = request_firmware(&adapter->firmware, | |
712 | adapter->fw_name, | |
713 | adapter->dev); | |
4c5dae59 AK |
714 | } |
715 | ||
755b37c9 BN |
716 | if (ret < 0) |
717 | mwifiex_dbg(adapter, ERROR, "request_firmware%s error %d\n", | |
718 | req_fw_nowait ? "_nowait" : "", ret); | |
5e6e3a92 BZ |
719 | return ret; |
720 | } | |
721 | ||
5e6e3a92 BZ |
722 | /* |
723 | * CFG802.11 network device handler for open. | |
724 | * | |
725 | * Starts the data queue. | |
726 | */ | |
727 | static int | |
728 | mwifiex_open(struct net_device *dev) | |
729 | { | |
ea2325b8 JB |
730 | netif_carrier_off(dev); |
731 | ||
5e6e3a92 BZ |
732 | return 0; |
733 | } | |
734 | ||
735 | /* | |
736 | * CFG802.11 network device handler for close. | |
737 | */ | |
738 | static int | |
739 | mwifiex_close(struct net_device *dev) | |
740 | { | |
f162cac8 AK |
741 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
742 | ||
743 | if (priv->scan_request) { | |
1d76250b AS |
744 | struct cfg80211_scan_info info = { |
745 | .aborted = true, | |
746 | }; | |
747 | ||
acebe8c1 ZL |
748 | mwifiex_dbg(priv->adapter, INFO, |
749 | "aborting scan on ndo_stop\n"); | |
1d76250b | 750 | cfg80211_scan_done(priv->scan_request, &info); |
f162cac8 | 751 | priv->scan_request = NULL; |
75ab753d | 752 | priv->scan_aborting = true; |
f162cac8 AK |
753 | } |
754 | ||
eaf46b5f XH |
755 | if (priv->sched_scanning) { |
756 | mwifiex_dbg(priv->adapter, INFO, | |
757 | "aborting bgscan on ndo_stop\n"); | |
758 | mwifiex_stop_bg_scan(priv); | |
b34939b9 | 759 | cfg80211_sched_scan_stopped(priv->wdev.wiphy, 0); |
eaf46b5f XH |
760 | } |
761 | ||
5e6e3a92 BZ |
762 | return 0; |
763 | } | |
764 | ||
a1777327 AP |
765 | static bool |
766 | mwifiex_bypass_tx_queue(struct mwifiex_private *priv, | |
767 | struct sk_buff *skb) | |
768 | { | |
769 | struct ethhdr *eth_hdr = (struct ethhdr *)skb->data; | |
770 | ||
771 | if (ntohs(eth_hdr->h_proto) == ETH_P_PAE || | |
772 | mwifiex_is_skb_mgmt_frame(skb) || | |
773 | (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA && | |
774 | ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && | |
775 | (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) { | |
776 | mwifiex_dbg(priv->adapter, DATA, | |
777 | "bypass txqueue; eth type %#x, mgmt %d\n", | |
778 | ntohs(eth_hdr->h_proto), | |
779 | mwifiex_is_skb_mgmt_frame(skb)); | |
780 | return true; | |
781 | } | |
782 | ||
783 | return false; | |
784 | } | |
e39faa73 SP |
785 | /* |
786 | * Add buffer into wmm tx queue and queue work to transmit it. | |
787 | */ | |
788 | int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb) | |
789 | { | |
47411a06 AP |
790 | struct netdev_queue *txq; |
791 | int index = mwifiex_1d_to_wmm_queue[skb->priority]; | |
792 | ||
793 | if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) { | |
794 | txq = netdev_get_tx_queue(priv->netdev, index); | |
795 | if (!netif_tx_queue_stopped(txq)) { | |
796 | netif_tx_stop_queue(txq); | |
acebe8c1 ZL |
797 | mwifiex_dbg(priv->adapter, DATA, |
798 | "stop queue: %d\n", index); | |
47411a06 AP |
799 | } |
800 | } | |
801 | ||
a1777327 AP |
802 | if (mwifiex_bypass_tx_queue(priv, skb)) { |
803 | atomic_inc(&priv->adapter->tx_pending); | |
804 | atomic_inc(&priv->adapter->bypass_tx_pending); | |
805 | mwifiex_wmm_add_buf_bypass_txqueue(priv, skb); | |
806 | } else { | |
807 | atomic_inc(&priv->adapter->tx_pending); | |
808 | mwifiex_wmm_add_buf_txqueue(priv, skb); | |
809 | } | |
e39faa73 | 810 | |
b2713f67 | 811 | mwifiex_queue_main_work(priv->adapter); |
e39faa73 SP |
812 | |
813 | return 0; | |
814 | } | |
815 | ||
18ca4382 | 816 | struct sk_buff * |
808bbebc | 817 | mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv, |
18ca4382 | 818 | struct sk_buff *skb, u8 flag, u64 *cookie) |
808bbebc AK |
819 | { |
820 | struct sk_buff *orig_skb = skb; | |
821 | struct mwifiex_txinfo *tx_info, *orig_tx_info; | |
822 | ||
823 | skb = skb_clone(skb, GFP_ATOMIC); | |
824 | if (skb) { | |
825 | unsigned long flags; | |
826 | int id; | |
827 | ||
828 | spin_lock_irqsave(&priv->ack_status_lock, flags); | |
829 | id = idr_alloc(&priv->ack_status_frames, orig_skb, | |
ee548d4b | 830 | 1, 0x10, GFP_ATOMIC); |
808bbebc AK |
831 | spin_unlock_irqrestore(&priv->ack_status_lock, flags); |
832 | ||
833 | if (id >= 0) { | |
834 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
835 | tx_info->ack_frame_id = id; | |
836 | tx_info->flags |= flag; | |
837 | orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb); | |
838 | orig_tx_info->ack_frame_id = id; | |
839 | orig_tx_info->flags |= flag; | |
18ca4382 AK |
840 | |
841 | if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie) | |
842 | orig_tx_info->cookie = *cookie; | |
843 | ||
808bbebc AK |
844 | } else if (skb_shared(skb)) { |
845 | kfree_skb(orig_skb); | |
846 | } else { | |
847 | kfree_skb(skb); | |
848 | skb = orig_skb; | |
849 | } | |
850 | } else { | |
851 | /* couldn't clone -- lose tx status ... */ | |
852 | skb = orig_skb; | |
853 | } | |
854 | ||
855 | return skb; | |
856 | } | |
857 | ||
5e6e3a92 BZ |
858 | /* |
859 | * CFG802.11 network device handler for data transmission. | |
860 | */ | |
861 | static int | |
862 | mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
863 | { | |
864 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
270e58e8 | 865 | struct sk_buff *new_skb; |
5e6e3a92 | 866 | struct mwifiex_txinfo *tx_info; |
808bbebc | 867 | bool multicast; |
5e6e3a92 | 868 | |
acebe8c1 ZL |
869 | mwifiex_dbg(priv->adapter, DATA, |
870 | "data: %lu BSS(%d-%d): Data <= kernel\n", | |
871 | jiffies, priv->bss_type, priv->bss_num); | |
5e6e3a92 BZ |
872 | |
873 | if (priv->adapter->surprise_removed) { | |
b53575ec | 874 | kfree_skb(skb); |
5e6e3a92 BZ |
875 | priv->stats.tx_dropped++; |
876 | return 0; | |
877 | } | |
878 | if (!skb->len || (skb->len > ETH_FRAME_LEN)) { | |
acebe8c1 ZL |
879 | mwifiex_dbg(priv->adapter, ERROR, |
880 | "Tx: bad skb len %d\n", skb->len); | |
b53575ec | 881 | kfree_skb(skb); |
5e6e3a92 BZ |
882 | priv->stats.tx_dropped++; |
883 | return 0; | |
884 | } | |
885 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { | |
acebe8c1 ZL |
886 | mwifiex_dbg(priv->adapter, DATA, |
887 | "data: Tx: insufficient skb headroom %d\n", | |
888 | skb_headroom(skb)); | |
5e6e3a92 BZ |
889 | /* Insufficient skb headroom - allocate a new skb */ |
890 | new_skb = | |
891 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); | |
892 | if (unlikely(!new_skb)) { | |
acebe8c1 ZL |
893 | mwifiex_dbg(priv->adapter, ERROR, |
894 | "Tx: cannot alloca new_skb\n"); | |
b53575ec | 895 | kfree_skb(skb); |
5e6e3a92 BZ |
896 | priv->stats.tx_dropped++; |
897 | return 0; | |
898 | } | |
899 | kfree_skb(skb); | |
900 | skb = new_skb; | |
acebe8c1 ZL |
901 | mwifiex_dbg(priv->adapter, INFO, |
902 | "info: new skb headroomd %d\n", | |
903 | skb_headroom(skb)); | |
5e6e3a92 BZ |
904 | } |
905 | ||
906 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
d76744a9 | 907 | memset(tx_info, 0, sizeof(*tx_info)); |
9da9a3b2 YAP |
908 | tx_info->bss_num = priv->bss_num; |
909 | tx_info->bss_type = priv->bss_type; | |
a1ed4849 | 910 | tx_info->pkt_len = skb->len; |
47411a06 | 911 | |
808bbebc AK |
912 | multicast = is_multicast_ether_addr(skb->data); |
913 | ||
914 | if (unlikely(!multicast && skb->sk && | |
915 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS && | |
916 | priv->adapter->fw_api_ver == MWIFIEX_FW_V15)) | |
917 | skb = mwifiex_clone_skb_for_tx_status(priv, | |
918 | skb, | |
18ca4382 | 919 | MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL); |
808bbebc | 920 | |
47411a06 AP |
921 | /* Record the current time the packet was queued; used to |
922 | * determine the amount of time the packet was queued in | |
923 | * the driver before it was sent to the firmware. | |
924 | * The delay is then sent along with the packet to the | |
925 | * firmware for aggregate delay calculation for stats and | |
926 | * MSDU lifetime expiry. | |
927 | */ | |
c64800e7 | 928 | __net_timestamp(skb); |
5e6e3a92 | 929 | |
9927baa3 AP |
930 | if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
931 | priv->bss_type == MWIFIEX_BSS_TYPE_STA && | |
932 | !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) { | |
933 | if (priv->adapter->auto_tdls && priv->check_tdls_tx) | |
934 | mwifiex_tdls_check_tx(priv, skb); | |
935 | } | |
936 | ||
e39faa73 | 937 | mwifiex_queue_tx_pkt(priv, skb); |
5e6e3a92 BZ |
938 | |
939 | return 0; | |
940 | } | |
941 | ||
4ba28f93 XH |
942 | int mwifiex_set_mac_address(struct mwifiex_private *priv, |
943 | struct net_device *dev) | |
5e6e3a92 | 944 | { |
270e58e8 | 945 | int ret; |
4ba28f93 | 946 | u64 mac_addr; |
5e6e3a92 | 947 | |
4ba28f93 XH |
948 | if (priv->bss_type != MWIFIEX_BSS_TYPE_P2P) |
949 | goto done; | |
950 | ||
951 | mac_addr = ether_addr_to_u64(priv->curr_addr); | |
952 | mac_addr |= BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT); | |
953 | u64_to_ether_addr(mac_addr, priv->curr_addr); | |
5e6e3a92 | 954 | |
600f5d90 | 955 | /* Send request to firmware */ |
fa0ecbb9 BZ |
956 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS, |
957 | HostCmd_ACT_GEN_SET, 0, NULL, true); | |
600f5d90 | 958 | |
4ba28f93 | 959 | if (ret) { |
acebe8c1 ZL |
960 | mwifiex_dbg(priv->adapter, ERROR, |
961 | "set mac address failed: ret=%d\n", ret); | |
4ba28f93 XH |
962 | return ret; |
963 | } | |
600f5d90 | 964 | |
4ba28f93 | 965 | done: |
5e6e3a92 | 966 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
4ba28f93 XH |
967 | return 0; |
968 | } | |
5e6e3a92 | 969 | |
4ba28f93 XH |
970 | /* CFG802.11 network device handler for setting MAC address. |
971 | */ | |
972 | static int | |
973 | mwifiex_ndo_set_mac_address(struct net_device *dev, void *addr) | |
974 | { | |
975 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
976 | struct sockaddr *hw_addr = addr; | |
977 | ||
978 | memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); | |
979 | return mwifiex_set_mac_address(priv, dev); | |
5e6e3a92 BZ |
980 | } |
981 | ||
982 | /* | |
983 | * CFG802.11 network device handler for setting multicast list. | |
984 | */ | |
985 | static void mwifiex_set_multicast_list(struct net_device *dev) | |
986 | { | |
987 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
600f5d90 AK |
988 | struct mwifiex_multicast_list mcast_list; |
989 | ||
990 | if (dev->flags & IFF_PROMISC) { | |
991 | mcast_list.mode = MWIFIEX_PROMISC_MODE; | |
992 | } else if (dev->flags & IFF_ALLMULTI || | |
993 | netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) { | |
994 | mcast_list.mode = MWIFIEX_ALL_MULTI_MODE; | |
995 | } else { | |
996 | mcast_list.mode = MWIFIEX_MULTICAST_MODE; | |
6390d885 DD |
997 | mcast_list.num_multicast_addr = |
998 | mwifiex_copy_mcast_addr(&mcast_list, dev); | |
600f5d90 AK |
999 | } |
1000 | mwifiex_request_set_multicast_list(priv, &mcast_list); | |
5e6e3a92 BZ |
1001 | } |
1002 | ||
1003 | /* | |
1004 | * CFG802.11 network device handler for transmission timeout. | |
1005 | */ | |
1006 | static void | |
1007 | mwifiex_tx_timeout(struct net_device *dev) | |
1008 | { | |
1009 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
1010 | ||
5e6e3a92 | 1011 | priv->num_tx_timeout++; |
8908c7d5 | 1012 | priv->tx_timeout_cnt++; |
acebe8c1 ZL |
1013 | mwifiex_dbg(priv->adapter, ERROR, |
1014 | "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n", | |
1015 | jiffies, priv->tx_timeout_cnt, priv->bss_type, | |
1016 | priv->bss_num); | |
8908c7d5 AN |
1017 | mwifiex_set_trans_start(dev); |
1018 | ||
1019 | if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD && | |
1020 | priv->adapter->if_ops.card_reset) { | |
acebe8c1 ZL |
1021 | mwifiex_dbg(priv->adapter, ERROR, |
1022 | "tx_timeout_cnt exceeds threshold.\t" | |
1023 | "Triggering card reset!\n"); | |
8908c7d5 AN |
1024 | priv->adapter->if_ops.card_reset(priv->adapter); |
1025 | } | |
5e6e3a92 BZ |
1026 | } |
1027 | ||
7e4e5d2c ZL |
1028 | void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter) |
1029 | { | |
1030 | struct usb_card_rec *card = adapter->card; | |
1031 | struct mwifiex_private *priv; | |
1032 | u16 tx_buf_size; | |
1033 | int i, ret; | |
1034 | ||
1035 | card->mc_resync_flag = true; | |
1036 | for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) { | |
1037 | if (atomic_read(&card->port[i].tx_data_urb_pending)) { | |
1038 | mwifiex_dbg(adapter, WARN, "pending data urb in sys\n"); | |
1039 | return; | |
1040 | } | |
1041 | } | |
1042 | ||
1043 | card->mc_resync_flag = false; | |
1044 | tx_buf_size = 0xffff; | |
1045 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
1046 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF, | |
1047 | HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false); | |
1048 | if (ret) | |
1049 | mwifiex_dbg(adapter, ERROR, | |
1050 | "send reconfig tx buf size cmd err\n"); | |
1051 | } | |
1052 | EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync); | |
1053 | ||
d27121fc | 1054 | int mwifiex_drv_info_dump(struct mwifiex_adapter *adapter, void **drv_info) |
11cd07a9 XH |
1055 | { |
1056 | void *p; | |
1057 | char drv_version[64]; | |
1058 | struct usb_card_rec *cardp; | |
1059 | struct sdio_mmc_card *sdio_card; | |
1060 | struct mwifiex_private *priv; | |
1061 | int i, idx; | |
1062 | struct netdev_queue *txq; | |
1063 | struct mwifiex_debug_info *debug_info; | |
d27121fc | 1064 | void *drv_info_dump; |
11cd07a9 | 1065 | |
9cc0dbf0 | 1066 | mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n"); |
11cd07a9 | 1067 | |
d27121fc XH |
1068 | /* memory allocate here should be free in mwifiex_upload_device_dump*/ |
1069 | drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX); | |
11cd07a9 | 1070 | |
d27121fc XH |
1071 | if (!drv_info_dump) |
1072 | return 0; | |
11cd07a9 | 1073 | |
d27121fc | 1074 | p = (char *)(drv_info_dump); |
11cd07a9 XH |
1075 | p += sprintf(p, "driver_name = " "\"mwifiex\"\n"); |
1076 | ||
1077 | mwifiex_drv_get_driver_version(adapter, drv_version, | |
1078 | sizeof(drv_version) - 1); | |
1079 | p += sprintf(p, "driver_version = %s\n", drv_version); | |
1080 | ||
1081 | if (adapter->iface_type == MWIFIEX_USB) { | |
1082 | cardp = (struct usb_card_rec *)adapter->card; | |
1083 | p += sprintf(p, "tx_cmd_urb_pending = %d\n", | |
1084 | atomic_read(&cardp->tx_cmd_urb_pending)); | |
308fe29e ZL |
1085 | p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n", |
1086 | atomic_read(&cardp->port[0].tx_data_urb_pending)); | |
1087 | p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n", | |
1088 | atomic_read(&cardp->port[1].tx_data_urb_pending)); | |
11cd07a9 XH |
1089 | p += sprintf(p, "rx_cmd_urb_pending = %d\n", |
1090 | atomic_read(&cardp->rx_cmd_urb_pending)); | |
1091 | p += sprintf(p, "rx_data_urb_pending = %d\n", | |
1092 | atomic_read(&cardp->rx_data_urb_pending)); | |
1093 | } | |
1094 | ||
1095 | p += sprintf(p, "tx_pending = %d\n", | |
1096 | atomic_read(&adapter->tx_pending)); | |
1097 | p += sprintf(p, "rx_pending = %d\n", | |
1098 | atomic_read(&adapter->rx_pending)); | |
1099 | ||
1100 | if (adapter->iface_type == MWIFIEX_SDIO) { | |
1101 | sdio_card = (struct sdio_mmc_card *)adapter->card; | |
1102 | p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n", | |
1103 | sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port); | |
1104 | p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n", | |
1105 | sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port); | |
1106 | } | |
1107 | ||
1108 | for (i = 0; i < adapter->priv_num; i++) { | |
1109 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) | |
1110 | continue; | |
1111 | priv = adapter->priv[i]; | |
1112 | p += sprintf(p, "\n[interface : \"%s\"]\n", | |
1113 | priv->netdev->name); | |
1114 | p += sprintf(p, "wmm_tx_pending[0] = %d\n", | |
1115 | atomic_read(&priv->wmm_tx_pending[0])); | |
1116 | p += sprintf(p, "wmm_tx_pending[1] = %d\n", | |
1117 | atomic_read(&priv->wmm_tx_pending[1])); | |
1118 | p += sprintf(p, "wmm_tx_pending[2] = %d\n", | |
1119 | atomic_read(&priv->wmm_tx_pending[2])); | |
1120 | p += sprintf(p, "wmm_tx_pending[3] = %d\n", | |
1121 | atomic_read(&priv->wmm_tx_pending[3])); | |
1122 | p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ? | |
1123 | "Disconnected" : "Connected"); | |
1124 | p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev) | |
1125 | ? "on" : "off")); | |
1126 | for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) { | |
1127 | txq = netdev_get_tx_queue(priv->netdev, idx); | |
1128 | p += sprintf(p, "tx queue %d:%s ", idx, | |
1129 | netif_tx_queue_stopped(txq) ? | |
1130 | "stopped" : "started"); | |
1131 | } | |
1132 | p += sprintf(p, "\n%s: num_tx_timeout = %d\n", | |
1133 | priv->netdev->name, priv->num_tx_timeout); | |
1134 | } | |
1135 | ||
4646968b XH |
1136 | if (adapter->iface_type == MWIFIEX_SDIO || |
1137 | adapter->iface_type == MWIFIEX_PCIE) { | |
1138 | p += sprintf(p, "\n=== %s register dump===\n", | |
1139 | adapter->iface_type == MWIFIEX_SDIO ? | |
1140 | "SDIO" : "PCIE"); | |
809c6ea8 XH |
1141 | if (adapter->if_ops.reg_dump) |
1142 | p += adapter->if_ops.reg_dump(adapter, p); | |
1143 | } | |
9cc0dbf0 | 1144 | p += sprintf(p, "\n=== more debug information\n"); |
11cd07a9 XH |
1145 | debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL); |
1146 | if (debug_info) { | |
1147 | for (i = 0; i < adapter->priv_num; i++) { | |
1148 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) | |
1149 | continue; | |
1150 | priv = adapter->priv[i]; | |
1151 | mwifiex_get_debug_info(priv, debug_info); | |
1152 | p += mwifiex_debug_info_to_buffer(priv, p, debug_info); | |
1153 | break; | |
1154 | } | |
1155 | kfree(debug_info); | |
1156 | } | |
1157 | ||
9cc0dbf0 | 1158 | mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n"); |
d27121fc XH |
1159 | *drv_info = drv_info_dump; |
1160 | return p - drv_info_dump; | |
11cd07a9 | 1161 | } |
fc697159 | 1162 | EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump); |
11cd07a9 | 1163 | |
d27121fc XH |
1164 | void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter, void *drv_info, |
1165 | int drv_info_size) | |
57670ee8 AK |
1166 | { |
1167 | u8 idx, *dump_data, *fw_dump_ptr; | |
1168 | u32 dump_len; | |
1169 | ||
1170 | dump_len = (strlen("========Start dump driverinfo========\n") + | |
d27121fc | 1171 | drv_info_size + |
57670ee8 AK |
1172 | strlen("\n========End dump========\n")); |
1173 | ||
1174 | for (idx = 0; idx < adapter->num_mem_types; idx++) { | |
1175 | struct memory_type_mapping *entry = | |
1176 | &adapter->mem_type_mapping_tbl[idx]; | |
1177 | ||
1178 | if (entry->mem_ptr) { | |
1179 | dump_len += (strlen("========Start dump ") + | |
1180 | strlen(entry->mem_name) + | |
1181 | strlen("========\n") + | |
1182 | (entry->mem_size + 1) + | |
1183 | strlen("\n========End dump========\n")); | |
1184 | } | |
1185 | } | |
1186 | ||
1187 | dump_data = vzalloc(dump_len + 1); | |
1188 | if (!dump_data) | |
1189 | goto done; | |
1190 | ||
1191 | fw_dump_ptr = dump_data; | |
1192 | ||
1193 | /* Dump all the memory data into single file, a userspace script will | |
1194 | * be used to split all the memory data to multiple files | |
1195 | */ | |
1196 | mwifiex_dbg(adapter, MSG, | |
1197 | "== mwifiex dump information to /sys/class/devcoredump start"); | |
1198 | ||
1199 | strcpy(fw_dump_ptr, "========Start dump driverinfo========\n"); | |
1200 | fw_dump_ptr += strlen("========Start dump driverinfo========\n"); | |
d27121fc XH |
1201 | memcpy(fw_dump_ptr, drv_info, drv_info_size); |
1202 | fw_dump_ptr += drv_info_size; | |
57670ee8 AK |
1203 | strcpy(fw_dump_ptr, "\n========End dump========\n"); |
1204 | fw_dump_ptr += strlen("\n========End dump========\n"); | |
1205 | ||
1206 | for (idx = 0; idx < adapter->num_mem_types; idx++) { | |
1207 | struct memory_type_mapping *entry = | |
1208 | &adapter->mem_type_mapping_tbl[idx]; | |
1209 | ||
1210 | if (entry->mem_ptr) { | |
1211 | strcpy(fw_dump_ptr, "========Start dump "); | |
1212 | fw_dump_ptr += strlen("========Start dump "); | |
1213 | ||
1214 | strcpy(fw_dump_ptr, entry->mem_name); | |
1215 | fw_dump_ptr += strlen(entry->mem_name); | |
1216 | ||
1217 | strcpy(fw_dump_ptr, "========\n"); | |
1218 | fw_dump_ptr += strlen("========\n"); | |
1219 | ||
1220 | memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size); | |
1221 | fw_dump_ptr += entry->mem_size; | |
1222 | ||
1223 | strcpy(fw_dump_ptr, "\n========End dump========\n"); | |
1224 | fw_dump_ptr += strlen("\n========End dump========\n"); | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | /* device dump data will be free in device coredump release function | |
1229 | * after 5 min | |
1230 | */ | |
1231 | dev_coredumpv(adapter->dev, dump_data, dump_len, GFP_KERNEL); | |
1232 | mwifiex_dbg(adapter, MSG, | |
1233 | "== mwifiex dump information to /sys/class/devcoredump end"); | |
1234 | ||
1235 | done: | |
1236 | for (idx = 0; idx < adapter->num_mem_types; idx++) { | |
1237 | struct memory_type_mapping *entry = | |
1238 | &adapter->mem_type_mapping_tbl[idx]; | |
1239 | ||
d27121fc XH |
1240 | vfree(entry->mem_ptr); |
1241 | entry->mem_ptr = NULL; | |
57670ee8 AK |
1242 | entry->mem_size = 0; |
1243 | } | |
1244 | ||
d27121fc | 1245 | vfree(drv_info); |
57670ee8 AK |
1246 | } |
1247 | EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump); | |
1248 | ||
5e6e3a92 BZ |
1249 | /* |
1250 | * CFG802.11 network device handler for statistics retrieval. | |
1251 | */ | |
1252 | static struct net_device_stats *mwifiex_get_stats(struct net_device *dev) | |
1253 | { | |
1254 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
1255 | ||
1256 | return &priv->stats; | |
1257 | } | |
1258 | ||
47411a06 | 1259 | static u16 |
f663dd9a | 1260 | mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, |
99932d4f | 1261 | void *accel_priv, select_queue_fallback_t fallback) |
47411a06 | 1262 | { |
fa9ffc74 | 1263 | skb->priority = cfg80211_classify8021d(skb, NULL); |
47411a06 AP |
1264 | return mwifiex_1d_to_wmm_queue[skb->priority]; |
1265 | } | |
1266 | ||
5e6e3a92 BZ |
1267 | /* Network device handlers */ |
1268 | static const struct net_device_ops mwifiex_netdev_ops = { | |
1269 | .ndo_open = mwifiex_open, | |
1270 | .ndo_stop = mwifiex_close, | |
1271 | .ndo_start_xmit = mwifiex_hard_start_xmit, | |
4ba28f93 | 1272 | .ndo_set_mac_address = mwifiex_ndo_set_mac_address, |
fe24372d | 1273 | .ndo_validate_addr = eth_validate_addr, |
5e6e3a92 BZ |
1274 | .ndo_tx_timeout = mwifiex_tx_timeout, |
1275 | .ndo_get_stats = mwifiex_get_stats, | |
afc4b13d | 1276 | .ndo_set_rx_mode = mwifiex_set_multicast_list, |
47411a06 | 1277 | .ndo_select_queue = mwifiex_netdev_select_wmm_queue, |
5e6e3a92 BZ |
1278 | }; |
1279 | ||
1280 | /* | |
1281 | * This function initializes the private structure parameters. | |
1282 | * | |
1283 | * The following wait queues are initialized - | |
1284 | * - IOCTL wait queue | |
1285 | * - Command wait queue | |
1286 | * - Statistics wait queue | |
1287 | * | |
1288 | * ...and the following default parameters are set - | |
1289 | * - Current key index : Set to 0 | |
1290 | * - Rate index : Set to auto | |
1291 | * - Media connected : Set to disconnected | |
1292 | * - Adhoc link sensed : Set to false | |
1293 | * - Nick name : Set to null | |
1294 | * - Number of Tx timeout : Set to 0 | |
1295 | * - Device address : Set to current address | |
cbf6e055 | 1296 | * - Rx histogram statistc : Set to 0 |
5e6e3a92 BZ |
1297 | * |
1298 | * In addition, the CFG80211 work queue is also created. | |
1299 | */ | |
93a1df48 | 1300 | void mwifiex_init_priv_params(struct mwifiex_private *priv, |
047eaaf6 | 1301 | struct net_device *dev) |
5e6e3a92 BZ |
1302 | { |
1303 | dev->netdev_ops = &mwifiex_netdev_ops; | |
cf124db5 | 1304 | dev->needs_free_netdev = true; |
5e6e3a92 | 1305 | /* Initialize private structure */ |
5e6e3a92 BZ |
1306 | priv->current_key_index = 0; |
1307 | priv->media_connected = false; | |
ede98bfa AP |
1308 | memset(priv->mgmt_ie, 0, |
1309 | sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX); | |
f31acabe AP |
1310 | priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK; |
1311 | priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK; | |
1312 | priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK; | |
2ade5667 | 1313 | priv->gen_idx = MWIFIEX_AUTO_IDX_MASK; |
5e6e3a92 | 1314 | priv->num_tx_timeout = 0; |
8d05eb22 | 1315 | ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr); |
cbf6e055 XH |
1316 | |
1317 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || | |
1318 | GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { | |
1319 | priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL); | |
1320 | if (priv->hist_data) | |
1321 | mwifiex_hist_data_reset(priv); | |
1322 | } | |
5e6e3a92 BZ |
1323 | } |
1324 | ||
5e6e3a92 BZ |
1325 | /* |
1326 | * This function check if command is pending. | |
1327 | */ | |
1328 | int is_command_pending(struct mwifiex_adapter *adapter) | |
1329 | { | |
1330 | unsigned long flags; | |
1331 | int is_cmd_pend_q_empty; | |
1332 | ||
1333 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
1334 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); | |
1335 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
1336 | ||
1337 | return !is_cmd_pend_q_empty; | |
1338 | } | |
1339 | ||
6e251174 AP |
1340 | /* |
1341 | * This is the RX work queue function. | |
1342 | * | |
1343 | * It handles the RX operations. | |
1344 | */ | |
1345 | static void mwifiex_rx_work_queue(struct work_struct *work) | |
1346 | { | |
1347 | struct mwifiex_adapter *adapter = | |
1348 | container_of(work, struct mwifiex_adapter, rx_work); | |
1349 | ||
1350 | if (adapter->surprise_removed) | |
1351 | return; | |
1352 | mwifiex_process_rx(adapter); | |
1353 | } | |
1354 | ||
5e6e3a92 BZ |
1355 | /* |
1356 | * This is the main work queue function. | |
1357 | * | |
1358 | * It handles the main process, which in turn handles the complete | |
1359 | * driver operations. | |
1360 | */ | |
1361 | static void mwifiex_main_work_queue(struct work_struct *work) | |
1362 | { | |
1363 | struct mwifiex_adapter *adapter = | |
1364 | container_of(work, struct mwifiex_adapter, main_work); | |
1365 | ||
1366 | if (adapter->surprise_removed) | |
1367 | return; | |
1368 | mwifiex_main_process(adapter); | |
1369 | } | |
1370 | ||
b6658b66 BN |
1371 | /* Common teardown code used for both device removal and reset */ |
1372 | static void mwifiex_uninit_sw(struct mwifiex_adapter *adapter) | |
4c5dae59 AK |
1373 | { |
1374 | struct mwifiex_private *priv; | |
1375 | int i; | |
1376 | ||
4c5dae59 AK |
1377 | /* We can no longer handle interrupts once we start doing the teardown |
1378 | * below. | |
1379 | */ | |
1380 | if (adapter->if_ops.disable_int) | |
1381 | adapter->if_ops.disable_int(adapter); | |
1382 | ||
1383 | adapter->surprise_removed = true; | |
1384 | mwifiex_terminate_workqueue(adapter); | |
4b1f5a0d | 1385 | adapter->int_status = 0; |
4c5dae59 AK |
1386 | |
1387 | /* Stop data */ | |
1388 | for (i = 0; i < adapter->priv_num; i++) { | |
1389 | priv = adapter->priv[i]; | |
1390 | if (priv && priv->netdev) { | |
1391 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); | |
1392 | if (netif_carrier_ok(priv->netdev)) | |
1393 | netif_carrier_off(priv->netdev); | |
1394 | netif_device_detach(priv->netdev); | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n"); | |
5bf15e3f | 1399 | mwifiex_shutdown_drv(adapter); |
4c5dae59 | 1400 | mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n"); |
b6658b66 | 1401 | |
4c5dae59 AK |
1402 | if (atomic_read(&adapter->rx_pending) || |
1403 | atomic_read(&adapter->tx_pending) || | |
1404 | atomic_read(&adapter->cmd_pending)) { | |
1405 | mwifiex_dbg(adapter, ERROR, | |
1406 | "rx_pending=%d, tx_pending=%d,\t" | |
1407 | "cmd_pending=%d\n", | |
1408 | atomic_read(&adapter->rx_pending), | |
1409 | atomic_read(&adapter->tx_pending), | |
1410 | atomic_read(&adapter->cmd_pending)); | |
1411 | } | |
1412 | ||
1413 | for (i = 0; i < adapter->priv_num; i++) { | |
1414 | priv = adapter->priv[i]; | |
1415 | if (!priv) | |
1416 | continue; | |
1417 | rtnl_lock(); | |
1418 | if (priv->netdev && | |
1419 | priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) | |
1420 | mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev); | |
1421 | rtnl_unlock(); | |
1422 | } | |
643acea6 BN |
1423 | |
1424 | wiphy_unregister(adapter->wiphy); | |
1425 | wiphy_free(adapter->wiphy); | |
1426 | adapter->wiphy = NULL; | |
ce32d1d8 BN |
1427 | |
1428 | vfree(adapter->chan_stats); | |
1429 | mwifiex_free_cmd_buffers(adapter); | |
b6658b66 BN |
1430 | } |
1431 | ||
1432 | /* | |
1433 | * This function gets called during PCIe function level reset. | |
1434 | */ | |
1435 | int mwifiex_shutdown_sw(struct mwifiex_adapter *adapter) | |
1436 | { | |
1437 | struct mwifiex_private *priv; | |
1438 | ||
1439 | if (!adapter) | |
1440 | return 0; | |
1441 | ||
1442 | wait_for_completion(adapter->fw_done); | |
1443 | /* Caller should ensure we aren't suspending while this happens */ | |
1444 | reinit_completion(adapter->fw_done); | |
1445 | ||
1446 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
1447 | mwifiex_deauthenticate(priv, NULL); | |
1448 | ||
1449 | mwifiex_uninit_sw(adapter); | |
1450 | ||
1451 | if (adapter->if_ops.down_dev) | |
1452 | adapter->if_ops.down_dev(adapter); | |
4c5dae59 | 1453 | |
4c5dae59 AK |
1454 | return 0; |
1455 | } | |
8750ab62 | 1456 | EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw); |
4c5dae59 AK |
1457 | |
1458 | /* This function gets called during PCIe function level reset. Required | |
1459 | * code is extracted from mwifiex_add_card() | |
1460 | */ | |
8750ab62 XH |
1461 | int |
1462 | mwifiex_reinit_sw(struct mwifiex_adapter *adapter) | |
4c5dae59 | 1463 | { |
755b37c9 BN |
1464 | int ret; |
1465 | ||
4c5dae59 AK |
1466 | mwifiex_init_lock_list(adapter); |
1467 | if (adapter->if_ops.up_dev) | |
1468 | adapter->if_ops.up_dev(adapter); | |
1469 | ||
4c5dae59 AK |
1470 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
1471 | adapter->surprise_removed = false; | |
1472 | init_waitqueue_head(&adapter->init_wait_q); | |
1473 | adapter->is_suspended = false; | |
1474 | adapter->hs_activated = false; | |
9ae3fbd1 | 1475 | adapter->is_cmd_timedout = 0; |
4c5dae59 AK |
1476 | init_waitqueue_head(&adapter->hs_activate_wait_q); |
1477 | init_waitqueue_head(&adapter->cmd_wait_q.wait); | |
1478 | adapter->cmd_wait_q.status = 0; | |
1479 | adapter->scan_wait_q_woken = false; | |
1480 | ||
1481 | if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) | |
1482 | adapter->rx_work_enabled = true; | |
1483 | ||
1484 | adapter->workqueue = | |
1485 | alloc_workqueue("MWIFIEX_WORK_QUEUE", | |
1486 | WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); | |
1487 | if (!adapter->workqueue) | |
1488 | goto err_kmalloc; | |
1489 | ||
1490 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); | |
1491 | ||
1492 | if (adapter->rx_work_enabled) { | |
1493 | adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE", | |
1494 | WQ_HIGHPRI | | |
1495 | WQ_MEM_RECLAIM | | |
1496 | WQ_UNBOUND, 1); | |
1497 | if (!adapter->rx_workqueue) | |
1498 | goto err_kmalloc; | |
1499 | INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue); | |
1500 | } | |
1501 | ||
1502 | /* Register the device. Fill up the private data structure with | |
1503 | * relevant information from the card. Some code extracted from | |
1504 | * mwifiex_register_dev() | |
1505 | */ | |
1506 | mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__); | |
4c5dae59 | 1507 | |
4c5dae59 | 1508 | if (mwifiex_init_hw_fw(adapter, false)) { |
4c5dae59 AK |
1509 | mwifiex_dbg(adapter, ERROR, |
1510 | "%s: firmware init failed\n", __func__); | |
1511 | goto err_init_fw; | |
1512 | } | |
755b37c9 BN |
1513 | |
1514 | /* _mwifiex_fw_dpc() does its own cleanup */ | |
1515 | ret = _mwifiex_fw_dpc(adapter->firmware, adapter); | |
1516 | if (ret) { | |
1517 | pr_err("Failed to bring up adapter: %d\n", ret); | |
1518 | return ret; | |
1519 | } | |
4c5dae59 | 1520 | mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__); |
4a79aa17 | 1521 | |
4c5dae59 AK |
1522 | return 0; |
1523 | ||
1524 | err_init_fw: | |
1525 | mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__); | |
1526 | if (adapter->if_ops.unregister_dev) | |
1527 | adapter->if_ops.unregister_dev(adapter); | |
5bf15e3f XH |
1528 | |
1529 | err_kmalloc: | |
1530 | adapter->surprise_removed = true; | |
1531 | mwifiex_terminate_workqueue(adapter); | |
4c5dae59 AK |
1532 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) { |
1533 | mwifiex_dbg(adapter, ERROR, | |
1534 | "info: %s: shutdown mwifiex\n", __func__); | |
5bf15e3f | 1535 | mwifiex_shutdown_drv(adapter); |
ce32d1d8 | 1536 | mwifiex_free_cmd_buffers(adapter); |
4c5dae59 AK |
1537 | } |
1538 | ||
4a79aa17 | 1539 | complete_all(adapter->fw_done); |
4c5dae59 AK |
1540 | mwifiex_dbg(adapter, INFO, "%s, error\n", __func__); |
1541 | ||
1542 | return -1; | |
1543 | } | |
8750ab62 | 1544 | EXPORT_SYMBOL_GPL(mwifiex_reinit_sw); |
4c5dae59 | 1545 | |
853402a0 RJ |
1546 | static irqreturn_t mwifiex_irq_wakeup_handler(int irq, void *priv) |
1547 | { | |
1548 | struct mwifiex_adapter *adapter = priv; | |
1549 | ||
625b4dba XH |
1550 | dev_dbg(adapter->dev, "%s: wake by wifi", __func__); |
1551 | adapter->wake_by_wifi = true; | |
1552 | disable_irq_nosync(irq); | |
853402a0 RJ |
1553 | |
1554 | /* Notify PM core we are wakeup source */ | |
1555 | pm_wakeup_event(adapter->dev, 0); | |
ef7e0714 | 1556 | pm_system_wakeup(); |
853402a0 RJ |
1557 | |
1558 | return IRQ_HANDLED; | |
1559 | } | |
1560 | ||
5e28e5fb RJ |
1561 | static void mwifiex_probe_of(struct mwifiex_adapter *adapter) |
1562 | { | |
853402a0 | 1563 | int ret; |
5e28e5fb RJ |
1564 | struct device *dev = adapter->dev; |
1565 | ||
1566 | if (!dev->of_node) | |
2447e2ca | 1567 | goto err_exit; |
5e28e5fb RJ |
1568 | |
1569 | adapter->dt_node = dev->of_node; | |
853402a0 RJ |
1570 | adapter->irq_wakeup = irq_of_parse_and_map(adapter->dt_node, 0); |
1571 | if (!adapter->irq_wakeup) { | |
2447e2ca BN |
1572 | dev_dbg(dev, "fail to parse irq_wakeup from device tree\n"); |
1573 | goto err_exit; | |
853402a0 RJ |
1574 | } |
1575 | ||
1576 | ret = devm_request_irq(dev, adapter->irq_wakeup, | |
1577 | mwifiex_irq_wakeup_handler, IRQF_TRIGGER_LOW, | |
1578 | "wifi_wake", adapter); | |
1579 | if (ret) { | |
1580 | dev_err(dev, "Failed to request irq_wakeup %d (%d)\n", | |
1581 | adapter->irq_wakeup, ret); | |
1582 | goto err_exit; | |
1583 | } | |
1584 | ||
1585 | disable_irq(adapter->irq_wakeup); | |
1586 | if (device_init_wakeup(dev, true)) { | |
1587 | dev_err(dev, "fail to init wakeup for mwifiex\n"); | |
1588 | goto err_exit; | |
1589 | } | |
1590 | return; | |
1591 | ||
1592 | err_exit: | |
2447e2ca | 1593 | adapter->irq_wakeup = -1; |
5e28e5fb RJ |
1594 | } |
1595 | ||
5e6e3a92 BZ |
1596 | /* |
1597 | * This function adds the card. | |
1598 | * | |
1599 | * This function follows the following major steps to set up the device - | |
1600 | * - Initialize software. This includes probing the card, registering | |
1601 | * the interface operations table, and allocating/initializing the | |
1602 | * adapter structure | |
1603 | * - Set up the netlink socket | |
1604 | * - Create and start the main work queue | |
1605 | * - Register the device | |
1606 | * - Initialize firmware and hardware | |
1607 | * - Add logical interfaces | |
1608 | */ | |
1609 | int | |
4a79aa17 | 1610 | mwifiex_add_card(void *card, struct completion *fw_done, |
2e02b581 RJ |
1611 | struct mwifiex_if_ops *if_ops, u8 iface_type, |
1612 | struct device *dev) | |
5e6e3a92 | 1613 | { |
2be7859f | 1614 | struct mwifiex_adapter *adapter; |
5e6e3a92 | 1615 | |
ba1c7e45 | 1616 | if (mwifiex_register(card, dev, if_ops, (void **)&adapter)) { |
5e6e3a92 BZ |
1617 | pr_err("%s: software init failed\n", __func__); |
1618 | goto err_init_sw; | |
1619 | } | |
1620 | ||
5e28e5fb RJ |
1621 | mwifiex_probe_of(adapter); |
1622 | ||
d930faee | 1623 | adapter->iface_type = iface_type; |
4a79aa17 | 1624 | adapter->fw_done = fw_done; |
d930faee | 1625 | |
5e6e3a92 | 1626 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
5e6e3a92 BZ |
1627 | adapter->surprise_removed = false; |
1628 | init_waitqueue_head(&adapter->init_wait_q); | |
1629 | adapter->is_suspended = false; | |
1630 | adapter->hs_activated = false; | |
1631 | init_waitqueue_head(&adapter->hs_activate_wait_q); | |
600f5d90 | 1632 | init_waitqueue_head(&adapter->cmd_wait_q.wait); |
600f5d90 | 1633 | adapter->cmd_wait_q.status = 0; |
efaaa8b8 | 1634 | adapter->scan_wait_q_woken = false; |
5e6e3a92 | 1635 | |
0bc03cfd | 1636 | if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) |
6e251174 | 1637 | adapter->rx_work_enabled = true; |
6e251174 | 1638 | |
448a71cc AK |
1639 | adapter->workqueue = |
1640 | alloc_workqueue("MWIFIEX_WORK_QUEUE", | |
1641 | WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); | |
5e6e3a92 BZ |
1642 | if (!adapter->workqueue) |
1643 | goto err_kmalloc; | |
1644 | ||
1645 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); | |
6e251174 AP |
1646 | |
1647 | if (adapter->rx_work_enabled) { | |
1648 | adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE", | |
1649 | WQ_HIGHPRI | | |
1650 | WQ_MEM_RECLAIM | | |
1651 | WQ_UNBOUND, 1); | |
1652 | if (!adapter->rx_workqueue) | |
1653 | goto err_kmalloc; | |
1654 | ||
1655 | INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue); | |
1656 | } | |
1657 | ||
5e6e3a92 | 1658 | /* Register the device. Fill up the private data structure with relevant |
232fde06 | 1659 | information from the card. */ |
5e6e3a92 BZ |
1660 | if (adapter->if_ops.register_dev(adapter)) { |
1661 | pr_err("%s: failed to register mwifiex device\n", __func__); | |
1662 | goto err_registerdev; | |
1663 | } | |
1664 | ||
4c5dae59 | 1665 | if (mwifiex_init_hw_fw(adapter, true)) { |
5e6e3a92 BZ |
1666 | pr_err("%s: firmware init failed\n", __func__); |
1667 | goto err_init_fw; | |
1668 | } | |
2be7859f | 1669 | |
5e6e3a92 BZ |
1670 | return 0; |
1671 | ||
5e6e3a92 | 1672 | err_init_fw: |
5e6e3a92 | 1673 | pr_debug("info: %s: unregister device\n", __func__); |
4daffe35 AK |
1674 | if (adapter->if_ops.unregister_dev) |
1675 | adapter->if_ops.unregister_dev(adapter); | |
6b41f941 AK |
1676 | err_registerdev: |
1677 | adapter->surprise_removed = true; | |
1678 | mwifiex_terminate_workqueue(adapter); | |
5bf15e3f XH |
1679 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) { |
1680 | pr_debug("info: %s: shutdown mwifiex\n", __func__); | |
1681 | mwifiex_shutdown_drv(adapter); | |
ce32d1d8 | 1682 | mwifiex_free_cmd_buffers(adapter); |
5bf15e3f | 1683 | } |
6b41f941 | 1684 | err_kmalloc: |
f101d964 JC |
1685 | if (adapter->irq_wakeup >= 0) |
1686 | device_init_wakeup(adapter->dev, false); | |
5e6e3a92 BZ |
1687 | mwifiex_free_adapter(adapter); |
1688 | ||
1689 | err_init_sw: | |
5e6e3a92 | 1690 | |
5e6e3a92 BZ |
1691 | return -1; |
1692 | } | |
1693 | EXPORT_SYMBOL_GPL(mwifiex_add_card); | |
1694 | ||
1695 | /* | |
1696 | * This function removes the card. | |
1697 | * | |
1698 | * This function follows the following major steps to remove the device - | |
1699 | * - Stop data traffic | |
1700 | * - Shutdown firmware | |
1701 | * - Remove the logical interfaces | |
1702 | * - Terminate the work queue | |
1703 | * - Unregister the device | |
1704 | * - Free the adapter structure | |
1705 | */ | |
4a79aa17 | 1706 | int mwifiex_remove_card(struct mwifiex_adapter *adapter) |
5e6e3a92 | 1707 | { |
5e6e3a92 | 1708 | if (!adapter) |
b6658b66 | 1709 | return 0; |
93a1df48 | 1710 | |
b6658b66 | 1711 | mwifiex_uninit_sw(adapter); |
93a1df48 | 1712 | |
36908c4e BN |
1713 | if (adapter->irq_wakeup >= 0) |
1714 | device_init_wakeup(adapter->dev, false); | |
1715 | ||
5e6e3a92 | 1716 | /* Unregister device */ |
acebe8c1 ZL |
1717 | mwifiex_dbg(adapter, INFO, |
1718 | "info: unregister device\n"); | |
4daffe35 AK |
1719 | if (adapter->if_ops.unregister_dev) |
1720 | adapter->if_ops.unregister_dev(adapter); | |
5e6e3a92 | 1721 | /* Free adapter structure */ |
acebe8c1 ZL |
1722 | mwifiex_dbg(adapter, INFO, |
1723 | "info: free adapter\n"); | |
5e6e3a92 BZ |
1724 | mwifiex_free_adapter(adapter); |
1725 | ||
5e6e3a92 BZ |
1726 | return 0; |
1727 | } | |
1728 | EXPORT_SYMBOL_GPL(mwifiex_remove_card); | |
1729 | ||
36925e52 JP |
1730 | void _mwifiex_dbg(const struct mwifiex_adapter *adapter, int mask, |
1731 | const char *fmt, ...) | |
1732 | { | |
1733 | struct va_format vaf; | |
1734 | va_list args; | |
1735 | ||
ef6c7d3c | 1736 | if (!(adapter->debug_mask & mask)) |
36925e52 JP |
1737 | return; |
1738 | ||
1739 | va_start(args, fmt); | |
1740 | ||
1741 | vaf.fmt = fmt; | |
1742 | vaf.va = &args; | |
1743 | ||
ef6c7d3c XH |
1744 | if (adapter->dev) |
1745 | dev_info(adapter->dev, "%pV", &vaf); | |
1746 | else | |
1747 | pr_info("%pV", &vaf); | |
36925e52 JP |
1748 | |
1749 | va_end(args); | |
1750 | } | |
1751 | EXPORT_SYMBOL_GPL(_mwifiex_dbg); | |
1752 | ||
5e6e3a92 BZ |
1753 | /* |
1754 | * This function initializes the module. | |
1755 | * | |
1756 | * The debug FS is also initialized if configured. | |
1757 | */ | |
1758 | static int | |
1759 | mwifiex_init_module(void) | |
1760 | { | |
1761 | #ifdef CONFIG_DEBUG_FS | |
1762 | mwifiex_debugfs_init(); | |
1763 | #endif | |
1764 | return 0; | |
1765 | } | |
1766 | ||
1767 | /* | |
1768 | * This function cleans up the module. | |
1769 | * | |
1770 | * The debug FS is removed if available. | |
1771 | */ | |
1772 | static void | |
1773 | mwifiex_cleanup_module(void) | |
1774 | { | |
1775 | #ifdef CONFIG_DEBUG_FS | |
1776 | mwifiex_debugfs_remove(); | |
1777 | #endif | |
1778 | } | |
1779 | ||
1780 | module_init(mwifiex_init_module); | |
1781 | module_exit(mwifiex_cleanup_module); | |
1782 | ||
1783 | MODULE_AUTHOR("Marvell International Ltd."); | |
1784 | MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION); | |
1785 | MODULE_VERSION(VERSION); | |
1786 | MODULE_LICENSE("GPL v2"); |