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