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 | ||
27 | const char driver_version[] = "mwifiex " VERSION " (%s) "; | |
388ec385 AK |
28 | static char *cal_data_cfg; |
29 | module_param(cal_data_cfg, charp, 0); | |
5e6e3a92 | 30 | |
0013c7ce AP |
31 | static unsigned short driver_mode; |
32 | module_param(driver_mode, ushort, 0); | |
33 | MODULE_PARM_DESC(driver_mode, | |
34 | "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7"); | |
35 | ||
5e6e3a92 BZ |
36 | /* |
37 | * This function registers the device and performs all the necessary | |
38 | * initializations. | |
39 | * | |
40 | * The following initialization operations are performed - | |
41 | * - Allocate adapter structure | |
42 | * - Save interface specific operations table in adapter | |
43 | * - Call interface specific initialization routine | |
44 | * - Allocate private structures | |
45 | * - Set default adapter structure parameters | |
46 | * - Initialize locks | |
47 | * | |
48 | * In case of any errors during inittialization, this function also ensures | |
49 | * proper cleanup before exiting. | |
50 | */ | |
51 | static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, | |
287546df | 52 | void **padapter) |
5e6e3a92 | 53 | { |
2be7859f AK |
54 | struct mwifiex_adapter *adapter; |
55 | int i; | |
5e6e3a92 BZ |
56 | |
57 | adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); | |
5e6e3a92 | 58 | if (!adapter) |
b53575ec | 59 | return -ENOMEM; |
5e6e3a92 | 60 | |
287546df | 61 | *padapter = adapter; |
5e6e3a92 BZ |
62 | adapter->card = card; |
63 | ||
64 | /* Save interface specific operations in adapter */ | |
65 | memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); | |
66 | ||
67 | /* card specific initialization has been deferred until now .. */ | |
4daffe35 AK |
68 | if (adapter->if_ops.init_if) |
69 | if (adapter->if_ops.init_if(adapter)) | |
70 | goto error; | |
5e6e3a92 BZ |
71 | |
72 | adapter->priv_num = 0; | |
5e6e3a92 | 73 | |
64b05e2f AP |
74 | for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { |
75 | /* Allocate memory for private structure */ | |
76 | adapter->priv[i] = | |
77 | kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL); | |
78 | if (!adapter->priv[i]) | |
79 | goto error; | |
93a1df48 | 80 | |
64b05e2f | 81 | adapter->priv[i]->adapter = adapter; |
64b05e2f AP |
82 | adapter->priv_num++; |
83 | } | |
44b815c6 | 84 | mwifiex_init_lock_list(adapter); |
5e6e3a92 BZ |
85 | |
86 | init_timer(&adapter->cmd_timer); | |
87 | adapter->cmd_timer.function = mwifiex_cmd_timeout_func; | |
88 | adapter->cmd_timer.data = (unsigned long) adapter; | |
89 | ||
5e6e3a92 BZ |
90 | return 0; |
91 | ||
92 | error: | |
93 | dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); | |
94 | ||
93a1df48 | 95 | for (i = 0; i < adapter->priv_num; i++) |
5e6e3a92 | 96 | kfree(adapter->priv[i]); |
93a1df48 | 97 | |
5e6e3a92 BZ |
98 | kfree(adapter); |
99 | ||
100 | return -1; | |
101 | } | |
102 | ||
103 | /* | |
104 | * This function unregisters the device and performs all the necessary | |
105 | * cleanups. | |
106 | * | |
107 | * The following cleanup operations are performed - | |
108 | * - Free the timers | |
109 | * - Free beacon buffers | |
110 | * - Free private structures | |
111 | * - Free adapter structure | |
112 | */ | |
113 | static int mwifiex_unregister(struct mwifiex_adapter *adapter) | |
114 | { | |
270e58e8 | 115 | s32 i; |
5e6e3a92 | 116 | |
4cfda67d AK |
117 | if (adapter->if_ops.cleanup_if) |
118 | adapter->if_ops.cleanup_if(adapter); | |
119 | ||
629873f2 | 120 | del_timer_sync(&adapter->cmd_timer); |
5e6e3a92 BZ |
121 | |
122 | /* Free private structures */ | |
123 | for (i = 0; i < adapter->priv_num; i++) { | |
124 | if (adapter->priv[i]) { | |
125 | mwifiex_free_curr_bcn(adapter->priv[i]); | |
126 | kfree(adapter->priv[i]); | |
127 | } | |
128 | } | |
129 | ||
bf354433 | 130 | vfree(adapter->chan_stats); |
5e6e3a92 BZ |
131 | kfree(adapter); |
132 | return 0; | |
133 | } | |
134 | ||
6e251174 AP |
135 | static int mwifiex_process_rx(struct mwifiex_adapter *adapter) |
136 | { | |
137 | unsigned long flags; | |
138 | struct sk_buff *skb; | |
6e251174 AP |
139 | |
140 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); | |
141 | if (adapter->rx_processing || adapter->rx_locked) { | |
142 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
143 | goto exit_rx_proc; | |
144 | } else { | |
145 | adapter->rx_processing = true; | |
146 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
147 | } | |
148 | ||
149 | /* Check for Rx data */ | |
150 | while ((skb = skb_dequeue(&adapter->rx_data_q))) { | |
151 | atomic_dec(&adapter->rx_pending); | |
152 | if (adapter->delay_main_work && | |
b43a0d9d | 153 | (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) { |
cf6a64fd AK |
154 | if (adapter->if_ops.submit_rem_rx_urbs) |
155 | adapter->if_ops.submit_rem_rx_urbs(adapter); | |
6e251174 | 156 | adapter->delay_main_work = false; |
b43a0d9d | 157 | queue_work(adapter->workqueue, &adapter->main_work); |
6e251174 AP |
158 | } |
159 | mwifiex_handle_rx_packet(adapter, skb); | |
160 | } | |
161 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); | |
162 | adapter->rx_processing = false; | |
163 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
164 | ||
6e251174 AP |
165 | exit_rx_proc: |
166 | return 0; | |
167 | } | |
168 | ||
5e6e3a92 BZ |
169 | /* |
170 | * The main process. | |
171 | * | |
172 | * This function is the main procedure of the driver and handles various driver | |
173 | * operations. It runs in a loop and provides the core functionalities. | |
174 | * | |
175 | * The main responsibilities of this function are - | |
176 | * - Ensure concurrency control | |
177 | * - Handle pending interrupts and call interrupt handlers | |
178 | * - Wake up the card if required | |
179 | * - Handle command responses and call response handlers | |
180 | * - Handle events and call event handlers | |
181 | * - Execute pending commands | |
182 | * - Transmit pending data packets | |
183 | */ | |
184 | int mwifiex_main_process(struct mwifiex_adapter *adapter) | |
185 | { | |
186 | int ret = 0; | |
187 | unsigned long flags; | |
188 | ||
189 | spin_lock_irqsave(&adapter->main_proc_lock, flags); | |
190 | ||
191 | /* Check if already processing */ | |
192 | if (adapter->mwifiex_processing) { | |
193 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
194 | goto exit_main_proc; | |
195 | } else { | |
196 | adapter->mwifiex_processing = true; | |
197 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
198 | } | |
199 | process_start: | |
200 | do { | |
201 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) || | |
202 | (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)) | |
203 | break; | |
204 | ||
6e251174 AP |
205 | /* If we process interrupts first, it would increase RX pending |
206 | * even further. Avoid this by checking if rx_pending has | |
207 | * crossed high threshold and schedule rx work queue | |
208 | * and then process interrupts | |
209 | */ | |
210 | if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING) { | |
211 | adapter->delay_main_work = true; | |
212 | if (!adapter->rx_processing) | |
213 | queue_work(adapter->rx_workqueue, | |
214 | &adapter->rx_work); | |
215 | break; | |
216 | } | |
217 | ||
5e6e3a92 BZ |
218 | /* Handle pending interrupt if any */ |
219 | if (adapter->int_status) { | |
220 | if (adapter->hs_activated) | |
221 | mwifiex_process_hs_config(adapter); | |
4daffe35 AK |
222 | if (adapter->if_ops.process_int_status) |
223 | adapter->if_ops.process_int_status(adapter); | |
5e6e3a92 BZ |
224 | } |
225 | ||
6e251174 AP |
226 | if (adapter->rx_work_enabled && adapter->data_received) |
227 | queue_work(adapter->rx_workqueue, &adapter->rx_work); | |
228 | ||
5e6e3a92 BZ |
229 | /* Need to wake up the card ? */ |
230 | if ((adapter->ps_state == PS_STATE_SLEEP) && | |
231 | (adapter->pm_wakeup_card_req && | |
232 | !adapter->pm_wakeup_fw_try) && | |
f57c1edc YAP |
233 | (is_command_pending(adapter) || |
234 | !mwifiex_wmm_lists_empty(adapter))) { | |
5e6e3a92 BZ |
235 | adapter->pm_wakeup_fw_try = true; |
236 | adapter->if_ops.wakeup(adapter); | |
237 | continue; | |
238 | } | |
4daffe35 | 239 | |
5e6e3a92 | 240 | if (IS_CARD_RX_RCVD(adapter)) { |
6e251174 | 241 | adapter->data_received = false; |
5e6e3a92 BZ |
242 | adapter->pm_wakeup_fw_try = false; |
243 | if (adapter->ps_state == PS_STATE_SLEEP) | |
244 | adapter->ps_state = PS_STATE_AWAKE; | |
245 | } else { | |
246 | /* We have tried to wakeup the card already */ | |
247 | if (adapter->pm_wakeup_fw_try) | |
248 | break; | |
249 | if (adapter->ps_state != PS_STATE_AWAKE || | |
250 | adapter->tx_lock_flag) | |
251 | break; | |
252 | ||
5ec39efa | 253 | if ((!adapter->scan_chan_gap_enabled && |
5ec39efa | 254 | adapter->scan_processing) || adapter->data_sent || |
f57c1edc YAP |
255 | mwifiex_wmm_lists_empty(adapter)) { |
256 | if (adapter->cmd_sent || adapter->curr_cmd || | |
257 | (!is_command_pending(adapter))) | |
5e6e3a92 BZ |
258 | break; |
259 | } | |
260 | } | |
261 | ||
20474129 AK |
262 | /* Check for event */ |
263 | if (adapter->event_received) { | |
264 | adapter->event_received = false; | |
265 | mwifiex_process_event(adapter); | |
266 | } | |
267 | ||
5e6e3a92 BZ |
268 | /* Check for Cmd Resp */ |
269 | if (adapter->cmd_resp_received) { | |
270 | adapter->cmd_resp_received = false; | |
271 | mwifiex_process_cmdresp(adapter); | |
272 | ||
273 | /* call mwifiex back when init_fw is done */ | |
274 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) { | |
275 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
276 | mwifiex_init_fw_complete(adapter); | |
277 | } | |
278 | } | |
279 | ||
5e6e3a92 BZ |
280 | /* Check if we need to confirm Sleep Request |
281 | received previously */ | |
282 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) { | |
283 | if (!adapter->cmd_sent && !adapter->curr_cmd) | |
284 | mwifiex_check_ps_cond(adapter); | |
285 | } | |
286 | ||
287 | /* * The ps_state may have been changed during processing of | |
288 | * Sleep Request event. | |
289 | */ | |
f57c1edc YAP |
290 | if ((adapter->ps_state == PS_STATE_SLEEP) || |
291 | (adapter->ps_state == PS_STATE_PRE_SLEEP) || | |
292 | (adapter->ps_state == PS_STATE_SLEEP_CFM) || | |
293 | adapter->tx_lock_flag) | |
5e6e3a92 BZ |
294 | continue; |
295 | ||
296 | if (!adapter->cmd_sent && !adapter->curr_cmd) { | |
297 | if (mwifiex_exec_next_cmd(adapter) == -1) { | |
298 | ret = -1; | |
299 | break; | |
300 | } | |
301 | } | |
302 | ||
5ec39efa | 303 | if ((adapter->scan_chan_gap_enabled || |
d8d91253 | 304 | !adapter->scan_processing) && |
3249ba73 | 305 | !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) { |
5e6e3a92 BZ |
306 | mwifiex_wmm_process_tx(adapter); |
307 | if (adapter->hs_activated) { | |
308 | adapter->is_hs_configured = false; | |
309 | mwifiex_hs_activated_event | |
310 | (mwifiex_get_priv | |
311 | (adapter, MWIFIEX_BSS_ROLE_ANY), | |
312 | false); | |
313 | } | |
314 | } | |
315 | ||
316 | if (adapter->delay_null_pkt && !adapter->cmd_sent && | |
f57c1edc YAP |
317 | !adapter->curr_cmd && !is_command_pending(adapter) && |
318 | mwifiex_wmm_lists_empty(adapter)) { | |
5e6e3a92 BZ |
319 | if (!mwifiex_send_null_packet |
320 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), | |
321 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET | | |
322 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) { | |
323 | adapter->delay_null_pkt = false; | |
324 | adapter->ps_state = PS_STATE_SLEEP; | |
325 | } | |
326 | break; | |
327 | } | |
328 | } while (true); | |
329 | ||
453b0c3f | 330 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
f73e557b AP |
331 | if (!adapter->delay_main_work && |
332 | (adapter->int_status || IS_CARD_RX_RCVD(adapter))) { | |
453b0c3f | 333 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
5e6e3a92 | 334 | goto process_start; |
453b0c3f | 335 | } |
5e6e3a92 | 336 | |
5e6e3a92 BZ |
337 | adapter->mwifiex_processing = false; |
338 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); | |
339 | ||
340 | exit_main_proc: | |
341 | if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) | |
342 | mwifiex_shutdown_drv(adapter); | |
343 | return ret; | |
344 | } | |
601216e1 | 345 | EXPORT_SYMBOL_GPL(mwifiex_main_process); |
5e6e3a92 | 346 | |
5e6e3a92 BZ |
347 | /* |
348 | * This function frees the adapter structure. | |
349 | * | |
350 | * Additionally, this closes the netlink socket, frees the timers | |
351 | * and private structures. | |
352 | */ | |
353 | static void mwifiex_free_adapter(struct mwifiex_adapter *adapter) | |
354 | { | |
355 | if (!adapter) { | |
356 | pr_err("%s: adapter is NULL\n", __func__); | |
357 | return; | |
358 | } | |
359 | ||
360 | mwifiex_unregister(adapter); | |
361 | pr_debug("info: %s: free adapter\n", __func__); | |
362 | } | |
363 | ||
6b41f941 AK |
364 | /* |
365 | * This function cancels all works in the queue and destroys | |
366 | * the main workqueue. | |
367 | */ | |
368 | static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter) | |
369 | { | |
370 | flush_workqueue(adapter->workqueue); | |
371 | destroy_workqueue(adapter->workqueue); | |
372 | adapter->workqueue = NULL; | |
6e251174 AP |
373 | |
374 | if (adapter->rx_workqueue) { | |
375 | flush_workqueue(adapter->rx_workqueue); | |
376 | destroy_workqueue(adapter->rx_workqueue); | |
377 | adapter->rx_workqueue = NULL; | |
378 | } | |
6b41f941 AK |
379 | } |
380 | ||
5e6e3a92 | 381 | /* |
59a4cc25 | 382 | * This function gets firmware and initializes it. |
5e6e3a92 BZ |
383 | * |
384 | * The main initialization steps followed are - | |
385 | * - Download the correct firmware to card | |
5e6e3a92 BZ |
386 | * - Issue the init commands to firmware |
387 | */ | |
59a4cc25 | 388 | static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) |
5e6e3a92 | 389 | { |
bec568ff | 390 | int ret; |
59a4cc25 AK |
391 | char fmt[64]; |
392 | struct mwifiex_private *priv; | |
393 | struct mwifiex_adapter *adapter = context; | |
5e6e3a92 | 394 | struct mwifiex_fw_image fw; |
c3afd99f AK |
395 | struct semaphore *sem = adapter->card_sem; |
396 | bool init_failed = false; | |
68b76e99 | 397 | struct wireless_dev *wdev; |
5e6e3a92 | 398 | |
59a4cc25 AK |
399 | if (!firmware) { |
400 | dev_err(adapter->dev, | |
401 | "Failed to get firmware %s\n", adapter->fw_name); | |
6b41f941 | 402 | goto err_dnld_fw; |
5e6e3a92 | 403 | } |
59a4cc25 AK |
404 | |
405 | memset(&fw, 0, sizeof(struct mwifiex_fw_image)); | |
406 | adapter->firmware = firmware; | |
5e6e3a92 BZ |
407 | fw.fw_buf = (u8 *) adapter->firmware->data; |
408 | fw.fw_len = adapter->firmware->size; | |
409 | ||
4daffe35 AK |
410 | if (adapter->if_ops.dnld_fw) |
411 | ret = adapter->if_ops.dnld_fw(adapter, &fw); | |
412 | else | |
413 | ret = mwifiex_dnld_fw(adapter, &fw); | |
5e6e3a92 | 414 | if (ret == -1) |
6b41f941 | 415 | goto err_dnld_fw; |
5e6e3a92 BZ |
416 | |
417 | dev_notice(adapter->dev, "WLAN FW is active\n"); | |
418 | ||
388ec385 AK |
419 | if (cal_data_cfg) { |
420 | if ((request_firmware(&adapter->cal_data, cal_data_cfg, | |
421 | adapter->dev)) < 0) | |
422 | dev_err(adapter->dev, | |
423 | "Cal data request_firmware() failed\n"); | |
424 | } | |
425 | ||
232fde06 | 426 | /* enable host interrupt after fw dnld is successful */ |
6b41f941 AK |
427 | if (adapter->if_ops.enable_int) { |
428 | if (adapter->if_ops.enable_int(adapter)) | |
429 | goto err_dnld_fw; | |
430 | } | |
232fde06 | 431 | |
5e6e3a92 BZ |
432 | adapter->init_wait_q_woken = false; |
433 | ret = mwifiex_init_fw(adapter); | |
434 | if (ret == -1) { | |
6b41f941 | 435 | goto err_init_fw; |
5e6e3a92 BZ |
436 | } else if (!ret) { |
437 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
438 | goto done; | |
439 | } | |
440 | /* Wait for mwifiex_init to complete */ | |
441 | wait_event_interruptible(adapter->init_wait_q, | |
442 | adapter->init_wait_q_woken); | |
59a4cc25 | 443 | if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) |
6b41f941 | 444 | goto err_init_fw; |
59a4cc25 | 445 | |
d6bffe8b AP |
446 | priv = adapter->priv[MWIFIEX_BSS_ROLE_STA]; |
447 | if (mwifiex_register_cfg80211(adapter)) { | |
59a4cc25 | 448 | dev_err(adapter->dev, "cannot register with cfg80211\n"); |
d1af2943 | 449 | goto err_init_fw; |
59a4cc25 AK |
450 | } |
451 | ||
bf354433 AP |
452 | if (mwifiex_init_channel_scan_gap(adapter)) { |
453 | dev_err(adapter->dev, "could not init channel stats table\n"); | |
454 | goto err_init_fw; | |
455 | } | |
456 | ||
0013c7ce AP |
457 | if (driver_mode) { |
458 | driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK; | |
459 | driver_mode |= MWIFIEX_DRIVER_MODE_STA; | |
460 | } | |
461 | ||
59a4cc25 AK |
462 | rtnl_lock(); |
463 | /* Create station interface by default */ | |
68b76e99 AK |
464 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", |
465 | NL80211_IFTYPE_STATION, NULL, NULL); | |
466 | if (IS_ERR(wdev)) { | |
59a4cc25 | 467 | dev_err(adapter->dev, "cannot create default STA interface\n"); |
bec568ff | 468 | rtnl_unlock(); |
59a4cc25 | 469 | goto err_add_intf; |
5e6e3a92 | 470 | } |
0013c7ce AP |
471 | |
472 | if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) { | |
473 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", | |
474 | NL80211_IFTYPE_AP, NULL, NULL); | |
475 | if (IS_ERR(wdev)) { | |
476 | dev_err(adapter->dev, "cannot create AP interface\n"); | |
477 | rtnl_unlock(); | |
478 | goto err_add_intf; | |
479 | } | |
480 | } | |
481 | ||
482 | if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) { | |
483 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", | |
484 | NL80211_IFTYPE_P2P_CLIENT, NULL, | |
485 | NULL); | |
486 | if (IS_ERR(wdev)) { | |
487 | dev_err(adapter->dev, | |
488 | "cannot create p2p client interface\n"); | |
489 | rtnl_unlock(); | |
490 | goto err_add_intf; | |
491 | } | |
492 | } | |
59a4cc25 AK |
493 | rtnl_unlock(); |
494 | ||
495 | mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); | |
496 | dev_notice(adapter->dev, "driver_version = %s\n", fmt); | |
497 | goto done; | |
5e6e3a92 | 498 | |
59a4cc25 | 499 | err_add_intf: |
6b41f941 AK |
500 | wiphy_unregister(adapter->wiphy); |
501 | wiphy_free(adapter->wiphy); | |
59a4cc25 | 502 | err_init_fw: |
232fde06 DD |
503 | if (adapter->if_ops.disable_int) |
504 | adapter->if_ops.disable_int(adapter); | |
6b41f941 | 505 | err_dnld_fw: |
59a4cc25 | 506 | pr_debug("info: %s: unregister device\n", __func__); |
6b41f941 AK |
507 | if (adapter->if_ops.unregister_dev) |
508 | adapter->if_ops.unregister_dev(adapter); | |
509 | ||
510 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) || | |
511 | (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { | |
512 | pr_debug("info: %s: shutdown mwifiex\n", __func__); | |
513 | adapter->init_wait_q_woken = false; | |
514 | ||
515 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) | |
516 | wait_event_interruptible(adapter->init_wait_q, | |
517 | adapter->init_wait_q_woken); | |
518 | } | |
519 | adapter->surprise_removed = true; | |
520 | mwifiex_terminate_workqueue(adapter); | |
c3afd99f | 521 | init_failed = true; |
5e6e3a92 | 522 | done: |
388ec385 AK |
523 | if (adapter->cal_data) { |
524 | release_firmware(adapter->cal_data); | |
525 | adapter->cal_data = NULL; | |
526 | } | |
c3afd99f AK |
527 | if (adapter->firmware) { |
528 | release_firmware(adapter->firmware); | |
529 | adapter->firmware = NULL; | |
530 | } | |
c3afd99f AK |
531 | if (init_failed) |
532 | mwifiex_free_adapter(adapter); | |
533 | up(sem); | |
59a4cc25 AK |
534 | return; |
535 | } | |
536 | ||
537 | /* | |
538 | * This function initializes the hardware and gets firmware. | |
539 | */ | |
540 | static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter) | |
541 | { | |
542 | int ret; | |
543 | ||
59a4cc25 AK |
544 | ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, |
545 | adapter->dev, GFP_KERNEL, adapter, | |
546 | mwifiex_fw_dpc); | |
547 | if (ret < 0) | |
548 | dev_err(adapter->dev, | |
549 | "request_firmware_nowait() returned error %d\n", ret); | |
5e6e3a92 BZ |
550 | return ret; |
551 | } | |
552 | ||
5e6e3a92 BZ |
553 | /* |
554 | * CFG802.11 network device handler for open. | |
555 | * | |
556 | * Starts the data queue. | |
557 | */ | |
558 | static int | |
559 | mwifiex_open(struct net_device *dev) | |
560 | { | |
bbea3bc4 | 561 | netif_tx_start_all_queues(dev); |
5e6e3a92 BZ |
562 | return 0; |
563 | } | |
564 | ||
565 | /* | |
566 | * CFG802.11 network device handler for close. | |
567 | */ | |
568 | static int | |
569 | mwifiex_close(struct net_device *dev) | |
570 | { | |
f162cac8 AK |
571 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
572 | ||
573 | if (priv->scan_request) { | |
574 | dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n"); | |
575 | cfg80211_scan_done(priv->scan_request, 1); | |
576 | priv->scan_request = NULL; | |
75ab753d | 577 | priv->scan_aborting = true; |
f162cac8 AK |
578 | } |
579 | ||
5e6e3a92 BZ |
580 | return 0; |
581 | } | |
582 | ||
e39faa73 SP |
583 | /* |
584 | * Add buffer into wmm tx queue and queue work to transmit it. | |
585 | */ | |
586 | int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb) | |
587 | { | |
47411a06 AP |
588 | struct netdev_queue *txq; |
589 | int index = mwifiex_1d_to_wmm_queue[skb->priority]; | |
590 | ||
591 | if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) { | |
592 | txq = netdev_get_tx_queue(priv->netdev, index); | |
593 | if (!netif_tx_queue_stopped(txq)) { | |
594 | netif_tx_stop_queue(txq); | |
595 | dev_dbg(priv->adapter->dev, "stop queue: %d\n", index); | |
596 | } | |
597 | } | |
598 | ||
e39faa73 | 599 | atomic_inc(&priv->adapter->tx_pending); |
47411a06 | 600 | mwifiex_wmm_add_buf_txqueue(priv, skb); |
e39faa73 | 601 | |
e39faa73 SP |
602 | queue_work(priv->adapter->workqueue, &priv->adapter->main_work); |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
5e6e3a92 BZ |
607 | /* |
608 | * CFG802.11 network device handler for data transmission. | |
609 | */ | |
610 | static int | |
611 | mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
612 | { | |
613 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
270e58e8 | 614 | struct sk_buff *new_skb; |
5e6e3a92 BZ |
615 | struct mwifiex_txinfo *tx_info; |
616 | ||
9da9a3b2 | 617 | dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n", |
f57c1edc | 618 | jiffies, priv->bss_type, priv->bss_num); |
5e6e3a92 BZ |
619 | |
620 | if (priv->adapter->surprise_removed) { | |
b53575ec | 621 | kfree_skb(skb); |
5e6e3a92 BZ |
622 | priv->stats.tx_dropped++; |
623 | return 0; | |
624 | } | |
625 | if (!skb->len || (skb->len > ETH_FRAME_LEN)) { | |
626 | dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len); | |
b53575ec | 627 | kfree_skb(skb); |
5e6e3a92 BZ |
628 | priv->stats.tx_dropped++; |
629 | return 0; | |
630 | } | |
631 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { | |
632 | dev_dbg(priv->adapter->dev, | |
633 | "data: Tx: insufficient skb headroom %d\n", | |
f57c1edc | 634 | skb_headroom(skb)); |
5e6e3a92 BZ |
635 | /* Insufficient skb headroom - allocate a new skb */ |
636 | new_skb = | |
637 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); | |
638 | if (unlikely(!new_skb)) { | |
639 | dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n"); | |
b53575ec | 640 | kfree_skb(skb); |
5e6e3a92 BZ |
641 | priv->stats.tx_dropped++; |
642 | return 0; | |
643 | } | |
644 | kfree_skb(skb); | |
645 | skb = new_skb; | |
646 | dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n", | |
f57c1edc | 647 | skb_headroom(skb)); |
5e6e3a92 BZ |
648 | } |
649 | ||
650 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
d76744a9 | 651 | memset(tx_info, 0, sizeof(*tx_info)); |
9da9a3b2 YAP |
652 | tx_info->bss_num = priv->bss_num; |
653 | tx_info->bss_type = priv->bss_type; | |
a1ed4849 | 654 | tx_info->pkt_len = skb->len; |
47411a06 AP |
655 | |
656 | /* Record the current time the packet was queued; used to | |
657 | * determine the amount of time the packet was queued in | |
658 | * the driver before it was sent to the firmware. | |
659 | * The delay is then sent along with the packet to the | |
660 | * firmware for aggregate delay calculation for stats and | |
661 | * MSDU lifetime expiry. | |
662 | */ | |
c64800e7 | 663 | __net_timestamp(skb); |
5e6e3a92 | 664 | |
e39faa73 | 665 | mwifiex_queue_tx_pkt(priv, skb); |
5e6e3a92 BZ |
666 | |
667 | return 0; | |
668 | } | |
669 | ||
670 | /* | |
671 | * CFG802.11 network device handler for setting MAC address. | |
672 | */ | |
673 | static int | |
674 | mwifiex_set_mac_address(struct net_device *dev, void *addr) | |
675 | { | |
676 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
a5ffddb7 | 677 | struct sockaddr *hw_addr = addr; |
270e58e8 | 678 | int ret; |
5e6e3a92 BZ |
679 | |
680 | memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); | |
681 | ||
600f5d90 | 682 | /* Send request to firmware */ |
fa0ecbb9 BZ |
683 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS, |
684 | HostCmd_ACT_GEN_SET, 0, NULL, true); | |
600f5d90 AK |
685 | |
686 | if (!ret) | |
687 | memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN); | |
688 | else | |
f57c1edc YAP |
689 | dev_err(priv->adapter->dev, |
690 | "set mac address failed: ret=%d\n", ret); | |
600f5d90 | 691 | |
5e6e3a92 BZ |
692 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
693 | ||
600f5d90 | 694 | return ret; |
5e6e3a92 BZ |
695 | } |
696 | ||
697 | /* | |
698 | * CFG802.11 network device handler for setting multicast list. | |
699 | */ | |
700 | static void mwifiex_set_multicast_list(struct net_device *dev) | |
701 | { | |
702 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
600f5d90 AK |
703 | struct mwifiex_multicast_list mcast_list; |
704 | ||
705 | if (dev->flags & IFF_PROMISC) { | |
706 | mcast_list.mode = MWIFIEX_PROMISC_MODE; | |
707 | } else if (dev->flags & IFF_ALLMULTI || | |
708 | netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) { | |
709 | mcast_list.mode = MWIFIEX_ALL_MULTI_MODE; | |
710 | } else { | |
711 | mcast_list.mode = MWIFIEX_MULTICAST_MODE; | |
6390d885 DD |
712 | mcast_list.num_multicast_addr = |
713 | mwifiex_copy_mcast_addr(&mcast_list, dev); | |
600f5d90 AK |
714 | } |
715 | mwifiex_request_set_multicast_list(priv, &mcast_list); | |
5e6e3a92 BZ |
716 | } |
717 | ||
718 | /* | |
719 | * CFG802.11 network device handler for transmission timeout. | |
720 | */ | |
721 | static void | |
722 | mwifiex_tx_timeout(struct net_device *dev) | |
723 | { | |
724 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
725 | ||
5e6e3a92 | 726 | priv->num_tx_timeout++; |
8908c7d5 AN |
727 | priv->tx_timeout_cnt++; |
728 | dev_err(priv->adapter->dev, | |
729 | "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n", | |
730 | jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num); | |
731 | mwifiex_set_trans_start(dev); | |
732 | ||
733 | if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD && | |
734 | priv->adapter->if_ops.card_reset) { | |
735 | dev_err(priv->adapter->dev, | |
736 | "tx_timeout_cnt exceeds threshold. Triggering card reset!\n"); | |
737 | priv->adapter->if_ops.card_reset(priv->adapter); | |
738 | } | |
5e6e3a92 BZ |
739 | } |
740 | ||
741 | /* | |
742 | * CFG802.11 network device handler for statistics retrieval. | |
743 | */ | |
744 | static struct net_device_stats *mwifiex_get_stats(struct net_device *dev) | |
745 | { | |
746 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
747 | ||
748 | return &priv->stats; | |
749 | } | |
750 | ||
47411a06 | 751 | static u16 |
f663dd9a | 752 | mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, |
99932d4f | 753 | void *accel_priv, select_queue_fallback_t fallback) |
47411a06 | 754 | { |
fa9ffc74 | 755 | skb->priority = cfg80211_classify8021d(skb, NULL); |
47411a06 AP |
756 | return mwifiex_1d_to_wmm_queue[skb->priority]; |
757 | } | |
758 | ||
5e6e3a92 BZ |
759 | /* Network device handlers */ |
760 | static const struct net_device_ops mwifiex_netdev_ops = { | |
761 | .ndo_open = mwifiex_open, | |
762 | .ndo_stop = mwifiex_close, | |
763 | .ndo_start_xmit = mwifiex_hard_start_xmit, | |
764 | .ndo_set_mac_address = mwifiex_set_mac_address, | |
765 | .ndo_tx_timeout = mwifiex_tx_timeout, | |
766 | .ndo_get_stats = mwifiex_get_stats, | |
afc4b13d | 767 | .ndo_set_rx_mode = mwifiex_set_multicast_list, |
47411a06 | 768 | .ndo_select_queue = mwifiex_netdev_select_wmm_queue, |
5e6e3a92 BZ |
769 | }; |
770 | ||
771 | /* | |
772 | * This function initializes the private structure parameters. | |
773 | * | |
774 | * The following wait queues are initialized - | |
775 | * - IOCTL wait queue | |
776 | * - Command wait queue | |
777 | * - Statistics wait queue | |
778 | * | |
779 | * ...and the following default parameters are set - | |
780 | * - Current key index : Set to 0 | |
781 | * - Rate index : Set to auto | |
782 | * - Media connected : Set to disconnected | |
783 | * - Adhoc link sensed : Set to false | |
784 | * - Nick name : Set to null | |
785 | * - Number of Tx timeout : Set to 0 | |
786 | * - Device address : Set to current address | |
787 | * | |
788 | * In addition, the CFG80211 work queue is also created. | |
789 | */ | |
93a1df48 YAP |
790 | void mwifiex_init_priv_params(struct mwifiex_private *priv, |
791 | struct net_device *dev) | |
5e6e3a92 BZ |
792 | { |
793 | dev->netdev_ops = &mwifiex_netdev_ops; | |
f16fdc9d | 794 | dev->destructor = free_netdev; |
5e6e3a92 | 795 | /* Initialize private structure */ |
5e6e3a92 BZ |
796 | priv->current_key_index = 0; |
797 | priv->media_connected = false; | |
798 | memset(&priv->nick_name, 0, sizeof(priv->nick_name)); | |
ede98bfa AP |
799 | memset(priv->mgmt_ie, 0, |
800 | sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX); | |
f31acabe AP |
801 | priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK; |
802 | priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK; | |
803 | priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK; | |
804 | priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK; | |
5e6e3a92 | 805 | priv->num_tx_timeout = 0; |
5e6e3a92 BZ |
806 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
807 | } | |
808 | ||
5e6e3a92 BZ |
809 | /* |
810 | * This function check if command is pending. | |
811 | */ | |
812 | int is_command_pending(struct mwifiex_adapter *adapter) | |
813 | { | |
814 | unsigned long flags; | |
815 | int is_cmd_pend_q_empty; | |
816 | ||
817 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
818 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); | |
819 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
820 | ||
821 | return !is_cmd_pend_q_empty; | |
822 | } | |
823 | ||
6e251174 AP |
824 | /* |
825 | * This is the RX work queue function. | |
826 | * | |
827 | * It handles the RX operations. | |
828 | */ | |
829 | static void mwifiex_rx_work_queue(struct work_struct *work) | |
830 | { | |
831 | struct mwifiex_adapter *adapter = | |
832 | container_of(work, struct mwifiex_adapter, rx_work); | |
833 | ||
834 | if (adapter->surprise_removed) | |
835 | return; | |
836 | mwifiex_process_rx(adapter); | |
837 | } | |
838 | ||
5e6e3a92 BZ |
839 | /* |
840 | * This is the main work queue function. | |
841 | * | |
842 | * It handles the main process, which in turn handles the complete | |
843 | * driver operations. | |
844 | */ | |
845 | static void mwifiex_main_work_queue(struct work_struct *work) | |
846 | { | |
847 | struct mwifiex_adapter *adapter = | |
848 | container_of(work, struct mwifiex_adapter, main_work); | |
849 | ||
850 | if (adapter->surprise_removed) | |
851 | return; | |
852 | mwifiex_main_process(adapter); | |
853 | } | |
854 | ||
5e6e3a92 BZ |
855 | /* |
856 | * This function adds the card. | |
857 | * | |
858 | * This function follows the following major steps to set up the device - | |
859 | * - Initialize software. This includes probing the card, registering | |
860 | * the interface operations table, and allocating/initializing the | |
861 | * adapter structure | |
862 | * - Set up the netlink socket | |
863 | * - Create and start the main work queue | |
864 | * - Register the device | |
865 | * - Initialize firmware and hardware | |
866 | * - Add logical interfaces | |
867 | */ | |
868 | int | |
869 | mwifiex_add_card(void *card, struct semaphore *sem, | |
d930faee | 870 | struct mwifiex_if_ops *if_ops, u8 iface_type) |
5e6e3a92 | 871 | { |
2be7859f | 872 | struct mwifiex_adapter *adapter; |
5e6e3a92 BZ |
873 | |
874 | if (down_interruptible(sem)) | |
875 | goto exit_sem_err; | |
876 | ||
93a1df48 | 877 | if (mwifiex_register(card, if_ops, (void **)&adapter)) { |
5e6e3a92 BZ |
878 | pr_err("%s: software init failed\n", __func__); |
879 | goto err_init_sw; | |
880 | } | |
881 | ||
d930faee | 882 | adapter->iface_type = iface_type; |
6b41f941 | 883 | adapter->card_sem = sem; |
d930faee | 884 | |
5e6e3a92 | 885 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
5e6e3a92 BZ |
886 | adapter->surprise_removed = false; |
887 | init_waitqueue_head(&adapter->init_wait_q); | |
888 | adapter->is_suspended = false; | |
889 | adapter->hs_activated = false; | |
890 | init_waitqueue_head(&adapter->hs_activate_wait_q); | |
600f5d90 | 891 | init_waitqueue_head(&adapter->cmd_wait_q.wait); |
600f5d90 | 892 | adapter->cmd_wait_q.status = 0; |
efaaa8b8 | 893 | adapter->scan_wait_q_woken = false; |
5e6e3a92 | 894 | |
ec4a16b4 | 895 | if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) { |
6e251174 AP |
896 | adapter->rx_work_enabled = true; |
897 | pr_notice("rx work enabled, cpus %d\n", num_possible_cpus()); | |
898 | } | |
899 | ||
448a71cc AK |
900 | adapter->workqueue = |
901 | alloc_workqueue("MWIFIEX_WORK_QUEUE", | |
902 | WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); | |
5e6e3a92 BZ |
903 | if (!adapter->workqueue) |
904 | goto err_kmalloc; | |
905 | ||
906 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); | |
6e251174 AP |
907 | |
908 | if (adapter->rx_work_enabled) { | |
909 | adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE", | |
910 | WQ_HIGHPRI | | |
911 | WQ_MEM_RECLAIM | | |
912 | WQ_UNBOUND, 1); | |
913 | if (!adapter->rx_workqueue) | |
914 | goto err_kmalloc; | |
915 | ||
916 | INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue); | |
917 | } | |
918 | ||
92c2538f AK |
919 | if (adapter->if_ops.iface_work) |
920 | INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work); | |
5e6e3a92 BZ |
921 | |
922 | /* Register the device. Fill up the private data structure with relevant | |
232fde06 | 923 | information from the card. */ |
5e6e3a92 BZ |
924 | if (adapter->if_ops.register_dev(adapter)) { |
925 | pr_err("%s: failed to register mwifiex device\n", __func__); | |
926 | goto err_registerdev; | |
927 | } | |
928 | ||
5e6e3a92 BZ |
929 | if (mwifiex_init_hw_fw(adapter)) { |
930 | pr_err("%s: firmware init failed\n", __func__); | |
931 | goto err_init_fw; | |
932 | } | |
2be7859f | 933 | |
5e6e3a92 BZ |
934 | return 0; |
935 | ||
5e6e3a92 | 936 | err_init_fw: |
5e6e3a92 | 937 | pr_debug("info: %s: unregister device\n", __func__); |
4daffe35 AK |
938 | if (adapter->if_ops.unregister_dev) |
939 | adapter->if_ops.unregister_dev(adapter); | |
5e6e3a92 BZ |
940 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) || |
941 | (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { | |
942 | pr_debug("info: %s: shutdown mwifiex\n", __func__); | |
943 | adapter->init_wait_q_woken = false; | |
636c4598 YAP |
944 | |
945 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) | |
5e6e3a92 BZ |
946 | wait_event_interruptible(adapter->init_wait_q, |
947 | adapter->init_wait_q_woken); | |
948 | } | |
6b41f941 AK |
949 | err_registerdev: |
950 | adapter->surprise_removed = true; | |
951 | mwifiex_terminate_workqueue(adapter); | |
952 | err_kmalloc: | |
5e6e3a92 BZ |
953 | mwifiex_free_adapter(adapter); |
954 | ||
955 | err_init_sw: | |
956 | up(sem); | |
957 | ||
958 | exit_sem_err: | |
959 | return -1; | |
960 | } | |
961 | EXPORT_SYMBOL_GPL(mwifiex_add_card); | |
962 | ||
963 | /* | |
964 | * This function removes the card. | |
965 | * | |
966 | * This function follows the following major steps to remove the device - | |
967 | * - Stop data traffic | |
968 | * - Shutdown firmware | |
969 | * - Remove the logical interfaces | |
970 | * - Terminate the work queue | |
971 | * - Unregister the device | |
972 | * - Free the adapter structure | |
973 | */ | |
974 | int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem) | |
975 | { | |
976 | struct mwifiex_private *priv = NULL; | |
5e6e3a92 BZ |
977 | int i; |
978 | ||
979 | if (down_interruptible(sem)) | |
980 | goto exit_sem_err; | |
981 | ||
982 | if (!adapter) | |
983 | goto exit_remove; | |
984 | ||
232fde06 DD |
985 | /* We can no longer handle interrupts once we start doing the teardown |
986 | * below. */ | |
987 | if (adapter->if_ops.disable_int) | |
988 | adapter->if_ops.disable_int(adapter); | |
989 | ||
5e6e3a92 BZ |
990 | adapter->surprise_removed = true; |
991 | ||
992 | /* Stop data */ | |
993 | for (i = 0; i < adapter->priv_num; i++) { | |
994 | priv = adapter->priv[i]; | |
93a1df48 | 995 | if (priv && priv->netdev) { |
47411a06 | 996 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
5e6e3a92 BZ |
997 | if (netif_carrier_ok(priv->netdev)) |
998 | netif_carrier_off(priv->netdev); | |
999 | } | |
1000 | } | |
1001 | ||
1002 | dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n"); | |
1003 | adapter->init_wait_q_woken = false; | |
636c4598 YAP |
1004 | |
1005 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) | |
5e6e3a92 BZ |
1006 | wait_event_interruptible(adapter->init_wait_q, |
1007 | adapter->init_wait_q_woken); | |
1008 | dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n"); | |
1009 | if (atomic_read(&adapter->rx_pending) || | |
1010 | atomic_read(&adapter->tx_pending) || | |
600f5d90 | 1011 | atomic_read(&adapter->cmd_pending)) { |
5e6e3a92 | 1012 | dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, " |
600f5d90 | 1013 | "cmd_pending=%d\n", |
5e6e3a92 BZ |
1014 | atomic_read(&adapter->rx_pending), |
1015 | atomic_read(&adapter->tx_pending), | |
600f5d90 | 1016 | atomic_read(&adapter->cmd_pending)); |
5e6e3a92 BZ |
1017 | } |
1018 | ||
93a1df48 YAP |
1019 | for (i = 0; i < adapter->priv_num; i++) { |
1020 | priv = adapter->priv[i]; | |
1021 | ||
1022 | if (!priv) | |
1023 | continue; | |
1024 | ||
1025 | rtnl_lock(); | |
2da8cbf8 | 1026 | if (priv->wdev && priv->netdev) |
84efbb84 | 1027 | mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev); |
93a1df48 YAP |
1028 | rtnl_unlock(); |
1029 | } | |
1030 | ||
c2868ade AK |
1031 | wiphy_unregister(adapter->wiphy); |
1032 | wiphy_free(adapter->wiphy); | |
64b05e2f | 1033 | |
5e6e3a92 BZ |
1034 | mwifiex_terminate_workqueue(adapter); |
1035 | ||
1036 | /* Unregister device */ | |
1037 | dev_dbg(adapter->dev, "info: unregister device\n"); | |
4daffe35 AK |
1038 | if (adapter->if_ops.unregister_dev) |
1039 | adapter->if_ops.unregister_dev(adapter); | |
5e6e3a92 BZ |
1040 | /* Free adapter structure */ |
1041 | dev_dbg(adapter->dev, "info: free adapter\n"); | |
1042 | mwifiex_free_adapter(adapter); | |
1043 | ||
1044 | exit_remove: | |
1045 | up(sem); | |
1046 | exit_sem_err: | |
1047 | return 0; | |
1048 | } | |
1049 | EXPORT_SYMBOL_GPL(mwifiex_remove_card); | |
1050 | ||
1051 | /* | |
1052 | * This function initializes the module. | |
1053 | * | |
1054 | * The debug FS is also initialized if configured. | |
1055 | */ | |
1056 | static int | |
1057 | mwifiex_init_module(void) | |
1058 | { | |
1059 | #ifdef CONFIG_DEBUG_FS | |
1060 | mwifiex_debugfs_init(); | |
1061 | #endif | |
1062 | return 0; | |
1063 | } | |
1064 | ||
1065 | /* | |
1066 | * This function cleans up the module. | |
1067 | * | |
1068 | * The debug FS is removed if available. | |
1069 | */ | |
1070 | static void | |
1071 | mwifiex_cleanup_module(void) | |
1072 | { | |
1073 | #ifdef CONFIG_DEBUG_FS | |
1074 | mwifiex_debugfs_remove(); | |
1075 | #endif | |
1076 | } | |
1077 | ||
1078 | module_init(mwifiex_init_module); | |
1079 | module_exit(mwifiex_cleanup_module); | |
1080 | ||
1081 | MODULE_AUTHOR("Marvell International Ltd."); | |
1082 | MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION); | |
1083 | MODULE_VERSION(VERSION); | |
1084 | MODULE_LICENSE("GPL v2"); |