mwifiex: add del_station handler
[deliverable/linux.git] / drivers / net / wireless / mwifiex / init.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: HW/FW Initialization
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 "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28/*
29 * This function adds a BSS priority table to the table list.
30 *
31 * The function allocates a new BSS priority table node and adds it to
32 * the end of BSS priority table list, kept in driver memory.
33 */
34static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
35{
36 struct mwifiex_adapter *adapter = priv->adapter;
37 struct mwifiex_bss_prio_node *bss_prio;
931f1584 38 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
5e6e3a92
BZ
39 unsigned long flags;
40
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
0d2e7a5c 42 if (!bss_prio)
b53575ec 43 return -ENOMEM;
5e6e3a92
BZ
44
45 bss_prio->priv = priv;
46 INIT_LIST_HEAD(&bss_prio->list);
931f1584
YAP
47
48 spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
49 list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head);
50 spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
5e6e3a92 51
600f5d90 52 return 0;
5e6e3a92
BZ
53}
54
3249ba73
AK
55static void scan_delay_timer_fn(unsigned long data)
56{
57 struct mwifiex_private *priv = (struct mwifiex_private *)data;
58 struct mwifiex_adapter *adapter = priv->adapter;
59 struct cmd_ctrl_node *cmd_node, *tmp_node;
60 unsigned long flags;
61
06041118
AK
62 if (adapter->surprise_removed)
63 return;
64
bdd37bed
AK
65 if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT) {
66 /*
67 * Abort scan operation by cancelling all pending scan
68 * commands
69 */
70 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
71 list_for_each_entry_safe(cmd_node, tmp_node,
72 &adapter->scan_pending_q, list) {
73 list_del(&cmd_node->list);
bdd37bed
AK
74 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
75 }
76 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
77
78 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
79 adapter->scan_processing = false;
80 adapter->scan_delay_cnt = 0;
81 adapter->empty_tx_q_cnt = 0;
82 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
83
75ab753d
AK
84 if (priv->scan_request) {
85 dev_dbg(adapter->dev, "info: aborting scan\n");
86 cfg80211_scan_done(priv->scan_request, 1);
87 priv->scan_request = NULL;
88 } else {
89 priv->scan_aborting = false;
90 dev_dbg(adapter->dev, "info: scan already aborted\n");
bdd37bed
AK
91 }
92 goto done;
93 }
94
95 if (!atomic_read(&priv->adapter->is_tx_received)) {
96 adapter->empty_tx_q_cnt++;
97 if (adapter->empty_tx_q_cnt == MWIFIEX_MAX_EMPTY_TX_Q_CNT) {
3249ba73 98 /*
bdd37bed
AK
99 * No Tx traffic for 200msec. Get scan command from
100 * scan pending queue and put to cmd pending queue to
101 * resume scan operation
3249ba73 102 */
bdd37bed
AK
103 adapter->scan_delay_cnt = 0;
104 adapter->empty_tx_q_cnt = 0;
3249ba73 105 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
bdd37bed
AK
106 cmd_node = list_first_entry(&adapter->scan_pending_q,
107 struct cmd_ctrl_node, list);
108 list_del(&cmd_node->list);
3249ba73
AK
109 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
110 flags);
111
bdd37bed
AK
112 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
113 true);
9a17bad1 114 queue_work(adapter->workqueue, &adapter->main_work);
bdd37bed 115 goto done;
3249ba73
AK
116 }
117 } else {
bdd37bed 118 adapter->empty_tx_q_cnt = 0;
3249ba73 119 }
bdd37bed
AK
120
121 /* Delay scan operation further by 20msec */
122 mod_timer(&priv->scan_delay_timer, jiffies +
123 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
124 adapter->scan_delay_cnt++;
125
126done:
127 if (atomic_read(&priv->adapter->is_tx_received))
128 atomic_set(&priv->adapter->is_tx_received, false);
129
130 return;
3249ba73
AK
131}
132
5e6e3a92
BZ
133/*
134 * This function initializes the private structure and sets default
135 * values to the members.
136 *
137 * Additionally, it also initializes all the locks and sets up all the
138 * lists.
139 */
9197ab9e 140int mwifiex_init_priv(struct mwifiex_private *priv)
5e6e3a92
BZ
141{
142 u32 i;
5e6e3a92
BZ
143
144 priv->media_connected = false;
145 memset(priv->curr_addr, 0xff, ETH_ALEN);
146
147 priv->pkt_tx_ctrl = 0;
93a1df48 148 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
5e6e3a92
BZ
149 priv->data_rate = 0; /* Initially indicate the rate as auto */
150 priv->is_data_rate_auto = true;
151 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
152 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
153
5eb02e44 154 priv->sec_info.wep_enabled = 0;
f986b6d5 155 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
2be50b8d 156 priv->sec_info.encryption_mode = 0;
5e6e3a92
BZ
157 for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
158 memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
159 priv->wep_key_curr_index = 0;
160 priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
161 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
162
163 priv->beacon_period = 100; /* beacon interval */ ;
164 priv->attempted_bss_desc = NULL;
165 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
166 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
167
168 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
169 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
170 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
171 priv->assoc_rsp_size = 0;
172 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
173 priv->atim_window = 0;
174 priv->adhoc_state = ADHOC_IDLE;
175 priv->tx_power_level = 0;
176 priv->max_tx_power_level = 0;
177 priv->min_tx_power_level = 0;
178 priv->tx_rate = 0;
179 priv->rxpd_htinfo = 0;
180 priv->rxpd_rate = 0;
181 priv->rate_bitmap = 0;
182 priv->data_rssi_last = 0;
183 priv->data_rssi_avg = 0;
184 priv->data_nf_avg = 0;
185 priv->data_nf_last = 0;
186 priv->bcn_rssi_last = 0;
187 priv->bcn_rssi_avg = 0;
188 priv->bcn_nf_avg = 0;
189 priv->bcn_nf_last = 0;
190 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
191 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
192 priv->wpa_ie_len = 0;
193 priv->wpa_is_gtk_set = false;
194
195 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
196 priv->assoc_tlv_buf_len = 0;
197 memset(&priv->wps, 0, sizeof(priv->wps));
198 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
199 priv->gen_ie_buf_len = 0;
200 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
201
202 priv->wmm_required = true;
203 priv->wmm_enabled = false;
204 priv->wmm_qosinfo = 0;
205 priv->curr_bcn_buf = NULL;
206 priv->curr_bcn_size = 0;
13d7ba78
AP
207 priv->wps_ie = NULL;
208 priv->wps_ie_len = 0;
c8258913 209 priv->ap_11n_enabled = 0;
7feb4c48 210 memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
5e6e3a92
BZ
211
212 priv->scan_block = false;
213
3249ba73
AK
214 setup_timer(&priv->scan_delay_timer, scan_delay_timer_fn,
215 (unsigned long)priv);
216
636c4598 217 return mwifiex_add_bss_prio_tbl(priv);
5e6e3a92
BZ
218}
219
220/*
221 * This function allocates buffers for members of the adapter
222 * structure.
223 *
224 * The memory allocated includes scan table, command buffers, and
225 * sleep confirm command buffer. In addition, the queues are
226 * also initialized.
227 */
228static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
229{
270e58e8 230 int ret;
5e6e3a92
BZ
231
232 /* Allocate command buffer */
233 ret = mwifiex_alloc_cmd_buffer(adapter);
234 if (ret) {
235 dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n",
931f1584 236 __func__);
5e6e3a92
BZ
237 return -1;
238 }
239
240 adapter->sleep_cfm =
7cc5eb62 241 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
931f1584 242 + INTF_HEADER_LEN);
5e6e3a92
BZ
243
244 if (!adapter->sleep_cfm) {
245 dev_err(adapter->dev, "%s: failed to alloc sleep cfm"
246 " cmd buffer\n", __func__);
247 return -1;
248 }
249 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
250
251 return 0;
252}
253
254/*
255 * This function initializes the adapter structure and sets default
256 * values to the members of adapter.
257 *
258 * This also initializes the WMM related parameters in the driver private
259 * structures.
260 */
261static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
262{
7cc5eb62 263 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
5e6e3a92 264
7cc5eb62 265 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
5e6e3a92
BZ
266
267 adapter->cmd_sent = false;
d930faee 268
4daffe35 269 if (adapter->iface_type == MWIFIEX_SDIO)
d930faee 270 adapter->data_sent = true;
4daffe35
AK
271 else
272 adapter->data_sent = false;
d930faee 273
5e6e3a92
BZ
274 adapter->cmd_resp_received = false;
275 adapter->event_received = false;
276 adapter->data_received = false;
277
278 adapter->surprise_removed = false;
279
280 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
281
282 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
283 adapter->ps_state = PS_STATE_AWAKE;
284 adapter->need_to_wakeup = false;
285
286 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
287 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
288 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
289 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
290
5e6e3a92
BZ
291 adapter->scan_probes = 1;
292
5e6e3a92
BZ
293 adapter->multiple_dtim = 1;
294
295 adapter->local_listen_interval = 0; /* default value in firmware
296 will be used */
297
298 adapter->is_deep_sleep = false;
299
300 adapter->delay_null_pkt = false;
301 adapter->delay_to_ps = 1000;
302 adapter->enhanced_ps_mode = PS_MODE_AUTO;
303
304 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
305 default */
306 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
307 default */
308 adapter->pm_wakeup_card_req = false;
309
310 adapter->pm_wakeup_fw_try = false;
311
5e6e3a92
BZ
312 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
313 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
314
315 adapter->is_hs_configured = false;
cc0b5a64
AK
316 adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
317 adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
318 adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
5e6e3a92
BZ
319 adapter->hs_activated = false;
320
321 memset(adapter->event_body, 0, sizeof(adapter->event_body));
322 adapter->hw_dot_11n_dev_cap = 0;
323 adapter->hw_dev_mcs_support = 0;
21c3ba34 324 adapter->sec_chan_offset = 0;
5e6e3a92
BZ
325 adapter->adhoc_11n_enabled = false;
326
327 mwifiex_wmm_init(adapter);
328
329 if (adapter->sleep_cfm) {
8ed13033
YAP
330 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
331 adapter->sleep_cfm->data;
7cc5eb62
AK
332 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
333 sleep_cfm_buf->command =
334 cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
335 sleep_cfm_buf->size =
336 cpu_to_le16(adapter->sleep_cfm->len);
337 sleep_cfm_buf->result = 0;
338 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
339 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
5e6e3a92
BZ
340 }
341 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
342 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
343 adapter->tx_lock_flag = false;
344 adapter->null_pkt_interval = 0;
345 adapter->fw_bands = 0;
346 adapter->config_bands = 0;
347 adapter->adhoc_start_band = 0;
348 adapter->scan_channels = NULL;
349 adapter->fw_release_number = 0;
350 adapter->fw_cap_info = 0;
351 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
352 adapter->event_cause = 0;
353 adapter->region_code = 0;
354 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
355 adapter->adhoc_awake_period = 0;
356 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
357 adapter->arp_filter_size = 0;
ede98bfa 358 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
bdd37bed 359 adapter->empty_tx_q_cnt = 0;
5e6e3a92
BZ
360}
361
bbea3bc4
AP
362/*
363 * This function sets trans_start per tx_queue
364 */
365void mwifiex_set_trans_start(struct net_device *dev)
366{
367 int i;
368
369 for (i = 0; i < dev->num_tx_queues; i++)
370 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
371
372 dev->trans_start = jiffies;
373}
374
375/*
376 * This function wakes up all queues in net_device
377 */
378void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
379 struct mwifiex_adapter *adapter)
380{
381 unsigned long dev_queue_flags;
47411a06 382 unsigned int i;
bbea3bc4
AP
383
384 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
47411a06
AP
385
386 for (i = 0; i < netdev->num_tx_queues; i++) {
387 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
388
389 if (netif_tx_queue_stopped(txq))
390 netif_tx_wake_queue(txq);
391 }
392
bbea3bc4
AP
393 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
394}
395
396/*
397 * This function stops all queues in net_device
398 */
399void mwifiex_stop_net_dev_queue(struct net_device *netdev,
400 struct mwifiex_adapter *adapter)
401{
402 unsigned long dev_queue_flags;
47411a06 403 unsigned int i;
bbea3bc4
AP
404
405 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
47411a06
AP
406
407 for (i = 0; i < netdev->num_tx_queues; i++) {
408 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
409
410 if (!netif_tx_queue_stopped(txq))
411 netif_tx_stop_queue(txq);
412 }
413
bbea3bc4
AP
414 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
415}
416
711825a0
AK
417/*
418 * This function releases the lock variables and frees the locks and
419 * associated locks.
420 */
421static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
422{
423 struct mwifiex_private *priv;
424 s32 i, j;
425
426 /* Free lists */
427 list_del(&adapter->cmd_free_q);
428 list_del(&adapter->cmd_pending_q);
429 list_del(&adapter->scan_pending_q);
430
431 for (i = 0; i < adapter->priv_num; i++)
432 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
433
434 for (i = 0; i < adapter->priv_num; i++) {
435 if (adapter->priv[i]) {
436 priv = adapter->priv[i];
437 for (j = 0; j < MAX_NUM_TID; ++j)
438 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
439 list_del(&priv->tx_ba_stream_tbl_ptr);
440 list_del(&priv->rx_reorder_tbl_ptr);
017a92a1 441 list_del(&priv->sta_list);
711825a0
AK
442 }
443 }
444}
445
5e6e3a92 446/*
c56ecf5a 447 * This function performs cleanup for adapter structure.
5e6e3a92 448 *
c56ecf5a
AK
449 * The cleanup is done recursively, by canceling all pending
450 * commands, freeing the member buffers previously allocated
451 * (command buffers, scan table buffer, sleep confirm command
452 * buffer), stopping the timers and calling the cleanup routines
453 * for every interface.
5e6e3a92
BZ
454 */
455static void
c56ecf5a 456mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
5e6e3a92 457{
06041118
AK
458 int i;
459
5e6e3a92
BZ
460 if (!adapter) {
461 pr_err("%s: adapter is NULL\n", __func__);
462 return;
463 }
464
06041118
AK
465 for (i = 0; i < adapter->priv_num; i++) {
466 if (adapter->priv[i])
467 del_timer_sync(&adapter->priv[i]->scan_delay_timer);
468 }
469
5e6e3a92
BZ
470 mwifiex_cancel_all_pending_cmd(adapter);
471
472 /* Free lock variables */
473 mwifiex_free_lock_list(adapter);
474
475 /* Free command buffer */
476 dev_dbg(adapter->dev, "info: free cmd buffer\n");
477 mwifiex_free_cmd_buffer(adapter);
478
479 del_timer(&adapter->cmd_timer);
480
481 dev_dbg(adapter->dev, "info: free scan table\n");
5e6e3a92 482
4daffe35
AK
483 if (adapter->if_ops.cleanup_if)
484 adapter->if_ops.cleanup_if(adapter);
5e6e3a92 485
2da8cbf8
AK
486 if (adapter->sleep_cfm)
487 dev_kfree_skb_any(adapter->sleep_cfm);
5e6e3a92
BZ
488}
489
490/*
491 * This function intializes the lock variables and
492 * the list heads.
493 */
494int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
495{
270e58e8
YAP
496 struct mwifiex_private *priv;
497 s32 i, j;
5e6e3a92
BZ
498
499 spin_lock_init(&adapter->mwifiex_lock);
500 spin_lock_init(&adapter->int_lock);
501 spin_lock_init(&adapter->main_proc_lock);
502 spin_lock_init(&adapter->mwifiex_cmd_lock);
bbea3bc4 503 spin_lock_init(&adapter->queue_lock);
5e6e3a92
BZ
504 for (i = 0; i < adapter->priv_num; i++) {
505 if (adapter->priv[i]) {
506 priv = adapter->priv[i];
507 spin_lock_init(&priv->rx_pkt_lock);
508 spin_lock_init(&priv->wmm.ra_list_spinlock);
509 spin_lock_init(&priv->curr_bcn_buf_lock);
017a92a1 510 spin_lock_init(&priv->sta_list_spinlock);
5e6e3a92
BZ
511 }
512 }
513
514 /* Initialize cmd_free_q */
515 INIT_LIST_HEAD(&adapter->cmd_free_q);
516 /* Initialize cmd_pending_q */
517 INIT_LIST_HEAD(&adapter->cmd_pending_q);
518 /* Initialize scan_pending_q */
519 INIT_LIST_HEAD(&adapter->scan_pending_q);
520
521 spin_lock_init(&adapter->cmd_free_q_lock);
522 spin_lock_init(&adapter->cmd_pending_q_lock);
523 spin_lock_init(&adapter->scan_pending_q_lock);
524
4daffe35
AK
525 skb_queue_head_init(&adapter->usb_rx_data_q);
526
5e6e3a92
BZ
527 for (i = 0; i < adapter->priv_num; ++i) {
528 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
5e6e3a92
BZ
529 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
530 }
531
532 for (i = 0; i < adapter->priv_num; i++) {
533 if (!adapter->priv[i])
534 continue;
535 priv = adapter->priv[i];
6d2344ec 536 for (j = 0; j < MAX_NUM_TID; ++j)
5e6e3a92 537 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
5e6e3a92
BZ
538 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
539 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
017a92a1 540 INIT_LIST_HEAD(&priv->sta_list);
5e6e3a92
BZ
541
542 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
543 spin_lock_init(&priv->rx_reorder_tbl_lock);
544 }
545
546 return 0;
547}
548
5e6e3a92
BZ
549/*
550 * This function initializes the firmware.
551 *
552 * The following operations are performed sequentially -
553 * - Allocate adapter structure
554 * - Initialize the adapter structure
555 * - Initialize the private structure
556 * - Add BSS priority tables to the adapter structure
557 * - For each interface, send the init commands to firmware
558 * - Send the first command in command pending queue, if available
559 */
560int mwifiex_init_fw(struct mwifiex_adapter *adapter)
561{
270e58e8
YAP
562 int ret;
563 struct mwifiex_private *priv;
564 u8 i, first_sta = true;
5e6e3a92
BZ
565 int is_cmd_pend_q_empty;
566 unsigned long flags;
567
568 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
569
570 /* Allocate memory for member of adapter structure */
571 ret = mwifiex_allocate_adapter(adapter);
572 if (ret)
573 return -1;
574
575 /* Initialize adapter structure */
576 mwifiex_init_adapter(adapter);
577
578 for (i = 0; i < adapter->priv_num; i++) {
579 if (adapter->priv[i]) {
580 priv = adapter->priv[i];
581
582 /* Initialize private structure */
583 ret = mwifiex_init_priv(priv);
584 if (ret)
585 return -1;
586 }
587 }
c6d1d87a
AP
588
589 if (adapter->if_ops.init_fw_port) {
590 if (adapter->if_ops.init_fw_port(adapter))
591 return -1;
592 }
593
5e6e3a92
BZ
594 for (i = 0; i < adapter->priv_num; i++) {
595 if (adapter->priv[i]) {
596 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta);
597 if (ret == -1)
598 return -1;
599
600 first_sta = false;
601 }
602 }
603
604 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
605 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
606 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
607 if (!is_cmd_pend_q_empty) {
608 /* Send the first command in queue and return */
609 if (mwifiex_main_process(adapter) != -1)
610 ret = -EINPROGRESS;
611 } else {
612 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
613 }
614
615 return ret;
616}
617
618/*
619 * This function deletes the BSS priority tables.
620 *
621 * The function traverses through all the allocated BSS priority nodes
622 * in every BSS priority table and frees them.
623 */
624static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
625{
626 int i;
627 struct mwifiex_adapter *adapter = priv->adapter;
b006ed54 628 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
5e6e3a92 629 struct list_head *head;
931f1584 630 spinlock_t *lock; /* bss priority lock */
5e6e3a92
BZ
631 unsigned long flags;
632
633 for (i = 0; i < adapter->priv_num; ++i) {
634 head = &adapter->bss_prio_tbl[i].bss_prio_head;
5e6e3a92
BZ
635 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
636 dev_dbg(adapter->dev, "info: delete BSS priority table,"
9da9a3b2 637 " bss_type = %d, bss_num = %d, i = %d,"
b006ed54
AF
638 " head = %p\n",
639 priv->bss_type, priv->bss_num, i, head);
640
641 {
5e6e3a92
BZ
642 spin_lock_irqsave(lock, flags);
643 if (list_empty(head)) {
644 spin_unlock_irqrestore(lock, flags);
645 continue;
646 }
5e6e3a92
BZ
647 list_for_each_entry_safe(bssprio_node, tmp_node, head,
648 list) {
649 if (bssprio_node->priv == priv) {
650 dev_dbg(adapter->dev, "info: Delete "
651 "node %p, next = %p\n",
652 bssprio_node, tmp_node);
5e6e3a92 653 list_del(&bssprio_node->list);
5e6e3a92
BZ
654 kfree(bssprio_node);
655 }
656 }
b006ed54 657 spin_unlock_irqrestore(lock, flags);
5e6e3a92
BZ
658 }
659 }
660}
661
9197ab9e
SP
662/*
663 * This function frees the private structure, including cleans
664 * up the TX and RX queues and frees the BSS priority tables.
665 */
666void mwifiex_free_priv(struct mwifiex_private *priv)
667{
668 mwifiex_clean_txrx(priv);
669 mwifiex_delete_bss_prio_tbl(priv);
670 mwifiex_free_curr_bcn(priv);
671}
672
5e6e3a92
BZ
673/*
674 * This function is used to shutdown the driver.
675 *
676 * The following operations are performed sequentially -
677 * - Check if already shut down
678 * - Make sure the main process has stopped
679 * - Clean up the Tx and Rx queues
680 * - Delete BSS priority tables
681 * - Free the adapter
682 * - Notify completion
683 */
684int
685mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
686{
687 int ret = -EINPROGRESS;
270e58e8
YAP
688 struct mwifiex_private *priv;
689 s32 i;
5e6e3a92 690 unsigned long flags;
4daffe35 691 struct sk_buff *skb;
5e6e3a92
BZ
692
693 /* mwifiex already shutdown */
694 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
695 return 0;
696
697 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
698 /* wait for mwifiex_process to complete */
699 if (adapter->mwifiex_processing) {
700 dev_warn(adapter->dev, "main process is still running\n");
701 return ret;
702 }
703
084c7189
BZ
704 /* cancel current command */
705 if (adapter->curr_cmd) {
706 dev_warn(adapter->dev, "curr_cmd is still in processing\n");
707 del_timer(&adapter->cmd_timer);
9908b074 708 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
084c7189
BZ
709 adapter->curr_cmd = NULL;
710 }
711
5e6e3a92
BZ
712 /* shut down mwifiex */
713 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
714
715 /* Clean up Tx/Rx queues and delete BSS priority table */
716 for (i = 0; i < adapter->priv_num; i++) {
717 if (adapter->priv[i]) {
718 priv = adapter->priv[i];
719
720 mwifiex_clean_txrx(priv);
721 mwifiex_delete_bss_prio_tbl(priv);
722 }
723 }
724
725 spin_lock_irqsave(&adapter->mwifiex_lock, flags);
726
4daffe35
AK
727 if (adapter->if_ops.data_complete) {
728 while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) {
729 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
730
731 priv = adapter->priv[rx_info->bss_num];
732 if (priv)
733 priv->stats.rx_dropped++;
734
735 adapter->if_ops.data_complete(adapter, skb);
736 }
737 }
738
c56ecf5a 739 mwifiex_adapter_cleanup(adapter);
5e6e3a92
BZ
740
741 spin_unlock_irqrestore(&adapter->mwifiex_lock, flags);
742
743 /* Notify completion */
744 ret = mwifiex_shutdown_fw_complete(adapter);
745
746 return ret;
747}
748
749/*
750 * This function downloads the firmware to the card.
751 *
752 * The actual download is preceded by two sanity checks -
753 * - Check if firmware is already running
754 * - Check if the interface is the winner to download the firmware
755 *
756 * ...and followed by another -
757 * - Check if the firmware is downloaded successfully
758 *
759 * After download is successfully completed, the host interrupts are enabled.
760 */
761int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
762 struct mwifiex_fw_image *pmfw)
763{
d930faee 764 int ret;
5e6e3a92 765 u32 poll_num = 1;
5e6e3a92 766
4daffe35
AK
767 if (adapter->if_ops.check_fw_status) {
768 adapter->winner = 0;
d930faee 769
4daffe35
AK
770 /* check if firmware is already running */
771 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
772 if (!ret) {
773 dev_notice(adapter->dev,
774 "WLAN FW already running! Skip FW dnld\n");
775 goto done;
776 }
777
778 poll_num = MAX_FIRMWARE_POLL_TRIES;
779
780 /* check if we are the winner for downloading FW */
781 if (!adapter->winner) {
782 dev_notice(adapter->dev,
783 "FW already running! Skip FW dnld\n");
784 poll_num = MAX_MULTI_INTERFACE_POLL_TRIES;
785 goto poll_fw;
786 }
5e6e3a92 787 }
4daffe35 788
5e6e3a92
BZ
789 if (pmfw) {
790 /* Download firmware with helper */
791 ret = adapter->if_ops.prog_fw(adapter, pmfw);
792 if (ret) {
793 dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret);
794 return ret;
795 }
796 }
797
798poll_fw:
799 /* Check if the firmware is downloaded successfully or not */
d930faee 800 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
5e6e3a92
BZ
801 if (ret) {
802 dev_err(adapter->dev, "FW failed to be active in time\n");
803 return -1;
804 }
805done:
806 /* re-enable host interrupt for mwifiex after fw dnld is successful */
4daffe35
AK
807 if (adapter->if_ops.enable_int)
808 adapter->if_ops.enable_int(adapter);
809
5e6e3a92
BZ
810 return ret;
811}
This page took 0.241774 seconds and 5 git commands to generate.