mwifiex: remove_bss_prio_lock
[deliverable/linux.git] / drivers / net / wireless / mwifiex / main.c
CommitLineData
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
27const char driver_version[] = "mwifiex " VERSION " (%s) ";
388ec385
AK
28static char *cal_data_cfg;
29module_param(cal_data_cfg, charp, 0);
5e6e3a92 30
0013c7ce
AP
31static unsigned short driver_mode;
32module_param(driver_mode, ushort, 0);
33MODULE_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 */
51static 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 85
c6c33e77
JL
86 setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
87 (unsigned long)adapter);
5e6e3a92 88
5e6e3a92
BZ
89 return 0;
90
91error:
92 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
93
93a1df48 94 for (i = 0; i < adapter->priv_num; i++)
5e6e3a92 95 kfree(adapter->priv[i]);
93a1df48 96
5e6e3a92
BZ
97 kfree(adapter);
98
99 return -1;
100}
101
102/*
103 * This function unregisters the device and performs all the necessary
104 * cleanups.
105 *
106 * The following cleanup operations are performed -
107 * - Free the timers
108 * - Free beacon buffers
109 * - Free private structures
110 * - Free adapter structure
111 */
112static int mwifiex_unregister(struct mwifiex_adapter *adapter)
113{
270e58e8 114 s32 i;
5e6e3a92 115
4cfda67d
AK
116 if (adapter->if_ops.cleanup_if)
117 adapter->if_ops.cleanup_if(adapter);
118
629873f2 119 del_timer_sync(&adapter->cmd_timer);
5e6e3a92
BZ
120
121 /* Free private structures */
122 for (i = 0; i < adapter->priv_num; i++) {
123 if (adapter->priv[i]) {
124 mwifiex_free_curr_bcn(adapter->priv[i]);
125 kfree(adapter->priv[i]);
126 }
127 }
128
bf354433 129 vfree(adapter->chan_stats);
5e6e3a92
BZ
130 kfree(adapter);
131 return 0;
132}
133
b2713f67
SL
134void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
135{
136 unsigned long flags;
137
138 spin_lock_irqsave(&adapter->main_proc_lock, flags);
139 if (adapter->mwifiex_processing) {
140 adapter->more_task_flag = true;
141 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
142 } else {
143 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
144 queue_work(adapter->workqueue, &adapter->main_work);
145 }
146}
147EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
148
149static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
150{
151 unsigned long flags;
152
153 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
154 if (adapter->rx_processing) {
155 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
156 } else {
157 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
158 queue_work(adapter->rx_workqueue, &adapter->rx_work);
159 }
160}
161
6e251174
AP
162static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
163{
164 unsigned long flags;
165 struct sk_buff *skb;
6e251174
AP
166
167 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
168 if (adapter->rx_processing || adapter->rx_locked) {
169 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
170 goto exit_rx_proc;
171 } else {
172 adapter->rx_processing = true;
173 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
174 }
175
176 /* Check for Rx data */
177 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
178 atomic_dec(&adapter->rx_pending);
381e9fff
AK
179 if ((adapter->delay_main_work ||
180 adapter->iface_type == MWIFIEX_USB) &&
b43a0d9d 181 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
cf6a64fd
AK
182 if (adapter->if_ops.submit_rem_rx_urbs)
183 adapter->if_ops.submit_rem_rx_urbs(adapter);
6e251174 184 adapter->delay_main_work = false;
b2713f67 185 mwifiex_queue_main_work(adapter);
6e251174
AP
186 }
187 mwifiex_handle_rx_packet(adapter, skb);
188 }
189 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
190 adapter->rx_processing = false;
191 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
192
6e251174
AP
193exit_rx_proc:
194 return 0;
195}
196
5e6e3a92
BZ
197/*
198 * The main process.
199 *
200 * This function is the main procedure of the driver and handles various driver
201 * operations. It runs in a loop and provides the core functionalities.
202 *
203 * The main responsibilities of this function are -
204 * - Ensure concurrency control
205 * - Handle pending interrupts and call interrupt handlers
206 * - Wake up the card if required
207 * - Handle command responses and call response handlers
208 * - Handle events and call event handlers
209 * - Execute pending commands
210 * - Transmit pending data packets
211 */
212int mwifiex_main_process(struct mwifiex_adapter *adapter)
213{
214 int ret = 0;
215 unsigned long flags;
216
217 spin_lock_irqsave(&adapter->main_proc_lock, flags);
218
219 /* Check if already processing */
a9adbcb3 220 if (adapter->mwifiex_processing || adapter->main_locked) {
04c7b363 221 adapter->more_task_flag = true;
5e6e3a92
BZ
222 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
223 goto exit_main_proc;
224 } else {
225 adapter->mwifiex_processing = true;
5e6e3a92
BZ
226 }
227process_start:
228 do {
04c7b363
SL
229 adapter->more_task_flag = false;
230 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
5e6e3a92
BZ
231 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
232 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
233 break;
234
381e9fff
AK
235 /* For non-USB interfaces, If we process interrupts first, it
236 * would increase RX pending even further. Avoid this by
237 * checking if rx_pending has crossed high threshold and
238 * schedule rx work queue and then process interrupts.
239 * For USB interface, there are no interrupts. We already have
240 * HIGH_RX_PENDING check in usb.c
6e251174 241 */
381e9fff
AK
242 if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
243 adapter->iface_type != MWIFIEX_USB) {
6e251174 244 adapter->delay_main_work = true;
b2713f67 245 mwifiex_queue_rx_work(adapter);
6e251174
AP
246 break;
247 }
248
5e6e3a92
BZ
249 /* Handle pending interrupt if any */
250 if (adapter->int_status) {
251 if (adapter->hs_activated)
252 mwifiex_process_hs_config(adapter);
4daffe35
AK
253 if (adapter->if_ops.process_int_status)
254 adapter->if_ops.process_int_status(adapter);
5e6e3a92
BZ
255 }
256
6e251174 257 if (adapter->rx_work_enabled && adapter->data_received)
b2713f67 258 mwifiex_queue_rx_work(adapter);
6e251174 259
5e6e3a92
BZ
260 /* Need to wake up the card ? */
261 if ((adapter->ps_state == PS_STATE_SLEEP) &&
262 (adapter->pm_wakeup_card_req &&
263 !adapter->pm_wakeup_fw_try) &&
f57c1edc
YAP
264 (is_command_pending(adapter) ||
265 !mwifiex_wmm_lists_empty(adapter))) {
5e6e3a92 266 adapter->pm_wakeup_fw_try = true;
4636187d 267 mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
5e6e3a92 268 adapter->if_ops.wakeup(adapter);
04c7b363 269 spin_lock_irqsave(&adapter->main_proc_lock, flags);
5e6e3a92
BZ
270 continue;
271 }
4daffe35 272
5e6e3a92 273 if (IS_CARD_RX_RCVD(adapter)) {
6e251174 274 adapter->data_received = false;
5e6e3a92 275 adapter->pm_wakeup_fw_try = false;
6e9344fd 276 del_timer(&adapter->wakeup_timer);
5e6e3a92
BZ
277 if (adapter->ps_state == PS_STATE_SLEEP)
278 adapter->ps_state = PS_STATE_AWAKE;
279 } else {
280 /* We have tried to wakeup the card already */
281 if (adapter->pm_wakeup_fw_try)
282 break;
283 if (adapter->ps_state != PS_STATE_AWAKE ||
284 adapter->tx_lock_flag)
285 break;
286
5ec39efa 287 if ((!adapter->scan_chan_gap_enabled &&
5ec39efa 288 adapter->scan_processing) || adapter->data_sent ||
f57c1edc
YAP
289 mwifiex_wmm_lists_empty(adapter)) {
290 if (adapter->cmd_sent || adapter->curr_cmd ||
291 (!is_command_pending(adapter)))
5e6e3a92
BZ
292 break;
293 }
294 }
295
20474129
AK
296 /* Check for event */
297 if (adapter->event_received) {
298 adapter->event_received = false;
299 mwifiex_process_event(adapter);
300 }
301
5e6e3a92
BZ
302 /* Check for Cmd Resp */
303 if (adapter->cmd_resp_received) {
304 adapter->cmd_resp_received = false;
305 mwifiex_process_cmdresp(adapter);
306
307 /* call mwifiex back when init_fw is done */
308 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
309 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
310 mwifiex_init_fw_complete(adapter);
311 }
312 }
313
5e6e3a92
BZ
314 /* Check if we need to confirm Sleep Request
315 received previously */
316 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
317 if (!adapter->cmd_sent && !adapter->curr_cmd)
318 mwifiex_check_ps_cond(adapter);
319 }
320
321 /* * The ps_state may have been changed during processing of
322 * Sleep Request event.
323 */
f57c1edc
YAP
324 if ((adapter->ps_state == PS_STATE_SLEEP) ||
325 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
326 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
04c7b363
SL
327 adapter->tx_lock_flag){
328 spin_lock_irqsave(&adapter->main_proc_lock, flags);
5e6e3a92 329 continue;
04c7b363 330 }
5e6e3a92
BZ
331
332 if (!adapter->cmd_sent && !adapter->curr_cmd) {
333 if (mwifiex_exec_next_cmd(adapter) == -1) {
334 ret = -1;
335 break;
336 }
337 }
338
5ec39efa 339 if ((adapter->scan_chan_gap_enabled ||
d8d91253 340 !adapter->scan_processing) &&
3249ba73 341 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
5e6e3a92
BZ
342 mwifiex_wmm_process_tx(adapter);
343 if (adapter->hs_activated) {
344 adapter->is_hs_configured = false;
345 mwifiex_hs_activated_event
346 (mwifiex_get_priv
347 (adapter, MWIFIEX_BSS_ROLE_ANY),
348 false);
349 }
350 }
351
352 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
f57c1edc
YAP
353 !adapter->curr_cmd && !is_command_pending(adapter) &&
354 mwifiex_wmm_lists_empty(adapter)) {
5e6e3a92
BZ
355 if (!mwifiex_send_null_packet
356 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
357 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
358 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
359 adapter->delay_null_pkt = false;
360 adapter->ps_state = PS_STATE_SLEEP;
361 }
362 break;
363 }
04c7b363 364 spin_lock_irqsave(&adapter->main_proc_lock, flags);
5e6e3a92
BZ
365 } while (true);
366
453b0c3f 367 spin_lock_irqsave(&adapter->main_proc_lock, flags);
04c7b363 368 if (adapter->more_task_flag)
5e6e3a92 369 goto process_start;
5e6e3a92
BZ
370 adapter->mwifiex_processing = false;
371 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
372
373exit_main_proc:
374 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
375 mwifiex_shutdown_drv(adapter);
376 return ret;
377}
601216e1 378EXPORT_SYMBOL_GPL(mwifiex_main_process);
5e6e3a92 379
5e6e3a92
BZ
380/*
381 * This function frees the adapter structure.
382 *
383 * Additionally, this closes the netlink socket, frees the timers
384 * and private structures.
385 */
386static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
387{
388 if (!adapter) {
389 pr_err("%s: adapter is NULL\n", __func__);
390 return;
391 }
392
393 mwifiex_unregister(adapter);
394 pr_debug("info: %s: free adapter\n", __func__);
395}
396
6b41f941
AK
397/*
398 * This function cancels all works in the queue and destroys
399 * the main workqueue.
400 */
401static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
402{
403 flush_workqueue(adapter->workqueue);
404 destroy_workqueue(adapter->workqueue);
405 adapter->workqueue = NULL;
6e251174
AP
406
407 if (adapter->rx_workqueue) {
408 flush_workqueue(adapter->rx_workqueue);
409 destroy_workqueue(adapter->rx_workqueue);
410 adapter->rx_workqueue = NULL;
411 }
6b41f941
AK
412}
413
5e6e3a92 414/*
59a4cc25 415 * This function gets firmware and initializes it.
5e6e3a92
BZ
416 *
417 * The main initialization steps followed are -
418 * - Download the correct firmware to card
5e6e3a92
BZ
419 * - Issue the init commands to firmware
420 */
59a4cc25 421static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
5e6e3a92 422{
bec568ff 423 int ret;
59a4cc25
AK
424 char fmt[64];
425 struct mwifiex_private *priv;
426 struct mwifiex_adapter *adapter = context;
5e6e3a92 427 struct mwifiex_fw_image fw;
c3afd99f
AK
428 struct semaphore *sem = adapter->card_sem;
429 bool init_failed = false;
68b76e99 430 struct wireless_dev *wdev;
5e6e3a92 431
59a4cc25
AK
432 if (!firmware) {
433 dev_err(adapter->dev,
434 "Failed to get firmware %s\n", adapter->fw_name);
6b41f941 435 goto err_dnld_fw;
5e6e3a92 436 }
59a4cc25
AK
437
438 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
439 adapter->firmware = firmware;
5e6e3a92
BZ
440 fw.fw_buf = (u8 *) adapter->firmware->data;
441 fw.fw_len = adapter->firmware->size;
442
4daffe35
AK
443 if (adapter->if_ops.dnld_fw)
444 ret = adapter->if_ops.dnld_fw(adapter, &fw);
445 else
446 ret = mwifiex_dnld_fw(adapter, &fw);
5e6e3a92 447 if (ret == -1)
6b41f941 448 goto err_dnld_fw;
5e6e3a92
BZ
449
450 dev_notice(adapter->dev, "WLAN FW is active\n");
451
388ec385
AK
452 if (cal_data_cfg) {
453 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
454 adapter->dev)) < 0)
455 dev_err(adapter->dev,
456 "Cal data request_firmware() failed\n");
457 }
458
232fde06 459 /* enable host interrupt after fw dnld is successful */
6b41f941
AK
460 if (adapter->if_ops.enable_int) {
461 if (adapter->if_ops.enable_int(adapter))
462 goto err_dnld_fw;
463 }
232fde06 464
5e6e3a92
BZ
465 adapter->init_wait_q_woken = false;
466 ret = mwifiex_init_fw(adapter);
467 if (ret == -1) {
6b41f941 468 goto err_init_fw;
5e6e3a92
BZ
469 } else if (!ret) {
470 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
471 goto done;
472 }
473 /* Wait for mwifiex_init to complete */
474 wait_event_interruptible(adapter->init_wait_q,
475 adapter->init_wait_q_woken);
59a4cc25 476 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
6b41f941 477 goto err_init_fw;
59a4cc25 478
d6bffe8b
AP
479 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
480 if (mwifiex_register_cfg80211(adapter)) {
59a4cc25 481 dev_err(adapter->dev, "cannot register with cfg80211\n");
d1af2943 482 goto err_init_fw;
59a4cc25
AK
483 }
484
bf354433
AP
485 if (mwifiex_init_channel_scan_gap(adapter)) {
486 dev_err(adapter->dev, "could not init channel stats table\n");
487 goto err_init_fw;
488 }
489
0013c7ce
AP
490 if (driver_mode) {
491 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
492 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
493 }
494
59a4cc25
AK
495 rtnl_lock();
496 /* Create station interface by default */
68b76e99
AK
497 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
498 NL80211_IFTYPE_STATION, NULL, NULL);
499 if (IS_ERR(wdev)) {
59a4cc25 500 dev_err(adapter->dev, "cannot create default STA interface\n");
bec568ff 501 rtnl_unlock();
59a4cc25 502 goto err_add_intf;
5e6e3a92 503 }
0013c7ce
AP
504
505 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
506 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d",
507 NL80211_IFTYPE_AP, NULL, NULL);
508 if (IS_ERR(wdev)) {
509 dev_err(adapter->dev, "cannot create AP interface\n");
510 rtnl_unlock();
511 goto err_add_intf;
512 }
513 }
514
515 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
516 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d",
517 NL80211_IFTYPE_P2P_CLIENT, NULL,
518 NULL);
519 if (IS_ERR(wdev)) {
520 dev_err(adapter->dev,
521 "cannot create p2p client interface\n");
522 rtnl_unlock();
523 goto err_add_intf;
524 }
525 }
59a4cc25
AK
526 rtnl_unlock();
527
528 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
529 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
530 goto done;
5e6e3a92 531
59a4cc25 532err_add_intf:
6b41f941
AK
533 wiphy_unregister(adapter->wiphy);
534 wiphy_free(adapter->wiphy);
59a4cc25 535err_init_fw:
232fde06
DD
536 if (adapter->if_ops.disable_int)
537 adapter->if_ops.disable_int(adapter);
6b41f941 538err_dnld_fw:
59a4cc25 539 pr_debug("info: %s: unregister device\n", __func__);
6b41f941
AK
540 if (adapter->if_ops.unregister_dev)
541 adapter->if_ops.unregister_dev(adapter);
542
7197325b 543 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
6b41f941
AK
544 pr_debug("info: %s: shutdown mwifiex\n", __func__);
545 adapter->init_wait_q_woken = false;
546
547 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
548 wait_event_interruptible(adapter->init_wait_q,
549 adapter->init_wait_q_woken);
550 }
551 adapter->surprise_removed = true;
552 mwifiex_terminate_workqueue(adapter);
c3afd99f 553 init_failed = true;
5e6e3a92 554done:
388ec385
AK
555 if (adapter->cal_data) {
556 release_firmware(adapter->cal_data);
557 adapter->cal_data = NULL;
558 }
c3afd99f
AK
559 if (adapter->firmware) {
560 release_firmware(adapter->firmware);
561 adapter->firmware = NULL;
562 }
c3afd99f
AK
563 if (init_failed)
564 mwifiex_free_adapter(adapter);
565 up(sem);
59a4cc25
AK
566 return;
567}
568
569/*
570 * This function initializes the hardware and gets firmware.
571 */
572static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
573{
574 int ret;
575
59a4cc25
AK
576 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
577 adapter->dev, GFP_KERNEL, adapter,
578 mwifiex_fw_dpc);
579 if (ret < 0)
580 dev_err(adapter->dev,
581 "request_firmware_nowait() returned error %d\n", ret);
5e6e3a92
BZ
582 return ret;
583}
584
5e6e3a92
BZ
585/*
586 * CFG802.11 network device handler for open.
587 *
588 * Starts the data queue.
589 */
590static int
591mwifiex_open(struct net_device *dev)
592{
ea2325b8
JB
593 netif_carrier_off(dev);
594
5e6e3a92
BZ
595 return 0;
596}
597
598/*
599 * CFG802.11 network device handler for close.
600 */
601static int
602mwifiex_close(struct net_device *dev)
603{
f162cac8
AK
604 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
605
606 if (priv->scan_request) {
607 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
608 cfg80211_scan_done(priv->scan_request, 1);
609 priv->scan_request = NULL;
75ab753d 610 priv->scan_aborting = true;
f162cac8
AK
611 }
612
5e6e3a92
BZ
613 return 0;
614}
615
e39faa73
SP
616/*
617 * Add buffer into wmm tx queue and queue work to transmit it.
618 */
619int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
620{
47411a06
AP
621 struct netdev_queue *txq;
622 int index = mwifiex_1d_to_wmm_queue[skb->priority];
623
624 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
625 txq = netdev_get_tx_queue(priv->netdev, index);
626 if (!netif_tx_queue_stopped(txq)) {
627 netif_tx_stop_queue(txq);
628 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
629 }
630 }
631
e39faa73 632 atomic_inc(&priv->adapter->tx_pending);
47411a06 633 mwifiex_wmm_add_buf_txqueue(priv, skb);
e39faa73 634
b2713f67 635 mwifiex_queue_main_work(priv->adapter);
e39faa73
SP
636
637 return 0;
638}
639
18ca4382 640struct sk_buff *
808bbebc 641mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
18ca4382 642 struct sk_buff *skb, u8 flag, u64 *cookie)
808bbebc
AK
643{
644 struct sk_buff *orig_skb = skb;
645 struct mwifiex_txinfo *tx_info, *orig_tx_info;
646
647 skb = skb_clone(skb, GFP_ATOMIC);
648 if (skb) {
649 unsigned long flags;
650 int id;
651
652 spin_lock_irqsave(&priv->ack_status_lock, flags);
653 id = idr_alloc(&priv->ack_status_frames, orig_skb,
654 1, 0xff, GFP_ATOMIC);
655 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
656
657 if (id >= 0) {
658 tx_info = MWIFIEX_SKB_TXCB(skb);
659 tx_info->ack_frame_id = id;
660 tx_info->flags |= flag;
661 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
662 orig_tx_info->ack_frame_id = id;
663 orig_tx_info->flags |= flag;
18ca4382
AK
664
665 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
666 orig_tx_info->cookie = *cookie;
667
808bbebc
AK
668 } else if (skb_shared(skb)) {
669 kfree_skb(orig_skb);
670 } else {
671 kfree_skb(skb);
672 skb = orig_skb;
673 }
674 } else {
675 /* couldn't clone -- lose tx status ... */
676 skb = orig_skb;
677 }
678
679 return skb;
680}
681
5e6e3a92
BZ
682/*
683 * CFG802.11 network device handler for data transmission.
684 */
685static int
686mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
687{
688 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
270e58e8 689 struct sk_buff *new_skb;
5e6e3a92 690 struct mwifiex_txinfo *tx_info;
808bbebc 691 bool multicast;
5e6e3a92 692
9da9a3b2 693 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
f57c1edc 694 jiffies, priv->bss_type, priv->bss_num);
5e6e3a92
BZ
695
696 if (priv->adapter->surprise_removed) {
b53575ec 697 kfree_skb(skb);
5e6e3a92
BZ
698 priv->stats.tx_dropped++;
699 return 0;
700 }
701 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
702 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
b53575ec 703 kfree_skb(skb);
5e6e3a92
BZ
704 priv->stats.tx_dropped++;
705 return 0;
706 }
707 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
708 dev_dbg(priv->adapter->dev,
709 "data: Tx: insufficient skb headroom %d\n",
f57c1edc 710 skb_headroom(skb));
5e6e3a92
BZ
711 /* Insufficient skb headroom - allocate a new skb */
712 new_skb =
713 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
714 if (unlikely(!new_skb)) {
715 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
b53575ec 716 kfree_skb(skb);
5e6e3a92
BZ
717 priv->stats.tx_dropped++;
718 return 0;
719 }
720 kfree_skb(skb);
721 skb = new_skb;
722 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
f57c1edc 723 skb_headroom(skb));
5e6e3a92
BZ
724 }
725
726 tx_info = MWIFIEX_SKB_TXCB(skb);
d76744a9 727 memset(tx_info, 0, sizeof(*tx_info));
9da9a3b2
YAP
728 tx_info->bss_num = priv->bss_num;
729 tx_info->bss_type = priv->bss_type;
a1ed4849 730 tx_info->pkt_len = skb->len;
47411a06 731
808bbebc
AK
732 multicast = is_multicast_ether_addr(skb->data);
733
734 if (unlikely(!multicast && skb->sk &&
735 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
736 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
737 skb = mwifiex_clone_skb_for_tx_status(priv,
738 skb,
18ca4382 739 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
808bbebc 740
47411a06
AP
741 /* Record the current time the packet was queued; used to
742 * determine the amount of time the packet was queued in
743 * the driver before it was sent to the firmware.
744 * The delay is then sent along with the packet to the
745 * firmware for aggregate delay calculation for stats and
746 * MSDU lifetime expiry.
747 */
c64800e7 748 __net_timestamp(skb);
5e6e3a92 749
9927baa3
AP
750 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
751 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
752 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
753 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
754 mwifiex_tdls_check_tx(priv, skb);
755 }
756
e39faa73 757 mwifiex_queue_tx_pkt(priv, skb);
5e6e3a92
BZ
758
759 return 0;
760}
761
762/*
763 * CFG802.11 network device handler for setting MAC address.
764 */
765static int
766mwifiex_set_mac_address(struct net_device *dev, void *addr)
767{
768 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
a5ffddb7 769 struct sockaddr *hw_addr = addr;
270e58e8 770 int ret;
5e6e3a92
BZ
771
772 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
773
600f5d90 774 /* Send request to firmware */
fa0ecbb9
BZ
775 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
776 HostCmd_ACT_GEN_SET, 0, NULL, true);
600f5d90
AK
777
778 if (!ret)
779 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
780 else
f57c1edc
YAP
781 dev_err(priv->adapter->dev,
782 "set mac address failed: ret=%d\n", ret);
600f5d90 783
5e6e3a92
BZ
784 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
785
600f5d90 786 return ret;
5e6e3a92
BZ
787}
788
789/*
790 * CFG802.11 network device handler for setting multicast list.
791 */
792static void mwifiex_set_multicast_list(struct net_device *dev)
793{
794 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
600f5d90
AK
795 struct mwifiex_multicast_list mcast_list;
796
797 if (dev->flags & IFF_PROMISC) {
798 mcast_list.mode = MWIFIEX_PROMISC_MODE;
799 } else if (dev->flags & IFF_ALLMULTI ||
800 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
801 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
802 } else {
803 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
6390d885
DD
804 mcast_list.num_multicast_addr =
805 mwifiex_copy_mcast_addr(&mcast_list, dev);
600f5d90
AK
806 }
807 mwifiex_request_set_multicast_list(priv, &mcast_list);
5e6e3a92
BZ
808}
809
810/*
811 * CFG802.11 network device handler for transmission timeout.
812 */
813static void
814mwifiex_tx_timeout(struct net_device *dev)
815{
816 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
817
5e6e3a92 818 priv->num_tx_timeout++;
8908c7d5
AN
819 priv->tx_timeout_cnt++;
820 dev_err(priv->adapter->dev,
821 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
822 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
823 mwifiex_set_trans_start(dev);
824
825 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
826 priv->adapter->if_ops.card_reset) {
827 dev_err(priv->adapter->dev,
828 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
829 priv->adapter->if_ops.card_reset(priv->adapter);
830 }
5e6e3a92
BZ
831}
832
11cd07a9
XH
833void mwifiex_dump_drv_info(struct mwifiex_adapter *adapter)
834{
835 void *p;
836 char drv_version[64];
837 struct usb_card_rec *cardp;
838 struct sdio_mmc_card *sdio_card;
839 struct mwifiex_private *priv;
840 int i, idx;
841 struct netdev_queue *txq;
842 struct mwifiex_debug_info *debug_info;
843
844 if (adapter->drv_info_dump) {
845 vfree(adapter->drv_info_dump);
846 adapter->drv_info_size = 0;
847 }
848
849 dev_info(adapter->dev, "=== DRIVER INFO DUMP START===\n");
850
851 adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
852
853 if (!adapter->drv_info_dump)
854 return;
855
856 p = (char *)(adapter->drv_info_dump);
857 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
858
859 mwifiex_drv_get_driver_version(adapter, drv_version,
860 sizeof(drv_version) - 1);
861 p += sprintf(p, "driver_version = %s\n", drv_version);
862
863 if (adapter->iface_type == MWIFIEX_USB) {
864 cardp = (struct usb_card_rec *)adapter->card;
865 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
866 atomic_read(&cardp->tx_cmd_urb_pending));
867 p += sprintf(p, "tx_data_urb_pending = %d\n",
868 atomic_read(&cardp->tx_data_urb_pending));
869 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
870 atomic_read(&cardp->rx_cmd_urb_pending));
871 p += sprintf(p, "rx_data_urb_pending = %d\n",
872 atomic_read(&cardp->rx_data_urb_pending));
873 }
874
875 p += sprintf(p, "tx_pending = %d\n",
876 atomic_read(&adapter->tx_pending));
877 p += sprintf(p, "rx_pending = %d\n",
878 atomic_read(&adapter->rx_pending));
879
880 if (adapter->iface_type == MWIFIEX_SDIO) {
881 sdio_card = (struct sdio_mmc_card *)adapter->card;
882 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
883 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
884 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
885 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
886 }
887
888 for (i = 0; i < adapter->priv_num; i++) {
889 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
890 continue;
891 priv = adapter->priv[i];
892 p += sprintf(p, "\n[interface : \"%s\"]\n",
893 priv->netdev->name);
894 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
895 atomic_read(&priv->wmm_tx_pending[0]));
896 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
897 atomic_read(&priv->wmm_tx_pending[1]));
898 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
899 atomic_read(&priv->wmm_tx_pending[2]));
900 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
901 atomic_read(&priv->wmm_tx_pending[3]));
902 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
903 "Disconnected" : "Connected");
904 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
905 ? "on" : "off"));
906 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
907 txq = netdev_get_tx_queue(priv->netdev, idx);
908 p += sprintf(p, "tx queue %d:%s ", idx,
909 netif_tx_queue_stopped(txq) ?
910 "stopped" : "started");
911 }
912 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
913 priv->netdev->name, priv->num_tx_timeout);
914 }
915
809c6ea8
XH
916 if (adapter->iface_type == MWIFIEX_SDIO) {
917 p += sprintf(p, "\n=== SDIO register DUMP===\n");
918 if (adapter->if_ops.reg_dump)
919 p += adapter->if_ops.reg_dump(adapter, p);
920 }
921
11cd07a9
XH
922 p += sprintf(p, "\n=== MORE DEBUG INFORMATION\n");
923 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
924 if (debug_info) {
925 for (i = 0; i < adapter->priv_num; i++) {
926 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
927 continue;
928 priv = adapter->priv[i];
929 mwifiex_get_debug_info(priv, debug_info);
930 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
931 break;
932 }
933 kfree(debug_info);
934 }
935
936 adapter->drv_info_size = p - adapter->drv_info_dump;
937 dev_info(adapter->dev, "=== DRIVER INFO DUMP END===\n");
938}
939EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info);
940
5e6e3a92
BZ
941/*
942 * CFG802.11 network device handler for statistics retrieval.
943 */
944static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
945{
946 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
947
948 return &priv->stats;
949}
950
47411a06 951static u16
f663dd9a 952mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
99932d4f 953 void *accel_priv, select_queue_fallback_t fallback)
47411a06 954{
fa9ffc74 955 skb->priority = cfg80211_classify8021d(skb, NULL);
47411a06
AP
956 return mwifiex_1d_to_wmm_queue[skb->priority];
957}
958
5e6e3a92
BZ
959/* Network device handlers */
960static const struct net_device_ops mwifiex_netdev_ops = {
961 .ndo_open = mwifiex_open,
962 .ndo_stop = mwifiex_close,
963 .ndo_start_xmit = mwifiex_hard_start_xmit,
964 .ndo_set_mac_address = mwifiex_set_mac_address,
965 .ndo_tx_timeout = mwifiex_tx_timeout,
966 .ndo_get_stats = mwifiex_get_stats,
afc4b13d 967 .ndo_set_rx_mode = mwifiex_set_multicast_list,
47411a06 968 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
5e6e3a92
BZ
969};
970
971/*
972 * This function initializes the private structure parameters.
973 *
974 * The following wait queues are initialized -
975 * - IOCTL wait queue
976 * - Command wait queue
977 * - Statistics wait queue
978 *
979 * ...and the following default parameters are set -
980 * - Current key index : Set to 0
981 * - Rate index : Set to auto
982 * - Media connected : Set to disconnected
983 * - Adhoc link sensed : Set to false
984 * - Nick name : Set to null
985 * - Number of Tx timeout : Set to 0
986 * - Device address : Set to current address
cbf6e055 987 * - Rx histogram statistc : Set to 0
5e6e3a92
BZ
988 *
989 * In addition, the CFG80211 work queue is also created.
990 */
93a1df48 991void mwifiex_init_priv_params(struct mwifiex_private *priv,
047eaaf6 992 struct net_device *dev)
5e6e3a92
BZ
993{
994 dev->netdev_ops = &mwifiex_netdev_ops;
f16fdc9d 995 dev->destructor = free_netdev;
5e6e3a92 996 /* Initialize private structure */
5e6e3a92
BZ
997 priv->current_key_index = 0;
998 priv->media_connected = false;
ede98bfa
AP
999 memset(priv->mgmt_ie, 0,
1000 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
f31acabe
AP
1001 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
1002 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
1003 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
2ade5667 1004 priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
5e6e3a92 1005 priv->num_tx_timeout = 0;
8d05eb22 1006 ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
5e6e3a92 1007 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
cbf6e055
XH
1008
1009 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
1010 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1011 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
1012 if (priv->hist_data)
1013 mwifiex_hist_data_reset(priv);
1014 }
5e6e3a92
BZ
1015}
1016
5e6e3a92
BZ
1017/*
1018 * This function check if command is pending.
1019 */
1020int is_command_pending(struct mwifiex_adapter *adapter)
1021{
1022 unsigned long flags;
1023 int is_cmd_pend_q_empty;
1024
1025 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1026 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
1027 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1028
1029 return !is_cmd_pend_q_empty;
1030}
1031
6e251174
AP
1032/*
1033 * This is the RX work queue function.
1034 *
1035 * It handles the RX operations.
1036 */
1037static void mwifiex_rx_work_queue(struct work_struct *work)
1038{
1039 struct mwifiex_adapter *adapter =
1040 container_of(work, struct mwifiex_adapter, rx_work);
1041
1042 if (adapter->surprise_removed)
1043 return;
1044 mwifiex_process_rx(adapter);
1045}
1046
5e6e3a92
BZ
1047/*
1048 * This is the main work queue function.
1049 *
1050 * It handles the main process, which in turn handles the complete
1051 * driver operations.
1052 */
1053static void mwifiex_main_work_queue(struct work_struct *work)
1054{
1055 struct mwifiex_adapter *adapter =
1056 container_of(work, struct mwifiex_adapter, main_work);
1057
1058 if (adapter->surprise_removed)
1059 return;
1060 mwifiex_main_process(adapter);
1061}
1062
5e6e3a92
BZ
1063/*
1064 * This function adds the card.
1065 *
1066 * This function follows the following major steps to set up the device -
1067 * - Initialize software. This includes probing the card, registering
1068 * the interface operations table, and allocating/initializing the
1069 * adapter structure
1070 * - Set up the netlink socket
1071 * - Create and start the main work queue
1072 * - Register the device
1073 * - Initialize firmware and hardware
1074 * - Add logical interfaces
1075 */
1076int
1077mwifiex_add_card(void *card, struct semaphore *sem,
d930faee 1078 struct mwifiex_if_ops *if_ops, u8 iface_type)
5e6e3a92 1079{
2be7859f 1080 struct mwifiex_adapter *adapter;
5e6e3a92
BZ
1081
1082 if (down_interruptible(sem))
1083 goto exit_sem_err;
1084
93a1df48 1085 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
5e6e3a92
BZ
1086 pr_err("%s: software init failed\n", __func__);
1087 goto err_init_sw;
1088 }
1089
d930faee 1090 adapter->iface_type = iface_type;
6b41f941 1091 adapter->card_sem = sem;
d930faee 1092
5e6e3a92 1093 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
5e6e3a92
BZ
1094 adapter->surprise_removed = false;
1095 init_waitqueue_head(&adapter->init_wait_q);
1096 adapter->is_suspended = false;
1097 adapter->hs_activated = false;
1098 init_waitqueue_head(&adapter->hs_activate_wait_q);
600f5d90 1099 init_waitqueue_head(&adapter->cmd_wait_q.wait);
600f5d90 1100 adapter->cmd_wait_q.status = 0;
efaaa8b8 1101 adapter->scan_wait_q_woken = false;
5e6e3a92 1102
ec4a16b4 1103 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
6e251174
AP
1104 adapter->rx_work_enabled = true;
1105 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1106 }
1107
448a71cc
AK
1108 adapter->workqueue =
1109 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1110 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
5e6e3a92
BZ
1111 if (!adapter->workqueue)
1112 goto err_kmalloc;
1113
1114 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
6e251174
AP
1115
1116 if (adapter->rx_work_enabled) {
1117 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1118 WQ_HIGHPRI |
1119 WQ_MEM_RECLAIM |
1120 WQ_UNBOUND, 1);
1121 if (!adapter->rx_workqueue)
1122 goto err_kmalloc;
1123
1124 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1125 }
1126
92c2538f
AK
1127 if (adapter->if_ops.iface_work)
1128 INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work);
5e6e3a92
BZ
1129
1130 /* Register the device. Fill up the private data structure with relevant
232fde06 1131 information from the card. */
5e6e3a92
BZ
1132 if (adapter->if_ops.register_dev(adapter)) {
1133 pr_err("%s: failed to register mwifiex device\n", __func__);
1134 goto err_registerdev;
1135 }
1136
5e6e3a92
BZ
1137 if (mwifiex_init_hw_fw(adapter)) {
1138 pr_err("%s: firmware init failed\n", __func__);
1139 goto err_init_fw;
1140 }
2be7859f 1141
5e6e3a92
BZ
1142 return 0;
1143
5e6e3a92 1144err_init_fw:
5e6e3a92 1145 pr_debug("info: %s: unregister device\n", __func__);
4daffe35
AK
1146 if (adapter->if_ops.unregister_dev)
1147 adapter->if_ops.unregister_dev(adapter);
7197325b 1148 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
5e6e3a92
BZ
1149 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1150 adapter->init_wait_q_woken = false;
636c4598
YAP
1151
1152 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
5e6e3a92
BZ
1153 wait_event_interruptible(adapter->init_wait_q,
1154 adapter->init_wait_q_woken);
1155 }
6b41f941
AK
1156err_registerdev:
1157 adapter->surprise_removed = true;
1158 mwifiex_terminate_workqueue(adapter);
1159err_kmalloc:
5e6e3a92
BZ
1160 mwifiex_free_adapter(adapter);
1161
1162err_init_sw:
1163 up(sem);
1164
1165exit_sem_err:
1166 return -1;
1167}
1168EXPORT_SYMBOL_GPL(mwifiex_add_card);
1169
1170/*
1171 * This function removes the card.
1172 *
1173 * This function follows the following major steps to remove the device -
1174 * - Stop data traffic
1175 * - Shutdown firmware
1176 * - Remove the logical interfaces
1177 * - Terminate the work queue
1178 * - Unregister the device
1179 * - Free the adapter structure
1180 */
1181int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1182{
1183 struct mwifiex_private *priv = NULL;
5e6e3a92
BZ
1184 int i;
1185
1186 if (down_interruptible(sem))
1187 goto exit_sem_err;
1188
1189 if (!adapter)
1190 goto exit_remove;
1191
232fde06
DD
1192 /* We can no longer handle interrupts once we start doing the teardown
1193 * below. */
1194 if (adapter->if_ops.disable_int)
1195 adapter->if_ops.disable_int(adapter);
1196
5e6e3a92
BZ
1197 adapter->surprise_removed = true;
1198
9d2e85e0
MY
1199 mwifiex_terminate_workqueue(adapter);
1200
5e6e3a92
BZ
1201 /* Stop data */
1202 for (i = 0; i < adapter->priv_num; i++) {
1203 priv = adapter->priv[i];
93a1df48 1204 if (priv && priv->netdev) {
47411a06 1205 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
5e6e3a92
BZ
1206 if (netif_carrier_ok(priv->netdev))
1207 netif_carrier_off(priv->netdev);
1208 }
1209 }
1210
1211 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
1212 adapter->init_wait_q_woken = false;
636c4598
YAP
1213
1214 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
5e6e3a92
BZ
1215 wait_event_interruptible(adapter->init_wait_q,
1216 adapter->init_wait_q_woken);
1217 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
1218 if (atomic_read(&adapter->rx_pending) ||
1219 atomic_read(&adapter->tx_pending) ||
600f5d90 1220 atomic_read(&adapter->cmd_pending)) {
5e6e3a92 1221 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
600f5d90 1222 "cmd_pending=%d\n",
5e6e3a92
BZ
1223 atomic_read(&adapter->rx_pending),
1224 atomic_read(&adapter->tx_pending),
600f5d90 1225 atomic_read(&adapter->cmd_pending));
5e6e3a92
BZ
1226 }
1227
93a1df48
YAP
1228 for (i = 0; i < adapter->priv_num; i++) {
1229 priv = adapter->priv[i];
1230
1231 if (!priv)
1232 continue;
1233
1234 rtnl_lock();
4facc34a
AP
1235 if (priv->netdev &&
1236 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1237 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
93a1df48
YAP
1238 rtnl_unlock();
1239 }
1240
c2868ade
AK
1241 wiphy_unregister(adapter->wiphy);
1242 wiphy_free(adapter->wiphy);
64b05e2f 1243
5e6e3a92
BZ
1244 /* Unregister device */
1245 dev_dbg(adapter->dev, "info: unregister device\n");
4daffe35
AK
1246 if (adapter->if_ops.unregister_dev)
1247 adapter->if_ops.unregister_dev(adapter);
5e6e3a92
BZ
1248 /* Free adapter structure */
1249 dev_dbg(adapter->dev, "info: free adapter\n");
1250 mwifiex_free_adapter(adapter);
1251
1252exit_remove:
1253 up(sem);
1254exit_sem_err:
1255 return 0;
1256}
1257EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1258
1259/*
1260 * This function initializes the module.
1261 *
1262 * The debug FS is also initialized if configured.
1263 */
1264static int
1265mwifiex_init_module(void)
1266{
1267#ifdef CONFIG_DEBUG_FS
1268 mwifiex_debugfs_init();
1269#endif
1270 return 0;
1271}
1272
1273/*
1274 * This function cleans up the module.
1275 *
1276 * The debug FS is removed if available.
1277 */
1278static void
1279mwifiex_cleanup_module(void)
1280{
1281#ifdef CONFIG_DEBUG_FS
1282 mwifiex_debugfs_remove();
1283#endif
1284}
1285
1286module_init(mwifiex_init_module);
1287module_exit(mwifiex_cleanup_module);
1288
1289MODULE_AUTHOR("Marvell International Ltd.");
1290MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1291MODULE_VERSION(VERSION);
1292MODULE_LICENSE("GPL v2");
This page took 0.483889 seconds and 5 git commands to generate.