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