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