xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/mvl88w8977/mlan/mlan_init.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /** @file mlan_init.c
2  *
3  *  @brief This file contains the initialization for FW
4  *  and HW.
5  *
6  *  Copyright (C) 2008-2017, Marvell International Ltd.
7  *
8  *  This software file (the "File") is distributed by Marvell International
9  *  Ltd. under the terms of the GNU General Public License Version 2, June 1991
10  *  (the "License").  You may use, redistribute and/or modify this File in
11  *  accordance with the terms and conditions of the License, a copy of which
12  *  is available by writing to the Free Software Foundation, Inc.,
13  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
14  *  worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
15  *
16  *  THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
19  *  this warranty disclaimer.
20  */
21 
22 /********************************************************
23 Change log:
24     10/13/2008: initial version
25 ********************************************************/
26 
27 #include "mlan.h"
28 #ifdef STA_SUPPORT
29 #include "mlan_join.h"
30 #endif
31 #include "mlan_util.h"
32 #include "mlan_fw.h"
33 #include "mlan_main.h"
34 #include "mlan_init.h"
35 #include "mlan_wmm.h"
36 #include "mlan_11n.h"
37 #include "mlan_11h.h"
38 #include "mlan_meas.h"
39 #include "mlan_sdio.h"
40 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
41 #include "hostsa_init.h"
42 #endif
43 
44 /********************************************************
45 			Global Variables
46 ********************************************************/
47 extern mlan_operations *mlan_ops[];
48 /*******************************************************
49 			Local Functions
50 ********************************************************/
51 
52 /**
53  *  @brief This function adds a BSS priority table
54  *
55  *  @param priv     A pointer to mlan_private structure
56  *
57  *  @return         MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
58  */
59 static mlan_status
wlan_add_bsspriotbl(pmlan_private priv)60 wlan_add_bsspriotbl(pmlan_private priv)
61 {
62 	pmlan_adapter pmadapter = priv->adapter;
63 	mlan_bssprio_node *pbssprio = MNULL;
64 	mlan_status status = MLAN_STATUS_SUCCESS;
65 
66 	ENTER();
67 
68 	status = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
69 						  sizeof(mlan_bssprio_node),
70 						  MLAN_MEM_DEF,
71 						  (t_u8 **)&pbssprio);
72 	if (status) {
73 		PRINTM(MERROR, "Failed to allocate bsspriotbl\n");
74 		LEAVE();
75 		return status;
76 	}
77 
78 	pbssprio->priv = priv;
79 
80 	util_init_list((pmlan_linked_list)pbssprio);
81 
82 	if (!pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur)
83 		pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur
84 			= pbssprio;
85 
86 	util_enqueue_list_tail(pmadapter->pmoal_handle,
87 			       &pmadapter->bssprio_tbl[priv->bss_priority].
88 			       bssprio_head, (pmlan_linked_list)pbssprio,
89 			       pmadapter->callbacks.moal_spin_lock,
90 			       pmadapter->callbacks.moal_spin_unlock);
91 
92 	LEAVE();
93 	return status;
94 }
95 
96 /**
97  *  @brief This function deletes the BSS priority table
98  *
99  *  @param priv     A pointer to mlan_private structure
100  *
101  *  @return         N/A
102  */
103 static t_void
wlan_delete_bsspriotbl(pmlan_private priv)104 wlan_delete_bsspriotbl(pmlan_private priv)
105 {
106 	int i;
107 	pmlan_adapter pmadapter = priv->adapter;
108 	mlan_bssprio_node *pbssprio_node = MNULL, *ptmp_node = MNULL, **ppcur =
109 		MNULL;
110 	pmlan_list_head phead;
111 
112 	ENTER();
113 
114 	for (i = 0; i < pmadapter->priv_num; ++i) {
115 		phead = &pmadapter->bssprio_tbl[i].bssprio_head;
116 		ppcur = &pmadapter->bssprio_tbl[i].bssprio_cur;
117 		PRINTM(MINFO,
118 		       "Delete BSS priority table, index = %d, i = %d, phead = %p, pcur = %p\n",
119 		       priv->bss_index, i, phead, *ppcur);
120 		if (*ppcur) {
121 			pbssprio_node =
122 				(mlan_bssprio_node *)util_peek_list(pmadapter->
123 								    pmoal_handle,
124 								    phead,
125 								    pmadapter->
126 								    callbacks.
127 								    moal_spin_lock,
128 								    pmadapter->
129 								    callbacks.
130 								    moal_spin_unlock);
131 			while (pbssprio_node &&
132 			       ((pmlan_list_head)pbssprio_node != phead)) {
133 				ptmp_node = pbssprio_node->pnext;
134 				if (pbssprio_node->priv == priv) {
135 					PRINTM(MINFO,
136 					       "Delete node, pnode = %p, pnext = %p\n",
137 					       pbssprio_node, ptmp_node);
138 					util_unlink_list(pmadapter->
139 							 pmoal_handle, phead,
140 							 (pmlan_linked_list)
141 							 pbssprio_node,
142 							 pmadapter->callbacks.
143 							 moal_spin_lock,
144 							 pmadapter->callbacks.
145 							 moal_spin_unlock);
146 					pmadapter->callbacks.
147 						moal_mfree(pmadapter->
148 							   pmoal_handle,
149 							   (t_u8 *)
150 							   pbssprio_node);
151 				}
152 				pbssprio_node = ptmp_node;
153 			}
154 			*ppcur = (mlan_bssprio_node *)phead;
155 		}
156 	}
157 
158 	LEAVE();
159 }
160 
161 /********************************************************
162 			Global Functions
163 ********************************************************/
164 
165 /**
166  *  @brief This function allocates buffer for the members of adapter
167  *          structure like command buffer and BSSID list.
168  *
169  *  @param pmadapter    A pointer to mlan_adapter structure
170  *
171  *  @return             MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
172  */
173 mlan_status
wlan_allocate_adapter(pmlan_adapter pmadapter)174 wlan_allocate_adapter(pmlan_adapter pmadapter)
175 {
176 	mlan_status ret = MLAN_STATUS_SUCCESS;
177 #ifdef STA_SUPPORT
178 	t_u32 beacon_buffer_size;
179 	t_u32 buf_size;
180 	BSSDescriptor_t *ptemp_scan_table = MNULL;
181 	t_u8 chan_2g[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
182 	t_u8 chan_5g[] = {
183 		12, 16, 34, 38, 42, 46, 36, 40, 44,
184 		48, 52, 56, 60, 64, 100, 104, 108,
185 		112, 116, 120, 124, 128, 132, 136,
186 		140, 144, 149, 153, 157, 161, 165
187 	};
188 #endif
189 	t_u32 max_mp_regs = MAX_MP_REGS;
190 #if defined(SDIO_MULTI_PORT_TX_AGGR) || defined(SDIO_MULTI_PORT_RX_AGGR)
191 	t_u32 mp_tx_aggr_buf_size = SDIO_MP_TX_AGGR_DEF_BUF_SIZE;
192 	t_u32 mp_rx_aggr_buf_size = SDIO_MP_RX_AGGR_DEF_BUF_SIZE;
193 #endif
194 
195 	ENTER();
196 
197 #ifdef STA_SUPPORT
198 	/* Allocate buffer to store the BSSID list */
199 	buf_size = sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST;
200 	if (pmadapter->callbacks.moal_vmalloc &&
201 	    pmadapter->callbacks.moal_vfree)
202 		ret = pmadapter->callbacks.moal_vmalloc(pmadapter->pmoal_handle,
203 							buf_size,
204 							(t_u8 **)
205 							&ptemp_scan_table);
206 	else
207 		ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
208 						       buf_size, MLAN_MEM_DEF,
209 						       (t_u8 **)
210 						       &ptemp_scan_table);
211 	if (ret != MLAN_STATUS_SUCCESS || !ptemp_scan_table) {
212 		PRINTM(MERROR, "Failed to allocate scan table\n");
213 		LEAVE();
214 		return MLAN_STATUS_FAILURE;
215 	}
216 	pmadapter->pscan_table = ptemp_scan_table;
217 
218 	if (pmadapter->fixed_beacon_buffer)
219 		beacon_buffer_size = MAX_SCAN_BEACON_BUFFER;
220 	else
221 		beacon_buffer_size = DEFAULT_SCAN_BEACON_BUFFER;
222 	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
223 					       beacon_buffer_size, MLAN_MEM_DEF,
224 					       (t_u8 **)&pmadapter->bcn_buf);
225 	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->bcn_buf) {
226 		PRINTM(MERROR, "Failed to allocate bcn buf\n");
227 		LEAVE();
228 		return MLAN_STATUS_FAILURE;
229 	}
230 	pmadapter->bcn_buf_size = beacon_buffer_size;
231 
232 	pmadapter->num_in_chan_stats = sizeof(chan_2g);
233 	pmadapter->num_in_chan_stats += sizeof(chan_5g);
234 	buf_size = sizeof(ChanStatistics_t) * pmadapter->num_in_chan_stats;
235 	if (pmadapter->callbacks.moal_vmalloc &&
236 	    pmadapter->callbacks.moal_vfree)
237 		ret = pmadapter->callbacks.moal_vmalloc(pmadapter->pmoal_handle,
238 							buf_size,
239 							(t_u8 **)&pmadapter->
240 							pchan_stats);
241 	else
242 		ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
243 						       buf_size, MLAN_MEM_DEF,
244 						       (t_u8 **)&pmadapter->
245 						       pchan_stats);
246 	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->pchan_stats) {
247 		PRINTM(MERROR, "Failed to allocate channel statistics\n");
248 		LEAVE();
249 		return MLAN_STATUS_FAILURE;
250 	}
251 #endif
252 
253 	/* Allocate command buffer */
254 	ret = wlan_alloc_cmd_buffer(pmadapter);
255 	if (ret != MLAN_STATUS_SUCCESS) {
256 		PRINTM(MERROR, "Failed to allocate command buffer\n");
257 		LEAVE();
258 		return MLAN_STATUS_FAILURE;
259 	}
260 
261 	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
262 					       max_mp_regs + DMA_ALIGNMENT,
263 					       MLAN_MEM_DEF | MLAN_MEM_DMA,
264 					       (t_u8 **)&pmadapter->
265 					       mp_regs_buf);
266 	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->mp_regs_buf) {
267 		PRINTM(MERROR, "Failed to allocate mp_regs_buf\n");
268 		LEAVE();
269 		return MLAN_STATUS_FAILURE;
270 	}
271 	pmadapter->mp_regs =
272 		(t_u8 *)ALIGN_ADDR(pmadapter->mp_regs_buf, DMA_ALIGNMENT);
273 
274 #if defined(SDIO_MULTI_PORT_RX_AGGR)
275 	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
276 					       SDIO_CMD53_MAX_SIZE +
277 					       DMA_ALIGNMENT,
278 					       MLAN_MEM_DEF | MLAN_MEM_DMA,
279 					       (t_u8 **)&pmadapter->rx_buffer);
280 	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->rx_buffer) {
281 		PRINTM(MERROR, "Failed to allocate receive buffer\n");
282 		LEAVE();
283 		return MLAN_STATUS_FAILURE;
284 	}
285 	pmadapter->rx_buf =
286 		(t_u8 *)ALIGN_ADDR(pmadapter->rx_buffer, DMA_ALIGNMENT);
287 #endif
288 
289 #if defined(SDIO_MULTI_PORT_TX_AGGR) || defined(SDIO_MULTI_PORT_RX_AGGR)
290 	pmadapter->max_sp_tx_size = MAX_SUPPORT_AMSDU_SIZE;
291 	pmadapter->max_sp_rx_size = MAX_SUPPORT_AMSDU_SIZE;
292 	ret = wlan_alloc_sdio_mpa_buffers(pmadapter, mp_tx_aggr_buf_size,
293 					  mp_rx_aggr_buf_size);
294 	if (ret != MLAN_STATUS_SUCCESS) {
295 		PRINTM(MERROR, "Failed to allocate sdio mp-a buffers\n");
296 		LEAVE();
297 		return MLAN_STATUS_FAILURE;
298 	}
299 #ifdef DEBUG_LEVEL1
300 	if (mlan_drvdbg & MMPA_D) {
301 		pmadapter->mpa_buf_size =
302 			SDIO_MP_DBG_NUM * SDIO_MP_AGGR_DEF_PKT_LIMIT *
303 			MLAN_SDIO_BLOCK_SIZE;
304 		if (pmadapter->callbacks.moal_vmalloc &&
305 		    pmadapter->callbacks.moal_vfree)
306 			ret = pmadapter->callbacks.moal_vmalloc(pmadapter->
307 								pmoal_handle,
308 								pmadapter->
309 								mpa_buf_size,
310 								(t_u8 **)
311 								&pmadapter->
312 								mpa_buf);
313 		else
314 			ret = pmadapter->callbacks.moal_malloc(pmadapter->
315 							       pmoal_handle,
316 							       pmadapter->
317 							       mpa_buf_size,
318 							       MLAN_MEM_DEF,
319 							       (t_u8 **)
320 							       &pmadapter->
321 							       mpa_buf);
322 		if (ret != MLAN_STATUS_SUCCESS || !pmadapter->mpa_buf) {
323 			PRINTM(MERROR, "Failed to allocate mpa buf\n");
324 			LEAVE();
325 			return MLAN_STATUS_FAILURE;
326 		}
327 	}
328 #endif
329 #endif
330 
331 	pmadapter->psleep_cfm =
332 		wlan_alloc_mlan_buffer(pmadapter,
333 				       sizeof(opt_sleep_confirm_buffer), 0,
334 				       MOAL_MALLOC_BUFFER);
335 
336 	LEAVE();
337 	return MLAN_STATUS_SUCCESS;
338 }
339 
340 /**
341  *  @brief This function initializes the private structure
342  *          and sets default values to the members of mlan_private.
343  *
344  *  @param priv     A pointer to mlan_private structure
345  *
346  *  @return         MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
347  */
348 mlan_status
wlan_init_priv(pmlan_private priv)349 wlan_init_priv(pmlan_private priv)
350 {
351 	t_u32 i;
352 	pmlan_adapter pmadapter = priv->adapter;
353 	mlan_status ret = MLAN_STATUS_SUCCESS;
354 
355 	ENTER();
356 
357 	priv->media_connected = MFALSE;
358 	memset(pmadapter, priv->curr_addr, 0xff, MLAN_MAC_ADDR_LENGTH);
359 
360 #ifdef STA_SUPPORT
361 	priv->pkt_tx_ctrl = 0;
362 	priv->bss_mode = MLAN_BSS_MODE_INFRA;
363 	priv->data_rate = 0;	/* Initially indicate the rate as auto */
364 	priv->is_data_rate_auto = MTRUE;
365 	priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
366 	priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
367 
368 	priv->sec_info.wep_status = Wlan802_11WEPDisabled;
369 	priv->sec_info.authentication_mode = MLAN_AUTH_MODE_AUTO;
370 	priv->sec_info.encryption_mode = MLAN_ENCRYPTION_MODE_NONE;
371 	for (i = 0; i < MRVL_NUM_WEP_KEY; i++)
372 		memset(pmadapter, &priv->wep_key[i], 0, sizeof(mrvl_wep_key_t));
373 	priv->wep_key_curr_index = 0;
374 	priv->ewpa_query = MFALSE;
375 	priv->adhoc_aes_enabled = MFALSE;
376 	priv->curr_pkt_filter =
377 		HostCmd_ACT_MAC_RTS_CTS_ENABLE |
378 		HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
379 		HostCmd_ACT_MAC_ETHERNETII_ENABLE;
380 
381 	priv->beacon_period = MLAN_BEACON_INTERVAL;
382 	priv->pattempted_bss_desc = MNULL;
383 	memset(pmadapter, &priv->gtk_rekey, 0,
384 	       sizeof(mlan_ds_misc_gtk_rekey_data));
385 	memset(pmadapter, &priv->curr_bss_params, 0,
386 	       sizeof(priv->curr_bss_params));
387 	priv->listen_interval = MLAN_DEFAULT_LISTEN_INTERVAL;
388 
389 	memset(pmadapter, &priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
390 	priv->assoc_rsp_size = 0;
391 
392 	wlan_11d_priv_init(priv);
393 	wlan_11h_priv_init(priv);
394 	priv->enable_11k = MFALSE;
395 
396 #ifdef UAP_SUPPORT
397 	priv->uap_bss_started = MFALSE;
398 	priv->uap_host_based = MFALSE;
399 	memset(pmadapter, &priv->uap_state_chan_cb, 0,
400 	       sizeof(priv->uap_state_chan_cb));
401 #endif
402 #if defined(UAP_SUPPORT)
403 	priv->num_drop_pkts = 0;
404 #endif
405 #if defined(STA_SUPPORT)
406 	priv->adhoc_state_prev = ADHOC_IDLE;
407 	memset(pmadapter, &priv->adhoc_last_start_ssid, 0,
408 	       sizeof(priv->adhoc_last_start_ssid));
409 #endif
410 	priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
411 	priv->atim_window = 0;
412 	priv->adhoc_state = ADHOC_IDLE;
413 	priv->tx_power_level = 0;
414 	priv->max_tx_power_level = 0;
415 	priv->min_tx_power_level = 0;
416 	priv->tx_rate = 0;
417 	priv->rxpd_rate_info = 0;
418 	priv->rx_pkt_info = MFALSE;
419 	priv->rxpd_rate = 0;
420 	priv->rate_bitmap = 0;
421 	priv->data_rssi_last = 0;
422 	priv->data_rssi_avg = 0;
423 	priv->data_nf_avg = 0;
424 	priv->data_nf_last = 0;
425 	priv->bcn_rssi_last = 0;
426 	priv->bcn_rssi_avg = 0;
427 	priv->bcn_nf_avg = 0;
428 	priv->bcn_nf_last = 0;
429 
430 	priv->sec_info.ewpa_enabled = MFALSE;
431 	priv->sec_info.wpa_enabled = MFALSE;
432 	priv->sec_info.wpa2_enabled = MFALSE;
433 	memset(pmadapter, &priv->wpa_ie, 0, sizeof(priv->wpa_ie));
434 	memset(pmadapter, &priv->aes_key, 0, sizeof(priv->aes_key));
435 	priv->wpa_ie_len = 0;
436 	priv->wpa_is_gtk_set = MFALSE;
437 #if defined(STA_SUPPORT)
438 	priv->pmfcfg.mfpc = 0;
439 	priv->pmfcfg.mfpr = 0;
440 #endif
441 	priv->sec_info.wapi_enabled = MFALSE;
442 	priv->wapi_ie_len = 0;
443 	priv->sec_info.wapi_key_on = MFALSE;
444 
445 	memset(pmadapter, &priv->wps, 0, sizeof(priv->wps));
446 	memset(pmadapter, &priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
447 	priv->gen_ie_buf_len = 0;
448 #endif /* STA_SUPPORT */
449 	priv->wmm_required = MTRUE;
450 	priv->wmm_enabled = MFALSE;
451 	priv->wmm_qosinfo = 0;
452 	priv->saved_wmm_qosinfo = 0;
453 	priv->host_tdls_cs_support = MTRUE;
454 	priv->host_tdls_uapsd_support = MTRUE;
455 	priv->tdls_cs_channel = 0;
456 	priv->supp_regulatory_class_len = 0;
457 	priv->chan_supp_len = 0;
458 	priv->tdls_idle_time = TDLS_IDLE_TIMEOUT;
459 	priv->txaggrctrl = MTRUE;
460 #ifdef STA_SUPPORT
461 	priv->pcurr_bcn_buf = MNULL;
462 	priv->curr_bcn_size = 0;
463 	memset(pmadapter, &priv->ext_cap, 0, sizeof(priv->ext_cap));
464 
465 	SET_EXTCAP_TDLS(priv->ext_cap);
466 	SET_EXTCAP_QOS_MAP(priv->ext_cap);
467 	/* Save default Extended Capability */
468 	memcpy(priv->adapter, &priv->def_ext_cap, &priv->ext_cap,
469 	       sizeof(priv->ext_cap));
470 #endif /* STA_SUPPORT */
471 
472 	for (i = 0; i < MAX_NUM_TID; i++)
473 		priv->addba_reject[i] = ADDBA_RSP_STATUS_ACCEPT;
474 	priv->addba_reject[6] = ADDBA_RSP_STATUS_REJECT;
475 	priv->addba_reject[7] = ADDBA_RSP_STATUS_REJECT;
476 	memcpy(priv->adapter, priv->ibss_addba_reject, priv->addba_reject,
477 	       sizeof(priv->addba_reject));
478 	priv->max_amsdu = 0;
479 #ifdef STA_SUPPORT
480 	if (priv->bss_type == MLAN_BSS_TYPE_STA) {
481 		priv->add_ba_param.tx_win_size = MLAN_STA_AMPDU_DEF_TXWINSIZE;
482 		priv->add_ba_param.rx_win_size = MLAN_STA_AMPDU_DEF_RXWINSIZE;
483 	}
484 #endif
485 #ifdef WIFI_DIRECT_SUPPORT
486 	if (priv->bss_type == MLAN_BSS_TYPE_WIFIDIRECT) {
487 		priv->add_ba_param.tx_win_size = MLAN_WFD_AMPDU_DEF_TXRXWINSIZE;
488 		priv->add_ba_param.rx_win_size = MLAN_WFD_AMPDU_DEF_TXRXWINSIZE;
489 	}
490 #endif
491 #ifdef UAP_SUPPORT
492 	if (priv->bss_type == MLAN_BSS_TYPE_UAP) {
493 		priv->add_ba_param.tx_win_size = MLAN_UAP_AMPDU_DEF_TXWINSIZE;
494 		priv->add_ba_param.rx_win_size = MLAN_UAP_AMPDU_DEF_RXWINSIZE;
495 		priv->aggr_prio_tbl[6].ampdu_user =
496 			priv->aggr_prio_tbl[7].ampdu_user =
497 			BA_STREAM_NOT_ALLOWED;
498 	}
499 #endif
500 	priv->user_rxwinsize = priv->add_ba_param.rx_win_size;
501 
502 	priv->port_ctrl_mode = MTRUE;
503 
504 	priv->port_open = MFALSE;
505 
506 	priv->intf_hr_len = INTF_HEADER_LEN;
507 	ret = wlan_add_bsspriotbl(priv);
508 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
509 	hostsa_init(priv);
510 #endif
511 
512 	LEAVE();
513 	return ret;
514 }
515 
516 /**
517  *  @brief This function initializes the adapter structure
518  *          and sets default values to the members of adapter.
519  *
520  *  @param pmadapter    A pointer to mlan_adapter structure
521  *
522  *  @return             N/A
523  */
524 t_void
wlan_init_adapter(pmlan_adapter pmadapter)525 wlan_init_adapter(pmlan_adapter pmadapter)
526 {
527 	opt_sleep_confirm_buffer *sleep_cfm_buf = MNULL;
528 
529 	ENTER();
530 
531 	if (pmadapter->psleep_cfm) {
532 		sleep_cfm_buf =
533 			(opt_sleep_confirm_buffer *)(pmadapter->psleep_cfm->
534 						     pbuf +
535 						     pmadapter->psleep_cfm->
536 						     data_offset);
537 	}
538 #ifdef MFG_CMD_SUPPORT
539 	if (pmadapter->init_para.mfg_mode == MLAN_INIT_PARA_DISABLED)
540 		pmadapter->mfg_mode = MFALSE;
541 	else
542 		pmadapter->mfg_mode = pmadapter->init_para.mfg_mode;
543 #endif
544 
545 	pmadapter->int_mode = pmadapter->init_para.int_mode;
546 	pmadapter->gpio_pin = pmadapter->init_para.gpio_pin;
547 
548 #if defined(STA_SUPPORT)
549 	pmadapter->pwarm_reset_ioctl_req = MNULL;
550 #endif
551 	pmadapter->cmd_sent = MFALSE;
552 	pmadapter->data_sent = MTRUE;
553 	pmadapter->mp_rd_bitmap = 0;
554 	pmadapter->mp_wr_bitmap = 0;
555 	pmadapter->curr_rd_port = 0;
556 	pmadapter->curr_wr_port = 0;
557 	pmadapter->mp_data_port_mask = DATA_PORT_MASK;
558 	pmadapter->mp_invalid_update = 0;
559 	memset(pmadapter, pmadapter->mp_update, 0,
560 	       sizeof(pmadapter->mp_update));
561 #ifdef SDIO_MULTI_PORT_TX_AGGR
562 	pmadapter->mpa_tx.buf_len = 0;
563 	pmadapter->mpa_tx.pkt_cnt = 0;
564 	pmadapter->mpa_tx.start_port = 0;
565 
566 	if (!pmadapter->init_para.mpa_tx_cfg)
567 		pmadapter->mpa_tx.enabled = MFALSE;
568 	else if (pmadapter->init_para.mpa_tx_cfg == MLAN_INIT_PARA_DISABLED)
569 		pmadapter->mpa_tx.enabled = MFALSE;
570 	else
571 		pmadapter->mpa_tx.enabled = MTRUE;
572 	pmadapter->mpa_tx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
573 #endif /* SDIO_MULTI_PORT_TX_AGGR */
574 
575 #ifdef SDIO_MULTI_PORT_RX_AGGR
576 	pmadapter->mpa_rx.buf_len = 0;
577 	pmadapter->mpa_rx.pkt_cnt = 0;
578 	pmadapter->mpa_rx.start_port = 0;
579 
580 	if (!pmadapter->init_para.mpa_rx_cfg)
581 		pmadapter->mpa_rx.enabled = MFALSE;
582 	else if (pmadapter->init_para.mpa_rx_cfg == MLAN_INIT_PARA_DISABLED)
583 		pmadapter->mpa_rx.enabled = MFALSE;
584 	else
585 		pmadapter->mpa_rx.enabled = MTRUE;
586 	pmadapter->mpa_rx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
587 
588 #endif /* SDIO_MULTI_PORT_RX_AGGR */
589 
590 	pmadapter->rx_pkts_queued = 0;
591 	pmadapter->cmd_resp_received = MFALSE;
592 	pmadapter->event_received = MFALSE;
593 	pmadapter->data_received = MFALSE;
594 
595 	pmadapter->cmd_timer_is_set = MFALSE;
596 
597 	/* PnP and power profile */
598 	pmadapter->surprise_removed = MFALSE;
599 
600 	if (!pmadapter->init_para.ps_mode) {
601 		pmadapter->ps_mode = DEFAULT_PS_MODE;
602 	} else if (pmadapter->init_para.ps_mode == MLAN_INIT_PARA_DISABLED)
603 		pmadapter->ps_mode = Wlan802_11PowerModeCAM;
604 	else
605 		pmadapter->ps_mode = Wlan802_11PowerModePSP;
606 	pmadapter->ps_state = PS_STATE_AWAKE;
607 	pmadapter->need_to_wakeup = MFALSE;
608 
609 #ifdef STA_SUPPORT
610 	pmadapter->scan_block = MFALSE;
611 	/* Scan type */
612 	pmadapter->scan_type = MLAN_SCAN_TYPE_ACTIVE;
613 	/* Scan mode */
614 	pmadapter->scan_mode = HostCmd_BSS_MODE_ANY;
615 	/* Scan time */
616 	pmadapter->specific_scan_time = MRVDRV_SPECIFIC_SCAN_CHAN_TIME;
617 	pmadapter->active_scan_time = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
618 	pmadapter->passive_scan_time = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
619 
620 	pmadapter->num_in_scan_table = 0;
621 	memset(pmadapter, pmadapter->pscan_table, 0,
622 	       (sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST));
623 	pmadapter->active_scan_triggered = MFALSE;
624 	pmadapter->ext_scan = MTRUE;
625 	pmadapter->scan_probes = DEFAULT_PROBES;
626 
627 	memset(pmadapter, pmadapter->bcn_buf, 0, pmadapter->bcn_buf_size);
628 	pmadapter->pbcn_buf_end = pmadapter->bcn_buf;
629 
630 	pmadapter->radio_on = RADIO_ON;
631 	if (!pmadapter->multiple_dtim)
632 		pmadapter->multiple_dtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
633 
634 	pmadapter->local_listen_interval = 0;	/* default value in firmware will be used */
635 #endif /* STA_SUPPORT */
636 	pmadapter->fw_wakeup_method = WAKEUP_FW_UNCHANGED;
637 	pmadapter->fw_wakeup_gpio_pin = DEF_WAKEUP_FW_GPIO;
638 
639 	pmadapter->is_deep_sleep = MFALSE;
640 	pmadapter->idle_time = DEEP_SLEEP_IDLE_TIME;
641 	if (!pmadapter->init_para.auto_ds)
642 		pmadapter->init_auto_ds = DEFAULT_AUTO_DS_MODE;
643 	else if (pmadapter->init_para.auto_ds == MLAN_INIT_PARA_DISABLED)
644 		pmadapter->init_auto_ds = MFALSE;
645 	else
646 		pmadapter->init_auto_ds = MTRUE;
647 
648 	pmadapter->delay_null_pkt = MFALSE;
649 	pmadapter->delay_to_ps = DELAY_TO_PS_DEFAULT;
650 	pmadapter->enhanced_ps_mode = PS_MODE_AUTO;
651 
652 	pmadapter->gen_null_pkt = MFALSE;	/* Disable NULL Pkt generation-default */
653 	pmadapter->pps_uapsd_mode = MFALSE;	/* Disable pps/uapsd mode -default */
654 
655 	pmadapter->pm_wakeup_card_req = MFALSE;
656 
657 	pmadapter->pm_wakeup_fw_try = MFALSE;
658 
659 	if (!pmadapter->init_para.max_tx_buf)
660 		pmadapter->max_tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
661 	else
662 		pmadapter->max_tx_buf_size =
663 			(t_u16)pmadapter->init_para.max_tx_buf;
664 	pmadapter->tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
665 	pmadapter->curr_tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
666 
667 	pmadapter->is_hs_configured = MFALSE;
668 	pmadapter->hs_cfg.conditions = HOST_SLEEP_DEF_COND;
669 	pmadapter->hs_cfg.gpio = HOST_SLEEP_DEF_GPIO;
670 	pmadapter->hs_cfg.gap = HOST_SLEEP_DEF_GAP;
671 	pmadapter->hs_activated = MFALSE;
672 	pmadapter->min_wake_holdoff = HOST_SLEEP_DEF_WAKE_HOLDOFF;
673 	pmadapter->hs_inactivity_timeout = HOST_SLEEP_DEF_INACTIVITY_TIMEOUT;
674 
675 	memset(pmadapter, pmadapter->event_body, 0,
676 	       sizeof(pmadapter->event_body));
677 	pmadapter->hw_dot_11n_dev_cap = 0;
678 	pmadapter->hw_dev_mcs_support = 0;
679 	pmadapter->coex_rx_winsize = 1;
680 #ifdef STA_SUPPORT
681 	pmadapter->chan_bandwidth = 0;
682 	pmadapter->adhoc_11n_enabled = MFALSE;
683 	pmadapter->tdls_status = TDLS_NOT_SETUP;
684 #endif /* STA_SUPPORT */
685 
686 	pmadapter->max_sta_conn = 0;
687 	/* Initialize 802.11d */
688 	wlan_11d_init(pmadapter);
689 
690 	wlan_11h_init(pmadapter);
691 
692 	wlan_wmm_init(pmadapter);
693 	wlan_init_wmm_param(pmadapter);
694 	pmadapter->bypass_pkt_count = 0;
695 	if (pmadapter->psleep_cfm) {
696 		pmadapter->psleep_cfm->buf_type = MLAN_BUF_TYPE_CMD;
697 		pmadapter->psleep_cfm->data_len = sizeof(OPT_Confirm_Sleep);
698 		memset(pmadapter, &sleep_cfm_buf->ps_cfm_sleep, 0,
699 		       sizeof(OPT_Confirm_Sleep));
700 		sleep_cfm_buf->ps_cfm_sleep.command =
701 			wlan_cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
702 		sleep_cfm_buf->ps_cfm_sleep.size =
703 			wlan_cpu_to_le16(sizeof(OPT_Confirm_Sleep));
704 		sleep_cfm_buf->ps_cfm_sleep.result = 0;
705 		sleep_cfm_buf->ps_cfm_sleep.action =
706 			wlan_cpu_to_le16(SLEEP_CONFIRM);
707 		sleep_cfm_buf->ps_cfm_sleep.sleep_cfm.resp_ctrl =
708 			wlan_cpu_to_le16(RESP_NEEDED);
709 	}
710 	memset(pmadapter, &pmadapter->sleep_params, 0,
711 	       sizeof(pmadapter->sleep_params));
712 	memset(pmadapter, &pmadapter->sleep_period, 0,
713 	       sizeof(pmadapter->sleep_period));
714 	memset(pmadapter, &pmadapter->saved_sleep_period, 0,
715 	       sizeof(pmadapter->saved_sleep_period));
716 	pmadapter->tx_lock_flag = MFALSE;
717 	pmadapter->null_pkt_interval = 0;
718 	pmadapter->fw_bands = 0;
719 	pmadapter->config_bands = 0;
720 	pmadapter->adhoc_start_band = 0;
721 	pmadapter->pscan_channels = MNULL;
722 	pmadapter->fw_release_number = 0;
723 	pmadapter->fw_cap_info = 0;
724 	memset(pmadapter, &pmadapter->upld_buf, 0, sizeof(pmadapter->upld_buf));
725 	pmadapter->upld_len = 0;
726 	pmadapter->event_cause = 0;
727 	pmadapter->pmlan_buffer_event = MNULL;
728 	memset(pmadapter, &pmadapter->region_channel, 0,
729 	       sizeof(pmadapter->region_channel));
730 	pmadapter->region_code = 0;
731 	memcpy(pmadapter, pmadapter->country_code, MRVDRV_DEFAULT_COUNTRY_CODE,
732 	       COUNTRY_CODE_LEN);
733 	pmadapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
734 	pmadapter->adhoc_awake_period = 0;
735 #ifdef STA_SUPPORT
736 	memset(pmadapter, &pmadapter->arp_filter, 0,
737 	       sizeof(pmadapter->arp_filter));
738 	pmadapter->arp_filter_size = 0;
739 #endif /* STA_SUPPORT */
740 
741 	pmadapter->mc_status = MFALSE;
742 
743 	LEAVE();
744 	return;
745 }
746 
747 /**
748  *  @brief This function intializes the lock variables and
749  *  the list heads for interface
750  *
751  *  @param pmadapter  A pointer to a mlan_adapter structure
752  *  @param start_index   start index of mlan private
753  *
754  *  @return           MLAN_STATUS_SUCCESS -- on success,
755  *                    otherwise MLAN_STATUS_FAILURE
756  *
757  */
758 mlan_status
wlan_init_priv_lock_list(IN pmlan_adapter pmadapter,t_u8 start_index)759 wlan_init_priv_lock_list(IN pmlan_adapter pmadapter, t_u8 start_index)
760 {
761 	mlan_status ret = MLAN_STATUS_SUCCESS;
762 	pmlan_private priv = MNULL;
763 	pmlan_callbacks pcb = &pmadapter->callbacks;
764 	t_s32 i = 0;
765 	t_u32 j = 0;
766 	for (i = start_index; i < pmadapter->priv_num; i++) {
767 		if (pmadapter->priv[i]) {
768 			priv = pmadapter->priv[i];
769 			if (pcb->
770 			    moal_init_lock(pmadapter->pmoal_handle,
771 					   &priv->rx_pkt_lock)
772 			    != MLAN_STATUS_SUCCESS) {
773 				ret = MLAN_STATUS_FAILURE;
774 				goto error;
775 			}
776 			if (pcb->
777 			    moal_init_lock(pmadapter->pmoal_handle,
778 					   &priv->wmm.ra_list_spinlock)
779 			    != MLAN_STATUS_SUCCESS) {
780 				ret = MLAN_STATUS_FAILURE;
781 				goto error;
782 			}
783 #ifdef STA_SUPPORT
784 			if (pcb->
785 			    moal_init_lock(pmadapter->pmoal_handle,
786 					   &priv->curr_bcn_buf_lock)
787 			    != MLAN_STATUS_SUCCESS) {
788 				ret = MLAN_STATUS_FAILURE;
789 				goto error;
790 			}
791 #endif
792 		}
793 	}
794 	for (i = start_index; i < pmadapter->priv_num; ++i) {
795 		util_init_list_head((t_void *)pmadapter->pmoal_handle,
796 				    &pmadapter->bssprio_tbl[i].bssprio_head,
797 				    MTRUE, pmadapter->callbacks.moal_init_lock);
798 		pmadapter->bssprio_tbl[i].bssprio_cur = MNULL;
799 	}
800 
801 	for (i = start_index; i < pmadapter->priv_num; i++) {
802 		if (pmadapter->priv[i]) {
803 			priv = pmadapter->priv[i];
804 			for (j = 0; j < MAX_NUM_TID; ++j) {
805 				util_init_list_head((t_void *)pmadapter->
806 						    pmoal_handle,
807 						    &priv->wmm.tid_tbl_ptr[j].
808 						    ra_list, MTRUE,
809 						    priv->adapter->callbacks.
810 						    moal_init_lock);
811 			}
812 			util_init_list_head((t_void *)pmadapter->pmoal_handle,
813 					    &priv->tx_ba_stream_tbl_ptr, MTRUE,
814 					    pmadapter->callbacks.
815 					    moal_init_lock);
816 			util_init_list_head((t_void *)pmadapter->pmoal_handle,
817 					    &priv->rx_reorder_tbl_ptr, MTRUE,
818 					    pmadapter->callbacks.
819 					    moal_init_lock);
820 			util_scalar_init((t_void *)pmadapter->pmoal_handle,
821 					 &priv->wmm.tx_pkts_queued, 0,
822 					 priv->wmm.ra_list_spinlock,
823 					 pmadapter->callbacks.moal_init_lock);
824 			util_scalar_init((t_void *)pmadapter->pmoal_handle,
825 					 &priv->wmm.highest_queued_prio,
826 					 HIGH_PRIO_TID,
827 					 priv->wmm.ra_list_spinlock,
828 					 pmadapter->callbacks.moal_init_lock);
829 			util_init_list_head((t_void *)pmadapter->pmoal_handle,
830 					    &priv->sta_list, MTRUE,
831 					    pmadapter->callbacks.
832 					    moal_init_lock);
833 			/* Initialize tdls_pending_txq */
834 			util_init_list_head((t_void *)pmadapter->pmoal_handle,
835 					    &priv->tdls_pending_txq, MTRUE,
836 					    pmadapter->callbacks.
837 					    moal_init_lock);
838 			/* Initialize bypass_txq */
839 			util_init_list_head((t_void *)pmadapter->pmoal_handle,
840 					    &priv->bypass_txq, MTRUE,
841 					    pmadapter->callbacks.
842 					    moal_init_lock);
843 		}
844 	}
845 error:
846 	LEAVE();
847 	return ret;
848 }
849 
850 /**
851  *  @brief This function intializes the lock variables and
852  *  the list heads.
853  *
854  *  @param pmadapter  A pointer to a mlan_adapter structure
855  *
856  *  @return           MLAN_STATUS_SUCCESS -- on success,
857  *                    otherwise MLAN_STATUS_FAILURE
858  *
859  */
860 mlan_status
wlan_init_lock_list(IN pmlan_adapter pmadapter)861 wlan_init_lock_list(IN pmlan_adapter pmadapter)
862 {
863 	mlan_status ret = MLAN_STATUS_SUCCESS;
864 	pmlan_callbacks pcb = &pmadapter->callbacks;
865 	ENTER();
866 
867 	if (pcb->moal_init_lock(pmadapter->pmoal_handle, &pmadapter->pmlan_lock)
868 	    != MLAN_STATUS_SUCCESS) {
869 		ret = MLAN_STATUS_FAILURE;
870 		goto error;
871 	}
872 	if (pcb->moal_init_lock(pmadapter->pmoal_handle, &pmadapter->pint_lock)
873 	    != MLAN_STATUS_SUCCESS) {
874 		ret = MLAN_STATUS_FAILURE;
875 		goto error;
876 	}
877 	if (pcb->
878 	    moal_init_lock(pmadapter->pmoal_handle, &pmadapter->pmain_proc_lock)
879 	    != MLAN_STATUS_SUCCESS) {
880 		ret = MLAN_STATUS_FAILURE;
881 		goto error;
882 	}
883 	if (pcb->
884 	    moal_init_lock(pmadapter->pmoal_handle, &pmadapter->prx_proc_lock)
885 	    != MLAN_STATUS_SUCCESS) {
886 		ret = MLAN_STATUS_FAILURE;
887 		goto error;
888 	}
889 	if (pcb->
890 	    moal_init_lock(pmadapter->pmoal_handle, &pmadapter->pmlan_cmd_lock)
891 	    != MLAN_STATUS_SUCCESS) {
892 		ret = MLAN_STATUS_FAILURE;
893 		goto error;
894 	}
895 
896 	util_init_list_head((t_void *)pmadapter->pmoal_handle,
897 			    &pmadapter->rx_data_queue, MTRUE,
898 			    pmadapter->callbacks.moal_init_lock);
899 	util_scalar_init((t_void *)pmadapter->pmoal_handle,
900 			 &pmadapter->pending_bridge_pkts, 0,
901 			 MNULL, pmadapter->callbacks.moal_init_lock);
902 	/* Initialize cmd_free_q */
903 	util_init_list_head((t_void *)pmadapter->pmoal_handle,
904 			    &pmadapter->cmd_free_q, MTRUE,
905 			    pmadapter->callbacks.moal_init_lock);
906 	/* Initialize cmd_pending_q */
907 	util_init_list_head((t_void *)pmadapter->pmoal_handle,
908 			    &pmadapter->cmd_pending_q, MTRUE,
909 			    pmadapter->callbacks.moal_init_lock);
910 	/* Initialize scan_pending_q */
911 	util_init_list_head((t_void *)pmadapter->pmoal_handle,
912 			    &pmadapter->scan_pending_q, MTRUE,
913 			    pmadapter->callbacks.moal_init_lock);
914 
915 	/* Initialize ioctl_pending_q */
916 	util_init_list_head((t_void *)pmadapter->pmoal_handle,
917 			    &pmadapter->ioctl_pending_q, MTRUE,
918 			    pmadapter->callbacks.moal_init_lock);
919 
920 error:
921 	LEAVE();
922 	return ret;
923 }
924 
925 /**
926  *  @brief This function releases the lock variables
927  *
928  *  @param pmadapter  A pointer to a mlan_adapter structure
929  *
930  *  @return           None
931  *
932  */
933 t_void
wlan_free_lock_list(IN pmlan_adapter pmadapter)934 wlan_free_lock_list(IN pmlan_adapter pmadapter)
935 {
936 	pmlan_private priv = MNULL;
937 	pmlan_callbacks pcb = &pmadapter->callbacks;
938 	t_s32 i = 0;
939 	t_s32 j = 0;
940 
941 	ENTER();
942 
943 	if (pmadapter->pmlan_lock)
944 		pcb->moal_free_lock(pmadapter->pmoal_handle,
945 				    pmadapter->pmlan_lock);
946 	if (pmadapter->pint_lock)
947 		pcb->moal_free_lock(pmadapter->pmoal_handle,
948 				    pmadapter->pint_lock);
949 	if (pmadapter->prx_proc_lock)
950 		pcb->moal_free_lock(pmadapter->pmoal_handle,
951 				    pmadapter->prx_proc_lock);
952 	if (pmadapter->pmain_proc_lock)
953 		pcb->moal_free_lock(pmadapter->pmoal_handle,
954 				    pmadapter->pmain_proc_lock);
955 	if (pmadapter->pmlan_cmd_lock)
956 		pcb->moal_free_lock(pmadapter->pmoal_handle,
957 				    pmadapter->pmlan_cmd_lock);
958 
959 	for (i = 0; i < pmadapter->priv_num; i++) {
960 		if (pmadapter->priv[i]) {
961 			priv = pmadapter->priv[i];
962 			if (priv->rx_pkt_lock)
963 				pcb->moal_free_lock(pmadapter->pmoal_handle,
964 						    priv->rx_pkt_lock);
965 			if (priv->wmm.ra_list_spinlock)
966 				pcb->moal_free_lock(pmadapter->pmoal_handle,
967 						    priv->wmm.ra_list_spinlock);
968 #ifdef STA_SUPPORT
969 			if (priv->curr_bcn_buf_lock)
970 				pcb->moal_free_lock(pmadapter->pmoal_handle,
971 						    priv->curr_bcn_buf_lock);
972 #endif
973 		}
974 	}
975 
976 	/* Free lists */
977 	util_free_list_head((t_void *)pmadapter->pmoal_handle,
978 			    &pmadapter->rx_data_queue, pcb->moal_free_lock);
979 
980 	util_scalar_free((t_void *)pmadapter->pmoal_handle,
981 			 &pmadapter->pending_bridge_pkts, pcb->moal_free_lock);
982 	util_free_list_head((t_void *)pmadapter->pmoal_handle,
983 			    &pmadapter->cmd_free_q,
984 			    pmadapter->callbacks.moal_free_lock);
985 
986 	util_free_list_head((t_void *)pmadapter->pmoal_handle,
987 			    &pmadapter->cmd_pending_q,
988 			    pmadapter->callbacks.moal_free_lock);
989 
990 	util_free_list_head((t_void *)pmadapter->pmoal_handle,
991 			    &pmadapter->scan_pending_q,
992 			    pmadapter->callbacks.moal_free_lock);
993 
994 	util_free_list_head((t_void *)pmadapter->pmoal_handle,
995 			    &pmadapter->ioctl_pending_q,
996 			    pmadapter->callbacks.moal_free_lock);
997 
998 	for (i = 0; i < pmadapter->priv_num; i++)
999 		util_free_list_head((t_void *)pmadapter->pmoal_handle,
1000 				    &pmadapter->bssprio_tbl[i].bssprio_head,
1001 				    pcb->moal_free_lock);
1002 
1003 	for (i = 0; i < pmadapter->priv_num; i++) {
1004 		if (pmadapter->priv[i]) {
1005 			priv = pmadapter->priv[i];
1006 			util_free_list_head((t_void *)pmadapter->pmoal_handle,
1007 					    &priv->sta_list,
1008 					    priv->adapter->callbacks.
1009 					    moal_free_lock);
1010 			util_free_list_head((t_void *)pmadapter->pmoal_handle,
1011 					    &priv->tdls_pending_txq,
1012 					    pmadapter->callbacks.
1013 					    moal_free_lock);
1014 			util_free_list_head((t_void *)pmadapter->pmoal_handle,
1015 					    &priv->bypass_txq,
1016 					    pmadapter->callbacks.
1017 					    moal_free_lock);
1018 
1019 			for (j = 0; j < MAX_NUM_TID; ++j)
1020 				util_free_list_head((t_void *)priv->adapter->
1021 						    pmoal_handle,
1022 						    &priv->wmm.tid_tbl_ptr[j].
1023 						    ra_list,
1024 						    priv->adapter->callbacks.
1025 						    moal_free_lock);
1026 			util_free_list_head((t_void *)priv->adapter->
1027 					    pmoal_handle,
1028 					    &priv->tx_ba_stream_tbl_ptr,
1029 					    priv->adapter->callbacks.
1030 					    moal_free_lock);
1031 			util_free_list_head((t_void *)priv->adapter->
1032 					    pmoal_handle,
1033 					    &priv->rx_reorder_tbl_ptr,
1034 					    priv->adapter->callbacks.
1035 					    moal_free_lock);
1036 			util_scalar_free((t_void *)priv->adapter->pmoal_handle,
1037 					 &priv->wmm.tx_pkts_queued,
1038 					 priv->adapter->callbacks.
1039 					 moal_free_lock);
1040 			util_scalar_free((t_void *)priv->adapter->pmoal_handle,
1041 					 &priv->wmm.highest_queued_prio,
1042 					 priv->adapter->callbacks.
1043 					 moal_free_lock);
1044 		}
1045 	}
1046 
1047 	LEAVE();
1048 	return;
1049 }
1050 
1051 /**
1052  *  @brief This function intializes the timers
1053  *
1054  *  @param pmadapter  A pointer to a mlan_adapter structure
1055  *
1056  *  @return           MLAN_STATUS_SUCCESS -- on success,
1057  *                    otherwise MLAN_STATUS_FAILURE
1058  *
1059  */
1060 mlan_status
wlan_init_timer(IN pmlan_adapter pmadapter)1061 wlan_init_timer(IN pmlan_adapter pmadapter)
1062 {
1063 	mlan_status ret = MLAN_STATUS_SUCCESS;
1064 	pmlan_callbacks pcb = &pmadapter->callbacks;
1065 	ENTER();
1066 
1067 	if (pcb->
1068 	    moal_init_timer(pmadapter->pmoal_handle,
1069 			    &pmadapter->pmlan_cmd_timer, wlan_cmd_timeout_func,
1070 			    pmadapter)
1071 	    != MLAN_STATUS_SUCCESS) {
1072 		ret = MLAN_STATUS_FAILURE;
1073 		goto error;
1074 	}
1075 error:
1076 	LEAVE();
1077 	return ret;
1078 }
1079 
1080 /**
1081  *  @brief This function releases the timers
1082  *
1083  *  @param pmadapter  A pointer to a mlan_adapter structure
1084  *
1085  *  @return           None
1086  *
1087  */
1088 t_void
wlan_free_timer(IN pmlan_adapter pmadapter)1089 wlan_free_timer(IN pmlan_adapter pmadapter)
1090 {
1091 	pmlan_callbacks pcb = &pmadapter->callbacks;
1092 	ENTER();
1093 
1094 	if (pmadapter->pmlan_cmd_timer)
1095 		pcb->moal_free_timer(pmadapter->pmoal_handle,
1096 				     pmadapter->pmlan_cmd_timer);
1097 
1098 	LEAVE();
1099 	return;
1100 }
1101 
1102 /**
1103  *  @brief  This function initializes firmware
1104  *
1105  *  @param pmadapter		A pointer to mlan_adapter
1106  *
1107  *  @return		MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or MLAN_STATUS_FAILURE
1108  */
1109 mlan_status
wlan_init_fw(IN pmlan_adapter pmadapter)1110 wlan_init_fw(IN pmlan_adapter pmadapter)
1111 {
1112 	mlan_status ret = MLAN_STATUS_SUCCESS;
1113 	ENTER();
1114 	/* Initialize adapter structure */
1115 	wlan_init_adapter(pmadapter);
1116 #ifdef MFG_CMD_SUPPORT
1117 	if (pmadapter->mfg_mode != MTRUE) {
1118 #endif
1119 		wlan_adapter_get_hw_spec(pmadapter);
1120 #ifdef MFG_CMD_SUPPORT
1121 	}
1122 #endif /* MFG_CMD_SUPPORT */
1123 	if (wlan_is_cmd_pending(pmadapter)) {
1124 		/* Send the first command in queue and return */
1125 		if (mlan_main_process(pmadapter) == MLAN_STATUS_FAILURE)
1126 			ret = MLAN_STATUS_FAILURE;
1127 		else
1128 			ret = MLAN_STATUS_PENDING;
1129 	}
1130 #ifdef MFG_CMD_SUPPORT
1131 	if (pmadapter->mfg_mode == MTRUE) {
1132 		pmadapter->hw_status = WlanHardwareStatusInitializing;
1133 		ret = wlan_get_hw_spec_complete(pmadapter);
1134 	}
1135 #endif
1136 	LEAVE();
1137 	return ret;
1138 }
1139 
1140 /**
1141  *  @brief  This function udpate hw spec info to each interface
1142  *
1143  *  @param pmadapter		A pointer to mlan_adapter
1144  *
1145  *  @return		MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or MLAN_STATUS_FAILURE
1146  */
1147 void
wlan_update_hw_spec(IN pmlan_adapter pmadapter)1148 wlan_update_hw_spec(IN pmlan_adapter pmadapter)
1149 {
1150 	t_u32 i;
1151 
1152 	ENTER();
1153 
1154 #ifdef STA_SUPPORT
1155 	if (IS_SUPPORT_MULTI_BANDS(pmadapter))
1156 		pmadapter->fw_bands = (t_u8)GET_FW_DEFAULT_BANDS(pmadapter);
1157 	else
1158 		pmadapter->fw_bands = BAND_B;
1159 
1160 	pmadapter->config_bands = pmadapter->fw_bands;
1161 	for (i = 0; i < pmadapter->priv_num; i++) {
1162 		if (pmadapter->priv[i]) {
1163 			pmadapter->priv[i]->config_bands = pmadapter->fw_bands;
1164 		}
1165 	}
1166 
1167 	if (pmadapter->fw_bands & BAND_A) {
1168 		if (pmadapter->fw_bands & BAND_GN) {
1169 			pmadapter->config_bands |= BAND_AN;
1170 			for (i = 0; i < pmadapter->priv_num; i++) {
1171 				if (pmadapter->priv[i])
1172 					pmadapter->priv[i]->config_bands |=
1173 						BAND_AN;
1174 			}
1175 
1176 			pmadapter->fw_bands |= BAND_AN;
1177 		}
1178 		if ((pmadapter->fw_bands & BAND_AN)
1179 			) {
1180 			pmadapter->adhoc_start_band = BAND_A | BAND_AN;
1181 			pmadapter->adhoc_11n_enabled = MTRUE;
1182 		} else
1183 			pmadapter->adhoc_start_band = BAND_A;
1184 		for (i = 0; i < pmadapter->priv_num; i++) {
1185 			if (pmadapter->priv[i])
1186 				pmadapter->priv[i]->adhoc_channel =
1187 					DEFAULT_AD_HOC_CHANNEL_A;
1188 		}
1189 
1190 	} else if ((pmadapter->fw_bands & BAND_GN)
1191 		) {
1192 		pmadapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
1193 		for (i = 0; i < pmadapter->priv_num; i++) {
1194 			if (pmadapter->priv[i])
1195 				pmadapter->priv[i]->adhoc_channel =
1196 					DEFAULT_AD_HOC_CHANNEL;
1197 		}
1198 		pmadapter->adhoc_11n_enabled = MTRUE;
1199 	} else if (pmadapter->fw_bands & BAND_G) {
1200 		pmadapter->adhoc_start_band = BAND_G | BAND_B;
1201 		for (i = 0; i < pmadapter->priv_num; i++) {
1202 			if (pmadapter->priv[i])
1203 				pmadapter->priv[i]->adhoc_channel =
1204 					DEFAULT_AD_HOC_CHANNEL;
1205 		}
1206 	} else if (pmadapter->fw_bands & BAND_B) {
1207 		pmadapter->adhoc_start_band = BAND_B;
1208 		for (i = 0; i < pmadapter->priv_num; i++) {
1209 			if (pmadapter->priv[i])
1210 				pmadapter->priv[i]->adhoc_channel =
1211 					DEFAULT_AD_HOC_CHANNEL;
1212 		}
1213 	}
1214 #endif /* STA_SUPPORT */
1215 
1216 	for (i = 0; i < pmadapter->priv_num; i++) {
1217 		if (pmadapter->priv[i]->curr_addr[0] == 0xff)
1218 			memmove(pmadapter, pmadapter->priv[i]->curr_addr,
1219 				pmadapter->permanent_addr,
1220 				MLAN_MAC_ADDR_LENGTH);
1221 	}
1222 
1223 	for (i = 0; i < pmadapter->priv_num; i++) {
1224 		if (pmadapter->priv[i])
1225 			wlan_update_11n_cap(pmadapter->priv[i]);
1226 	}
1227 	if (ISSUPP_BEAMFORMING(pmadapter->hw_dot_11n_dev_cap)) {
1228 		PRINTM(MCMND, "Enable Beamforming\n");
1229 		for (i = 0; i < pmadapter->priv_num; i++) {
1230 			if (pmadapter->priv[i])
1231 				pmadapter->priv[i]->tx_bf_cap =
1232 					DEFAULT_11N_TX_BF_CAP;
1233 		}
1234 	}
1235 
1236 	LEAVE();
1237 	return;
1238 }
1239 
1240 /**
1241  *  @brief  This function initializes firmware for interface
1242  *
1243  *  @param pmadapter		A pointer to mlan_adapter
1244  *
1245  *  @return		MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or MLAN_STATUS_FAILURE
1246  */
1247 mlan_status
wlan_init_priv_fw(IN pmlan_adapter pmadapter)1248 wlan_init_priv_fw(IN pmlan_adapter pmadapter)
1249 {
1250 	mlan_status ret = MLAN_STATUS_SUCCESS;
1251 	pmlan_private priv = MNULL;
1252 	t_u8 i = 0;
1253 
1254 	ENTER();
1255 
1256 	wlan_init_priv_lock_list(pmadapter, 1);
1257 	for (i = 0; i < pmadapter->priv_num; i++) {
1258 		if (pmadapter->priv[i]) {
1259 			priv = pmadapter->priv[i];
1260 
1261 			/* Initialize private structure */
1262 			ret = wlan_init_priv(priv);
1263 			if (ret) {
1264 				ret = MLAN_STATUS_FAILURE;
1265 				goto done;
1266 			}
1267 		}
1268 	}
1269 #ifdef MFG_CMD_SUPPORT
1270 	if (pmadapter->mfg_mode != MTRUE) {
1271 #endif
1272 		wlan_update_hw_spec(pmadapter);
1273 		/* Issue firmware initialize commands for first BSS,
1274 		 * for other interfaces it will be called after getting
1275 		 * the last init command response of previous interface
1276 		 */
1277 		priv = wlan_get_priv(pmadapter, MLAN_BSS_ROLE_ANY);
1278 		if (!priv) {
1279 			ret = MLAN_STATUS_FAILURE;
1280 			goto done;
1281 		}
1282 
1283 		ret = priv->ops.init_cmd(priv, MTRUE);
1284 		if (ret == MLAN_STATUS_FAILURE)
1285 			goto done;
1286 #ifdef MFG_CMD_SUPPORT
1287 	}
1288 #endif /* MFG_CMD_SUPPORT */
1289 
1290 	if (wlan_is_cmd_pending(pmadapter)) {
1291 		/* Send the first command in queue and return */
1292 		if (mlan_main_process(pmadapter) == MLAN_STATUS_FAILURE)
1293 			ret = MLAN_STATUS_FAILURE;
1294 		else
1295 			ret = MLAN_STATUS_PENDING;
1296 	} else {
1297 		pmadapter->hw_status = WlanHardwareStatusReady;
1298 	}
1299 done:
1300 	LEAVE();
1301 	return ret;
1302 }
1303 
1304 /**
1305  *  @brief This function frees the structure of adapter
1306  *
1307  *  @param pmadapter    A pointer to mlan_adapter structure
1308  *
1309  *  @return             N/A
1310  */
1311 t_void
wlan_free_adapter(pmlan_adapter pmadapter)1312 wlan_free_adapter(pmlan_adapter pmadapter)
1313 {
1314 	mlan_callbacks *pcb = (mlan_callbacks *)&pmadapter->callbacks;
1315 	ENTER();
1316 
1317 	if (!pmadapter) {
1318 		PRINTM(MERROR, "The adapter is NULL\n");
1319 		LEAVE();
1320 		return;
1321 	}
1322 
1323 	wlan_cancel_all_pending_cmd(pmadapter);
1324 	/* Free command buffer */
1325 	PRINTM(MINFO, "Free Command buffer\n");
1326 	wlan_free_cmd_buffer(pmadapter);
1327 
1328 	if (pmadapter->cmd_timer_is_set) {
1329 		/* Cancel command timeout timer */
1330 		pcb->moal_stop_timer(pmadapter->pmoal_handle,
1331 				     pmadapter->pmlan_cmd_timer);
1332 		pmadapter->cmd_timer_is_set = MFALSE;
1333 	}
1334 	wlan_free_fw_cfp_tables(pmadapter);
1335 #ifdef STA_SUPPORT
1336 	PRINTM(MINFO, "Free ScanTable\n");
1337 	if (pmadapter->pscan_table) {
1338 		if (pcb->moal_vmalloc && pcb->moal_vfree)
1339 			pcb->moal_vfree(pmadapter->pmoal_handle,
1340 					(t_u8 *)pmadapter->pscan_table);
1341 		else
1342 			pcb->moal_mfree(pmadapter->pmoal_handle,
1343 					(t_u8 *)pmadapter->pscan_table);
1344 		pmadapter->pscan_table = MNULL;
1345 	}
1346 	if (pmadapter->pchan_stats) {
1347 		if (pcb->moal_vmalloc && pcb->moal_vfree)
1348 			pcb->moal_vfree(pmadapter->pmoal_handle,
1349 					(t_u8 *)pmadapter->pchan_stats);
1350 		else
1351 			pcb->moal_mfree(pmadapter->pmoal_handle,
1352 					(t_u8 *)pmadapter->pchan_stats);
1353 		pmadapter->pchan_stats = MNULL;
1354 	}
1355 	if (pmadapter->bcn_buf) {
1356 		pcb->moal_mfree(pmadapter->pmoal_handle,
1357 				(t_u8 *)pmadapter->bcn_buf);
1358 		pmadapter->bcn_buf = MNULL;
1359 	}
1360 #endif
1361 
1362 	wlan_11h_cleanup(pmadapter);
1363 
1364 	if (pmadapter->mp_regs_buf) {
1365 		pcb->moal_mfree(pmadapter->pmoal_handle,
1366 				(t_u8 *)pmadapter->mp_regs_buf);
1367 		pmadapter->mp_regs_buf = MNULL;
1368 		pmadapter->mp_regs = MNULL;
1369 	}
1370 #if defined(SDIO_MULTI_PORT_RX_AGGR)
1371 	if (pmadapter->rx_buffer) {
1372 		pcb->moal_mfree(pmadapter->pmoal_handle,
1373 				(t_u8 *)pmadapter->rx_buffer);
1374 		pmadapter->rx_buffer = MNULL;
1375 		pmadapter->rx_buf = MNULL;
1376 	}
1377 #endif
1378 #if defined(SDIO_MULTI_PORT_TX_AGGR) || defined(SDIO_MULTI_PORT_RX_AGGR)
1379 	wlan_free_sdio_mpa_buffers(pmadapter);
1380 #ifdef DEBUG_LEVEL1
1381 	if (pmadapter->mpa_buf) {
1382 		if (pcb->moal_vmalloc && pcb->moal_vfree)
1383 			pcb->moal_vfree(pmadapter->pmoal_handle,
1384 					(t_u8 *)pmadapter->mpa_buf);
1385 		else
1386 			pcb->moal_mfree(pmadapter->pmoal_handle,
1387 					(t_u8 *)pmadapter->mpa_buf);
1388 		pmadapter->mpa_buf = MNULL;
1389 		pmadapter->mpa_buf_size = 0;
1390 	}
1391 #endif
1392 #endif
1393 	wlan_free_mlan_buffer(pmadapter, pmadapter->psleep_cfm);
1394 	pmadapter->psleep_cfm = MNULL;
1395 
1396 	LEAVE();
1397 	return;
1398 }
1399 
1400 /**
1401  *  @brief This function frees the structure of priv
1402  *
1403  *  @param pmpriv   A pointer to mlan_private structure
1404  *
1405  *  @return         N/A
1406  */
1407 t_void
wlan_free_priv(mlan_private * pmpriv)1408 wlan_free_priv(mlan_private *pmpriv)
1409 {
1410 	ENTER();
1411 	wlan_clean_txrx(pmpriv);
1412 	wlan_delete_bsspriotbl(pmpriv);
1413 
1414 #ifdef STA_SUPPORT
1415 	wlan_free_curr_bcn(pmpriv);
1416 #endif /* STA_SUPPORT */
1417 
1418 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
1419 	hostsa_cleanup(pmpriv);
1420 #endif /*EMBEDDED AUTHENTICATOR */
1421 
1422 	wlan_delete_station_list(pmpriv);
1423 	LEAVE();
1424 }
1425 
1426 /**
1427  *  @brief This function init interface based on pmadapter's bss_attr table
1428  *
1429  *  @param pmadapter    A pointer to mlan_adapter structure
1430  *
1431  *  @return             N/A
1432  */
1433 mlan_status
wlan_init_interface(IN pmlan_adapter pmadapter)1434 wlan_init_interface(IN pmlan_adapter pmadapter)
1435 {
1436 	mlan_status ret = MLAN_STATUS_SUCCESS;
1437 	pmlan_callbacks pcb = MNULL;
1438 	t_u8 i = 0;
1439 	t_u32 j = 0;
1440 
1441 	ENTER();
1442 
1443 	pcb = &pmadapter->callbacks;
1444 	for (i = 0; i < MLAN_MAX_BSS_NUM; i++) {
1445 		if (pmadapter->bss_attr[i].active == MTRUE) {
1446 			if (!pmadapter->priv[i]) {
1447 				/* For valid bss_attr, allocate memory for private structure */
1448 				if (pcb->moal_vmalloc && pcb->moal_vfree)
1449 					ret = pcb->moal_vmalloc(pmadapter->
1450 								pmoal_handle,
1451 								sizeof
1452 								(mlan_private),
1453 								(t_u8 **)
1454 								&pmadapter->
1455 								priv[i]);
1456 				else
1457 					ret = pcb->moal_malloc(pmadapter->
1458 							       pmoal_handle,
1459 							       sizeof
1460 							       (mlan_private),
1461 							       MLAN_MEM_DEF,
1462 							       (t_u8 **)
1463 							       &pmadapter->
1464 							       priv[i]);
1465 				if (ret != MLAN_STATUS_SUCCESS ||
1466 				    !pmadapter->priv[i]) {
1467 					ret = MLAN_STATUS_FAILURE;
1468 					goto error;
1469 				}
1470 
1471 				pmadapter->priv_num++;
1472 				memset(pmadapter, pmadapter->priv[i], 0,
1473 				       sizeof(mlan_private));
1474 			}
1475 			pmadapter->priv[i]->adapter = pmadapter;
1476 
1477 			/* Save bss_type, frame_type & bss_priority */
1478 			pmadapter->priv[i]->bss_type =
1479 				(t_u8)pmadapter->bss_attr[i].bss_type;
1480 			pmadapter->priv[i]->frame_type =
1481 				(t_u8)pmadapter->bss_attr[i].frame_type;
1482 			pmadapter->priv[i]->bss_priority =
1483 				(t_u8)pmadapter->bss_attr[i].bss_priority;
1484 			if (pmadapter->bss_attr[i].bss_type ==
1485 			    MLAN_BSS_TYPE_STA)
1486 				pmadapter->priv[i]->bss_role =
1487 					MLAN_BSS_ROLE_STA;
1488 			else if (pmadapter->bss_attr[i].bss_type ==
1489 				 MLAN_BSS_TYPE_UAP)
1490 				pmadapter->priv[i]->bss_role =
1491 					MLAN_BSS_ROLE_UAP;
1492 #ifdef WIFI_DIRECT_SUPPORT
1493 			else if (pmadapter->bss_attr[i].bss_type ==
1494 				 MLAN_BSS_TYPE_WIFIDIRECT) {
1495 				pmadapter->priv[i]->bss_role =
1496 					MLAN_BSS_ROLE_STA;
1497 				if (pmadapter->bss_attr[i].bss_virtual)
1498 					pmadapter->priv[i]->bss_virtual = MTRUE;
1499 			}
1500 #endif
1501 			/* Save bss_index and bss_num */
1502 			pmadapter->priv[i]->bss_index = i;
1503 			pmadapter->priv[i]->bss_num =
1504 				(t_u8)pmadapter->bss_attr[i].bss_num;
1505 
1506 			/* init function table */
1507 			for (j = 0; mlan_ops[j]; j++) {
1508 				if (mlan_ops[j]->bss_role ==
1509 				    GET_BSS_ROLE(pmadapter->priv[i])) {
1510 					memcpy(pmadapter,
1511 					       &pmadapter->priv[i]->ops,
1512 					       mlan_ops[j],
1513 					       sizeof(mlan_operations));
1514 				}
1515 			}
1516 		}
1517 	}
1518 	/*wmm init */
1519 	wlan_wmm_init(pmadapter);
1520 	/* Initialize firmware, may return PENDING */
1521 	ret = wlan_init_priv_fw(pmadapter);
1522 	PRINTM(MINFO, "wlan_init_priv_fw returned ret=0x%x\n", ret);
1523 error:
1524 	LEAVE();
1525 	return ret;
1526 }
1527 
1528 /**
1529  *  @brief The cmdresp handler calls this function for init_fw_complete callback
1530  *
1531  *  @param pmadapter	A pointer to mlan_adapter structure
1532  *
1533  *  @return		MLAN_STATUS_SUCCESS
1534  *              The firmware initialization callback succeeded.
1535  */
1536 mlan_status
wlan_get_hw_spec_complete(IN pmlan_adapter pmadapter)1537 wlan_get_hw_spec_complete(IN pmlan_adapter pmadapter)
1538 {
1539 	mlan_status status = MLAN_STATUS_SUCCESS;
1540 	mlan_status ret = MLAN_STATUS_SUCCESS;
1541 	pmlan_callbacks pcb = &pmadapter->callbacks;
1542 	mlan_hw_info info;
1543 	mlan_bss_tbl bss_tbl;
1544 
1545 	ENTER();
1546 #ifdef MFG_CMD_SUPPORT
1547 	if (pmadapter->mfg_mode != MTRUE) {
1548 #endif
1549 		/* Check if hardware is ready */
1550 		if (pmadapter->hw_status != WlanHardwareStatusInitializing)
1551 			status = MLAN_STATUS_FAILURE;
1552 		else {
1553 			memset(pmadapter, &info, 0, sizeof(info));
1554 			info.fw_cap = pmadapter->fw_cap_info;
1555 			memset(pmadapter, &bss_tbl, 0, sizeof(bss_tbl));
1556 			memcpy(pmadapter, bss_tbl.bss_attr, pmadapter->bss_attr,
1557 			       sizeof(mlan_bss_tbl));
1558 		}
1559 		/* Invoke callback */
1560 		ret = pcb->moal_get_hw_spec_complete(pmadapter->pmoal_handle,
1561 						     status, &info, &bss_tbl);
1562 		if (ret == MLAN_STATUS_SUCCESS && status == MLAN_STATUS_SUCCESS)
1563 			memcpy(pmadapter, pmadapter->bss_attr, bss_tbl.bss_attr,
1564 			       sizeof(mlan_bss_tbl));
1565 #ifdef MFG_CMD_SUPPORT
1566 	}
1567 #endif
1568 	if (pmadapter->hw_status == WlanHardwareStatusInitializing)
1569 		ret = wlan_init_interface(pmadapter);
1570 	LEAVE();
1571 	return ret;
1572 }
1573 
1574 /**
1575  *  @brief The cmdresp handler calls this function for init_fw_complete callback
1576  *
1577  *  @param pmadapter	A pointer to mlan_adapter structure
1578  *
1579  *  @return		MLAN_STATUS_SUCCESS
1580  *              The firmware initialization callback succeeded.
1581  */
1582 mlan_status
wlan_init_fw_complete(IN pmlan_adapter pmadapter)1583 wlan_init_fw_complete(IN pmlan_adapter pmadapter)
1584 {
1585 	mlan_status status = MLAN_STATUS_SUCCESS;
1586 	mlan_status ret = MLAN_STATUS_SUCCESS;
1587 	pmlan_callbacks pcb = &pmadapter->callbacks;
1588 
1589 	ENTER();
1590 
1591 	/* Check if hardware is ready */
1592 	if (pmadapter->hw_status != WlanHardwareStatusReady)
1593 		status = MLAN_STATUS_FAILURE;
1594 
1595 	/* Reconfigure wmm parameter */
1596 	if (status == MLAN_STATUS_SUCCESS) {
1597 		wlan_prepare_cmd(wlan_get_priv(pmadapter, MLAN_BSS_ROLE_STA),
1598 				 HostCmd_CMD_WMM_PARAM_CONFIG,
1599 				 HostCmd_ACT_GEN_SET, 0, MNULL,
1600 				 &pmadapter->ac_params);
1601 	}
1602 	/* Invoke callback */
1603 	ret = pcb->moal_init_fw_complete(pmadapter->pmoal_handle, status);
1604 	LEAVE();
1605 	return ret;
1606 }
1607 
1608 /**
1609  *  @brief The cmdresp handler calls this function
1610  *          for shutdown_fw_complete callback
1611  *
1612  *  @param pmadapter    A pointer to mlan_adapter structure
1613  *
1614  *  @return             MLAN_STATUS_SUCCESS
1615  *                      The firmware shutdown callback succeeded.
1616  */
1617 mlan_status
wlan_shutdown_fw_complete(IN pmlan_adapter pmadapter)1618 wlan_shutdown_fw_complete(IN pmlan_adapter pmadapter)
1619 {
1620 	pmlan_callbacks pcb = &pmadapter->callbacks;
1621 	mlan_status status = MLAN_STATUS_SUCCESS;
1622 	mlan_status ret = MLAN_STATUS_SUCCESS;
1623 
1624 	ENTER();
1625 	pmadapter->hw_status = WlanHardwareStatusNotReady;
1626 	/* Invoke callback */
1627 	ret = pcb->moal_shutdown_fw_complete(pmadapter->pmoal_handle, status);
1628 	LEAVE();
1629 	return ret;
1630 }
1631