1 /** @file mlan_init.c
2 *
3 * @brief This file contains the initialization for FW
4 * and HW.
5 *
6 *
7 * Copyright 2008-2021 NXP
8 *
9 * This software file (the File) is distributed by NXP
10 * under the terms of the GNU General Public License Version 2, June 1991
11 * (the License). You may use, redistribute and/or modify the File in
12 * accordance with the terms and conditions of the License, a copy of which
13 * is available by writing to the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
15 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
16 *
17 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
19 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
20 * this warranty disclaimer.
21 *
22 */
23
24 /********************************************************
25 Change log:
26 10/13/2008: initial version
27 ********************************************************/
28
29 #include "mlan.h"
30 #ifdef STA_SUPPORT
31 #include "mlan_join.h"
32 #endif
33 #include "mlan_util.h"
34 #include "mlan_fw.h"
35 #include "mlan_main.h"
36 #include "mlan_init.h"
37 #include "mlan_wmm.h"
38 #include "mlan_11n.h"
39 #include "mlan_11ac.h"
40 #include "mlan_11h.h"
41 #include "mlan_meas.h"
42 #ifdef SDIO
43 #include "mlan_sdio.h"
44 #endif
45 #ifdef PCIE
46 #include "mlan_pcie.h"
47 #endif /* PCIE */
48 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
49 #include "hostsa_init.h"
50 #endif
51 #include "mlan_11ax.h"
52
53 /********************************************************
54 Global Variables
55 ********************************************************/
56
57 /*******************************************************
58 Local Functions
59 ********************************************************/
60
61 /**
62 * @brief This function adds a BSS priority table
63 *
64 * @param priv A pointer to mlan_private structure
65 *
66 * @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
67 */
wlan_add_bsspriotbl(pmlan_private priv)68 static mlan_status wlan_add_bsspriotbl(pmlan_private priv)
69 {
70 pmlan_adapter pmadapter = priv->adapter;
71 mlan_bssprio_node *pbssprio = MNULL;
72 mlan_status status = MLAN_STATUS_SUCCESS;
73
74 ENTER();
75
76 status = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
77 sizeof(mlan_bssprio_node),
78 MLAN_MEM_DEF,
79 (t_u8 **)&pbssprio);
80 if (status) {
81 PRINTM(MERROR, "Failed to allocate bsspriotbl\n");
82 LEAVE();
83 return status;
84 }
85
86 pbssprio->priv = priv;
87
88 util_init_list((pmlan_linked_list)pbssprio);
89
90 if (!pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur)
91 pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur =
92 pbssprio;
93
94 util_enqueue_list_tail(
95 pmadapter->pmoal_handle,
96 &pmadapter->bssprio_tbl[priv->bss_priority].bssprio_head,
97 (pmlan_linked_list)pbssprio,
98 pmadapter->callbacks.moal_spin_lock,
99 pmadapter->callbacks.moal_spin_unlock);
100
101 LEAVE();
102 return status;
103 }
104
105 /**
106 * @brief This function deletes the BSS priority table
107 *
108 * @param priv A pointer to mlan_private structure
109 *
110 * @return N/A
111 */
wlan_delete_bsspriotbl(pmlan_private priv)112 static t_void wlan_delete_bsspriotbl(pmlan_private priv)
113 {
114 int i;
115 pmlan_adapter pmadapter = priv->adapter;
116 mlan_bssprio_node *pbssprio_node = MNULL, *ptmp_node = MNULL,
117 **ppcur = MNULL;
118 pmlan_list_head phead;
119
120 ENTER();
121
122 for (i = 0; i < pmadapter->priv_num; ++i) {
123 phead = &pmadapter->bssprio_tbl[i].bssprio_head;
124 ppcur = &pmadapter->bssprio_tbl[i].bssprio_cur;
125 PRINTM(MINFO,
126 "Delete BSS priority table, index = %d, i = %d, phead = %p, pcur = %p\n",
127 priv->bss_index, i, phead, *ppcur);
128 if (*ppcur) {
129 pbssprio_node = (mlan_bssprio_node *)util_peek_list(
130 pmadapter->pmoal_handle, phead,
131 pmadapter->callbacks.moal_spin_lock,
132 pmadapter->callbacks.moal_spin_unlock);
133 while (pbssprio_node &&
134 ((pmlan_list_head)pbssprio_node != phead)) {
135 ptmp_node = pbssprio_node->pnext;
136 if (pbssprio_node->priv == priv) {
137 PRINTM(MINFO,
138 "Delete node, pnode = %p, pnext = %p\n",
139 pbssprio_node, ptmp_node);
140 util_unlink_list(
141 pmadapter->pmoal_handle, phead,
142 (pmlan_linked_list)pbssprio_node,
143 pmadapter->callbacks
144 .moal_spin_lock,
145 pmadapter->callbacks
146 .moal_spin_unlock);
147 pmadapter->callbacks.moal_mfree(
148 pmadapter->pmoal_handle,
149 (t_u8 *)pbssprio_node);
150 }
151 pbssprio_node = ptmp_node;
152 }
153 *ppcur = (mlan_bssprio_node *)phead;
154 }
155 }
156
157 LEAVE();
158 }
159
160 /**
161 * @brief The function handles VDLL init
162 *
163 * @param pmadapter A pointer to mlan_adapter structure
164 *
165 * @return MLAN_STATUS_SUCCESS
166 *
167 */
vdll_init(pmlan_adapter pmadapter)168 static mlan_status vdll_init(pmlan_adapter pmadapter)
169 {
170 mlan_status status = MLAN_STATUS_SUCCESS;
171 vdll_dnld_ctrl *ctrl = &pmadapter->vdll_ctrl;
172
173 ENTER();
174 memset(pmadapter, ctrl, 0, sizeof(vdll_dnld_ctrl));
175 #if defined(SDIO) || defined(PCIE)
176 if (!IS_USB(pmadapter->card_type)) {
177 ctrl->cmd_buf =
178 wlan_alloc_mlan_buffer(pmadapter,
179 MRVDRV_SIZE_OF_CMD_BUFFER, 0,
180 MOAL_MALLOC_BUFFER);
181 if (!ctrl->cmd_buf) {
182 PRINTM(MERROR,
183 "vdll init: fail to alloc command buffer");
184 status = MLAN_STATUS_FAILURE;
185 }
186 }
187 #endif
188 LEAVE();
189 return status;
190 }
191 /**
192 * @brief The function handles VDLL deinit
193 *
194 * @param pmadapter A pointer to mlan_adapter structure
195 *
196 * @return MLAN_STATUS_SUCCESS
197 *
198 */
vdll_deinit(pmlan_adapter pmadapter)199 static t_void vdll_deinit(pmlan_adapter pmadapter)
200 {
201 pmlan_callbacks pcb = &pmadapter->callbacks;
202 ENTER();
203 if (pmadapter->vdll_ctrl.vdll_mem != MNULL) {
204 if (pcb->moal_vmalloc && pcb->moal_vfree)
205 pcb->moal_vfree(pmadapter->pmoal_handle,
206 (t_u8 *)pmadapter->vdll_ctrl.vdll_mem);
207 else
208 pcb->moal_mfree(pmadapter->pmoal_handle,
209 (t_u8 *)pmadapter->vdll_ctrl.vdll_mem);
210 pmadapter->vdll_ctrl.vdll_mem = MNULL;
211 pmadapter->vdll_ctrl.vdll_len = 0;
212 }
213 #if defined(SDIO) || defined(PCIE)
214 if (!IS_USB(pmadapter->card_type) &&
215 pmadapter->vdll_ctrl.cmd_buf != MNULL) {
216 wlan_free_mlan_buffer(pmadapter, pmadapter->vdll_ctrl.cmd_buf);
217 pmadapter->vdll_ctrl.cmd_buf = MNULL;
218 }
219 #endif
220 LEAVE();
221 }
222
223 /********************************************************
224 Global Functions
225 ********************************************************/
226
227 /**
228 * @brief This function allocates buffer for the members of adapter
229 * structure like command buffer and BSSID list.
230 *
231 * @param pmadapter A pointer to mlan_adapter structure
232 *
233 * @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
234 */
wlan_allocate_adapter(pmlan_adapter pmadapter)235 mlan_status wlan_allocate_adapter(pmlan_adapter pmadapter)
236 {
237 mlan_status ret = MLAN_STATUS_SUCCESS;
238 #ifdef STA_SUPPORT
239 t_u32 beacon_buffer_size;
240 t_u32 buf_size;
241 BSSDescriptor_t *ptemp_scan_table = MNULL;
242 t_u8 chan_2g[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
243 t_u8 chan_5g[] = {12, 16, 34, 38, 42, 46, 36, 40, 44,
244 48, 52, 56, 60, 64, 100, 104, 108, 112,
245 116, 120, 124, 128, 132, 136, 140, 144, 149,
246 153, 157, 161, 165, 169, 173, 177};
247 #endif
248 #ifdef SDIO
249 t_u32 max_mp_regs = 0;
250 t_u32 mp_tx_aggr_buf_size = 0;
251 t_u32 mp_rx_aggr_buf_size = 0;
252 #endif
253
254 ENTER();
255
256 #ifdef SDIO
257 if (IS_SD(pmadapter->card_type)) {
258 max_mp_regs = pmadapter->pcard_sd->reg->max_mp_regs;
259 mp_tx_aggr_buf_size = pmadapter->pcard_sd->mp_tx_aggr_buf_size;
260 mp_rx_aggr_buf_size = pmadapter->pcard_sd->mp_rx_aggr_buf_size;
261 }
262 #endif
263
264 #ifdef STA_SUPPORT
265 /* Allocate buffer to store the BSSID list */
266 buf_size = sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST;
267 if (pmadapter->callbacks.moal_vmalloc &&
268 pmadapter->callbacks.moal_vfree)
269 ret = pmadapter->callbacks.moal_vmalloc(
270 pmadapter->pmoal_handle, buf_size,
271 (t_u8 **)&ptemp_scan_table);
272 else
273 ret = pmadapter->callbacks.moal_malloc(
274 pmadapter->pmoal_handle, buf_size, MLAN_MEM_DEF,
275 (t_u8 **)&ptemp_scan_table);
276 if (ret != MLAN_STATUS_SUCCESS || !ptemp_scan_table) {
277 PRINTM(MERROR, "Failed to allocate scan table\n");
278 LEAVE();
279 return MLAN_STATUS_FAILURE;
280 }
281 pmadapter->pscan_table = ptemp_scan_table;
282
283 if (pmadapter->fixed_beacon_buffer)
284 beacon_buffer_size = MAX_SCAN_BEACON_BUFFER;
285 else
286 beacon_buffer_size = DEFAULT_SCAN_BEACON_BUFFER;
287 if (pmadapter->callbacks.moal_vmalloc &&
288 pmadapter->callbacks.moal_vfree)
289 ret = pmadapter->callbacks.moal_vmalloc(
290 pmadapter->pmoal_handle, beacon_buffer_size,
291 (t_u8 **)&pmadapter->bcn_buf);
292 else
293 ret = pmadapter->callbacks.moal_malloc(
294 pmadapter->pmoal_handle, beacon_buffer_size,
295 MLAN_MEM_DEF, (t_u8 **)&pmadapter->bcn_buf);
296 if (ret != MLAN_STATUS_SUCCESS || !pmadapter->bcn_buf) {
297 PRINTM(MERROR, "Failed to allocate bcn buf\n");
298 LEAVE();
299 return MLAN_STATUS_FAILURE;
300 }
301 pmadapter->bcn_buf_size = beacon_buffer_size;
302
303 pmadapter->num_in_chan_stats = sizeof(chan_2g);
304 pmadapter->num_in_chan_stats += sizeof(chan_5g);
305 buf_size = sizeof(ChanStatistics_t) * pmadapter->num_in_chan_stats;
306 if (pmadapter->callbacks.moal_vmalloc &&
307 pmadapter->callbacks.moal_vfree)
308 ret = pmadapter->callbacks.moal_vmalloc(
309 pmadapter->pmoal_handle, buf_size,
310 (t_u8 **)&pmadapter->pchan_stats);
311 else
312 ret = pmadapter->callbacks.moal_malloc(
313 pmadapter->pmoal_handle, buf_size, MLAN_MEM_DEF,
314 (t_u8 **)&pmadapter->pchan_stats);
315 if (ret != MLAN_STATUS_SUCCESS || !pmadapter->pchan_stats) {
316 PRINTM(MERROR, "Failed to allocate channel statistics\n");
317 LEAVE();
318 return MLAN_STATUS_FAILURE;
319 }
320 #endif
321
322 /* Allocate command buffer */
323 ret = wlan_alloc_cmd_buffer(pmadapter);
324 if (ret != MLAN_STATUS_SUCCESS) {
325 PRINTM(MERROR, "Failed to allocate command buffer\n");
326 LEAVE();
327 return MLAN_STATUS_FAILURE;
328 }
329
330 #ifdef SDIO
331 if (IS_SD(pmadapter->card_type)) {
332 ret = pmadapter->callbacks.moal_malloc(
333 pmadapter->pmoal_handle, max_mp_regs + DMA_ALIGNMENT,
334 MLAN_MEM_DEF | MLAN_MEM_DMA,
335 (t_u8 **)&pmadapter->pcard_sd->mp_regs_buf);
336 if (ret != MLAN_STATUS_SUCCESS ||
337 !pmadapter->pcard_sd->mp_regs_buf) {
338 PRINTM(MERROR, "Failed to allocate mp_regs_buf\n");
339 LEAVE();
340 return MLAN_STATUS_FAILURE;
341 }
342 pmadapter->pcard_sd->mp_regs = (t_u8 *)ALIGN_ADDR(
343 pmadapter->pcard_sd->mp_regs_buf, DMA_ALIGNMENT);
344
345 ret = pmadapter->callbacks.moal_malloc(
346 pmadapter->pmoal_handle, MAX_SUPPORT_AMSDU_SIZE,
347 MLAN_MEM_DEF | MLAN_MEM_DMA,
348 (t_u8 **)&pmadapter->pcard_sd->rx_buffer);
349
350 if (ret != MLAN_STATUS_SUCCESS ||
351 !pmadapter->pcard_sd->rx_buffer) {
352 PRINTM(MERROR, "Failed to allocate receive buffer\n");
353 LEAVE();
354 return MLAN_STATUS_FAILURE;
355 }
356 pmadapter->pcard_sd->rx_buf = (t_u8 *)ALIGN_ADDR(
357 pmadapter->pcard_sd->rx_buffer, DMA_ALIGNMENT);
358
359 pmadapter->pcard_sd->max_sp_tx_size = MAX_SUPPORT_AMSDU_SIZE;
360 pmadapter->pcard_sd->max_sp_rx_size = MAX_SUPPORT_AMSDU_SIZE;
361 ret = wlan_alloc_sdio_mpa_buffers(
362 pmadapter, mp_tx_aggr_buf_size, mp_rx_aggr_buf_size);
363 if (ret != MLAN_STATUS_SUCCESS) {
364 PRINTM(MERROR,
365 "Failed to allocate sdio mp-a buffers\n");
366 LEAVE();
367 return MLAN_STATUS_FAILURE;
368 }
369 #ifdef DEBUG_LEVEL1
370 if (mlan_drvdbg & MMPA_D) {
371 pmadapter->pcard_sd->mpa_buf_size =
372 SDIO_MP_DBG_NUM *
373 pmadapter->pcard_sd->mp_aggr_pkt_limit *
374 MLAN_SDIO_BLOCK_SIZE;
375 if (pmadapter->callbacks.moal_vmalloc &&
376 pmadapter->callbacks.moal_vfree)
377 ret = pmadapter->callbacks.moal_vmalloc(
378 pmadapter->pmoal_handle,
379 pmadapter->pcard_sd->mpa_buf_size,
380 (t_u8 **)&pmadapter->pcard_sd->mpa_buf);
381 else
382 ret = pmadapter->callbacks.moal_malloc(
383 pmadapter->pmoal_handle,
384 pmadapter->pcard_sd->mpa_buf_size,
385 MLAN_MEM_DEF,
386 (t_u8 **)&pmadapter->pcard_sd->mpa_buf);
387 if (ret != MLAN_STATUS_SUCCESS ||
388 !pmadapter->pcard_sd->mpa_buf) {
389 PRINTM(MERROR, "Failed to allocate mpa buf\n");
390 LEAVE();
391 return MLAN_STATUS_FAILURE;
392 }
393 }
394 #endif
395 }
396 #endif
397
398 pmadapter->psleep_cfm =
399 wlan_alloc_mlan_buffer(pmadapter,
400 sizeof(opt_sleep_confirm_buffer), 0,
401 MOAL_MALLOC_BUFFER);
402
403 #ifdef PCIE
404 /* Initialize PCIE ring buffer */
405 if (IS_PCIE(pmadapter->card_type)) {
406 ret = wlan_alloc_pcie_ring_buf(pmadapter);
407 if (MLAN_STATUS_SUCCESS != ret) {
408 PRINTM(MERROR,
409 "Failed to allocate PCIE host buffers\n");
410 LEAVE();
411 return MLAN_STATUS_FAILURE;
412 }
413 }
414 #endif /* PCIE */
415
416 vdll_init(pmadapter);
417 LEAVE();
418 return MLAN_STATUS_SUCCESS;
419 }
420
421 /**
422 * @brief This function initializes the private structure
423 * and sets default values to the members of mlan_private.
424 *
425 * @param priv A pointer to mlan_private structure
426 *
427 * @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
428 */
wlan_init_priv(pmlan_private priv)429 mlan_status wlan_init_priv(pmlan_private priv)
430 {
431 t_u32 i;
432 pmlan_adapter pmadapter = priv->adapter;
433 mlan_status ret = MLAN_STATUS_SUCCESS;
434 #ifdef USB
435 pusb_tx_aggr_params pusb_tx_aggr = MNULL;
436 #endif
437
438 ENTER();
439
440 priv->media_connected = MFALSE;
441 memset(pmadapter, priv->curr_addr, 0xff, MLAN_MAC_ADDR_LENGTH);
442
443 #ifdef STA_SUPPORT
444 priv->pkt_tx_ctrl = 0;
445 priv->bss_mode = MLAN_BSS_MODE_INFRA;
446 priv->data_rate = 0; /* Initially indicate the rate as auto */
447 priv->is_data_rate_auto = MTRUE;
448 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
449 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
450
451 priv->sec_info.wep_status = Wlan802_11WEPDisabled;
452 priv->sec_info.authentication_mode = MLAN_AUTH_MODE_AUTO;
453 priv->sec_info.encryption_mode = MLAN_ENCRYPTION_MODE_NONE;
454 for (i = 0; i < MRVL_NUM_WEP_KEY; i++)
455 memset(pmadapter, &priv->wep_key[i], 0, sizeof(mrvl_wep_key_t));
456 priv->wep_key_curr_index = 0;
457 priv->ewpa_query = MFALSE;
458 priv->curr_pkt_filter = HostCmd_ACT_MAC_STATIC_DYNAMIC_BW_ENABLE |
459 HostCmd_ACT_MAC_RTS_CTS_ENABLE |
460 HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
461 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
462
463 priv->beacon_period = MLAN_BEACON_INTERVAL;
464 priv->pattempted_bss_desc = MNULL;
465 memset(pmadapter, &priv->gtk_rekey, 0,
466 sizeof(mlan_ds_misc_gtk_rekey_data));
467 memset(pmadapter, &priv->curr_bss_params, 0,
468 sizeof(priv->curr_bss_params));
469 priv->listen_interval = MLAN_DEFAULT_LISTEN_INTERVAL;
470
471 memset(pmadapter, &priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
472 priv->assoc_rsp_size = 0;
473
474 wlan_11d_priv_init(priv);
475 wlan_11h_priv_init(priv);
476
477 #ifdef UAP_SUPPORT
478 priv->is_11n_enabled = MFALSE;
479 priv->is_11ac_enabled = MFALSE;
480 priv->is_11ax_enabled = MFALSE;
481 priv->uap_bss_started = MFALSE;
482 priv->uap_host_based = MFALSE;
483 memset(pmadapter, &priv->uap_state_chan_cb, 0,
484 sizeof(priv->uap_state_chan_cb));
485 #endif
486 #ifdef UAP_SUPPORT
487 priv->num_drop_pkts = 0;
488 #endif
489 #if defined(STA_SUPPORT)
490 priv->adhoc_state_prev = ADHOC_IDLE;
491 memset(pmadapter, &priv->adhoc_last_start_ssid, 0,
492 sizeof(priv->adhoc_last_start_ssid));
493 #endif
494 priv->atim_window = 0;
495 priv->adhoc_state = ADHOC_IDLE;
496 priv->tx_power_level = 0;
497 priv->max_tx_power_level = 0;
498 priv->min_tx_power_level = 0;
499 priv->tx_rate = 0;
500 priv->rxpd_rate_info = 0;
501 priv->rx_pkt_info = MFALSE;
502 /* refer to V15 CMD_TX_RATE_QUERY */
503 priv->rxpd_vhtinfo = 0;
504 priv->rxpd_rate = 0;
505 priv->data_rssi_last = 0;
506 priv->data_rssi_avg = 0;
507 priv->data_nf_avg = 0;
508 priv->data_nf_last = 0;
509 priv->bcn_rssi_last = 0;
510 priv->bcn_rssi_avg = 0;
511 priv->bcn_nf_avg = 0;
512 priv->bcn_nf_last = 0;
513 priv->sec_info.ewpa_enabled = MFALSE;
514 priv->sec_info.wpa_enabled = MFALSE;
515 priv->sec_info.wpa2_enabled = MFALSE;
516 memset(pmadapter, &priv->wpa_ie, 0, sizeof(priv->wpa_ie));
517 memset(pmadapter, &priv->aes_key, 0, sizeof(priv->aes_key));
518 priv->wpa_ie_len = 0;
519 priv->wpa_is_gtk_set = MFALSE;
520 #if defined(STA_SUPPORT)
521 priv->pmfcfg.mfpc = 0;
522 priv->pmfcfg.mfpr = 0;
523 memset(pmadapter, &priv->pmfcfg, 0, sizeof(priv->pmfcfg));
524 #endif
525 priv->sec_info.wapi_enabled = MFALSE;
526 priv->wapi_ie_len = 0;
527 priv->sec_info.wapi_key_on = MFALSE;
528 priv->osen_ie_len = 0;
529 memset(pmadapter, &priv->osen_ie, 0, sizeof(priv->osen_ie));
530
531 memset(pmadapter, &priv->wps, 0, sizeof(priv->wps));
532 memset(pmadapter, &priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
533 priv->gen_ie_buf_len = 0;
534 #endif /* STA_SUPPORT */
535 priv->wmm_required = MTRUE;
536 priv->wmm_enabled = MFALSE;
537 priv->disconnect_reason_code = 0;
538 priv->wmm_qosinfo = 0;
539 priv->saved_wmm_qosinfo = 0;
540 priv->host_tdls_cs_support = MTRUE;
541 priv->host_tdls_uapsd_support = MTRUE;
542 priv->tdls_cs_channel = 0;
543 priv->supp_regulatory_class_len = 0;
544 priv->chan_supp_len = 0;
545 memset(pmadapter, &priv->chan_supp, 0, sizeof(priv->chan_supp));
546 memset(pmadapter, &priv->supp_regulatory_class, 0,
547 sizeof(priv->supp_regulatory_class));
548 priv->tdls_idle_time = TDLS_IDLE_TIMEOUT;
549 priv->txaggrctrl = MTRUE;
550 for (i = 0; i < MAX_MGMT_IE_INDEX; i++)
551 memset(pmadapter, &priv->mgmt_ie[i], 0, sizeof(custom_ie));
552 priv->mgmt_frame_passthru_mask = 0;
553 #ifdef STA_SUPPORT
554 priv->pcurr_bcn_buf = MNULL;
555 priv->curr_bcn_size = 0;
556 memset(pmadapter, &priv->ext_cap, 0, sizeof(priv->ext_cap));
557
558 SET_EXTCAP_OPERMODENTF(priv->ext_cap);
559 SET_EXTCAP_TDLS(priv->ext_cap);
560 SET_EXTCAP_QOS_MAP(priv->ext_cap);
561 /* Save default Extended Capability */
562 memcpy_ext(priv->adapter, &priv->def_ext_cap, &priv->ext_cap,
563 sizeof(priv->ext_cap), sizeof(priv->def_ext_cap));
564 #endif /* STA_SUPPORT */
565
566 priv->amsdu_rx_cnt = 0;
567 priv->msdu_in_rx_amsdu_cnt = 0;
568 priv->amsdu_tx_cnt = 0;
569 priv->msdu_in_tx_amsdu_cnt = 0;
570 for (i = 0; i < MAX_NUM_TID; i++)
571 priv->addba_reject[i] = ADDBA_RSP_STATUS_ACCEPT;
572 priv->addba_reject[6] = ADDBA_RSP_STATUS_REJECT;
573 priv->addba_reject[7] = ADDBA_RSP_STATUS_REJECT;
574 memcpy_ext(priv->adapter, priv->ibss_addba_reject, priv->addba_reject,
575 sizeof(priv->addba_reject), sizeof(priv->ibss_addba_reject));
576 priv->max_amsdu = 0;
577 #ifdef STA_SUPPORT
578 if (priv->bss_type == MLAN_BSS_TYPE_STA) {
579 priv->add_ba_param.tx_win_size = MLAN_STA_AMPDU_DEF_TXWINSIZE;
580 priv->add_ba_param.rx_win_size = MLAN_STA_AMPDU_DEF_RXWINSIZE;
581 }
582 #endif
583 #ifdef WIFI_DIRECT_SUPPORT
584 if (priv->bss_type == MLAN_BSS_TYPE_WIFIDIRECT) {
585 priv->add_ba_param.tx_win_size = MLAN_WFD_AMPDU_DEF_TXRXWINSIZE;
586 priv->add_ba_param.rx_win_size = MLAN_WFD_AMPDU_DEF_TXRXWINSIZE;
587 }
588 #endif
589 #ifdef UAP_SUPPORT
590 if (priv->bss_type == MLAN_BSS_TYPE_UAP) {
591 priv->add_ba_param.tx_win_size = MLAN_UAP_AMPDU_DEF_TXWINSIZE;
592 priv->add_ba_param.rx_win_size = MLAN_UAP_AMPDU_DEF_RXWINSIZE;
593 priv->aggr_prio_tbl[6].ampdu_user =
594 priv->aggr_prio_tbl[7].ampdu_user =
595 BA_STREAM_NOT_ALLOWED;
596 }
597 #endif
598 priv->user_rxwinsize = priv->add_ba_param.rx_win_size;
599 memset(pmadapter, priv->rx_seq, 0, sizeof(priv->rx_seq));
600 priv->port_ctrl_mode = MTRUE;
601 priv->port_open = MFALSE;
602 priv->prior_port_status = MFALSE;
603 priv->tx_pause = MFALSE;
604 priv->hotspot_cfg = 0;
605
606 priv->intf_hr_len = pmadapter->ops.intf_header_len;
607 memset(pmadapter, &priv->chan_rep_req, 0, sizeof(priv->chan_rep_req));
608 #ifdef USB
609 if (IS_USB(pmadapter->card_type)) {
610 pusb_tx_aggr =
611 wlan_get_usb_tx_aggr_params(pmadapter, priv->port);
612 if (pusb_tx_aggr && pusb_tx_aggr->aggr_ctrl.aggr_mode ==
613 MLAN_USB_AGGR_MODE_LEN_V2) {
614 priv->intf_hr_len = MLAN_USB_TX_AGGR_HEADER;
615 }
616 priv->port = pmadapter->tx_data_ep;
617 }
618 #endif
619 ret = wlan_add_bsspriotbl(priv);
620 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
621 hostsa_init(priv);
622 #endif
623
624 LEAVE();
625 return ret;
626 }
627
628 /**
629 * @brief This function initializes the adapter structure
630 * and sets default values to the members of adapter.
631 *
632 * @param pmadapter A pointer to mlan_adapter structure
633 *
634 * @return N/A
635 */
wlan_init_adapter(pmlan_adapter pmadapter)636 t_void wlan_init_adapter(pmlan_adapter pmadapter)
637 {
638 opt_sleep_confirm_buffer *sleep_cfm_buf = MNULL;
639 #ifdef USB
640 t_s32 i = 0;
641 #endif
642 ENTER();
643
644 if (pmadapter->psleep_cfm) {
645 sleep_cfm_buf = (opt_sleep_confirm_buffer
646 *)(pmadapter->psleep_cfm->pbuf +
647 pmadapter->psleep_cfm->data_offset);
648 }
649 #ifdef MFG_CMD_SUPPORT
650 if (pmadapter->init_para.mfg_mode == MLAN_INIT_PARA_DISABLED)
651 pmadapter->mfg_mode = MFALSE;
652 else
653 pmadapter->mfg_mode = pmadapter->init_para.mfg_mode;
654 #endif
655
656 #ifdef STA_SUPPORT
657 pmadapter->pwarm_reset_ioctl_req = MNULL;
658 #endif
659 pmadapter->pscan_ioctl_req = MNULL;
660 pmadapter->cmd_sent = MFALSE;
661 pmadapter->mlan_processing = MFALSE;
662 pmadapter->main_process_cnt = 0;
663 pmadapter->mlan_rx_processing = MFALSE;
664 pmadapter->more_rx_task_flag = MFALSE;
665 pmadapter->more_task_flag = MFALSE;
666 pmadapter->delay_task_flag = MFALSE;
667 pmadapter->data_sent = MFALSE;
668 pmadapter->data_sent_cnt = 0;
669
670 #ifdef SDIO
671 if (IS_SD(pmadapter->card_type)) {
672 pmadapter->pcard_sd->int_mode = pmadapter->init_para.int_mode;
673 pmadapter->pcard_sd->gpio_pin = pmadapter->init_para.gpio_pin;
674 pmadapter->data_sent = MTRUE;
675 pmadapter->pcard_sd->mp_rd_bitmap = 0;
676 pmadapter->pcard_sd->mp_wr_bitmap = 0;
677 pmadapter->pcard_sd->curr_rd_port =
678 pmadapter->pcard_sd->reg->start_rd_port;
679 pmadapter->pcard_sd->curr_wr_port =
680 pmadapter->pcard_sd->reg->start_wr_port;
681 pmadapter->pcard_sd->mp_data_port_mask =
682 pmadapter->pcard_sd->reg->data_port_mask;
683 pmadapter->pcard_sd->mp_invalid_update = 0;
684 memset(pmadapter, pmadapter->pcard_sd->mp_update, 0,
685 sizeof(pmadapter->pcard_sd->mp_update));
686 pmadapter->pcard_sd->mpa_tx.buf_len = 0;
687 pmadapter->pcard_sd->mpa_tx.pkt_cnt = 0;
688 pmadapter->pcard_sd->mpa_tx.start_port =
689 pmadapter->pcard_sd->reg->start_wr_port;
690
691 if (!pmadapter->init_para.mpa_tx_cfg)
692 pmadapter->pcard_sd->mpa_tx.enabled = MFALSE;
693 else if (pmadapter->init_para.mpa_tx_cfg ==
694 MLAN_INIT_PARA_DISABLED)
695 pmadapter->pcard_sd->mpa_tx.enabled = MFALSE;
696 else
697 pmadapter->pcard_sd->mpa_tx.enabled = MTRUE;
698 pmadapter->pcard_sd->mpa_tx.pkt_aggr_limit =
699 pmadapter->pcard_sd->mp_aggr_pkt_limit;
700
701 pmadapter->pcard_sd->mpa_rx.buf_len = 0;
702 pmadapter->pcard_sd->mpa_rx.pkt_cnt = 0;
703 pmadapter->pcard_sd->mpa_rx.start_port =
704 pmadapter->pcard_sd->reg->start_rd_port;
705
706 if (!pmadapter->init_para.mpa_rx_cfg)
707 pmadapter->pcard_sd->mpa_rx.enabled = MFALSE;
708 else if (pmadapter->init_para.mpa_rx_cfg ==
709 MLAN_INIT_PARA_DISABLED)
710 pmadapter->pcard_sd->mpa_rx.enabled = MFALSE;
711 else
712 pmadapter->pcard_sd->mpa_rx.enabled = MTRUE;
713 pmadapter->pcard_sd->mpa_rx.pkt_aggr_limit =
714 pmadapter->pcard_sd->mp_aggr_pkt_limit;
715 }
716 #endif
717
718 pmadapter->rx_pkts_queued = 0;
719 pmadapter->cmd_resp_received = MFALSE;
720 pmadapter->event_received = MFALSE;
721 pmadapter->data_received = MFALSE;
722 pmadapter->seq_num = 0;
723 pmadapter->num_cmd_timeout = 0;
724 pmadapter->last_init_cmd = 0;
725 pmadapter->pending_ioctl = MFALSE;
726 pmadapter->scan_processing = MFALSE;
727 pmadapter->fw_roaming = MFALSE;
728 pmadapter->userset_passphrase = MFALSE;
729 pmadapter->cmd_timer_is_set = MFALSE;
730 pmadapter->dnld_cmd_in_secs = 0;
731
732 /* PnP and power profile */
733 pmadapter->surprise_removed = MFALSE;
734 /* FW hang report */
735 pmadapter->fw_hang_report = MFALSE;
736 pmadapter->ecsa_enable = MFALSE;
737 pmadapter->getlog_enable = MFALSE;
738
739 if (!pmadapter->init_para.ps_mode) {
740 pmadapter->ps_mode = DEFAULT_PS_MODE;
741 } else if (pmadapter->init_para.ps_mode == MLAN_INIT_PARA_DISABLED)
742 pmadapter->ps_mode = Wlan802_11PowerModeCAM;
743 else
744 pmadapter->ps_mode = Wlan802_11PowerModePSP;
745 pmadapter->ps_state = PS_STATE_AWAKE;
746 pmadapter->need_to_wakeup = MFALSE;
747
748 #ifdef STA_SUPPORT
749 pmadapter->scan_block = MFALSE;
750 /* Scan type */
751 pmadapter->scan_type = MLAN_SCAN_TYPE_ACTIVE;
752 /* Scan mode */
753 pmadapter->scan_mode = HostCmd_BSS_MODE_ANY;
754 /* Scan time */
755 pmadapter->specific_scan_time = MRVDRV_SPECIFIC_SCAN_CHAN_TIME;
756 pmadapter->active_scan_time = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
757 pmadapter->passive_scan_time = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
758 if (!pmadapter->init_para.passive_to_active_scan)
759 pmadapter->passive_to_active_scan = MLAN_PASS_TO_ACT_SCAN_EN;
760 else if (pmadapter->init_para.passive_to_active_scan ==
761 MLAN_INIT_PARA_DISABLED)
762 pmadapter->passive_to_active_scan = MLAN_PASS_TO_ACT_SCAN_DIS;
763 else
764 pmadapter->passive_to_active_scan = MLAN_PASS_TO_ACT_SCAN_EN;
765
766 pmadapter->scan_chan_gap = 0;
767 pmadapter->num_in_scan_table = 0;
768 memset(pmadapter, pmadapter->pscan_table, 0,
769 (sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST));
770 pmadapter->active_scan_triggered = MFALSE;
771 if (!pmadapter->init_para.ext_scan)
772 pmadapter->ext_scan = EXT_SCAN_TYPE_ENH;
773 else if (pmadapter->init_para.ext_scan == EXT_SCAN_TYPE_ENH)
774 pmadapter->ext_scan = EXT_SCAN_TYPE_ENH;
775 else
776 pmadapter->ext_scan = MTRUE;
777 pmadapter->ext_scan_enh = MFALSE;
778 pmadapter->ext_scan_timeout = MFALSE;
779 pmadapter->scan_probes = DEFAULT_PROBES;
780
781 memset(pmadapter, pmadapter->bcn_buf, 0, pmadapter->bcn_buf_size);
782 pmadapter->pbcn_buf_end = pmadapter->bcn_buf;
783
784 pmadapter->radio_on = RADIO_ON;
785 if (!pmadapter->multiple_dtim)
786 pmadapter->multiple_dtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
787
788 pmadapter->local_listen_interval = 0; /* default value in firmware will
789 be used */
790 #endif /* STA_SUPPORT */
791
792 pmadapter->is_deep_sleep = MFALSE;
793 pmadapter->idle_time = DEEP_SLEEP_IDLE_TIME;
794 if (!pmadapter->init_para.auto_ds)
795 pmadapter->init_auto_ds = DEFAULT_AUTO_DS_MODE;
796 else if (pmadapter->init_para.auto_ds == MLAN_INIT_PARA_DISABLED)
797 pmadapter->init_auto_ds = MFALSE;
798 else
799 pmadapter->init_auto_ds = MTRUE;
800
801 pmadapter->delay_null_pkt = MFALSE;
802 pmadapter->delay_to_ps = DELAY_TO_PS_DEFAULT;
803 pmadapter->enhanced_ps_mode = PS_MODE_AUTO;
804
805 pmadapter->gen_null_pkt = MFALSE; /* Disable NULL Pkt generation-default
806 */
807 pmadapter->pps_uapsd_mode = MFALSE; /* Disable pps/uapsd mode -default
808 */
809
810 pmadapter->pm_wakeup_card_req = MFALSE;
811
812 pmadapter->pm_wakeup_fw_try = MFALSE;
813 pmadapter->pm_wakeup_timeout = 0;
814
815 if (!pmadapter->init_para.max_tx_buf)
816 pmadapter->max_tx_buf_size =
817 pmadapter->pcard_info->max_tx_buf_size;
818 else
819 pmadapter->max_tx_buf_size =
820 (t_u16)pmadapter->init_para.max_tx_buf;
821 pmadapter->tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
822 pmadapter->curr_tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
823
824 #ifdef USB
825 if (IS_USB(pmadapter->card_type)) {
826 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
827 pmadapter->pcard_usb->usb_tx_aggr[i].aggr_ctrl.enable =
828 MFALSE;
829 pmadapter->pcard_usb->usb_tx_aggr[i]
830 .aggr_ctrl.aggr_mode =
831 MLAN_USB_AGGR_MODE_LEN_V2;
832 pmadapter->pcard_usb->usb_tx_aggr[i]
833 .aggr_ctrl.aggr_align =
834 MLAN_USB_TX_AGGR_V2_ALIGN;
835 pmadapter->pcard_usb->usb_tx_aggr[i].aggr_ctrl.aggr_max =
836 MLAN_USB_TX_AGGR_MAX_LEN;
837 pmadapter->pcard_usb->usb_tx_aggr[i].aggr_ctrl.aggr_tmo =
838 MLAN_USB_TX_AGGR_TIMEOUT_MSEC * 1000;
839
840 pmadapter->pcard_usb->usb_tx_aggr[i].pmbuf_aggr = MNULL;
841 pmadapter->pcard_usb->usb_tx_aggr[i].aggr_len = 0;
842 pmadapter->pcard_usb->usb_tx_aggr[i].hold_timeout_msec =
843 MLAN_USB_TX_AGGR_TIMEOUT_MSEC;
844 pmadapter->pcard_usb->usb_tx_aggr[i].port =
845 pmadapter->tx_data_ep;
846 pmadapter->pcard_usb->usb_tx_aggr[i].phandle =
847 (t_void *)pmadapter;
848 }
849
850 pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.enable = MFALSE;
851 pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.aggr_mode =
852 MLAN_USB_AGGR_MODE_NUM;
853 pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.aggr_align =
854 MLAN_USB_RX_ALIGN_SIZE;
855 pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.aggr_max =
856 MLAN_USB_RX_MAX_AGGR_NUM;
857 pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.aggr_tmo =
858 MLAN_USB_RX_DEAGGR_TIMEOUT_USEC;
859
860 pmadapter->pcard_usb->fw_usb_aggr = MTRUE;
861 }
862 #endif
863
864 pmadapter->is_hs_configured = MFALSE;
865 pmadapter->hs_cfg.conditions = HOST_SLEEP_DEF_COND;
866 pmadapter->hs_cfg.gpio = HOST_SLEEP_DEF_GPIO;
867 pmadapter->hs_cfg.gap = HOST_SLEEP_DEF_GAP;
868 pmadapter->hs_activated = MFALSE;
869 pmadapter->min_wake_holdoff = HOST_SLEEP_DEF_WAKE_HOLDOFF;
870 pmadapter->hs_inactivity_timeout = HOST_SLEEP_DEF_INACTIVITY_TIMEOUT;
871
872 memset(pmadapter, pmadapter->event_body, 0,
873 sizeof(pmadapter->event_body));
874 pmadapter->hw_dot_11n_dev_cap = 0;
875 pmadapter->hw_dev_mcs_support = 0;
876 pmadapter->coex_rx_winsize = 1;
877 #ifdef STA_SUPPORT
878 pmadapter->chan_bandwidth = 0;
879 pmadapter->tdls_status = TDLS_NOT_SETUP;
880 #endif /* STA_SUPPORT */
881
882 pmadapter->min_ba_threshold = MIN_BA_THRESHOLD;
883 pmadapter->hw_dot_11ac_dev_cap = 0;
884 pmadapter->hw_dot_11ac_mcs_support = 0;
885 pmadapter->max_sta_conn = 0;
886 /* Initialize 802.11d */
887 wlan_11d_init(pmadapter);
888
889 wlan_11h_init(pmadapter);
890
891 wlan_wmm_init(pmadapter);
892 wlan_init_wmm_param(pmadapter);
893 pmadapter->bypass_pkt_count = 0;
894 if (pmadapter->psleep_cfm) {
895 pmadapter->psleep_cfm->buf_type = MLAN_BUF_TYPE_CMD;
896 pmadapter->psleep_cfm->data_len = sizeof(OPT_Confirm_Sleep);
897 memset(pmadapter, &sleep_cfm_buf->ps_cfm_sleep, 0,
898 sizeof(OPT_Confirm_Sleep));
899 sleep_cfm_buf->ps_cfm_sleep.command =
900 wlan_cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
901 sleep_cfm_buf->ps_cfm_sleep.size =
902 wlan_cpu_to_le16(sizeof(OPT_Confirm_Sleep));
903 sleep_cfm_buf->ps_cfm_sleep.result = 0;
904 sleep_cfm_buf->ps_cfm_sleep.action =
905 wlan_cpu_to_le16(SLEEP_CONFIRM);
906 sleep_cfm_buf->ps_cfm_sleep.sleep_cfm.resp_ctrl =
907 wlan_cpu_to_le16(RESP_NEEDED);
908 #ifdef USB
909 if (IS_USB(pmadapter->card_type)) {
910 sleep_cfm_buf->hdr =
911 wlan_cpu_to_le32(MLAN_USB_TYPE_CMD);
912 pmadapter->psleep_cfm->data_len += MLAN_TYPE_LEN;
913 }
914 #endif
915 }
916 memset(pmadapter, &pmadapter->sleep_params, 0,
917 sizeof(pmadapter->sleep_params));
918 memset(pmadapter, &pmadapter->sleep_period, 0,
919 sizeof(pmadapter->sleep_period));
920 memset(pmadapter, &pmadapter->saved_sleep_period, 0,
921 sizeof(pmadapter->saved_sleep_period));
922 pmadapter->tx_lock_flag = MFALSE;
923 pmadapter->rx_lock_flag = MFALSE;
924 pmadapter->main_lock_flag = MFALSE;
925 pmadapter->null_pkt_interval = 0;
926 pmadapter->fw_bands = 0;
927 pmadapter->config_bands = 0;
928 pmadapter->adhoc_start_band = 0;
929 pmadapter->pscan_channels = MNULL;
930 pmadapter->fw_release_number = 0;
931 pmadapter->fw_cap_info = 0;
932 memset(pmadapter, &pmadapter->upld_buf, 0, sizeof(pmadapter->upld_buf));
933 pmadapter->upld_len = 0;
934 pmadapter->event_cause = 0;
935 pmadapter->pmlan_buffer_event = MNULL;
936 memset(pmadapter, &pmadapter->region_channel, 0,
937 sizeof(pmadapter->region_channel));
938 pmadapter->region_code = 0;
939 memcpy_ext(pmadapter, pmadapter->country_code,
940 MRVDRV_DEFAULT_COUNTRY_CODE, COUNTRY_CODE_LEN,
941 COUNTRY_CODE_LEN);
942 pmadapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
943 #ifdef STA_SUPPORT
944 memset(pmadapter, &pmadapter->arp_filter, 0,
945 sizeof(pmadapter->arp_filter));
946 pmadapter->arp_filter_size = 0;
947 #endif /* STA_SUPPORT */
948
949 #ifdef PCIE
950 if (IS_PCIE(pmadapter->card_type)) {
951 pmadapter->pcard_pcie->txbd_wrptr = 0;
952 pmadapter->pcard_pcie->txbd_rdptr = 0;
953 pmadapter->pcard_pcie->rxbd_rdptr = 0;
954 pmadapter->pcard_pcie->evtbd_rdptr = 0;
955 #if defined(PCIE8997) || defined(PCIE8897)
956 if (!pmadapter->pcard_pcie->reg->use_adma) {
957 pmadapter->pcard_pcie->rxbd_wrptr =
958 pmadapter->pcard_pcie->reg
959 ->txrx_rw_ptr_rollover_ind;
960 pmadapter->pcard_pcie->evtbd_wrptr =
961 EVT_RW_PTR_ROLLOVER_IND;
962 }
963 #endif
964 #if defined(PCIE9098) || defined(PCIE9097) || defined(PCIENW62X)
965 if (pmadapter->pcard_pcie->reg->use_adma) {
966 pmadapter->pcard_pcie->rxbd_wrptr =
967 pmadapter->pcard_pcie->txrx_bd_size;
968 pmadapter->pcard_pcie->evtbd_wrptr = MLAN_MAX_EVT_BD;
969 }
970 #endif
971 }
972 #endif
973 LEAVE();
974 return;
975 }
976
977 /**
978 * @brief This function intializes the lock variables and
979 * the list heads for interface
980 *
981 * @param pmadapter A pointer to a mlan_adapter structure
982 * @param start_index start index of mlan private
983 *
984 * @return MLAN_STATUS_SUCCESS -- on success,
985 * otherwise MLAN_STATUS_FAILURE
986 *
987 */
wlan_init_priv_lock_list(pmlan_adapter pmadapter,t_u8 start_index)988 mlan_status wlan_init_priv_lock_list(pmlan_adapter pmadapter, t_u8 start_index)
989 {
990 mlan_status ret = MLAN_STATUS_SUCCESS;
991 pmlan_private priv = MNULL;
992 pmlan_callbacks pcb = &pmadapter->callbacks;
993 t_s32 i = 0;
994 t_u32 j = 0;
995 for (i = start_index; i < pmadapter->priv_num; i++) {
996 if (pmadapter->priv[i]) {
997 priv = pmadapter->priv[i];
998 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
999 &priv->rx_pkt_lock) !=
1000 MLAN_STATUS_SUCCESS) {
1001 ret = MLAN_STATUS_FAILURE;
1002 goto error;
1003 }
1004 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1005 &priv->wmm.ra_list_spinlock) !=
1006 MLAN_STATUS_SUCCESS) {
1007 ret = MLAN_STATUS_FAILURE;
1008 goto error;
1009 }
1010 #ifdef STA_SUPPORT
1011 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1012 &priv->curr_bcn_buf_lock) !=
1013 MLAN_STATUS_SUCCESS) {
1014 ret = MLAN_STATUS_FAILURE;
1015 goto error;
1016 }
1017 #endif
1018 }
1019 }
1020 for (i = start_index; i < pmadapter->priv_num; ++i) {
1021 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1022 &pmadapter->bssprio_tbl[i].bssprio_head,
1023 MTRUE, pmadapter->callbacks.moal_init_lock);
1024 pmadapter->bssprio_tbl[i].bssprio_cur = MNULL;
1025 }
1026
1027 for (i = start_index; i < pmadapter->priv_num; i++) {
1028 if (pmadapter->priv[i]) {
1029 priv = pmadapter->priv[i];
1030 for (j = 0; j < MAX_NUM_TID; ++j) {
1031 util_init_list_head(
1032 (t_void *)pmadapter->pmoal_handle,
1033 &priv->wmm.tid_tbl_ptr[j].ra_list,
1034 MTRUE,
1035 priv->adapter->callbacks.moal_init_lock);
1036 }
1037 util_init_list_head(
1038 (t_void *)pmadapter->pmoal_handle,
1039 &priv->tx_ba_stream_tbl_ptr, MTRUE,
1040 pmadapter->callbacks.moal_init_lock);
1041 util_init_list_head(
1042 (t_void *)pmadapter->pmoal_handle,
1043 &priv->rx_reorder_tbl_ptr, MTRUE,
1044 pmadapter->callbacks.moal_init_lock);
1045 util_scalar_init((t_void *)pmadapter->pmoal_handle,
1046 &priv->wmm.tx_pkts_queued, 0,
1047 priv->wmm.ra_list_spinlock,
1048 pmadapter->callbacks.moal_init_lock);
1049 util_scalar_init((t_void *)pmadapter->pmoal_handle,
1050 &priv->wmm.highest_queued_prio,
1051 HIGH_PRIO_TID,
1052 priv->wmm.ra_list_spinlock,
1053 pmadapter->callbacks.moal_init_lock);
1054 util_init_list_head(
1055 (t_void *)pmadapter->pmoal_handle,
1056 &priv->sta_list, MTRUE,
1057 pmadapter->callbacks.moal_init_lock);
1058 /* Initialize tdls_pending_txq */
1059 util_init_list_head(
1060 (t_void *)pmadapter->pmoal_handle,
1061 &priv->tdls_pending_txq, MTRUE,
1062 pmadapter->callbacks.moal_init_lock);
1063 /* Initialize bypass_txq */
1064 util_init_list_head(
1065 (t_void *)pmadapter->pmoal_handle,
1066 &priv->bypass_txq, MTRUE,
1067 pmadapter->callbacks.moal_init_lock);
1068 }
1069 }
1070 error:
1071 LEAVE();
1072 return ret;
1073 }
1074
1075 /**
1076 * @brief This function intializes the lock variables and
1077 * the list heads.
1078 *
1079 * @param pmadapter A pointer to a mlan_adapter structure
1080 *
1081 * @return MLAN_STATUS_SUCCESS -- on success,
1082 * otherwise MLAN_STATUS_FAILURE
1083 *
1084 */
wlan_init_lock_list(pmlan_adapter pmadapter)1085 mlan_status wlan_init_lock_list(pmlan_adapter pmadapter)
1086 {
1087 mlan_status ret = MLAN_STATUS_SUCCESS;
1088 pmlan_callbacks pcb = &pmadapter->callbacks;
1089 #if defined(USB)
1090 t_s32 i = 0;
1091 #endif
1092 ENTER();
1093
1094 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1095 &pmadapter->pmlan_lock) !=
1096 MLAN_STATUS_SUCCESS) {
1097 ret = MLAN_STATUS_FAILURE;
1098 goto error;
1099 }
1100 #if defined(SDIO) || defined(PCIE)
1101 if (!IS_USB(pmadapter->card_type)) {
1102 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1103 &pmadapter->pint_lock) !=
1104 MLAN_STATUS_SUCCESS) {
1105 ret = MLAN_STATUS_FAILURE;
1106 goto error;
1107 }
1108 }
1109 #endif
1110 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1111 &pmadapter->pmain_proc_lock) !=
1112 MLAN_STATUS_SUCCESS) {
1113 ret = MLAN_STATUS_FAILURE;
1114 goto error;
1115 }
1116 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1117 &pmadapter->prx_proc_lock) !=
1118 MLAN_STATUS_SUCCESS) {
1119 ret = MLAN_STATUS_FAILURE;
1120 goto error;
1121 }
1122 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1123 &pmadapter->pmlan_cmd_lock) !=
1124 MLAN_STATUS_SUCCESS) {
1125 ret = MLAN_STATUS_FAILURE;
1126 goto error;
1127 }
1128 #if defined(USB)
1129 if (IS_USB(pmadapter->card_type)) {
1130 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
1131 if (pcb->moal_init_lock(pmadapter->pmoal_handle,
1132 &pmadapter->pcard_usb
1133 ->usb_tx_aggr[i]
1134 .paggr_lock) !=
1135 MLAN_STATUS_SUCCESS) {
1136 ret = MLAN_STATUS_FAILURE;
1137 goto error;
1138 }
1139 }
1140 }
1141 #endif
1142
1143 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1144 &pmadapter->rx_data_queue, MTRUE,
1145 pmadapter->callbacks.moal_init_lock);
1146 util_scalar_init((t_void *)pmadapter->pmoal_handle,
1147 &pmadapter->pending_bridge_pkts, 0, MNULL,
1148 pmadapter->callbacks.moal_init_lock);
1149 /* Initialize cmd_free_q */
1150 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1151 &pmadapter->cmd_free_q, MTRUE,
1152 pmadapter->callbacks.moal_init_lock);
1153 /* Initialize cmd_pending_q */
1154 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1155 &pmadapter->cmd_pending_q, MTRUE,
1156 pmadapter->callbacks.moal_init_lock);
1157 /* Initialize scan_pending_q */
1158 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1159 &pmadapter->scan_pending_q, MTRUE,
1160 pmadapter->callbacks.moal_init_lock);
1161 /* Initialize ext_cmd_pending_q */
1162 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1163 &pmadapter->ext_cmd_pending_q, MTRUE,
1164 pmadapter->callbacks.moal_init_lock);
1165 /* Initialize ioctl_pending_q */
1166 util_init_list_head((t_void *)pmadapter->pmoal_handle,
1167 &pmadapter->ioctl_pending_q, MTRUE,
1168 pmadapter->callbacks.moal_init_lock);
1169
1170 error:
1171 LEAVE();
1172 return ret;
1173 }
1174
1175 /**
1176 * @brief This function releases the lock variables
1177 *
1178 * @param pmadapter A pointer to a mlan_adapter structure
1179 *
1180 * @return None
1181 *
1182 */
wlan_free_lock_list(pmlan_adapter pmadapter)1183 t_void wlan_free_lock_list(pmlan_adapter pmadapter)
1184 {
1185 pmlan_private priv = MNULL;
1186 pmlan_callbacks pcb = &pmadapter->callbacks;
1187 t_s32 i = 0;
1188 t_s32 j = 0;
1189
1190 ENTER();
1191
1192 if (pmadapter->pmlan_lock)
1193 pcb->moal_free_lock(pmadapter->pmoal_handle,
1194 pmadapter->pmlan_lock);
1195 #if defined(SDIO) || defined(PCIE)
1196 if (!IS_USB(pmadapter->card_type) && pmadapter->pint_lock)
1197 pcb->moal_free_lock(pmadapter->pmoal_handle,
1198 pmadapter->pint_lock);
1199 #endif
1200 if (pmadapter->prx_proc_lock)
1201 pcb->moal_free_lock(pmadapter->pmoal_handle,
1202 pmadapter->prx_proc_lock);
1203 if (pmadapter->pmain_proc_lock)
1204 pcb->moal_free_lock(pmadapter->pmoal_handle,
1205 pmadapter->pmain_proc_lock);
1206 if (pmadapter->pmlan_cmd_lock)
1207 pcb->moal_free_lock(pmadapter->pmoal_handle,
1208 pmadapter->pmlan_cmd_lock);
1209 #if defined(USB)
1210 if (IS_USB(pmadapter->card_type)) {
1211 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
1212 if (pmadapter->pcard_usb->usb_tx_aggr[i].paggr_lock)
1213 pcb->moal_free_lock(pmadapter->pmoal_handle,
1214 pmadapter->pcard_usb
1215 ->usb_tx_aggr[i]
1216 .paggr_lock);
1217 }
1218 }
1219 #endif
1220
1221 for (i = 0; i < pmadapter->priv_num; i++) {
1222 if (pmadapter->priv[i]) {
1223 priv = pmadapter->priv[i];
1224 if (priv->rx_pkt_lock)
1225 pcb->moal_free_lock(pmadapter->pmoal_handle,
1226 priv->rx_pkt_lock);
1227 if (priv->wmm.ra_list_spinlock)
1228 pcb->moal_free_lock(pmadapter->pmoal_handle,
1229 priv->wmm.ra_list_spinlock);
1230 #ifdef STA_SUPPORT
1231 if (priv->curr_bcn_buf_lock)
1232 pcb->moal_free_lock(pmadapter->pmoal_handle,
1233 priv->curr_bcn_buf_lock);
1234 #endif
1235 }
1236 }
1237
1238 /* Free lists */
1239 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1240 &pmadapter->rx_data_queue, pcb->moal_free_lock);
1241
1242 util_scalar_free((t_void *)pmadapter->pmoal_handle,
1243 &pmadapter->pending_bridge_pkts, pcb->moal_free_lock);
1244 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1245 &pmadapter->cmd_free_q,
1246 pmadapter->callbacks.moal_free_lock);
1247
1248 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1249 &pmadapter->cmd_pending_q,
1250 pmadapter->callbacks.moal_free_lock);
1251
1252 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1253 &pmadapter->scan_pending_q,
1254 pmadapter->callbacks.moal_free_lock);
1255
1256 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1257 &pmadapter->ext_cmd_pending_q,
1258 pmadapter->callbacks.moal_free_lock);
1259
1260 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1261 &pmadapter->ioctl_pending_q,
1262 pmadapter->callbacks.moal_free_lock);
1263
1264 for (i = 0; i < pmadapter->priv_num; i++)
1265 util_free_list_head((t_void *)pmadapter->pmoal_handle,
1266 &pmadapter->bssprio_tbl[i].bssprio_head,
1267 pcb->moal_free_lock);
1268
1269 for (i = 0; i < pmadapter->priv_num; i++) {
1270 if (pmadapter->priv[i]) {
1271 priv = pmadapter->priv[i];
1272 util_free_list_head(
1273 (t_void *)pmadapter->pmoal_handle,
1274 &priv->sta_list,
1275 priv->adapter->callbacks.moal_free_lock);
1276 util_free_list_head(
1277 (t_void *)pmadapter->pmoal_handle,
1278 &priv->tdls_pending_txq,
1279 pmadapter->callbacks.moal_free_lock);
1280 util_free_list_head(
1281 (t_void *)pmadapter->pmoal_handle,
1282 &priv->bypass_txq,
1283 pmadapter->callbacks.moal_free_lock);
1284 for (j = 0; j < MAX_NUM_TID; ++j)
1285 util_free_list_head(
1286 (t_void *)priv->adapter->pmoal_handle,
1287 &priv->wmm.tid_tbl_ptr[j].ra_list,
1288 priv->adapter->callbacks.moal_free_lock);
1289 util_free_list_head(
1290 (t_void *)priv->adapter->pmoal_handle,
1291 &priv->tx_ba_stream_tbl_ptr,
1292 priv->adapter->callbacks.moal_free_lock);
1293 util_free_list_head(
1294 (t_void *)priv->adapter->pmoal_handle,
1295 &priv->rx_reorder_tbl_ptr,
1296 priv->adapter->callbacks.moal_free_lock);
1297 util_scalar_free(
1298 (t_void *)priv->adapter->pmoal_handle,
1299 &priv->wmm.tx_pkts_queued,
1300 priv->adapter->callbacks.moal_free_lock);
1301 util_scalar_free(
1302 (t_void *)priv->adapter->pmoal_handle,
1303 &priv->wmm.highest_queued_prio,
1304 priv->adapter->callbacks.moal_free_lock);
1305 }
1306 }
1307
1308 LEAVE();
1309 return;
1310 }
1311
1312 /**
1313 * @brief This function intializes the timers
1314 *
1315 * @param pmadapter A pointer to a mlan_adapter structure
1316 *
1317 * @return MLAN_STATUS_SUCCESS -- on success,
1318 * otherwise MLAN_STATUS_FAILURE
1319 *
1320 */
wlan_init_timer(pmlan_adapter pmadapter)1321 mlan_status wlan_init_timer(pmlan_adapter pmadapter)
1322 {
1323 mlan_status ret = MLAN_STATUS_SUCCESS;
1324 pmlan_callbacks pcb = &pmadapter->callbacks;
1325 #if defined(USB)
1326 t_s32 i = 0;
1327 #endif
1328 ENTER();
1329
1330 if (pcb->moal_init_timer(
1331 pmadapter->pmoal_handle, &pmadapter->pmlan_cmd_timer,
1332 wlan_cmd_timeout_func, pmadapter) != MLAN_STATUS_SUCCESS) {
1333 ret = MLAN_STATUS_FAILURE;
1334 goto error;
1335 }
1336 #if defined(USB)
1337 if (IS_USB(pmadapter->card_type)) {
1338 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
1339 if (pcb->moal_init_timer(
1340 pmadapter->pmoal_handle,
1341 &pmadapter->pcard_usb->usb_tx_aggr[i]
1342 .paggr_hold_timer,
1343 wlan_usb_tx_aggr_timeout_func,
1344 &pmadapter->pcard_usb->usb_tx_aggr[i]) !=
1345 MLAN_STATUS_SUCCESS) {
1346 ret = MLAN_STATUS_FAILURE;
1347 goto error;
1348 }
1349 }
1350 }
1351 #endif
1352 if (pcb->moal_init_timer(pmadapter->pmoal_handle,
1353 &pmadapter->pwakeup_fw_timer,
1354 wlan_wakeup_card_timeout_func,
1355 pmadapter) != MLAN_STATUS_SUCCESS) {
1356 ret = MLAN_STATUS_FAILURE;
1357 goto error;
1358 }
1359 pmadapter->wakeup_fw_timer_is_set = MFALSE;
1360 error:
1361 LEAVE();
1362 return ret;
1363 }
1364
1365 /**
1366 * @brief This function releases the timers
1367 *
1368 * @param pmadapter A pointer to a mlan_adapter structure
1369 *
1370 * @return None
1371 *
1372 */
wlan_free_timer(pmlan_adapter pmadapter)1373 t_void wlan_free_timer(pmlan_adapter pmadapter)
1374 {
1375 pmlan_callbacks pcb = &pmadapter->callbacks;
1376 #if defined(USB)
1377 t_s32 i = 0;
1378 #endif
1379 ENTER();
1380
1381 if (pmadapter->pmlan_cmd_timer)
1382 pcb->moal_free_timer(pmadapter->pmoal_handle,
1383 pmadapter->pmlan_cmd_timer);
1384 #if defined(USB)
1385 if (IS_USB(pmadapter->card_type)) {
1386 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
1387 if (pmadapter->pcard_usb->usb_tx_aggr[i]
1388 .paggr_hold_timer)
1389 pcb->moal_free_timer(pmadapter->pmoal_handle,
1390 pmadapter->pcard_usb
1391 ->usb_tx_aggr[i]
1392 .paggr_hold_timer);
1393 }
1394 }
1395 #endif
1396
1397 if (pmadapter->pwakeup_fw_timer)
1398 pcb->moal_free_timer(pmadapter->pmoal_handle,
1399 pmadapter->pwakeup_fw_timer);
1400
1401 LEAVE();
1402 return;
1403 }
1404
1405 /**
1406 * @brief This function initializes firmware
1407 *
1408 * @param pmadapter A pointer to mlan_adapter
1409 *
1410 * @return MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or
1411 * MLAN_STATUS_FAILURE
1412 */
wlan_init_fw(pmlan_adapter pmadapter)1413 mlan_status wlan_init_fw(pmlan_adapter pmadapter)
1414 {
1415 mlan_status ret = MLAN_STATUS_SUCCESS;
1416 #ifdef PCIE
1417 pmlan_private priv = pmadapter->priv[0];
1418 #endif
1419 ENTER();
1420 /* Initialize adapter structure */
1421 wlan_init_adapter(pmadapter);
1422 #ifdef MFG_CMD_SUPPORT
1423 if (pmadapter->mfg_mode != MTRUE) {
1424 #endif
1425 wlan_adapter_get_hw_spec(pmadapter);
1426 #ifdef MFG_CMD_SUPPORT
1427 }
1428 #ifdef PCIE
1429 else if (IS_PCIE(pmadapter->card_type)) {
1430 if (MLAN_STATUS_SUCCESS != wlan_set_pcie_buf_config(priv)) {
1431 ret = MLAN_STATUS_FAILURE;
1432 goto done;
1433 }
1434 }
1435 #endif /* PCIE */
1436 #endif /* MFG_CMD_SUPPORT */
1437 if (wlan_is_cmd_pending(pmadapter)) {
1438 /* Send the first command in queue and return */
1439 if (mlan_main_process(pmadapter) == MLAN_STATUS_FAILURE)
1440 ret = MLAN_STATUS_FAILURE;
1441 else
1442 ret = MLAN_STATUS_PENDING;
1443 #if defined(MFG_CMD_SUPPORT) && defined(PCIE)
1444 if (IS_PCIE(pmadapter->card_type) && pmadapter->mfg_mode) {
1445 ret = MLAN_STATUS_SUCCESS;
1446 }
1447 #endif
1448 }
1449 #ifdef PCIE
1450 done:
1451 #endif
1452 #ifdef MFG_CMD_SUPPORT
1453 if (pmadapter->mfg_mode == MTRUE) {
1454 pmadapter->hw_status = WlanHardwareStatusInitializing;
1455 ret = wlan_get_hw_spec_complete(pmadapter);
1456 }
1457 #endif
1458 LEAVE();
1459 return ret;
1460 }
1461
1462 /**
1463 * @brief This function udpate hw spec info to each interface
1464 *
1465 * @param pmadapter A pointer to mlan_adapter
1466 *
1467 * @return MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or
1468 * MLAN_STATUS_FAILURE
1469 */
wlan_update_hw_spec(pmlan_adapter pmadapter)1470 static void wlan_update_hw_spec(pmlan_adapter pmadapter)
1471 {
1472 t_u32 i;
1473 MrvlIEtypes_He_cap_t *user_he_cap_tlv = MNULL;
1474
1475 ENTER();
1476
1477 #ifdef STA_SUPPORT
1478 if (IS_SUPPORT_MULTI_BANDS(pmadapter))
1479 pmadapter->fw_bands = (t_u8)GET_FW_DEFAULT_BANDS(pmadapter);
1480 else
1481 pmadapter->fw_bands = BAND_B;
1482
1483 if ((pmadapter->fw_bands & BAND_A) && (pmadapter->fw_bands & BAND_GN))
1484 pmadapter->fw_bands |= BAND_AN;
1485 if (!(pmadapter->fw_bands & BAND_G) && (pmadapter->fw_bands & BAND_GN))
1486 pmadapter->fw_bands &= ~BAND_GN;
1487
1488 pmadapter->config_bands = pmadapter->fw_bands;
1489 for (i = 0; i < pmadapter->priv_num; i++) {
1490 if (pmadapter->priv[i]) {
1491 pmadapter->priv[i]->config_bands = pmadapter->fw_bands;
1492 }
1493 }
1494
1495 if (pmadapter->fw_bands & BAND_A) {
1496 if (pmadapter->fw_bands & BAND_AN) {
1497 pmadapter->config_bands |= BAND_AN;
1498 for (i = 0; i < pmadapter->priv_num; i++) {
1499 if (pmadapter->priv[i])
1500 pmadapter->priv[i]->config_bands |=
1501 BAND_AN;
1502 }
1503 }
1504 if (pmadapter->fw_bands & BAND_AAC) {
1505 pmadapter->config_bands |= BAND_AAC;
1506 for (i = 0; i < pmadapter->priv_num; i++) {
1507 if (pmadapter->priv[i])
1508 pmadapter->priv[i]->config_bands |=
1509 BAND_AAC;
1510 }
1511 }
1512 pmadapter->adhoc_start_band = BAND_A;
1513 for (i = 0; i < pmadapter->priv_num; i++) {
1514 if (pmadapter->priv[i])
1515 pmadapter->priv[i]->adhoc_channel =
1516 DEFAULT_AD_HOC_CHANNEL_A;
1517 }
1518 } else if (pmadapter->fw_bands & BAND_G) {
1519 pmadapter->adhoc_start_band = BAND_G | BAND_B;
1520 for (i = 0; i < pmadapter->priv_num; i++) {
1521 if (pmadapter->priv[i])
1522 pmadapter->priv[i]->adhoc_channel =
1523 DEFAULT_AD_HOC_CHANNEL;
1524 }
1525 } else if (pmadapter->fw_bands & BAND_B) {
1526 pmadapter->adhoc_start_band = BAND_B;
1527 for (i = 0; i < pmadapter->priv_num; i++) {
1528 if (pmadapter->priv[i])
1529 pmadapter->priv[i]->adhoc_channel =
1530 DEFAULT_AD_HOC_CHANNEL;
1531 }
1532 }
1533 #endif /* STA_SUPPORT */
1534 for (i = 0; i < pmadapter->priv_num; i++) {
1535 if (pmadapter->priv[i]->curr_addr[0] == 0xff)
1536 memmove(pmadapter, pmadapter->priv[i]->curr_addr,
1537 pmadapter->permanent_addr,
1538 MLAN_MAC_ADDR_LENGTH);
1539 }
1540 for (i = 0; i < pmadapter->priv_num; i++) {
1541 if (pmadapter->priv[i])
1542 wlan_update_11n_cap(pmadapter->priv[i]);
1543 }
1544 if (ISSUPP_BEAMFORMING(pmadapter->hw_dot_11n_dev_cap)) {
1545 PRINTM(MCMND, "Enable Beamforming\n");
1546 for (i = 0; i < pmadapter->priv_num; i++) {
1547 if (pmadapter->priv[i])
1548 pmadapter->priv[i]->tx_bf_cap =
1549 pmadapter->pcard_info
1550 ->default_11n_tx_bf_cap;
1551 }
1552 }
1553 for (i = 0; i < pmadapter->priv_num; i++) {
1554 if (pmadapter->priv[i])
1555 wlan_update_11ac_cap(pmadapter->priv[i]);
1556 }
1557 if (IS_FW_SUPPORT_11AX(pmadapter)) {
1558 if (pmadapter->hw_2g_hecap_len) {
1559 pmadapter->fw_bands |= BAND_GAX;
1560 pmadapter->config_bands |= BAND_GAX;
1561 }
1562 if (pmadapter->hw_hecap_len) {
1563 pmadapter->fw_bands |= BAND_AAX;
1564 pmadapter->config_bands |= BAND_AAX;
1565 }
1566 for (i = 0; i < pmadapter->priv_num; i++) {
1567 if (pmadapter->priv[i]) {
1568 pmadapter->priv[i]->config_bands =
1569 pmadapter->config_bands;
1570 pmadapter->priv[i]->user_2g_hecap_len =
1571 pmadapter->hw_2g_hecap_len;
1572 memcpy_ext(pmadapter,
1573 pmadapter->priv[i]->user_2g_he_cap,
1574 pmadapter->hw_2g_he_cap,
1575 pmadapter->hw_2g_hecap_len,
1576 sizeof(pmadapter->priv[i]
1577 ->user_2g_he_cap));
1578 pmadapter->priv[i]->user_hecap_len =
1579 pmadapter->hw_hecap_len;
1580 memcpy_ext(
1581 pmadapter,
1582 pmadapter->priv[i]->user_he_cap,
1583 pmadapter->hw_he_cap,
1584 pmadapter->hw_hecap_len,
1585 sizeof(pmadapter->priv[i]->user_he_cap));
1586 user_he_cap_tlv =
1587 (MrvlIEtypes_He_cap_t *)&pmadapter
1588 ->priv[i]
1589 ->user_2g_he_cap;
1590 if (pmadapter->priv[i]->bss_role ==
1591 MLAN_BSS_ROLE_STA)
1592 user_he_cap_tlv->he_mac_cap[0] &=
1593 ~HE_MAC_CAP_TWT_RESP_SUPPORT;
1594 else
1595 user_he_cap_tlv->he_mac_cap[0] &=
1596 ~HE_MAC_CAP_TWT_REQ_SUPPORT;
1597 user_he_cap_tlv =
1598 (MrvlIEtypes_He_cap_t *)&pmadapter
1599 ->priv[i]
1600 ->user_he_cap;
1601 if (pmadapter->priv[i]->bss_role ==
1602 MLAN_BSS_ROLE_STA)
1603 user_he_cap_tlv->he_mac_cap[0] &=
1604 ~HE_MAC_CAP_TWT_RESP_SUPPORT;
1605 else
1606 user_he_cap_tlv->he_mac_cap[0] &=
1607 ~HE_MAC_CAP_TWT_REQ_SUPPORT;
1608 }
1609 }
1610 }
1611 LEAVE();
1612 return;
1613 }
1614
1615 /**
1616 * @brief This function initializes firmware for interface
1617 *
1618 * @param pmadapter A pointer to mlan_adapter
1619 *
1620 * @return MLAN_STATUS_SUCCESS, MLAN_STATUS_PENDING or
1621 * MLAN_STATUS_FAILURE
1622 */
wlan_init_priv_fw(pmlan_adapter pmadapter)1623 static mlan_status wlan_init_priv_fw(pmlan_adapter pmadapter)
1624 {
1625 mlan_status ret = MLAN_STATUS_SUCCESS;
1626 pmlan_private priv = MNULL;
1627 t_u8 i = 0;
1628
1629 ENTER();
1630
1631 wlan_init_priv_lock_list(pmadapter, 1);
1632 for (i = 0; i < pmadapter->priv_num; i++) {
1633 if (pmadapter->priv[i]) {
1634 priv = pmadapter->priv[i];
1635
1636 /* Initialize private structure */
1637 ret = wlan_init_priv(priv);
1638 if (ret) {
1639 ret = MLAN_STATUS_FAILURE;
1640 goto done;
1641 }
1642 }
1643 }
1644 #ifdef MFG_CMD_SUPPORT
1645 if (pmadapter->mfg_mode != MTRUE) {
1646 #endif
1647 wlan_update_hw_spec(pmadapter);
1648 /* Issue firmware initialize commands for first BSS,
1649 * for other interfaces it will be called after getting
1650 * the last init command response of previous interface
1651 */
1652 priv = wlan_get_priv(pmadapter, MLAN_BSS_ROLE_ANY);
1653 if (!priv) {
1654 ret = MLAN_STATUS_FAILURE;
1655 goto done;
1656 }
1657
1658 ret = priv->ops.init_cmd(priv, MTRUE);
1659 if (ret == MLAN_STATUS_FAILURE)
1660 goto done;
1661 #ifdef MFG_CMD_SUPPORT
1662 }
1663 #endif /* MFG_CMD_SUPPORT */
1664
1665 if (wlan_is_cmd_pending(pmadapter)) {
1666 /* Send the first command in queue and return */
1667 if (mlan_main_process(pmadapter) == MLAN_STATUS_FAILURE)
1668 ret = MLAN_STATUS_FAILURE;
1669 else
1670 ret = MLAN_STATUS_PENDING;
1671 #if defined(MFG_CMD_SUPPORT) && defined(PCIE)
1672 if (IS_PCIE(pmadapter->card_type) && pmadapter->mfg_mode) {
1673 ret = MLAN_STATUS_SUCCESS;
1674 pmadapter->hw_status = WlanHardwareStatusReady;
1675 }
1676 #endif
1677 } else {
1678 pmadapter->hw_status = WlanHardwareStatusReady;
1679 }
1680 done:
1681 LEAVE();
1682 return ret;
1683 }
1684
1685 /**
1686 * @brief This function frees the structure of adapter
1687 *
1688 * @param pmadapter A pointer to mlan_adapter structure
1689 *
1690 * @return N/A
1691 */
wlan_free_adapter(pmlan_adapter pmadapter)1692 t_void wlan_free_adapter(pmlan_adapter pmadapter)
1693 {
1694 mlan_callbacks *pcb = (mlan_callbacks *)&pmadapter->callbacks;
1695 #if defined(USB)
1696 t_s32 i = 0;
1697 #endif
1698 ENTER();
1699
1700 if (!pmadapter) {
1701 PRINTM(MERROR, "The adapter is NULL\n");
1702 LEAVE();
1703 return;
1704 }
1705
1706 wlan_cancel_all_pending_cmd(pmadapter, MTRUE);
1707 /* Free command buffer */
1708 PRINTM(MINFO, "Free Command buffer\n");
1709 wlan_free_cmd_buffer(pmadapter);
1710
1711 if (pmadapter->cmd_timer_is_set) {
1712 /* Cancel command timeout timer */
1713 pcb->moal_stop_timer(pmadapter->pmoal_handle,
1714 pmadapter->pmlan_cmd_timer);
1715 pmadapter->cmd_timer_is_set = MFALSE;
1716 }
1717 #if defined(USB)
1718 if (IS_USB(pmadapter->card_type)) {
1719 for (i = 0; i < MAX_USB_TX_PORT_NUM; i++) {
1720 if (pmadapter->pcard_usb->usb_tx_aggr[i]
1721 .aggr_hold_timer_is_set) {
1722 /* Cancel usb_tx_aggregation timeout timer */
1723 pcb->moal_stop_timer(pmadapter->pmoal_handle,
1724 pmadapter->pcard_usb
1725 ->usb_tx_aggr[i]
1726 .paggr_hold_timer);
1727 pmadapter->pcard_usb->usb_tx_aggr[i]
1728 .aggr_hold_timer_is_set = MFALSE;
1729 }
1730 }
1731 }
1732 #endif
1733 if (pmadapter->wakeup_fw_timer_is_set) {
1734 /* Cancel wakeup card timer */
1735 pcb->moal_stop_timer(pmadapter->pmoal_handle,
1736 pmadapter->pwakeup_fw_timer);
1737 pmadapter->wakeup_fw_timer_is_set = MFALSE;
1738 }
1739 wlan_free_fw_cfp_tables(pmadapter);
1740 #ifdef STA_SUPPORT
1741 PRINTM(MINFO, "Free ScanTable\n");
1742 if (pmadapter->pscan_table) {
1743 if (pcb->moal_vmalloc && pcb->moal_vfree)
1744 pcb->moal_vfree(pmadapter->pmoal_handle,
1745 (t_u8 *)pmadapter->pscan_table);
1746 else
1747 pcb->moal_mfree(pmadapter->pmoal_handle,
1748 (t_u8 *)pmadapter->pscan_table);
1749 pmadapter->pscan_table = MNULL;
1750 }
1751 if (pmadapter->pchan_stats) {
1752 if (pcb->moal_vmalloc && pcb->moal_vfree)
1753 pcb->moal_vfree(pmadapter->pmoal_handle,
1754 (t_u8 *)pmadapter->pchan_stats);
1755 else
1756 pcb->moal_mfree(pmadapter->pmoal_handle,
1757 (t_u8 *)pmadapter->pchan_stats);
1758 pmadapter->pchan_stats = MNULL;
1759 }
1760 if (pmadapter->bcn_buf) {
1761 if (pcb->moal_vmalloc && pcb->moal_vfree)
1762 pcb->moal_vfree(pmadapter->pmoal_handle,
1763 (t_u8 *)pmadapter->bcn_buf);
1764 else
1765 pcb->moal_mfree(pmadapter->pmoal_handle,
1766 (t_u8 *)pmadapter->bcn_buf);
1767 pmadapter->bcn_buf = MNULL;
1768 }
1769 #endif
1770
1771 wlan_11h_cleanup(pmadapter);
1772
1773 #ifdef SDIO
1774 if (IS_SD(pmadapter->card_type)) {
1775 if (pmadapter->pcard_sd->mp_regs_buf) {
1776 pcb->moal_mfree(
1777 pmadapter->pmoal_handle,
1778 (t_u8 *)pmadapter->pcard_sd->mp_regs_buf);
1779 pmadapter->pcard_sd->mp_regs_buf = MNULL;
1780 pmadapter->pcard_sd->mp_regs = MNULL;
1781 }
1782 if (pmadapter->pcard_sd->rx_buffer) {
1783 pcb->moal_mfree(pmadapter->pmoal_handle,
1784 (t_u8 *)pmadapter->pcard_sd->rx_buffer);
1785 pmadapter->pcard_sd->rx_buffer = MNULL;
1786 pmadapter->pcard_sd->rx_buf = MNULL;
1787 }
1788 wlan_free_sdio_mpa_buffers(pmadapter);
1789 #ifdef DEBUG_LEVEL1
1790 if (pmadapter->pcard_sd->mpa_buf) {
1791 if (pcb->moal_vmalloc && pcb->moal_vfree)
1792 pcb->moal_vfree(
1793 pmadapter->pmoal_handle,
1794 (t_u8 *)pmadapter->pcard_sd->mpa_buf);
1795 else
1796 pcb->moal_mfree(
1797 pmadapter->pmoal_handle,
1798 (t_u8 *)pmadapter->pcard_sd->mpa_buf);
1799 pmadapter->pcard_sd->mpa_buf = MNULL;
1800 pmadapter->pcard_sd->mpa_buf_size = 0;
1801 }
1802 #endif
1803 }
1804 #endif
1805
1806 wlan_free_mlan_buffer(pmadapter, pmadapter->psleep_cfm);
1807 pmadapter->psleep_cfm = MNULL;
1808
1809 #ifdef PCIE
1810 if (IS_PCIE(pmadapter->card_type)) {
1811 /* Free ssu dma buffer just in case */
1812 wlan_free_ssu_pcie_buf(pmadapter);
1813 /* Free PCIE ring buffers */
1814 wlan_free_pcie_ring_buf(pmadapter);
1815 }
1816 #endif
1817
1818 /* Free timers */
1819 wlan_free_timer(pmadapter);
1820
1821 /* Free lock variables */
1822 wlan_free_lock_list(pmadapter);
1823
1824 #ifdef SDIO
1825 if (pmadapter->pcard_sd) {
1826 pcb->moal_mfree(pmadapter->pmoal_handle,
1827 (t_u8 *)pmadapter->pcard_sd);
1828 pmadapter->pcard_sd = MNULL;
1829 }
1830 #endif
1831 #ifdef PCIE
1832 if (pmadapter->pcard_pcie) {
1833 pcb->moal_mfree(pmadapter->pmoal_handle,
1834 (t_u8 *)pmadapter->pcard_pcie);
1835 pmadapter->pcard_pcie = MNULL;
1836 }
1837 #endif
1838 #ifdef USB
1839 if (pmadapter->pcard_usb) {
1840 pcb->moal_mfree(pmadapter->pmoal_handle,
1841 (t_u8 *)pmadapter->pcard_usb);
1842 pmadapter->pcard_usb = MNULL;
1843 }
1844 #endif
1845 vdll_deinit(pmadapter);
1846
1847 LEAVE();
1848 return;
1849 }
1850
1851 /**
1852 * @brief This function frees the structure of priv
1853 *
1854 * @param pmpriv A pointer to mlan_private structure
1855 *
1856 * @return N/A
1857 */
wlan_free_priv(mlan_private * pmpriv)1858 t_void wlan_free_priv(mlan_private *pmpriv)
1859 {
1860 ENTER();
1861 wlan_clean_txrx(pmpriv);
1862 wlan_delete_bsspriotbl(pmpriv);
1863
1864 #ifdef STA_SUPPORT
1865 wlan_free_curr_bcn(pmpriv);
1866 #endif /* STA_SUPPORT */
1867
1868 #if defined(DRV_EMBEDDED_AUTHENTICATOR) || defined(DRV_EMBEDDED_SUPPLICANT)
1869 hostsa_cleanup(pmpriv);
1870 #endif /*EMBEDDED AUTHENTICATOR*/
1871
1872 wlan_delete_station_list(pmpriv);
1873 LEAVE();
1874 }
1875
1876 /**
1877 * @brief This function init interface based on pmadapter's bss_attr table
1878 *
1879 * @param pmadapter A pointer to mlan_adapter structure
1880 *
1881 * @return N/A
1882 */
wlan_init_interface(pmlan_adapter pmadapter)1883 static mlan_status wlan_init_interface(pmlan_adapter pmadapter)
1884 {
1885 mlan_status ret = MLAN_STATUS_SUCCESS;
1886 pmlan_callbacks pcb = MNULL;
1887 t_u8 i = 0;
1888 t_u32 j = 0;
1889
1890 ENTER();
1891
1892 pcb = &pmadapter->callbacks;
1893 for (i = 0; i < MLAN_MAX_BSS_NUM; i++) {
1894 if (pmadapter->bss_attr[i].active == MTRUE) {
1895 if (!pmadapter->priv[i]) {
1896 /* For valid bss_attr, allocate memory for
1897 * private structure */
1898 if (pcb->moal_vmalloc && pcb->moal_vfree)
1899 ret = pcb->moal_vmalloc(
1900 pmadapter->pmoal_handle,
1901 sizeof(mlan_private),
1902 (t_u8 **)&pmadapter->priv[i]);
1903 else
1904 ret = pcb->moal_malloc(
1905 pmadapter->pmoal_handle,
1906 sizeof(mlan_private),
1907 MLAN_MEM_DEF,
1908 (t_u8 **)&pmadapter->priv[i]);
1909 if (ret != MLAN_STATUS_SUCCESS ||
1910 !pmadapter->priv[i]) {
1911 ret = MLAN_STATUS_FAILURE;
1912 goto error;
1913 }
1914
1915 pmadapter->priv_num++;
1916 memset(pmadapter, pmadapter->priv[i], 0,
1917 sizeof(mlan_private));
1918 }
1919 pmadapter->priv[i]->adapter = pmadapter;
1920
1921 /* Save bss_type, frame_type & bss_priority */
1922 pmadapter->priv[i]->bss_type =
1923 (t_u8)pmadapter->bss_attr[i].bss_type;
1924 pmadapter->priv[i]->frame_type =
1925 (t_u8)pmadapter->bss_attr[i].frame_type;
1926 pmadapter->priv[i]->bss_priority =
1927 (t_u8)pmadapter->bss_attr[i].bss_priority;
1928 if (pmadapter->bss_attr[i].bss_type ==
1929 MLAN_BSS_TYPE_STA)
1930 pmadapter->priv[i]->bss_role =
1931 MLAN_BSS_ROLE_STA;
1932 else if (pmadapter->bss_attr[i].bss_type ==
1933 MLAN_BSS_TYPE_UAP ||
1934 pmadapter->bss_attr[i].bss_type ==
1935 MLAN_BSS_TYPE_DFS)
1936 pmadapter->priv[i]->bss_role =
1937 MLAN_BSS_ROLE_UAP;
1938 #ifdef WIFI_DIRECT_SUPPORT
1939 else if (pmadapter->bss_attr[i].bss_type ==
1940 MLAN_BSS_TYPE_WIFIDIRECT) {
1941 pmadapter->priv[i]->bss_role =
1942 MLAN_BSS_ROLE_STA;
1943 if (pmadapter->bss_attr[i].bss_virtual)
1944 pmadapter->priv[i]->bss_virtual = MTRUE;
1945 }
1946 #endif
1947 /* Save bss_index and bss_num */
1948 pmadapter->priv[i]->bss_index = i;
1949 pmadapter->priv[i]->bss_num =
1950 (t_u8)pmadapter->bss_attr[i].bss_num;
1951
1952 /* init function table */
1953 for (j = 0; mlan_ops[j]; j++) {
1954 if (mlan_ops[j]->bss_role ==
1955 GET_BSS_ROLE(pmadapter->priv[i])) {
1956 memcpy_ext(pmadapter,
1957 &pmadapter->priv[i]->ops,
1958 mlan_ops[j],
1959 sizeof(mlan_operations),
1960 sizeof(mlan_operations));
1961 break;
1962 }
1963 }
1964 }
1965 }
1966 /*wmm init*/
1967 wlan_wmm_init(pmadapter);
1968 /* Initialize firmware, may return PENDING */
1969 ret = wlan_init_priv_fw(pmadapter);
1970 PRINTM(MINFO, "wlan_init_priv_fw returned ret=0x%x\n", ret);
1971 error:
1972 LEAVE();
1973 return ret;
1974 }
1975
1976 /**
1977 * @brief The cmdresp handler calls this function for init_fw_complete callback
1978 *
1979 * @param pmadapter A pointer to mlan_adapter structure
1980 *
1981 * @return MLAN_STATUS_SUCCESS
1982 * The firmware initialization callback succeeded.
1983 */
wlan_get_hw_spec_complete(pmlan_adapter pmadapter)1984 mlan_status wlan_get_hw_spec_complete(pmlan_adapter pmadapter)
1985 {
1986 mlan_status status = MLAN_STATUS_SUCCESS;
1987 mlan_status ret = MLAN_STATUS_SUCCESS;
1988 pmlan_callbacks pcb = &pmadapter->callbacks;
1989 mlan_hw_info info;
1990 mlan_bss_tbl bss_tbl;
1991
1992 ENTER();
1993 #ifdef MFG_CMD_SUPPORT
1994 if (pmadapter->mfg_mode != MTRUE) {
1995 #endif
1996 /* Check if hardware is ready */
1997 if (pmadapter->hw_status != WlanHardwareStatusInitializing)
1998 status = MLAN_STATUS_FAILURE;
1999 else {
2000 memset(pmadapter, &info, 0, sizeof(info));
2001 info.fw_cap = pmadapter->fw_cap_info;
2002 info.fw_cap_ext = pmadapter->fw_cap_ext;
2003 memset(pmadapter, &bss_tbl, 0, sizeof(bss_tbl));
2004 memcpy_ext(pmadapter, bss_tbl.bss_attr,
2005 pmadapter->bss_attr, sizeof(mlan_bss_tbl),
2006 sizeof(mlan_bss_tbl));
2007 }
2008 /* Invoke callback */
2009 ret = pcb->moal_get_hw_spec_complete(pmadapter->pmoal_handle,
2010 status, &info, &bss_tbl);
2011 if (ret == MLAN_STATUS_SUCCESS && status == MLAN_STATUS_SUCCESS)
2012 memcpy_ext(pmadapter, pmadapter->bss_attr,
2013 bss_tbl.bss_attr, sizeof(mlan_bss_tbl),
2014 sizeof(mlan_bss_tbl));
2015 else {
2016 pmadapter->hw_status = WlanHardwareStatusNotReady;
2017 wlan_init_fw_complete(pmadapter);
2018 }
2019 #ifdef MFG_CMD_SUPPORT
2020 }
2021 #endif
2022 if (pmadapter->hw_status == WlanHardwareStatusInitializing)
2023 ret = wlan_init_interface(pmadapter);
2024 LEAVE();
2025 return ret;
2026 }
2027
2028 /**
2029 * @brief The cmdresp handler calls this function for init_fw_complete callback
2030 *
2031 * @param pmadapter A pointer to mlan_adapter structure
2032 *
2033 * @return MLAN_STATUS_SUCCESS
2034 * The firmware initialization callback succeeded.
2035 */
wlan_init_fw_complete(pmlan_adapter pmadapter)2036 mlan_status wlan_init_fw_complete(pmlan_adapter pmadapter)
2037 {
2038 mlan_status status = MLAN_STATUS_SUCCESS;
2039 mlan_status ret = MLAN_STATUS_SUCCESS;
2040 pmlan_callbacks pcb = &pmadapter->callbacks;
2041 mlan_private *pmpriv = MNULL;
2042
2043 ENTER();
2044
2045 /* Check if hardware is ready */
2046 if (pmadapter->hw_status != WlanHardwareStatusReady)
2047 status = MLAN_STATUS_FAILURE;
2048
2049 /* Reconfigure wmm parameter*/
2050 if (status == MLAN_STATUS_SUCCESS) {
2051 pmpriv = wlan_get_priv(pmadapter, MLAN_BSS_ROLE_STA);
2052 if (pmpriv)
2053 status = wlan_prepare_cmd(pmpriv,
2054 HostCmd_CMD_WMM_PARAM_CONFIG,
2055 HostCmd_ACT_GEN_SET, 0, MNULL,
2056 &pmadapter->ac_params);
2057 }
2058 /* Invoke callback */
2059 ret = pcb->moal_init_fw_complete(pmadapter->pmoal_handle, status);
2060 LEAVE();
2061 return ret;
2062 }
2063
2064 /**
2065 * @brief The cmdresp handler calls this function
2066 * for shutdown_fw_complete callback
2067 *
2068 * @param pmadapter A pointer to mlan_adapter structure
2069 *
2070 * @return MLAN_STATUS_SUCCESS
2071 * The firmware shutdown callback succeeded.
2072 */
wlan_shutdown_fw_complete(pmlan_adapter pmadapter)2073 mlan_status wlan_shutdown_fw_complete(pmlan_adapter pmadapter)
2074 {
2075 pmlan_callbacks pcb = &pmadapter->callbacks;
2076 mlan_status status = MLAN_STATUS_SUCCESS;
2077 mlan_status ret = MLAN_STATUS_SUCCESS;
2078
2079 ENTER();
2080 pmadapter->hw_status = WlanHardwareStatusNotReady;
2081 /* Invoke callback */
2082 ret = pcb->moal_shutdown_fw_complete(pmadapter->pmoal_handle, status);
2083 LEAVE();
2084 return ret;
2085 }
2086