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