blob: c1cb004db913cd0064c55758962900f2ed5aa04f [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;
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070038 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070039 unsigned long flags;
40
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
42 if (!bss_prio) {
43 dev_err(adapter->dev, "%s: failed to alloc bss_prio\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070044 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +020045 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070046 }
47
48 bss_prio->priv = priv;
49 INIT_LIST_HEAD(&bss_prio->list);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070050 if (!tbl[priv->bss_priority].bss_prio_cur)
51 tbl[priv->bss_priority].bss_prio_cur = bss_prio;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070053 spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
54 list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head);
55 spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070057 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058}
59
60/*
61 * This function initializes the private structure and sets default
62 * values to the members.
63 *
64 * Additionally, it also initializes all the locks and sets up all the
65 * lists.
66 */
67static int mwifiex_init_priv(struct mwifiex_private *priv)
68{
69 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070070
71 priv->media_connected = false;
72 memset(priv->curr_addr, 0xff, ETH_ALEN);
73
74 priv->pkt_tx_ctrl = 0;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070075 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076 priv->data_rate = 0; /* Initially indicate the rate as auto */
77 priv->is_data_rate_auto = true;
78 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
79 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
80
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -080081 priv->sec_info.wep_enabled = 0;
Marc Yangf986b6d2011-03-28 17:55:42 -070082 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070083 priv->sec_info.encryption_mode = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084 for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
85 memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
86 priv->wep_key_curr_index = 0;
87 priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
88 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
89
90 priv->beacon_period = 100; /* beacon interval */ ;
91 priv->attempted_bss_desc = NULL;
92 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
93 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
94
95 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
96 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
97 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
98 priv->assoc_rsp_size = 0;
99 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
100 priv->atim_window = 0;
101 priv->adhoc_state = ADHOC_IDLE;
102 priv->tx_power_level = 0;
103 priv->max_tx_power_level = 0;
104 priv->min_tx_power_level = 0;
105 priv->tx_rate = 0;
106 priv->rxpd_htinfo = 0;
107 priv->rxpd_rate = 0;
108 priv->rate_bitmap = 0;
109 priv->data_rssi_last = 0;
110 priv->data_rssi_avg = 0;
111 priv->data_nf_avg = 0;
112 priv->data_nf_last = 0;
113 priv->bcn_rssi_last = 0;
114 priv->bcn_rssi_avg = 0;
115 priv->bcn_nf_avg = 0;
116 priv->bcn_nf_last = 0;
117 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
118 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
119 priv->wpa_ie_len = 0;
120 priv->wpa_is_gtk_set = false;
121
122 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
123 priv->assoc_tlv_buf_len = 0;
124 memset(&priv->wps, 0, sizeof(priv->wps));
125 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
126 priv->gen_ie_buf_len = 0;
127 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
128
129 priv->wmm_required = true;
130 priv->wmm_enabled = false;
131 priv->wmm_qosinfo = 0;
132 priv->curr_bcn_buf = NULL;
133 priv->curr_bcn_size = 0;
Avinash Patil13d7ba72012-04-09 20:06:56 -0700134 priv->wps_ie = NULL;
135 priv->wps_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700136
137 priv->scan_block = false;
138
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700139 return mwifiex_add_bss_prio_tbl(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700140}
141
142/*
143 * This function allocates buffers for members of the adapter
144 * structure.
145 *
146 * The memory allocated includes scan table, command buffers, and
147 * sleep confirm command buffer. In addition, the queues are
148 * also initialized.
149 */
150static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
151{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700152 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153
154 /* Allocate command buffer */
155 ret = mwifiex_alloc_cmd_buffer(adapter);
156 if (ret) {
157 dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700158 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700159 return -1;
160 }
161
162 adapter->sleep_cfm =
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700163 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700164 + INTF_HEADER_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700165
166 if (!adapter->sleep_cfm) {
167 dev_err(adapter->dev, "%s: failed to alloc sleep cfm"
168 " cmd buffer\n", __func__);
169 return -1;
170 }
171 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
172
173 return 0;
174}
175
176/*
177 * This function initializes the adapter structure and sets default
178 * values to the members of adapter.
179 *
180 * This also initializes the WMM related parameters in the driver private
181 * structures.
182 */
183static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
184{
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700185 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700186
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700187 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188
189 adapter->cmd_sent = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700190
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700191 if (adapter->iface_type == MWIFIEX_SDIO)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700192 adapter->data_sent = true;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700193 else
194 adapter->data_sent = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700195
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700196 adapter->cmd_resp_received = false;
197 adapter->event_received = false;
198 adapter->data_received = false;
199
200 adapter->surprise_removed = false;
201
202 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
203
204 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
205 adapter->ps_state = PS_STATE_AWAKE;
206 adapter->need_to_wakeup = false;
207
208 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
209 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
210 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
211 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
212
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700213 adapter->scan_probes = 1;
214
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215 adapter->multiple_dtim = 1;
216
217 adapter->local_listen_interval = 0; /* default value in firmware
218 will be used */
219
220 adapter->is_deep_sleep = false;
221
222 adapter->delay_null_pkt = false;
223 adapter->delay_to_ps = 1000;
224 adapter->enhanced_ps_mode = PS_MODE_AUTO;
225
226 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
227 default */
228 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
229 default */
230 adapter->pm_wakeup_card_req = false;
231
232 adapter->pm_wakeup_fw_try = false;
233
234 adapter->max_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
235 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
236 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
237
238 adapter->is_hs_configured = false;
239 adapter->hs_cfg.conditions = cpu_to_le32(HOST_SLEEP_CFG_COND_DEF);
240 adapter->hs_cfg.gpio = HOST_SLEEP_CFG_GPIO_DEF;
241 adapter->hs_cfg.gap = HOST_SLEEP_CFG_GAP_DEF;
242 adapter->hs_activated = false;
243
244 memset(adapter->event_body, 0, sizeof(adapter->event_body));
245 adapter->hw_dot_11n_dev_cap = 0;
246 adapter->hw_dev_mcs_support = 0;
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800247 adapter->sec_chan_offset = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700248 adapter->adhoc_11n_enabled = false;
249
250 mwifiex_wmm_init(adapter);
251
252 if (adapter->sleep_cfm) {
Yogesh Ashok Powar8ed13032011-11-07 21:41:10 -0800253 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
254 adapter->sleep_cfm->data;
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700255 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
256 sleep_cfm_buf->command =
257 cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
258 sleep_cfm_buf->size =
259 cpu_to_le16(adapter->sleep_cfm->len);
260 sleep_cfm_buf->result = 0;
261 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
262 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263 }
264 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
265 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
266 adapter->tx_lock_flag = false;
267 adapter->null_pkt_interval = 0;
268 adapter->fw_bands = 0;
269 adapter->config_bands = 0;
270 adapter->adhoc_start_band = 0;
271 adapter->scan_channels = NULL;
272 adapter->fw_release_number = 0;
273 adapter->fw_cap_info = 0;
274 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
275 adapter->event_cause = 0;
276 adapter->region_code = 0;
277 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
278 adapter->adhoc_awake_period = 0;
279 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
280 adapter->arp_filter_size = 0;
Amitkumar Karwar3dc5e172012-02-01 20:41:45 -0800281 adapter->channel_type = NL80211_CHAN_HT20;
Avinash Patilede98bf2012-05-08 18:30:28 -0700282 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283}
284
285/*
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800286 * This function sets trans_start per tx_queue
287 */
288void mwifiex_set_trans_start(struct net_device *dev)
289{
290 int i;
291
292 for (i = 0; i < dev->num_tx_queues; i++)
293 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
294
295 dev->trans_start = jiffies;
296}
297
298/*
299 * This function wakes up all queues in net_device
300 */
301void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
302 struct mwifiex_adapter *adapter)
303{
304 unsigned long dev_queue_flags;
305
306 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
307 netif_tx_wake_all_queues(netdev);
308 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
309}
310
311/*
312 * This function stops all queues in net_device
313 */
314void mwifiex_stop_net_dev_queue(struct net_device *netdev,
315 struct mwifiex_adapter *adapter)
316{
317 unsigned long dev_queue_flags;
318
319 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
320 netif_tx_stop_all_queues(netdev);
321 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
322}
323
324/*
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700325 * This function releases the lock variables and frees the locks and
326 * associated locks.
327 */
328static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
329{
330 struct mwifiex_private *priv;
331 s32 i, j;
332
333 /* Free lists */
334 list_del(&adapter->cmd_free_q);
335 list_del(&adapter->cmd_pending_q);
336 list_del(&adapter->scan_pending_q);
337
338 for (i = 0; i < adapter->priv_num; i++)
339 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
340
341 for (i = 0; i < adapter->priv_num; i++) {
342 if (adapter->priv[i]) {
343 priv = adapter->priv[i];
344 for (j = 0; j < MAX_NUM_TID; ++j)
345 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
346 list_del(&priv->tx_ba_stream_tbl_ptr);
347 list_del(&priv->rx_reorder_tbl_ptr);
348 }
349 }
350}
351
352/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353 * This function frees the adapter structure.
354 *
355 * The freeing operation is done recursively, by canceling all
356 * pending commands, freeing the member buffers previously
357 * allocated (command buffers, scan table buffer, sleep confirm
358 * command buffer), stopping the timers and calling the cleanup
359 * routines for every interface, before the actual adapter
360 * structure is freed.
361 */
362static void
363mwifiex_free_adapter(struct mwifiex_adapter *adapter)
364{
365 if (!adapter) {
366 pr_err("%s: adapter is NULL\n", __func__);
367 return;
368 }
369
370 mwifiex_cancel_all_pending_cmd(adapter);
371
372 /* Free lock variables */
373 mwifiex_free_lock_list(adapter);
374
375 /* Free command buffer */
376 dev_dbg(adapter->dev, "info: free cmd buffer\n");
377 mwifiex_free_cmd_buffer(adapter);
378
379 del_timer(&adapter->cmd_timer);
380
381 dev_dbg(adapter->dev, "info: free scan table\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700383 if (adapter->if_ops.cleanup_if)
384 adapter->if_ops.cleanup_if(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700385
Amitkumar Karwar2da8cbf2012-02-03 20:34:02 -0800386 if (adapter->sleep_cfm)
387 dev_kfree_skb_any(adapter->sleep_cfm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388}
389
390/*
391 * This function intializes the lock variables and
392 * the list heads.
393 */
394int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
395{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700396 struct mwifiex_private *priv;
397 s32 i, j;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398
399 spin_lock_init(&adapter->mwifiex_lock);
400 spin_lock_init(&adapter->int_lock);
401 spin_lock_init(&adapter->main_proc_lock);
402 spin_lock_init(&adapter->mwifiex_cmd_lock);
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800403 spin_lock_init(&adapter->queue_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 for (i = 0; i < adapter->priv_num; i++) {
405 if (adapter->priv[i]) {
406 priv = adapter->priv[i];
407 spin_lock_init(&priv->rx_pkt_lock);
408 spin_lock_init(&priv->wmm.ra_list_spinlock);
409 spin_lock_init(&priv->curr_bcn_buf_lock);
410 }
411 }
412
413 /* Initialize cmd_free_q */
414 INIT_LIST_HEAD(&adapter->cmd_free_q);
415 /* Initialize cmd_pending_q */
416 INIT_LIST_HEAD(&adapter->cmd_pending_q);
417 /* Initialize scan_pending_q */
418 INIT_LIST_HEAD(&adapter->scan_pending_q);
419
420 spin_lock_init(&adapter->cmd_free_q_lock);
421 spin_lock_init(&adapter->cmd_pending_q_lock);
422 spin_lock_init(&adapter->scan_pending_q_lock);
423
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700424 skb_queue_head_init(&adapter->usb_rx_data_q);
425
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700426 for (i = 0; i < adapter->priv_num; ++i) {
427 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
428 adapter->bss_prio_tbl[i].bss_prio_cur = NULL;
429 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
430 }
431
432 for (i = 0; i < adapter->priv_num; i++) {
433 if (!adapter->priv[i])
434 continue;
435 priv = adapter->priv[i];
436 for (j = 0; j < MAX_NUM_TID; ++j) {
437 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
438 spin_lock_init(&priv->wmm.tid_tbl_ptr[j].tid_tbl_lock);
439 }
440 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
441 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
442
443 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
444 spin_lock_init(&priv->rx_reorder_tbl_lock);
445 }
446
447 return 0;
448}
449
450/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700451 * This function initializes the firmware.
452 *
453 * The following operations are performed sequentially -
454 * - Allocate adapter structure
455 * - Initialize the adapter structure
456 * - Initialize the private structure
457 * - Add BSS priority tables to the adapter structure
458 * - For each interface, send the init commands to firmware
459 * - Send the first command in command pending queue, if available
460 */
461int mwifiex_init_fw(struct mwifiex_adapter *adapter)
462{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700463 int ret;
464 struct mwifiex_private *priv;
465 u8 i, first_sta = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466 int is_cmd_pend_q_empty;
467 unsigned long flags;
468
469 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
470
471 /* Allocate memory for member of adapter structure */
472 ret = mwifiex_allocate_adapter(adapter);
473 if (ret)
474 return -1;
475
476 /* Initialize adapter structure */
477 mwifiex_init_adapter(adapter);
478
479 for (i = 0; i < adapter->priv_num; i++) {
480 if (adapter->priv[i]) {
481 priv = adapter->priv[i];
482
483 /* Initialize private structure */
484 ret = mwifiex_init_priv(priv);
485 if (ret)
486 return -1;
487 }
488 }
489 for (i = 0; i < adapter->priv_num; i++) {
490 if (adapter->priv[i]) {
491 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta);
492 if (ret == -1)
493 return -1;
494
495 first_sta = false;
496 }
497 }
498
499 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
500 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
501 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
502 if (!is_cmd_pend_q_empty) {
503 /* Send the first command in queue and return */
504 if (mwifiex_main_process(adapter) != -1)
505 ret = -EINPROGRESS;
506 } else {
507 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
508 }
509
510 return ret;
511}
512
513/*
514 * This function deletes the BSS priority tables.
515 *
516 * The function traverses through all the allocated BSS priority nodes
517 * in every BSS priority table and frees them.
518 */
519static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
520{
521 int i;
522 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700523 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node, **cur;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700524 struct list_head *head;
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700525 spinlock_t *lock; /* bss priority lock */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700526 unsigned long flags;
527
528 for (i = 0; i < adapter->priv_num; ++i) {
529 head = &adapter->bss_prio_tbl[i].bss_prio_head;
530 cur = &adapter->bss_prio_tbl[i].bss_prio_cur;
531 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
532 dev_dbg(adapter->dev, "info: delete BSS priority table,"
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800533 " bss_type = %d, bss_num = %d, i = %d,"
534 " head = %p, cur = %p\n",
535 priv->bss_type, priv->bss_num, i, head, *cur);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 if (*cur) {
537 spin_lock_irqsave(lock, flags);
538 if (list_empty(head)) {
539 spin_unlock_irqrestore(lock, flags);
540 continue;
541 }
542 bssprio_node = list_first_entry(head,
543 struct mwifiex_bss_prio_node, list);
544 spin_unlock_irqrestore(lock, flags);
545
546 list_for_each_entry_safe(bssprio_node, tmp_node, head,
547 list) {
548 if (bssprio_node->priv == priv) {
549 dev_dbg(adapter->dev, "info: Delete "
550 "node %p, next = %p\n",
551 bssprio_node, tmp_node);
552 spin_lock_irqsave(lock, flags);
553 list_del(&bssprio_node->list);
554 spin_unlock_irqrestore(lock, flags);
555 kfree(bssprio_node);
556 }
557 }
558 *cur = (struct mwifiex_bss_prio_node *)head;
559 }
560 }
561}
562
563/*
564 * This function is used to shutdown the driver.
565 *
566 * The following operations are performed sequentially -
567 * - Check if already shut down
568 * - Make sure the main process has stopped
569 * - Clean up the Tx and Rx queues
570 * - Delete BSS priority tables
571 * - Free the adapter
572 * - Notify completion
573 */
574int
575mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
576{
577 int ret = -EINPROGRESS;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700578 struct mwifiex_private *priv;
579 s32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700580 unsigned long flags;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700581 struct sk_buff *skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582
583 /* mwifiex already shutdown */
584 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
585 return 0;
586
587 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
588 /* wait for mwifiex_process to complete */
589 if (adapter->mwifiex_processing) {
590 dev_warn(adapter->dev, "main process is still running\n");
591 return ret;
592 }
593
594 /* shut down mwifiex */
595 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
596
597 /* Clean up Tx/Rx queues and delete BSS priority table */
598 for (i = 0; i < adapter->priv_num; i++) {
599 if (adapter->priv[i]) {
600 priv = adapter->priv[i];
601
602 mwifiex_clean_txrx(priv);
603 mwifiex_delete_bss_prio_tbl(priv);
604 }
605 }
606
607 spin_lock_irqsave(&adapter->mwifiex_lock, flags);
608
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700609 if (adapter->if_ops.data_complete) {
610 while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) {
611 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
612
613 priv = adapter->priv[rx_info->bss_num];
614 if (priv)
615 priv->stats.rx_dropped++;
616
617 adapter->if_ops.data_complete(adapter, skb);
618 }
619 }
620
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621 /* Free adapter structure */
622 mwifiex_free_adapter(adapter);
623
624 spin_unlock_irqrestore(&adapter->mwifiex_lock, flags);
625
626 /* Notify completion */
627 ret = mwifiex_shutdown_fw_complete(adapter);
628
629 return ret;
630}
631
632/*
633 * This function downloads the firmware to the card.
634 *
635 * The actual download is preceded by two sanity checks -
636 * - Check if firmware is already running
637 * - Check if the interface is the winner to download the firmware
638 *
639 * ...and followed by another -
640 * - Check if the firmware is downloaded successfully
641 *
642 * After download is successfully completed, the host interrupts are enabled.
643 */
644int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
645 struct mwifiex_fw_image *pmfw)
646{
Amitkumar Karward930fae2011-10-11 17:41:21 -0700647 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700648 u32 poll_num = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700650 if (adapter->if_ops.check_fw_status) {
651 adapter->winner = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700652
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700653 /* check if firmware is already running */
654 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
655 if (!ret) {
656 dev_notice(adapter->dev,
657 "WLAN FW already running! Skip FW dnld\n");
658 goto done;
659 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700660
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700661 poll_num = MAX_FIRMWARE_POLL_TRIES;
662
663 /* check if we are the winner for downloading FW */
664 if (!adapter->winner) {
665 dev_notice(adapter->dev,
666 "FW already running! Skip FW dnld\n");
667 poll_num = MAX_MULTI_INTERFACE_POLL_TRIES;
668 goto poll_fw;
669 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700670 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700671
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700672 if (pmfw) {
673 /* Download firmware with helper */
674 ret = adapter->if_ops.prog_fw(adapter, pmfw);
675 if (ret) {
676 dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret);
677 return ret;
678 }
679 }
680
681poll_fw:
682 /* Check if the firmware is downloaded successfully or not */
Amitkumar Karward930fae2011-10-11 17:41:21 -0700683 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700684 if (ret) {
685 dev_err(adapter->dev, "FW failed to be active in time\n");
686 return -1;
687 }
688done:
689 /* re-enable host interrupt for mwifiex after fw dnld is successful */
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700690 if (adapter->if_ops.enable_int)
691 adapter->if_ops.enable_int(adapter);
692
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700693 return ret;
694}