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