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