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