blob: 26940455255ba4637fdd31ec19a3407640f71e87 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070038 unsigned long flags;
39
40 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
41 if (!bss_prio) {
42 dev_err(adapter->dev, "%s: failed to alloc bss_prio\n",
43 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +020044 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070045 }
46
47 bss_prio->priv = priv;
48 INIT_LIST_HEAD(&bss_prio->list);
49 if (!adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur)
50 adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
51 bss_prio;
52
53 spin_lock_irqsave(&adapter->bss_prio_tbl[priv->bss_priority]
54 .bss_prio_lock, flags);
55 list_add_tail(&bss_prio->list,
56 &adapter->bss_prio_tbl[priv->bss_priority]
57 .bss_prio_head);
58 spin_unlock_irqrestore(&adapter->bss_prio_tbl[priv->bss_priority]
59 .bss_prio_lock, flags);
60
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070061 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062}
63
64/*
65 * This function initializes the private structure and sets default
66 * values to the members.
67 *
68 * Additionally, it also initializes all the locks and sets up all the
69 * lists.
70 */
71static int mwifiex_init_priv(struct mwifiex_private *priv)
72{
73 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070074
75 priv->media_connected = false;
76 memset(priv->curr_addr, 0xff, ETH_ALEN);
77
78 priv->pkt_tx_ctrl = 0;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070079 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070080 priv->data_rate = 0; /* Initially indicate the rate as auto */
81 priv->is_data_rate_auto = true;
82 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
83 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
84
85 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
Marc Yangf986b6d2011-03-28 17:55:42 -070086 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070087 priv->sec_info.encryption_mode = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070088 for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
89 memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
90 priv->wep_key_curr_index = 0;
91 priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
92 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
93
94 priv->beacon_period = 100; /* beacon interval */ ;
95 priv->attempted_bss_desc = NULL;
96 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
97 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
98
99 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
100 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
101 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
102 priv->assoc_rsp_size = 0;
103 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
104 priv->atim_window = 0;
105 priv->adhoc_state = ADHOC_IDLE;
106 priv->tx_power_level = 0;
107 priv->max_tx_power_level = 0;
108 priv->min_tx_power_level = 0;
109 priv->tx_rate = 0;
110 priv->rxpd_htinfo = 0;
111 priv->rxpd_rate = 0;
112 priv->rate_bitmap = 0;
113 priv->data_rssi_last = 0;
114 priv->data_rssi_avg = 0;
115 priv->data_nf_avg = 0;
116 priv->data_nf_last = 0;
117 priv->bcn_rssi_last = 0;
118 priv->bcn_rssi_avg = 0;
119 priv->bcn_nf_avg = 0;
120 priv->bcn_nf_last = 0;
121 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
122 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
123 priv->wpa_ie_len = 0;
124 priv->wpa_is_gtk_set = false;
125
126 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
127 priv->assoc_tlv_buf_len = 0;
128 memset(&priv->wps, 0, sizeof(priv->wps));
129 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
130 priv->gen_ie_buf_len = 0;
131 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
132
133 priv->wmm_required = true;
134 priv->wmm_enabled = false;
135 priv->wmm_qosinfo = 0;
136 priv->curr_bcn_buf = NULL;
137 priv->curr_bcn_size = 0;
138
139 priv->scan_block = false;
140
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700141 return mwifiex_add_bss_prio_tbl(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700142}
143
144/*
145 * This function allocates buffers for members of the adapter
146 * structure.
147 *
148 * The memory allocated includes scan table, command buffers, and
149 * sleep confirm command buffer. In addition, the queues are
150 * also initialized.
151 */
152static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
153{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700154 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700155
156 /* Allocate command buffer */
157 ret = mwifiex_alloc_cmd_buffer(adapter);
158 if (ret) {
159 dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n",
160 __func__);
161 return -1;
162 }
163
164 adapter->sleep_cfm =
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700165 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166 + INTF_HEADER_LEN);
167
168 if (!adapter->sleep_cfm) {
169 dev_err(adapter->dev, "%s: failed to alloc sleep cfm"
170 " cmd buffer\n", __func__);
171 return -1;
172 }
173 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
174
175 return 0;
176}
177
178/*
179 * This function initializes the adapter structure and sets default
180 * values to the members of adapter.
181 *
182 * This also initializes the WMM related parameters in the driver private
183 * structures.
184 */
185static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
186{
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700187 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700189 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700190
191 adapter->cmd_sent = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700192
193 if (adapter->iface_type == MWIFIEX_PCIE)
194 adapter->data_sent = false;
195 else
196 adapter->data_sent = true;
197
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198 adapter->cmd_resp_received = false;
199 adapter->event_received = false;
200 adapter->data_received = false;
201
202 adapter->surprise_removed = false;
203
204 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
205
206 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
207 adapter->ps_state = PS_STATE_AWAKE;
208 adapter->need_to_wakeup = false;
209
210 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
211 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
212 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
213 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
214
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215 adapter->scan_probes = 1;
216
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700217 adapter->multiple_dtim = 1;
218
219 adapter->local_listen_interval = 0; /* default value in firmware
220 will be used */
221
222 adapter->is_deep_sleep = false;
223
224 adapter->delay_null_pkt = false;
225 adapter->delay_to_ps = 1000;
226 adapter->enhanced_ps_mode = PS_MODE_AUTO;
227
228 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
229 default */
230 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
231 default */
232 adapter->pm_wakeup_card_req = false;
233
234 adapter->pm_wakeup_fw_try = false;
235
236 adapter->max_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
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;
241 adapter->hs_cfg.conditions = cpu_to_le32(HOST_SLEEP_CFG_COND_DEF);
242 adapter->hs_cfg.gpio = HOST_SLEEP_CFG_GPIO_DEF;
243 adapter->hs_cfg.gap = HOST_SLEEP_CFG_GAP_DEF;
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700249 adapter->chan_offset = 0;
250 adapter->adhoc_11n_enabled = false;
251
252 mwifiex_wmm_init(adapter);
253
254 if (adapter->sleep_cfm) {
Yogesh Ashok Powar8ed13032011-11-07 21:41:10 -0800255 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
256 adapter->sleep_cfm->data;
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700257 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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700265 }
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283}
284
285/*
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700286 * This function releases the lock variables and frees the locks and
287 * associated locks.
288 */
289static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
290{
291 struct mwifiex_private *priv;
292 s32 i, j;
293
294 /* Free lists */
295 list_del(&adapter->cmd_free_q);
296 list_del(&adapter->cmd_pending_q);
297 list_del(&adapter->scan_pending_q);
298
299 for (i = 0; i < adapter->priv_num; i++)
300 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
301
302 for (i = 0; i < adapter->priv_num; i++) {
303 if (adapter->priv[i]) {
304 priv = adapter->priv[i];
305 for (j = 0; j < MAX_NUM_TID; ++j)
306 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
307 list_del(&priv->tx_ba_stream_tbl_ptr);
308 list_del(&priv->rx_reorder_tbl_ptr);
309 }
310 }
311}
312
313/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700314 * This function frees the adapter structure.
315 *
316 * The freeing operation is done recursively, by canceling all
317 * pending commands, freeing the member buffers previously
318 * allocated (command buffers, scan table buffer, sleep confirm
319 * command buffer), stopping the timers and calling the cleanup
320 * routines for every interface, before the actual adapter
321 * structure is freed.
322 */
323static void
324mwifiex_free_adapter(struct mwifiex_adapter *adapter)
325{
326 if (!adapter) {
327 pr_err("%s: adapter is NULL\n", __func__);
328 return;
329 }
330
331 mwifiex_cancel_all_pending_cmd(adapter);
332
333 /* Free lock variables */
334 mwifiex_free_lock_list(adapter);
335
336 /* Free command buffer */
337 dev_dbg(adapter->dev, "info: free cmd buffer\n");
338 mwifiex_free_cmd_buffer(adapter);
339
340 del_timer(&adapter->cmd_timer);
341
342 dev_dbg(adapter->dev, "info: free scan table\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700343
344 adapter->if_ops.cleanup_if(adapter);
345
346 dev_kfree_skb_any(adapter->sleep_cfm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347}
348
349/*
350 * This function intializes the lock variables and
351 * the list heads.
352 */
353int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
354{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700355 struct mwifiex_private *priv;
356 s32 i, j;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357
358 spin_lock_init(&adapter->mwifiex_lock);
359 spin_lock_init(&adapter->int_lock);
360 spin_lock_init(&adapter->main_proc_lock);
361 spin_lock_init(&adapter->mwifiex_cmd_lock);
362 for (i = 0; i < adapter->priv_num; i++) {
363 if (adapter->priv[i]) {
364 priv = adapter->priv[i];
365 spin_lock_init(&priv->rx_pkt_lock);
366 spin_lock_init(&priv->wmm.ra_list_spinlock);
367 spin_lock_init(&priv->curr_bcn_buf_lock);
368 }
369 }
370
371 /* Initialize cmd_free_q */
372 INIT_LIST_HEAD(&adapter->cmd_free_q);
373 /* Initialize cmd_pending_q */
374 INIT_LIST_HEAD(&adapter->cmd_pending_q);
375 /* Initialize scan_pending_q */
376 INIT_LIST_HEAD(&adapter->scan_pending_q);
377
378 spin_lock_init(&adapter->cmd_free_q_lock);
379 spin_lock_init(&adapter->cmd_pending_q_lock);
380 spin_lock_init(&adapter->scan_pending_q_lock);
381
382 for (i = 0; i < adapter->priv_num; ++i) {
383 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
384 adapter->bss_prio_tbl[i].bss_prio_cur = NULL;
385 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
386 }
387
388 for (i = 0; i < adapter->priv_num; i++) {
389 if (!adapter->priv[i])
390 continue;
391 priv = adapter->priv[i];
392 for (j = 0; j < MAX_NUM_TID; ++j) {
393 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
394 spin_lock_init(&priv->wmm.tid_tbl_ptr[j].tid_tbl_lock);
395 }
396 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
397 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
398
399 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
400 spin_lock_init(&priv->rx_reorder_tbl_lock);
401 }
402
403 return 0;
404}
405
406/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700407 * This function initializes the firmware.
408 *
409 * The following operations are performed sequentially -
410 * - Allocate adapter structure
411 * - Initialize the adapter structure
412 * - Initialize the private structure
413 * - Add BSS priority tables to the adapter structure
414 * - For each interface, send the init commands to firmware
415 * - Send the first command in command pending queue, if available
416 */
417int mwifiex_init_fw(struct mwifiex_adapter *adapter)
418{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700419 int ret;
420 struct mwifiex_private *priv;
421 u8 i, first_sta = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700422 int is_cmd_pend_q_empty;
423 unsigned long flags;
424
425 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
426
427 /* Allocate memory for member of adapter structure */
428 ret = mwifiex_allocate_adapter(adapter);
429 if (ret)
430 return -1;
431
432 /* Initialize adapter structure */
433 mwifiex_init_adapter(adapter);
434
435 for (i = 0; i < adapter->priv_num; i++) {
436 if (adapter->priv[i]) {
437 priv = adapter->priv[i];
438
439 /* Initialize private structure */
440 ret = mwifiex_init_priv(priv);
441 if (ret)
442 return -1;
443 }
444 }
445 for (i = 0; i < adapter->priv_num; i++) {
446 if (adapter->priv[i]) {
447 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta);
448 if (ret == -1)
449 return -1;
450
451 first_sta = false;
452 }
453 }
454
455 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
456 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
457 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
458 if (!is_cmd_pend_q_empty) {
459 /* Send the first command in queue and return */
460 if (mwifiex_main_process(adapter) != -1)
461 ret = -EINPROGRESS;
462 } else {
463 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
464 }
465
466 return ret;
467}
468
469/*
470 * This function deletes the BSS priority tables.
471 *
472 * The function traverses through all the allocated BSS priority nodes
473 * in every BSS priority table and frees them.
474 */
475static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
476{
477 int i;
478 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700479 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node, **cur;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480 struct list_head *head;
481 spinlock_t *lock;
482 unsigned long flags;
483
484 for (i = 0; i < adapter->priv_num; ++i) {
485 head = &adapter->bss_prio_tbl[i].bss_prio_head;
486 cur = &adapter->bss_prio_tbl[i].bss_prio_cur;
487 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
488 dev_dbg(adapter->dev, "info: delete BSS priority table,"
489 " index = %d, i = %d, head = %p, cur = %p\n",
490 priv->bss_index, i, head, *cur);
491 if (*cur) {
492 spin_lock_irqsave(lock, flags);
493 if (list_empty(head)) {
494 spin_unlock_irqrestore(lock, flags);
495 continue;
496 }
497 bssprio_node = list_first_entry(head,
498 struct mwifiex_bss_prio_node, list);
499 spin_unlock_irqrestore(lock, flags);
500
501 list_for_each_entry_safe(bssprio_node, tmp_node, head,
502 list) {
503 if (bssprio_node->priv == priv) {
504 dev_dbg(adapter->dev, "info: Delete "
505 "node %p, next = %p\n",
506 bssprio_node, tmp_node);
507 spin_lock_irqsave(lock, flags);
508 list_del(&bssprio_node->list);
509 spin_unlock_irqrestore(lock, flags);
510 kfree(bssprio_node);
511 }
512 }
513 *cur = (struct mwifiex_bss_prio_node *)head;
514 }
515 }
516}
517
518/*
519 * This function is used to shutdown the driver.
520 *
521 * The following operations are performed sequentially -
522 * - Check if already shut down
523 * - Make sure the main process has stopped
524 * - Clean up the Tx and Rx queues
525 * - Delete BSS priority tables
526 * - Free the adapter
527 * - Notify completion
528 */
529int
530mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
531{
532 int ret = -EINPROGRESS;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700533 struct mwifiex_private *priv;
534 s32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 unsigned long flags;
536
537 /* mwifiex already shutdown */
538 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
539 return 0;
540
541 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
542 /* wait for mwifiex_process to complete */
543 if (adapter->mwifiex_processing) {
544 dev_warn(adapter->dev, "main process is still running\n");
545 return ret;
546 }
547
548 /* shut down mwifiex */
549 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
550
551 /* Clean up Tx/Rx queues and delete BSS priority table */
552 for (i = 0; i < adapter->priv_num; i++) {
553 if (adapter->priv[i]) {
554 priv = adapter->priv[i];
555
556 mwifiex_clean_txrx(priv);
557 mwifiex_delete_bss_prio_tbl(priv);
558 }
559 }
560
561 spin_lock_irqsave(&adapter->mwifiex_lock, flags);
562
563 /* Free adapter structure */
564 mwifiex_free_adapter(adapter);
565
566 spin_unlock_irqrestore(&adapter->mwifiex_lock, flags);
567
568 /* Notify completion */
569 ret = mwifiex_shutdown_fw_complete(adapter);
570
571 return ret;
572}
573
574/*
575 * This function downloads the firmware to the card.
576 *
577 * The actual download is preceded by two sanity checks -
578 * - Check if firmware is already running
579 * - Check if the interface is the winner to download the firmware
580 *
581 * ...and followed by another -
582 * - Check if the firmware is downloaded successfully
583 *
584 * After download is successfully completed, the host interrupts are enabled.
585 */
586int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
587 struct mwifiex_fw_image *pmfw)
588{
Amitkumar Karward930fae2011-10-11 17:41:21 -0700589 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590 u32 poll_num = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591
Amitkumar Karward930fae2011-10-11 17:41:21 -0700592 adapter->winner = 0;
593
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 /* Check if firmware is already running */
Amitkumar Karward930fae2011-10-11 17:41:21 -0700595 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 if (!ret) {
597 dev_notice(adapter->dev,
598 "WLAN FW already running! Skip FW download\n");
599 goto done;
600 }
601 poll_num = MAX_FIRMWARE_POLL_TRIES;
602
603 /* Check if we are the winner for downloading FW */
Amitkumar Karward930fae2011-10-11 17:41:21 -0700604 if (!adapter->winner) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605 dev_notice(adapter->dev,
606 "Other interface already running!"
607 " Skip FW download\n");
608 poll_num = MAX_MULTI_INTERFACE_POLL_TRIES;
609 goto poll_fw;
610 }
611 if (pmfw) {
612 /* Download firmware with helper */
613 ret = adapter->if_ops.prog_fw(adapter, pmfw);
614 if (ret) {
615 dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret);
616 return ret;
617 }
618 }
619
620poll_fw:
621 /* Check if the firmware is downloaded successfully or not */
Amitkumar Karward930fae2011-10-11 17:41:21 -0700622 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623 if (ret) {
624 dev_err(adapter->dev, "FW failed to be active in time\n");
625 return -1;
626 }
627done:
628 /* re-enable host interrupt for mwifiex after fw dnld is successful */
629 adapter->if_ops.enable_int(adapter);
630 return ret;
631}