software/drivers/sd8887/src/wlan/mlan/mlan_init.c
/**
 *  @brief This function allocates buffer for the members of adapter
 *          structure like command buffer and BSSID list.
 *
 *  @param pmadapter    A pointer to mlan_adapter structure
 *
 *  @return             MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
@brief This function allocates buffer for the members of adapter
structure like command buffer and BSSID list.

@param pmadapter    A pointer to mlan_adapter structure


@brief This function allocates buffer for the members of adapter structure like command buffer and BSSID list . @param pmadapter A pointer to mlan_adapter structure
mlan_status
wlan_allocate_adapter(pmlan_adapter pmadapter)
{
	mlan_status ret = MLAN_STATUS_SUCCESS;
#ifdef STA_SUPPORT
	t_u32 beacon_buffer_size;
	t_u32 buf_size;
	BSSDescriptor_t *ptemp_scan_table = MNULL;
	t_u8 chan_2g[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
	t_u8 chan_5g[] = {
		12, 16, 34, 38, 42, 46, 36, 40, 44,
		48, 52, 56, 60, 64, 100, 104, 108,
		112, 116, 120, 124, 128, 132, 136,
		140, 144, 149, 153, 157, 161, 165
	};
#endif
	t_u32 max_mp_regs = MAX_MP_REGS;
#if defined(SDIO_MULTI_PORT_TX_AGGR) || defined(SDIO_MULTI_PORT_RX_AGGR)
	t_u32 mp_tx_aggr_buf_size = SDIO_MP_TX_AGGR_DEF_BUF_SIZE;
	t_u32 mp_rx_aggr_buf_size = SDIO_MP_RX_AGGR_DEF_BUF_SIZE;
#endif
	ENTER();
#ifdef STA_SUPPORT
	buf_size = sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST;
	if (pmadapter->callbacks.moal_vmalloc &&
	    pmadapter->callbacks.moal_vfree)
		ret = pmadapter->callbacks.moal_vmalloc(pmadapter->pmoal_handle,
							buf_size,
							(t_u8 **)
							&ptemp_scan_table);
	else
		ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
						       buf_size, MLAN_MEM_DEF,
						       (t_u8 **)
						       &ptemp_scan_table);
	if (ret != MLAN_STATUS_SUCCESS || !ptemp_scan_table) {
		PRINTM(MERROR, "Failed to allocate scan table\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
	pmadapter->pscan_table = ptemp_scan_table;
	if (pmadapter->fixed_beacon_buffer)
		beacon_buffer_size = MAX_SCAN_BEACON_BUFFER;
	else
		beacon_buffer_size = DEFAULT_SCAN_BEACON_BUFFER;
	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
					       beacon_buffer_size, MLAN_MEM_DEF,
					       (t_u8 **)&pmadapter->bcn_buf);
	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->bcn_buf) {
		PRINTM(MERROR, "Failed to allocate bcn buf\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
	pmadapter->bcn_buf_size = beacon_buffer_size;
	pmadapter->num_in_chan_stats = sizeof(chan_2g);
	pmadapter->num_in_chan_stats += sizeof(chan_5g);
	buf_size = sizeof(ChanStatistics_t) * pmadapter->num_in_chan_stats;
	if (pmadapter->callbacks.moal_vmalloc &&
	    pmadapter->callbacks.moal_vfree)
		ret = pmadapter->callbacks.moal_vmalloc(pmadapter->pmoal_handle,
							buf_size,
							(t_u8 **)&pmadapter->
							pchan_stats);
	else
		ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
						       buf_size, MLAN_MEM_DEF,
						       (t_u8 **)&pmadapter->
						       pchan_stats);
	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->pchan_stats) {
		PRINTM(MERROR, "Failed to allocate channel statistics\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
#endif
	ret = wlan_alloc_cmd_buffer(pmadapter);
	if (ret != MLAN_STATUS_SUCCESS) {
		PRINTM(MERROR, "Failed to allocate command buffer\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
					       max_mp_regs + DMA_ALIGNMENT,
					       MLAN_MEM_DEF | MLAN_MEM_DMA,
					       (t_u8 **)&pmadapter->
					       mp_regs_buf);
	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->mp_regs_buf) {
		PRINTM(MERROR, "Failed to allocate mp_regs_buf\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
	pmadapter->mp_regs =
		(t_u8 *)ALIGN_ADDR(pmadapter->mp_regs_buf, DMA_ALIGNMENT);
#if defined(SDIO_MULTI_PORT_RX_AGGR)
	ret = pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
					       SDIO_CMD53_MAX_SIZE +
					       DMA_ALIGNMENT,
					       MLAN_MEM_DEF | MLAN_MEM_DMA,
					       (t_u8 **)&pmadapter->rx_buffer);
	if (ret != MLAN_STATUS_SUCCESS || !pmadapter->rx_buffer) {
		PRINTM(MERROR, "Failed to allocate receive buffer\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
	pmadapter->rx_buf =
		(t_u8 *)ALIGN_ADDR(pmadapter->rx_buffer, DMA_ALIGNMENT);
#endif
#if defined(SDIO_MULTI_PORT_TX_AGGR) || defined(SDIO_MULTI_PORT_RX_AGGR)
	pmadapter->max_sp_tx_size = MAX_SUPPORT_AMSDU_SIZE;
	pmadapter->max_sp_rx_size = MAX_SUPPORT_AMSDU_SIZE;
	ret = wlan_alloc_sdio_mpa_buffers(pmadapter, mp_tx_aggr_buf_size,
					  mp_rx_aggr_buf_size);
	if (ret != MLAN_STATUS_SUCCESS) {
		PRINTM(MERROR, "Failed to allocate sdio mp-a buffers\n");
		LEAVE();
		return MLAN_STATUS_FAILURE;
	}
#ifdef DEBUG_LEVEL1
	if (mlan_drvdbg & MMPA_D) {
		pmadapter->mpa_buf_size =
			SDIO_MP_DBG_NUM * SDIO_MP_AGGR_DEF_PKT_LIMIT *
			MLAN_SDIO_BLOCK_SIZE;
		if (pmadapter->callbacks.moal_vmalloc &&
		    pmadapter->callbacks.moal_vfree)
			ret = pmadapter->callbacks.moal_vmalloc(pmadapter->
								pmoal_handle,
								pmadapter->
								mpa_buf_size,
								(t_u8 **)
								&pmadapter->
								mpa_buf);
		else
			ret = pmadapter->callbacks.moal_malloc(pmadapter->
							       pmoal_handle,
							       pmadapter->
							       mpa_buf_size,
							       MLAN_MEM_DEF,
							       (t_u8 **)
							       &pmadapter->
							       mpa_buf);
		if (ret != MLAN_STATUS_SUCCESS || !pmadapter->mpa_buf) {
			PRINTM(MERROR, "Failed to allocate mpa buf\n");
			LEAVE();
			return MLAN_STATUS_FAILURE;
		}
	}
#endif
#endif
	pmadapter->psleep_cfm =
		wlan_alloc_mlan_buffer(pmadapter,
				       sizeof(opt_sleep_confirm_buffer), 0,
				       MOAL_MALLOC_BUFFER);
	LEAVE();
	return MLAN_STATUS_SUCCESS;
}
mlan_status wlan_allocate_adapter ( pmlan_adapter pmadapter ) { mlan_status ret = MLAN_STATUS_SUCCESS ; #ifdef STA_SUPPORT t_u32 beacon_buffer_size ; t_u32 buf_size ; BSSDescriptor_t * ptemp_scan_table = MNULL ; t_u8 chan_2g [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 } ; t_u8 chan_5g [ ] = { 12 , 16 , 34 , 38 , 42 , 46 , 36 , 40 , 44 , 48 , 52 , 56 , 60 , 64 , 100 , 104 , 108 , 112 , 116 , 120 , 124 , 128 , 132 , 136 , 140 , 144 , 149 , 153 , 157 , 161 , 165 } ; #endif t_u32 max_mp_regs = MAX_MP_REGS ; #if defined ( SDIO_MULTI_PORT_TX_AGGR ) || defined ( SDIO_MULTI_PORT_RX_AGGR ) t_u32 mp_tx_aggr_buf_size = SDIO_MP_TX_AGGR_DEF_BUF_SIZE ; t_u32 mp_rx_aggr_buf_size = SDIO_MP_RX_AGGR_DEF_BUF_SIZE ; #endif ENTER ( ) ; #ifdef STA_SUPPORT buf_size = sizeof ( BSSDescriptor_t ) * MRVDRV_MAX_BSSID_LIST ; if ( pmadapter -> callbacks . moal_vmalloc && pmadapter -> callbacks . moal_vfree ) ret = pmadapter -> callbacks . moal_vmalloc ( pmadapter -> pmoal_handle , buf_size , ( t_u8 * * ) & ptemp_scan_table ) ; else ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , buf_size , MLAN_MEM_DEF , ( t_u8 * * ) & ptemp_scan_table ) ; if ( ret != MLAN_STATUS_SUCCESS || ! ptemp_scan_table ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } pmadapter -> pscan_table = ptemp_scan_table ; if ( pmadapter -> fixed_beacon_buffer ) beacon_buffer_size = MAX_SCAN_BEACON_BUFFER ; else beacon_buffer_size = DEFAULT_SCAN_BEACON_BUFFER ; ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , beacon_buffer_size , MLAN_MEM_DEF , ( t_u8 * * ) & pmadapter -> bcn_buf ) ; if ( ret != MLAN_STATUS_SUCCESS || ! pmadapter -> bcn_buf ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } pmadapter -> bcn_buf_size = beacon_buffer_size ; pmadapter -> num_in_chan_stats = sizeof ( chan_2g ) ; pmadapter -> num_in_chan_stats += sizeof ( chan_5g ) ; buf_size = sizeof ( ChanStatistics_t ) * pmadapter -> num_in_chan_stats ; if ( pmadapter -> callbacks . moal_vmalloc && pmadapter -> callbacks . moal_vfree ) ret = pmadapter -> callbacks . moal_vmalloc ( pmadapter -> pmoal_handle , buf_size , ( t_u8 * * ) & pmadapter -> pchan_stats ) ; else ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , buf_size , MLAN_MEM_DEF , ( t_u8 * * ) & pmadapter -> pchan_stats ) ; if ( ret != MLAN_STATUS_SUCCESS || ! pmadapter -> pchan_stats ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } #endif ret = wlan_alloc_cmd_buffer ( pmadapter ) ; if ( ret != MLAN_STATUS_SUCCESS ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , max_mp_regs + DMA_ALIGNMENT , MLAN_MEM_DEF | MLAN_MEM_DMA , ( t_u8 * * ) & pmadapter -> mp_regs_buf ) ; if ( ret != MLAN_STATUS_SUCCESS || ! pmadapter -> mp_regs_buf ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } pmadapter -> mp_regs = ( t_u8 * ) ALIGN_ADDR ( pmadapter -> mp_regs_buf , DMA_ALIGNMENT ) ; #if defined ( SDIO_MULTI_PORT_RX_AGGR ) ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , SDIO_CMD53_MAX_SIZE + DMA_ALIGNMENT , MLAN_MEM_DEF | MLAN_MEM_DMA , ( t_u8 * * ) & pmadapter -> rx_buffer ) ; if ( ret != MLAN_STATUS_SUCCESS || ! pmadapter -> rx_buffer ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } pmadapter -> rx_buf = ( t_u8 * ) ALIGN_ADDR ( pmadapter -> rx_buffer , DMA_ALIGNMENT ) ; #endif #if defined ( SDIO_MULTI_PORT_TX_AGGR ) || defined ( SDIO_MULTI_PORT_RX_AGGR ) pmadapter -> max_sp_tx_size = MAX_SUPPORT_AMSDU_SIZE ; pmadapter -> max_sp_rx_size = MAX_SUPPORT_AMSDU_SIZE ; ret = wlan_alloc_sdio_mpa_buffers ( pmadapter , mp_tx_aggr_buf_size , mp_rx_aggr_buf_size ) ; if ( ret != MLAN_STATUS_SUCCESS ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } #ifdef DEBUG_LEVEL1 if ( mlan_drvdbg & MMPA_D ) { pmadapter -> mpa_buf_size = SDIO_MP_DBG_NUM * SDIO_MP_AGGR_DEF_PKT_LIMIT * MLAN_SDIO_BLOCK_SIZE ; if ( pmadapter -> callbacks . moal_vmalloc && pmadapter -> callbacks . moal_vfree ) ret = pmadapter -> callbacks . moal_vmalloc ( pmadapter -> pmoal_handle , pmadapter -> mpa_buf_size , ( t_u8 * * ) & pmadapter -> mpa_buf ) ; else ret = pmadapter -> callbacks . moal_malloc ( pmadapter -> pmoal_handle , pmadapter -> mpa_buf_size , MLAN_MEM_DEF , ( t_u8 * * ) & pmadapter -> mpa_buf ) ; if ( ret != MLAN_STATUS_SUCCESS || ! pmadapter -> mpa_buf ) { PRINTM ( MERROR , " \n " ) ; LEAVE ( ) ; return MLAN_STATUS_FAILURE ; } } #endif #endif pmadapter -> psleep_cfm = wlan_alloc_mlan_buffer ( pmadapter , sizeof ( opt_sleep_confirm_buffer ) , 0 , MOAL_MALLOC_BUFFER ) ; LEAVE ( ) ; return MLAN_STATUS_SUCCESS ; }
@brief This function allocates buffer for the members of adapter
          structure like command buffer and BSSID list.
@brief This function allocates buffer for the members of adapter structure like command buffer and BSSID list .
/* Allocate buffer to store the BSSID list */ /* Allocate command buffer */