/*
 * Description
 *	Transmit xmitframe from queue
 *
 * Return
 *	_SUCCESS	ok
 *	_FAIL		something error
 */
s32 rtl8723as_xmit_handler(PADAPTER padapter)
{
	struct xmit_priv *pxmitpriv;
	PHAL_DATA_TYPE phal;
	s32 ret;
	_irqL irql;


	pxmitpriv = &padapter->xmitpriv;
	phal = GET_HAL_DATA(padapter);

wait:
	ret = _rtw_down_sema(&phal->SdioXmitSema);
	if (_FAIL == ret) {
		RT_TRACE(_module_hal_xmit_c_, _drv_emerg_, ("%s: down sema fail!\n", __FUNCTION__));
		return _FAIL;
	}

next:
	if ((padapter->bDriverStopped == _TRUE) ||
		(padapter->bSurpriseRemoved == _TRUE)) {
		RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
				 ("%s: bDriverStopped(%d) bSurpriseRemoved(%d)\n",
				  __FUNCTION__, padapter->bDriverStopped, padapter->bSurpriseRemoved));
		return _FAIL;
	}

	_enter_critical_bh(&pxmitpriv->lock, &irql);
	ret = rtw_txframes_pending(padapter);
	_exit_critical_bh(&pxmitpriv->lock, &irql);
	if (ret == 0) {
		return _SUCCESS;
	}

	// dequeue frame and write to hardware

	ret = xmit_xmitframes(padapter, pxmitpriv);
	if (ret == -2) {
		rtw_msleep_os(1);
		goto next;
	}

	_enter_critical_bh(&pxmitpriv->lock, &irql);
	ret = rtw_txframes_pending(padapter);
	_exit_critical_bh(&pxmitpriv->lock, &irql);
	if (ret == 1) {
		rtw_msleep_os(1);
		goto next;
	}

	return _SUCCESS;
}
static void wps_connect_to_AP_by_certificate(rtw_network_info_t *wifi)
{
#define RETRY_COUNT		3
	int retry_count = RETRY_COUNT, ret;

	printf("\r\n=============== wifi_certificate_info ===============\n");
	printf("\r\nwps_wifi.ssid = %s\n", wifi->ssid.val);
	printf("\r\nsecurity_type = %d\n", wifi->security_type);
	printf("\r\nwps_wifi.password = %s\n", wifi->password);
	printf("\r\nssid_len = %d\n", wifi->ssid.len);
	printf("\r\npassword_len = %d\n", wifi->password_len);
	while (1) {
		ret = wifi_connect((char*)wifi->ssid.val,
						 wifi->security_type,
						 (char*)wifi->password,
						 wifi->ssid.len,
						 wifi->password_len,
						 wifi->key_id,
						 NULL);
		if (ret == RTW_SUCCESS) {
			if(retry_count == RETRY_COUNT)
				rtw_msleep_os(1000);  //When start wps with OPEN AP, AP will send a disassociate frame after STA connected, need reconnect here.
			if(RTW_SUCCESS == wifi_is_ready_to_transceive(RTW_STA_INTERFACE)){
				//printf("\r\n[WPS]Ready to tranceive!!\n");
				wps_check_and_show_connection_info();
				break;
			}
		}
		if (retry_count == 0) {
			printf("\r\n[WPS]Join bss failed\n");
			break;
		}
		retry_count --;
	}
}
static int wps_connect_to_AP_by_open_system(char *target_ssid)
{
	int retry_count = 3, ret;
	
	if (target_ssid != NULL) {
		rtw_msleep_os(500);	//wait scan complete.
		while (1) {
			ret = wifi_connect(target_ssid,
							 RTW_SECURITY_OPEN,
							 NULL,
							 strlen(target_ssid),
							 0,
							 0,
							 NULL);
			if (ret == RTW_SUCCESS) {
			  	//wps_check_and_show_connection_info();
				break;
			}
			if (retry_count == 0) {
				printf("\r\n[WPS]Join bss failed\n");
				return -1;
			}
			retry_count --;
		}
		//
	} else {
		printf("\r\n[WPS]Target SSID is NULL\n");
	}

	return 0;
}
//todo: static
s32 rtl8188es_dequeue_writeport(PADAPTER padapter, u8 *freePage)
{
	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
	struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
	struct xmit_buf *pxmitbuf;
	PADAPTER pri_padapter = padapter;
	s32 ret = 0;

#ifdef CONFIG_CONCURRENT_MODE
	if (padapter->adapter_type > 0)
		pri_padapter = padapter->pbuddy_adapter;

	if(rtw_buddy_adapter_up(padapter))
		ret = check_buddy_fwstate( padapter,  _FW_UNDER_SURVEY);
#endif

	ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);

	if (_TRUE == ret)
		pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv);
	else
		pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);

	if (pxmitbuf == NULL)
		return _TRUE;

query_free_page:
	// check if hardware tx fifo page is enough
	if( _FALSE == rtl8188es_query_tx_freepage(pri_padapter, pxmitbuf))
	{
		rtw_msleep_os(1);
		goto query_free_page;
	}

	if ((padapter->bSurpriseRemoved == _TRUE)
		|| (padapter->bDriverStopped == _TRUE)
#ifdef CONFIG_CONCURRENT_MODE
		||((padapter->pbuddy_adapter)
		&& ((padapter->pbuddy_adapter->bSurpriseRemoved) ||(padapter->pbuddy_adapter->bDriverStopped)))
#endif
	){
		RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
			 ("%s: bSurpriseRemoved(wirte port)\n", __FUNCTION__));
		goto free_xmitbuf;
	}

	rtw_write_port(padapter, ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr), pxmitbuf->len, (u8 *)pxmitbuf);

free_xmitbuf:
	//rtw_free_xmitframe(pxmitpriv, pframe);
	//pxmitbuf->priv_data = NULL;
	rtw_free_xmitbuf(pxmitpriv, pxmitbuf);

#ifdef CONFIG_SDIO_TX_TASKLET
	tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
#endif

	return _FAIL;
}
/*
 * Description
 *	Transmit xmitframe from queue
 *
 * Return
 *	_SUCCESS	ok
 *	_FAIL		something error
 */
s32 rtl8723bs_xmit_handler(PADAPTER padapter)
{
    struct xmit_priv *pxmitpriv;
    s32 ret;
    _irqL irql;


    pxmitpriv = &padapter->xmitpriv;

wait:
    ret = _rtw_down_sema(&pxmitpriv->SdioXmitSema);
    if (_FAIL == ret) {
        DBG_871X_LEVEL(_drv_emerg_, "%s: down sema fail!\n", __FUNCTION__);
        return _FAIL;
    }

next:
    if ((padapter->bDriverStopped == _TRUE) ||
            (padapter->bSurpriseRemoved == _TRUE)) {
        RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
                 ("%s: bDriverStopped(%d) bSurpriseRemoved(%d)\n",
                  __FUNCTION__, padapter->bDriverStopped, padapter->bSurpriseRemoved));
        return _FAIL;
    }

    _enter_critical_bh(&pxmitpriv->lock, &irql);
    ret = rtw_txframes_pending(padapter);
    _exit_critical_bh(&pxmitpriv->lock, &irql);
    if (ret == 0) {
        if(!padapter->registrypriv.wifi_spec)
            rtw_yield_os();
        return _SUCCESS;
    }

    // dequeue frame and write to hardware

    ret = xmit_xmitframes(padapter, pxmitpriv);
    if (ret == -2) {
        //here sleep 1ms will cause big TP loss of TX
        //from 50+ to 40+
        if(padapter->registrypriv.wifi_spec)
            rtw_msleep_os(1);
        else
            rtw_yield_os();
        goto next;
    }

    _enter_critical_bh(&pxmitpriv->lock, &irql);
    ret = rtw_txframes_pending(padapter);
    _exit_critical_bh(&pxmitpriv->lock, &irql);
    if (ret == 1) {
        //rtw_msleep_os(1);
        goto next;
    }

    return _SUCCESS;
}
Beispiel #6
0
VOID
ODM_sleep_ms(IN u4Byte	ms)
{
#if(DM_ODM_SUPPORT_TYPE & (ODM_AP|ODM_ADSL))
	
#elif(DM_ODM_SUPPORT_TYPE & ODM_CE)
	rtw_msleep_os(ms);
#elif(DM_ODM_SUPPORT_TYPE & ODM_MP)	
#endif		
}
Beispiel #7
0
/*-----------------------------------------------------------------------------
 * Function:	MPT_DeInitAdapter()
 *
 * Overview:	Extra DeInitialization for Mass Production Test.
 *
 * Input:		PADAPTER	pAdapter
 *
 * Output:		NONE
 *
 * Return:		NONE
 *
 * Revised History:
 *	When		Who		Remark
 *	05/08/2007	MHC		Create Version 0.
 *	05/18/2007	MHC		Add normal driver MPHalt code.
 *
 *---------------------------------------------------------------------------*/
VOID
MPT_DeInitAdapter(
	IN	PADAPTER	pAdapter
	)
{
	PMPT_CONTEXT		pMptCtx = &pAdapter->mppriv.MptCtx;

	pMptCtx->bMptDrvUnload = _TRUE;
	#ifdef CONFIG_RTL8723A
	_rtw_free_sema(&(pMptCtx->MPh2c_Sema));
	_cancel_timer_ex( &pMptCtx->MPh2c_timeout_timer);
	
	rtw_write32(pAdapter, 0xcc, (rtw_read32(pAdapter, 0xcc)& 0xFFFFFFFD)| 0x00000002);
	rtw_write32(pAdapter, 0x6b, (rtw_read32(pAdapter, 0x6b)& 0xFFFFFFFB));
	rtw_msleep_os(500);
	rtw_write32(pAdapter, 0x6b, (rtw_read32(pAdapter, 0x6b)& 0xFFFFFFFB)| 0x00000004);
	rtw_write32(pAdapter, 0xcc, (rtw_read32(pAdapter, 0xcc)& 0xFFFFFFFD));
	rtw_msleep_os(1000);
	
	DBG_871X("_rtw_mp_xmit_priv reinit for normal mode\n");
	_rtw_mp_xmit_priv(&pAdapter->xmitpriv);
	#endif
#if 0 // for Windows
	PlatformFreeWorkItem( &(pMptCtx->MptWorkItem) );

	while(pMptCtx->bMptWorkItemInProgress)
	{
		if(NdisWaitEvent(&(pMptCtx->MptWorkItemEvent), 50))
		{
			break;
		}
	}
	NdisFreeSpinLock( &(pMptCtx->MptWorkItemSpinLock) );
#endif
	
}
Beispiel #8
0
int reset_tsf(PADAPTER Adapter, u8 reset_port )
{
	u8 reset_cnt_before = 0, reset_cnt_after = 0, loop_cnt = 0;
	u32 reg_reset_tsf_cnt = (IFACE_PORT0==reset_port) ?
				REG_FW_RESET_TSF_CNT_0:REG_FW_RESET_TSF_CNT_1;

	rtw_scan_abort(Adapter->pbuddy_adapter);	/*	site survey will cause reset_tsf fail	*/
	reset_cnt_after = reset_cnt_before = rtw_read8(Adapter,reg_reset_tsf_cnt);
	rtl8192d_reset_tsf(Adapter, reset_port);

	while ((reset_cnt_after == reset_cnt_before ) && (loop_cnt < 10)) {
		rtw_msleep_os(100);
		loop_cnt++;
		reset_cnt_after = rtw_read8(Adapter, reg_reset_tsf_cnt);
	}

	return(loop_cnt >= 10) ? _FAIL : _TRUE;
}
Beispiel #9
0
void _rtw_mdelay_os(int ms, const char *func, const int line)
{
	#if 0
	if(ms>10)
		DBG_871X("%s:%d %s(%d)\n", func, line, __FUNCTION__, ms);
		rtw_msleep_os(ms);
	return;
	#endif


	DBG_871X("%s:%d %s(%d)\n", func, line, __FUNCTION__, ms);

#if defined(PLATFORM_LINUX)

   	mdelay((unsigned long)ms); 

#endif


}
static u8 _is_fw_read_cmd_down(_adapter* padapter, u8 msgbox_num)
{
	u8	read_down = _FALSE;
	int	retry_cnts = 100;

	u8 valid;

	//DBG_8192C(" _is_fw_read_cmd_down ,reg_1cc(%x),msg_box(%d)...\n",rtw_read8(padapter,REG_HMETFR),msgbox_num);

	do{
		valid = rtw_read8(padapter,REG_HMETFR) & BIT(msgbox_num);
		if(0 == valid ){
			read_down = _TRUE;
		}
		else
			rtw_msleep_os(1);
	}while( (!read_down) && (retry_cnts--));

	return read_down;

}
Beispiel #11
0
void _rtw_mdelay_os(int ms, const char *func, const int line)
{
	if(ms>10)
		DBG_871X("%s:%d %s(%d)\n", func, line, __FUNCTION__, ms);
		rtw_msleep_os(ms);
	return;


	DBG_871X("%s:%d %s(%d)\n", func, line, __FUNCTION__, ms);

#if defined(PLATFORM_LINUX)

   	mdelay((unsigned long)ms); 

#elif defined(PLATFORM_WINDOWS)

	NdisStallExecution(ms*1000); //(us)*1000=(ms)

#endif


}
Beispiel #12
0
static u8 rtw_sdio_wait_enough_TxOQT_space(PADAPTER padapter, u8 agg_num)
{
	u32 n = 0;
	HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);

	while (pHalData->SdioTxOQTFreeSpace < agg_num) 
	{
		if ((padapter->bSurpriseRemoved == _TRUE) 
			|| (padapter->bDriverStopped == _TRUE)
#ifdef CONFIG_CONCURRENT_MODE
			||((padapter->pbuddy_adapter) 
		&& ((padapter->pbuddy_adapter->bSurpriseRemoved) ||(padapter->pbuddy_adapter->bDriverStopped)))
#endif		
		){
			DBG_871X("%s: bSurpriseRemoved or bDriverStopped (wait TxOQT)\n", __func__);
			return _FALSE;
		}

		HalQueryTxOQTBufferStatus8189ESdio(padapter);
		
		if ((++n % 60) == 0) {
			if ((n % 300) == 0) {			
				DBG_871X("%s(%d): QOT free space(%d), agg_num: %d\n",
 				__func__, n, pHalData->SdioTxOQTFreeSpace, agg_num);
			}	
			rtw_msleep_os(1);
			//yield();
		}
	}

	pHalData->SdioTxOQTFreeSpace -= agg_num;
	
	//if (n > 1)
	//	++priv->pshare->nr_out_of_txoqt_space;

	return _TRUE;
}
static u8 rtl8723bs_query_tx_freepage(_adapter *padapter, struct xmit_buf *pxmitbuf)
{
    HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
    struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
    u8	TxRequiredPageNum = 0;
    u8	DedicatedPgNum = 0;
    u8	RequiredPublicFreePgNum = 0;
    u8	PageIdx = 0;
    u8	bResult = _TRUE;
    u32	n, deviceId;

    TxRequiredPageNum = pxmitbuf->pg_num;

    deviceId = ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr);

    // translate fifo addr to queue index
    switch (deviceId) {
    case WLAN_TX_HIQ_DEVICE_ID:
        PageIdx = HI_QUEUE_IDX;
        break;

    case WLAN_TX_MIQ_DEVICE_ID:
        PageIdx = MID_QUEUE_IDX;
        break;

    case WLAN_TX_LOQ_DEVICE_ID:
        PageIdx = LOW_QUEUE_IDX;
        break;
    }

    // check if hardware tx fifo page is enough
    n = 0;
    do {
        if ((padapter->bSurpriseRemoved == _TRUE) || (padapter->bDriverStopped == _TRUE)) {
            RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
                     ("%s: bSurpriseRemoved(update TX FIFO page)\n", __FUNCTION__));
            break;
        }

        // The number of page which public page is included is available .
        if ((pHalData->SdioTxFIFOFreePage[PageIdx]+pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]) > (TxRequiredPageNum+1)) {
            DedicatedPgNum = pHalData->SdioTxFIFOFreePage[PageIdx];
            if (TxRequiredPageNum <= DedicatedPgNum) {
                pHalData->SdioTxFIFOFreePage[PageIdx] -= TxRequiredPageNum;
                break;
            } else {
                pHalData->SdioTxFIFOFreePage[PageIdx] = 0;
                RequiredPublicFreePgNum = TxRequiredPageNum - DedicatedPgNum;
                pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX] -= RequiredPublicFreePgNum;
                break;
            }
        }

        n++;

#if 0
        if (n >= 5000)
        {
            u8 reg_value_1 = 0;
            u8 reg_value_2 = 0;
            u8 reg_value_3 = 0;

            //try to recover the transmission
            reg_value_1 = rtw_read8(padapter, REG_SYS_FUNC_EN);
            reg_value_2 = rtw_read8(padapter, REG_CR);
            reg_value_3 = rtw_read8(padapter, REG_TXPAUSE);
            DBG_871X("Before recovery: REG_SYS_FUNC_EN = 0x%X, REG_CR = 0x%X, REG_TXPAUSE = 0x%X\n", reg_value_1, reg_value_2, reg_value_3);

            rtw_write8(padapter, REG_SYS_FUNC_EN, reg_value_1 | 0x01);
            rtw_write8(padapter, REG_CR, reg_value_2 | 0xC0);
            rtw_write8(padapter, REG_TXPAUSE, 0);
            DBG_871X("After recovery: REG_SYS_FUNC_EN = 0x%X, REG_CR = 0x%X, REG_TXPAUSE = 0x%X\n",
                     rtw_read8(padapter, REG_SYS_FUNC_EN), rtw_read8(padapter, REG_CR), rtw_read8(padapter, REG_TXPAUSE));
        }
#endif

        if ((n % 0x7F) == 0) {//or 80
            //DBG_871X("%s: FIFO starvation!(%d) len=%d agg=%d page=(R)%d(A)%d\n",
            //	__func__, n, pxmitbuf->len, pxmitbuf->agg_num, pframe->pg_num, freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]);
            rtw_msleep_os(1);
        }

        // Total number of page is NOT available, so update current FIFO status
        HalQueryTxBufferStatus8723BSdio(padapter);
    } while (1);

    return bResult;
}
Beispiel #14
0
void rtl8192d_set_wowlan_cmd(_adapter* padapter)
{
	u8	res=_SUCCESS;
	u32 test=0;
	struct recv_priv	*precvpriv = &padapter->recvpriv;

	SETWOWLAN_PARM pwowlan_parm;
	struct pwrctrl_priv *pwrpriv=&padapter->pwrctrlpriv;
	
_func_enter_;

	pwowlan_parm.mode =0;
	pwowlan_parm.gpio_index=0;
	pwowlan_parm.gpio_duration=0;
	pwowlan_parm.second_mode =0;
	pwowlan_parm.reserve=0;

	//pause RX DMA
	test = rtw_read8(padapter, REG_RXPKT_NUM+2);
	test |= BIT(2);
	rtw_write8(padapter, REG_RXPKT_NUM+2, test);
	//286 BIT(1) , not 1(means idle) do rx urb
	test = rtw_read8(padapter, REG_RXPKT_NUM+2) & BIT(1);
	//printk("line(%d) 0x286=%d\n", __LINE__, rtw_read8(padapter, REG_RXPKT_NUM+2));
	//check DMA idle?
	while(test != BIT(1))
	{
		tasklet_schedule(&precvpriv->recv_tasklet);
		test = rtw_read8(padapter, REG_RXPKT_NUM+2) & BIT(1);
		rtw_msleep_os(10);
		//printk("line(%d) 0x286=%d\n", __LINE__, test);
	}
	//mask usb se0 reset by Alex and DD
	test = rtw_read8(padapter, 0xf8);
	test &= ~(BIT(3)|BIT(4));
	rtw_write8(padapter, 0xf8, test);

	pwowlan_parm.mode |=FW_WOWLAN_FUN_EN;
	//printk("\n %s 1.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
	if(pwrpriv->wowlan_pattern ==_TRUE){
		pwowlan_parm.mode |= FW_WOWLAN_PATTERN_MATCH;
	//printk("\n %s 2.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
	}
	//if(pwrpriv->wowlan_magic ==_TRUE){
		//pwowlan_parm.mode |=FW_WOWLAN_MAGIC_PKT;
	//printk("\n %s 3.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
	//}
	if(pwrpriv->wowlan_unicast ==_TRUE){
		pwowlan_parm.mode |=FW_WOWLAN_UNICAST;
	//printk("\n %s 4.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
	}
	
	rtl8192d_set_FwJoinBssReport_cmd(padapter, 1);
	
	//WOWLAN_GPIO_ACTIVE means GPIO high active
	//pwowlan_parm.mode |=FW_WOWLAN_GPIO_ACTIVE;
	pwowlan_parm.mode |=FW_WOWLAN_REKEY_WAKEUP;
	pwowlan_parm.mode |=FW_WOWLAN_DEAUTH_WAKEUP;
	
	//GPIO 0
	pwowlan_parm.gpio_index=0;
	
	//duration unit is 64us
	pwowlan_parm.gpio_duration=0xff;
	
	pwowlan_parm.second_mode|=FW_WOWLAN_GPIO_WAKEUP_EN;
	pwowlan_parm.second_mode|=FW_FW_PARSE_MAGIC_PKT;
	//printk("\n %s 5.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
	{	u8 *ptr=(u8 *)&pwowlan_parm;
		printk("\n %s H2C_WO_WLAN=%x %02x:%02x:%02x:%02x:%02x \n",__FUNCTION__,H2C_WO_WLAN_CMD,ptr[0],ptr[1],ptr[2],ptr[3],ptr[4] );
	}
	FillH2CCmd92D(padapter, H2C_WO_WLAN_CMD, 4, (u8 *)&pwowlan_parm);
		
	
	//keep alive period = 3 * 10 BCN interval
	pwowlan_parm.mode =3;
	pwowlan_parm.gpio_index=3;
	FillH2CCmd92D(padapter, KEEP_ALIVE_CONTROL_CMD, 2, (u8 *)&pwowlan_parm);
	printk("%s after KEEP_ALIVE_CONTROL_CMD register 0x81=%x \n",__FUNCTION__,rtw_read8(padapter, 0x85));

	pwowlan_parm.mode =1;
	pwowlan_parm.gpio_index=0;
	pwowlan_parm.gpio_duration=0;
	FillH2CCmd92D(padapter, DISCONNECT_DECISION_CTRL_CMD, 3, (u8 *)&pwowlan_parm);
	printk("%s after DISCONNECT_DECISION_CTRL_CMD register 0x81=%x \n",__FUNCTION__,rtw_read8(padapter, 0x85));
	
	//enable GPIO wakeup
	pwowlan_parm.mode =1;
	pwowlan_parm.gpio_index=0;
	pwowlan_parm.gpio_duration=0;
	FillH2CCmd92D(padapter, REMOTE_WAKE_CTRL_CMD, 1, (u8 *)&pwowlan_parm);
	printk("%s after DISCONNECT_DECISION_CTRL_CMD register \n",__FUNCTION__);


	
_func_exit_;

	return ;

}
Beispiel #15
0
void usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
{

	NTSTATUS NtStatus = STATUS_SUCCESS;
    USB_PIPE	hPipe;
	_irqL	irqL;

	int 	fComplete	= _FALSE;
	DWORD	dwBytes 	= 0;
	DWORD	dwErr		= USB_CANCELED_ERROR;


	struct io_req 		*pio_req;

	_adapter 			*adapter 	= (_adapter *)pintfhdl->adapter;
	struct intf_priv 	*pintfpriv	= pintfhdl->pintfpriv;
	struct dvobj_priv   * pdvobj_priv   = (struct dvobj_priv*)pintfpriv->intf_dev;

	 
    struct xmit_priv	*pxmitpriv	= &adapter->xmitpriv;
	struct io_queue 	*pio_queue 	= (struct io_queue *)adapter->pio_queue; 

	LPCUSB_FUNCS usb_funcs_vp = pdvobj_priv->usb_extension._lpUsbFuncs;


_func_enter_;
	RT_TRACE( _module_hci_ops_os_c_, _drv_info_, ("usb_write_mem(%u) pintfhdl %p wmem %p\n", __LINE__, pintfhdl, wmem));

	// fetch a io_request from the io_queue
	pio_req = alloc_ioreq(pio_queue);
		
	if ((pio_req == NULL)||(adapter->bSurpriseRemoved))
	{
		RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("async_irp_write32 : pio_req =0x%x adapter->bSurpriseRemoved=0x%x",pio_req,adapter->bSurpriseRemoved ));
		goto exit;
	}	

	_enter_critical_bh(&(pio_queue->lock), &irqL);


	// insert the io_request into processing io_queue
	rtw_list_insert_tail(&(pio_req->list),&(pio_queue->processing));
	
	
	if((adapter->bDriverStopped) || (adapter->bSurpriseRemoved) ||(adapter->pwrctrlpriv.pnp_bstop_trx)) 
	{
		RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("\npadapter->pwrctrlpriv.pnp_bstop_trx==_TRUE\n"));
		goto exit;
	}
	
	//translate DMA FIFO addr to pipehandle
	hPipe = ffaddr2pipehdl(pdvobj_priv, addr);	

	RT_TRACE( _module_hci_ops_os_c_, _drv_info_,("usb_write_mem(%u)\n",__LINE__));

	pio_req->usb_transfer_write_mem = (*usb_funcs_vp->lpIssueBulkTransfer)(
		hPipe,
		usb_write_mem_complete, 
		pio_queue,
		USB_OUT_TRANSFER,
		cnt,
		wmem,
		0);

#if 0

	(*usb_funcs_vp->lpGetTransferStatus)(pio_req->usb_transfer_write_mem , &dwBytes, &dwErr);

	while( fComplete != _TRUE)
	{
		fComplete = (*usb_funcs_vp->lpIsTransferComplete)(pio_req->usb_transfer_write_mem);
		if(fComplete==_TRUE)
		{
			(*usb_funcs_vp->lpCloseTransfer)(pio_req->usb_transfer_write_mem );
			RT_TRACE( _module_hci_ops_os_c_, _drv_err_, ("usb_write_mem finished\n"));
			break;
		}
		else
		{
			RT_TRACE( _module_hci_ops_os_c_, _drv_err_, 
				("usb_write_mem not yet finished %X\n", 
				pio_req->usb_transfer_write_mem));
			rtw_msleep_os(10);
		}
		
	}

#endif


//	_rtw_down_sema(&pio_req->sema);	

	RT_TRACE( _module_hci_ops_os_c_, _drv_info_, ("-usb_write_mem(%X)\n",pio_req->usb_transfer_write_mem));

	_exit_critical_bh(&(pio_queue->lock), &irqL);

	_rtw_down_sema(&pio_req->sema); 
	free_ioreq(pio_req, pio_queue);

exit:
_func_exit_;
	return;
}
static int rtw_gspi_suspend(struct spi_device *spi, pm_message_t mesg)
{
	struct dvobj_priv *dvobj = spi_get_drvdata(spi);
	PADAPTER padapter = dvobj->if1;
	struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
	struct net_device *pnetdev = padapter->pnetdev;
	int ret = 0;

	u32 start_time = rtw_get_current_time();

	_func_enter_;

	DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);

	pwrpriv->bInSuspend = _TRUE;

	while (pwrpriv->bips_processing == _TRUE)
		rtw_msleep_os(1);

	if((!padapter->bup) || (padapter->bDriverStopped)||(padapter->bSurpriseRemoved))
	{
		DBG_871X("%s bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n", __FUNCTION__
			,padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
		goto exit;
	}

	rtw_cancel_all_timer(padapter);
	LeaveAllPowerSaveMode(padapter);

	//padapter->net_closed = _TRUE;
	//s1.
	if(pnetdev)
	{
		netif_carrier_off(pnetdev);
		rtw_netif_stop_queue(pnetdev);
	}
#ifdef CONFIG_WOWLAN
	padapter->pwrctrlpriv.bSupportRemoteWakeup=_TRUE;
#else
	//s2.
	//s2-1.  issue rtw_disassoc_cmd to fw
	disconnect_hdl(padapter, NULL);
	//rtw_disassoc_cmd(padapter);
#endif

#ifdef CONFIG_LAYER2_ROAMING_RESUME
	if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED) )
	{
		DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n",__FUNCTION__,
				pmlmepriv->cur_network.network.Ssid.Ssid,
				MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
				pmlmepriv->cur_network.network.Ssid.SsidLength,
				pmlmepriv->assoc_ssid.SsidLength);

		pmlmepriv->to_roaming = 1;
	}
#endif

	//s2-2.  indicate disconnect to os
	rtw_indicate_disconnect(padapter);
	//s2-3.
	rtw_free_assoc_resources(padapter, 1);

	//s2-4.
	rtw_free_network_queue(padapter, _TRUE);

	rtw_led_control(padapter, LED_CTL_POWER_OFF);

	rtw_dev_unload(padapter);

	if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
		rtw_indicate_scan_done(padapter, 1);

	if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
		rtw_indicate_disconnect(padapter);

	// interface deinit
	gspi_deinit(dvobj);
	RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("%s: deinit GSPI complete!\n", __FUNCTION__));

	rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_OFF);
	rtw_mdelay_os(1);
exit:
	DBG_871X("<===  %s return %d.............. in %dms\n", __FUNCTION__
		, ret, rtw_get_passing_time_ms(start_time));

	_func_exit_;
	return ret;
}
Beispiel #17
0
/*
* rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
* @adapter: pointer to _adapter structure
* @ips_deffer_ms: the ms wiil prevent from falling into IPS after wakeup
* Return _SUCCESS or _FAIL
*/
int _rtw_pwr_wakeup(struct rtw_adapter *padapter, u32 ips_deffer_ms,
		    const char *caller)
{
	struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
	int ret = _SUCCESS;
	u32 start = rtw_get_current_time();

#ifdef CONFIG_CONCURRENT_MODE
	if (padapter->pbuddy_adapter)
		LeaveAllPowerSaveMode(padapter->pbuddy_adapter);

	if ((padapter->isprimary == false) && padapter->pbuddy_adapter) {
		padapter = padapter->pbuddy_adapter;
		pwrpriv = &padapter->pwrctrlpriv;
		pmlmepriv = &padapter->mlmepriv;
	}
#endif

	if (pwrpriv->ips_deny_time <
	    rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
		pwrpriv->ips_deny_time =
		    rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);

	if (pwrpriv->ps_processing) {
		DBG_8192D("%s wait ps_processing...\n", __func__);
		while (pwrpriv->ps_processing &&
		       rtw_get_passing_time_ms(start) <= 3000)
			rtw_msleep_os(10);
		if (pwrpriv->ps_processing)
			DBG_8192D("%s wait ps_processing timeout\n", __func__);
		else
			DBG_8192D("%s wait ps_processing done\n", __func__);
	}

	if (pwrpriv->bInternalAutoSuspend == false && pwrpriv->bInSuspend) {
		DBG_8192D("%s wait bInSuspend...\n", __func__);
		while (pwrpriv->bInSuspend &&
		       ((rtw_get_passing_time_ms(start) <= 3000 &&
		       !rtw_is_do_late_resume(pwrpriv)) ||
		       (rtw_get_passing_time_ms(start) <= 500 &&
		       rtw_is_do_late_resume(pwrpriv)))) {
			rtw_msleep_os(10);
		}
		if (pwrpriv->bInSuspend)
			DBG_8192D("%s wait bInSuspend timeout\n", __func__);
		else
			DBG_8192D("%s wait bInSuspend done\n", __func__);
	}

	/* System suspend is not allowed to wakeup */
	if ((pwrpriv->bInternalAutoSuspend == false) &&
	    (true == pwrpriv->bInSuspend)) {
		ret = _FAIL;
		goto exit;
	}

	/* block??? */
	if ((pwrpriv->bInternalAutoSuspend == true) &&
	    (padapter->net_closed == true)) {
		ret = _FAIL;
		goto exit;
	}

	/* I think this should be check in IPS, LPS, autosuspend functions... */
	if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
		ret = _SUCCESS;
		goto exit;
	}

	if (rf_off == pwrpriv->rf_pwrstate) {
#ifdef CONFIG_AUTOSUSPEND
		if (pwrpriv->brfoffbyhw == true) {
			DBG_8192D("hw still in rf_off state ...........\n");
			ret = _FAIL;
			goto exit;
		} else if (padapter->registrypriv.usbss_enable) {
			DBG_8192D("%s call autoresume_enter....\n", __func__);
			if (_FAIL == autoresume_enter(padapter)) {
				DBG_8192D
				    ("======> autoresume fail.............\n");
				ret = _FAIL;
				goto exit;
			}
		} else
#endif
		{
#ifdef CONFIG_IPS
			DBG_8192D("%s call ips_leave....\n", __func__);
			if (_FAIL == ips_leave(padapter)) {
				DBG_8192D
				    ("======> ips_leave fail.............\n");
				ret = _FAIL;
				goto exit;
			}
#endif
		}
	}

	/* TODO: the following checking need to be merged... */
	if (padapter->bDriverStopped || !padapter->bup ||
	    !padapter->hw_init_completed) {
		DBG_8192D
		    ("%s: bDriverStopped=%d, bup=%d, hw_init_completed=%u\n",
		     caller, padapter->bDriverStopped, padapter->bup,
		     padapter->hw_init_completed);
		ret = false;
		goto exit;
	}

exit:
	if (pwrpriv->ips_deny_time <
	    rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms))
		pwrpriv->ips_deny_time =
		    rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
	return ret;
}
Beispiel #18
0
s32 rtw_init_xmit_priv(PADAPTER padapter)
{
	struct xmit_buf *pxmitbuf;
	sint	res=_SUCCESS;
	int i , j=0;
	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
	
	_rtw_init_queue(&pxmitpriv->free_xmit_queue);
	_rtw_init_queue(&pxmitpriv->xmitbuf_pending_queue);
	_rtw_spinlock_init(&pxmitpriv->lock_sctx);
	_rtw_init_sema(&pxmitpriv->xmit_sema, 0);
	//_rtw_init_sema(&padapter->XmitTerminateSema, 0);
	
	pxmitpriv->padapter = padapter;
	
	pxmitpriv->pallocated_freebuf = rtw_zvmalloc(NR_XMITBUFF*sizeof(struct xmit_buf)+4);
	if(pxmitpriv->pallocated_freebuf==NULL)
	{
		DBG_871X("%s: pallocated_freebuf failed!\n", __FUNCTION__);
		res = _FAIL;
		goto exit;
	}
	pxmitpriv->xmit_freebuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_freebuf), 4);

	pxmitbuf = (struct xmit_buf *)pxmitpriv->xmit_freebuf;
	for (i = 0; i < NR_XMITBUFF; i++)
	{
		_rtw_init_listhead(&(pxmitbuf->list));

		pxmitbuf->padapter = padapter;

		/* Tx buf allocation may fail sometimes, so sleep and retry. */
		if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE)) == _FAIL) {
			rtw_msleep_os(10);
			res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE);
			if (res == _FAIL) {
				goto free_os_resource;
			}
		}
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
		pxmitbuf->phead = pxmitbuf->pbuf;
		pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMITBUF_SZ;
		pxmitbuf->pkt_len = 0;
		pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
#endif

		rtw_list_insert_tail(&(pxmitbuf->list), &(pxmitpriv->free_xmit_queue.queue));
		#ifdef DBG_XMIT_BUF
		pxmitbuf->no=i;
		#endif
		pxmitbuf++;
	}
	pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;

#ifdef CONFIG_USB_HCI
		pxmitpriv->txirp_cnt=1;
	
		_rtw_init_sema(&(pxmitpriv->tx_retevt), 0);
	
		//per AC pending irp
		pxmitpriv->beq_cnt = 0;
		pxmitpriv->bkq_cnt = 0;
		pxmitpriv->viq_cnt = 0;
		pxmitpriv->voq_cnt = 0;
#endif

	if((res = rtw_hal_init_xmit_priv(padapter)) == _FAIL)
		goto free_os_resource;
	
free_os_resource:
	if(res == _FAIL){
		pxmitbuf = (struct xmit_buf *)pxmitpriv->xmit_freebuf;
		for(j=1;j<i;j++)
		{
			rtw_os_xmit_resource_free(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE);			
			pxmitbuf++;
		}
	}		
	if((res == _FAIL)&&(pxmitpriv->pallocated_freebuf))
		rtw_vmfree(pxmitpriv->pallocated_freebuf, NR_XMITBUFF*sizeof(struct xmit_buf)+4);

exit:

_func_exit_;	

	return res;
}
Beispiel #19
0
static void promisc_test_all(int duration, unsigned char len_used)
{
	int ch;
	unsigned int start_time;
	struct eth_frame *frame;
	eth_buffer.head = NULL;
	eth_buffer.tail = NULL;

	wifi_enter_promisc_mode();
	wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used);

	for(ch = 1; ch <= 13; ch ++) {
		if(wifi_set_channel(ch) == 0)
			printf("\n\n\rSwitch to channel(%d)", ch);

		start_time = xTaskGetTickCount();

		while(1) {
			unsigned int current_time = xTaskGetTickCount();

			if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
				frame = retrieve_frame();

				if(frame) {
					int i;
					printf("\n\rTYPE: 0x%x, ", frame->type);
					printf("DA:");
					for(i = 0; i < 6; i ++)
						printf(" %02x", frame->da[i]);
					printf(", SA:");
					for(i = 0; i < 6; i ++)
						printf(" %02x", frame->sa[i]);
					printf(", len=%d", frame->len);
					printf(", RSSI=%d", frame->rssi);
#if CONFIG_INIC_CMD_RSP
					if(inic_frame_tail){
						if(inic_frame_cnt < MAX_INIC_FRAME_NUM){
							memcpy(inic_frame_tail->da, frame->da, 6);
							memcpy(inic_frame_tail->sa, frame->sa, 6);
							inic_frame_tail->len = frame->len;
							inic_frame_tail->type = frame->type;
							inic_frame_tail++;
							inic_frame_cnt++;
						}
					}
#endif	
					vPortFree((void *) frame);
				}
				else
					vTaskDelay(1);	//delay 1 tick
			}
			else
				break;	
		}
#if CONFIG_INIC_CMD_RSP
		if(inic_frame){
			inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt);
			memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
				inic_frame_tail = inic_frame;
				inic_frame_cnt = 0;
			rtw_msleep_os(10);
		}
#endif
	}

	wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);

	while((frame = retrieve_frame()) != NULL)
		vPortFree((void *) frame);
}
Beispiel #20
0
void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps)
{
	struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
#ifdef CONFIG_P2P
	struct wifidirect_info	*pwdinfo = &( padapter->wdinfo );
#endif //CONFIG_P2P
#ifdef CONFIG_TDLS
	struct sta_priv *pstapriv = &padapter->stapriv;
	_irqL irqL;
	int i, j;
	_list	*plist, *phead;
	struct sta_info *ptdls_sta;
#endif //CONFIG_TDLS

_func_enter_;

	RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
			 ("%s: PowerMode=%d Smart_PS=%d\n",
			  __FUNCTION__, ps_mode, smart_ps));

	if(ps_mode > PM_Card_Disable) {
		RT_TRACE(_module_rtl871x_pwrctrl_c_,_drv_err_,("ps_mode:%d error\n", ps_mode));
		return;
	}

	if((pwrpriv->pwr_mode == ps_mode) &&
		(pwrpriv->smart_ps == smart_ps)){
		return;
	}

	//if(pwrpriv->pwr_mode == PS_MODE_ACTIVE)
	if(ps_mode == PS_MODE_ACTIVE)
	{
#ifdef CONFIG_P2P_PS
		if(pwdinfo->opp_ps == 0)
#endif // CONFIG_P2P_PS
		{
#ifdef CONFIG_LPS_LCLK
			_enter_pwrlock(&pwrpriv->lock);
#endif
			DBG_871X("rtw_set_ps_mode(): Busy Traffic , Leave 802.11 power save..\n");

#ifdef CONFIG_TDLS
			_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);

			for(i=0; i< NUM_STA; i++)
			{
				phead = &(pstapriv->sta_hash[i]);
				plist = get_next(phead);

				while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
				{
					ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);

					if( ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE )
						issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta, 0);
					plist = get_next(plist);
				}
			}

			_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
#endif //CONFIG_TDLS

			pwrpriv->smart_ps = smart_ps;
			pwrpriv->pwr_mode = ps_mode;

			rtw_set_rpwm(padapter, PS_STATE_S4);
#ifdef CONFIG_LPS_LCLK
{
			u32 n = 0;
			while (pwrpriv->cpwm != PS_STATE_S4) {
				n++;
				if (n == 10000) break;
				if (padapter->bSurpriseRemoved == _TRUE) break;
				rtw_msleep_os(1);
			}
			if (n == 10000)
				printk(KERN_ERR "%s: wait CPWM to S4 too long! cpwm=0x%02x\n", __func__, pwrpriv->cpwm);
}
#endif
			rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
			pwrpriv->bFwCurrentInPSMode = _FALSE;
#ifdef CONFIG_LPS_LCLK
			_exit_pwrlock(&pwrpriv->lock);
#endif
		}
	}
u2Byte
mptbt_BtSetGeneral(
	IN	PADAPTER		Adapter,
	IN	PBT_REQ_CMD 	pBtReq,
	IN	PBT_RSP_CMD 	pBtRsp
	)
{
	u1Byte				h2cParaBuf[6] ={0};
	u1Byte				h2cParaLen=0;
	u2Byte				paraLen=0;
	u1Byte				retStatus=BT_STATUS_BT_OP_SUCCESS;
	u1Byte				btOpcode;
	u1Byte				btOpcodeVer=0;
	u1Byte				setType=0;
	u2Byte				setParaLen=0, validParaLen=0;
	u1Byte				regType=0, bdAddr[6]={0}, calVal=0;
	u4Byte				regAddr=0, regValue=0;
	pu4Byte 			pu4Tmp;
	pu2Byte 			pu2Tmp;
	pu1Byte 			pu1Tmp;

	//
	// check upper layer parameters
	//
	
	// check upper layer opcode version
	if(pBtReq->opCodeVer != 1)
	{
		DBG_8192C("[MPT], Error!! Upper OP code version not match!!!\n");
		pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
		return paraLen;
	}
	// check upper layer parameter length
	if(pBtReq->paraLength < 1)
	{
		DBG_8192C("[MPT], Error!! wrong parameter length=%d (should larger than 1)\n", pBtReq->paraLength);
		pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
		return paraLen;
	}
	setParaLen = pBtReq->paraLength - 1;
	setType = pBtReq->pParamStart[0];
	
	DBG_8192C("[MPT], setType=%d, setParaLen=%d\n", setType, setParaLen);

	// check parameter first
	switch(setType)
	{
		case BT_GSET_REG:
			DBG_8192C ("[MPT], [BT_GSET_REG]\n");
			validParaLen = 9;
			if(setParaLen == validParaLen)
			{
				btOpcode = BT_LO_OP_WRITE_REG_VALUE;
				regType = pBtReq->pParamStart[1];
				pu4Tmp = (pu4Byte)&pBtReq->pParamStart[2];
				regAddr = *pu4Tmp;
				pu4Tmp = (pu4Byte)&pBtReq->pParamStart[6];
				regValue = *pu4Tmp;
				DBG_8192C("[MPT], BT_GSET_REG regType=0x%x, regAddr=0x%x, regValue=0x%x!!\n", 
					regType, regAddr, regValue);
				if(regType >= BT_REG_MAX)
				{
					pBtRsp->status = (btOpcode<<8)| BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
					return paraLen;
				}
				else
				{
					if( ((BT_REG_RF==regType)&&(regAddr>0x7f)) ||
						((BT_REG_MODEM==regType)&&(regAddr>0x1ff)) ||
						((BT_REG_BLUEWIZE==regType)&&(regAddr>0xfff)) ||
						((BT_REG_VENDOR==regType)&&(regAddr>0xfff)) ||
						((BT_REG_LE==regType)&&(regAddr>0xfff)) )
					{				
						pBtRsp->status = (btOpcode<<8)| BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
						return paraLen;
					}
				}
			}
			break;
		case BT_GSET_RESET:
			DBG_8192C("[MPT], [BT_GSET_RESET]\n");
			validParaLen = 0;
			break;
		case BT_GSET_TARGET_BD_ADDR:
			DBG_8192C("[MPT], [BT_GSET_TARGET_BD_ADDR]\n");
			validParaLen = 6;
			if(setParaLen == validParaLen)
			{
				btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_H;
				if( (pBtReq->pParamStart[1]==0) &&
					(pBtReq->pParamStart[2]==0) &&
					(pBtReq->pParamStart[3]==0) &&
					(pBtReq->pParamStart[4]==0) &&
					(pBtReq->pParamStart[5]==0) &&
					(pBtReq->pParamStart[6]==0) )
				{
					DBG_8192C("[MPT], Error!! targetBDAddr=all zero\n");
					pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
					return paraLen;
				}
				if( (pBtReq->pParamStart[1]==0xff) &&
					(pBtReq->pParamStart[2]==0xff) &&
					(pBtReq->pParamStart[3]==0xff) &&
					(pBtReq->pParamStart[4]==0xff) &&
					(pBtReq->pParamStart[5]==0xff) &&
					(pBtReq->pParamStart[6]==0xff) )
				{
					DBG_8192C("[MPT], Error!! targetBDAddr=all 0xf\n");
					pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
					return paraLen;
				}
				bdAddr[0] = pBtReq->pParamStart[6];
				bdAddr[1] = pBtReq->pParamStart[5];
				bdAddr[2] = pBtReq->pParamStart[4];
				bdAddr[3] = pBtReq->pParamStart[3];
				bdAddr[4] = pBtReq->pParamStart[2];
				bdAddr[5] = pBtReq->pParamStart[1];
				DBG_8192C ("[MPT], target BDAddr:%s", &bdAddr[0]);
			}
			break;
		case BT_GSET_TX_PWR_FINETUNE:
			DBG_8192C("[MPT], [BT_GSET_TX_PWR_FINETUNE]\n");
			validParaLen = 1;
			if(setParaLen == validParaLen)
			{
				btOpcode = BT_LO_OP_SET_TX_POWER_CALIBRATION;
				calVal = pBtReq->pParamStart[1];
				if( (calVal<1) || (calVal>9) )
				{
					pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
					return paraLen;
				}
				DBG_8192C ("[MPT], calVal=%d\n", calVal);
			}
			break;
		case BT_GSET_UPDATE_BT_PATCH:
			if(IS_HARDWARE_TYPE_8723AE(Adapter) && Adapter->bFWReady)
			{
				u1Byte i;
				DBG_8192C ("[MPT], write regs for load patch\n");
				//BTFwPatch8723A(Adapter);
				PlatformEFIOWrite1Byte(Adapter, 0xCC, 0x2d);
				rtw_msleep_os(50);
				PlatformEFIOWrite4Byte(Adapter, 0x68, 0xa005000c);
				rtw_msleep_os(50);
				PlatformEFIOWrite4Byte(Adapter, 0x68, 0xb005000c);
				rtw_msleep_os(50);
				PlatformEFIOWrite1Byte(Adapter, 0xCC, 0x29);
				for(i=0; i<12; i++)
				rtw_msleep_os(100);
//#if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
//				BTFwPatch8723A(Adapter);
//#endif
				DBG_8192C("[MPT], load BT FW Patch finished!!!\n");
			}
			break;
		default:
			{
				DBG_8192C ("[MPT], Error!! setType=%d, out of range\n", setType);
				pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
				return paraLen;
			}
			break;
	}
	if(setParaLen != validParaLen)
	{
		DBG_8192C("[MPT], Error!! wrong parameter length=%d for BT_SET_GEN_CMD cmd id=0x%x, paraLen should=0x%x\n",
			setParaLen, setType, validParaLen);
		pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
		return paraLen;
	}
	
	//
	// execute lower layer opcodes
	//
	if(BT_GSET_REG == setType)
	{
		// fill h2c parameters
		// here we should write reg value first then write the address, adviced by Austin
		btOpcode = BT_LO_OP_WRITE_REG_VALUE;
		h2cParaBuf[0] = pBtReq->pParamStart[6];
		h2cParaBuf[1] = pBtReq->pParamStart[7];
		h2cParaBuf[2] = pBtReq->pParamStart[8];
		h2cParaLen = 3;
		// execute h2c and check respond c2h from bt fw is correct or not
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
		// construct respond status code and data.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}
		
		// write reg address
		btOpcode = BT_LO_OP_WRITE_REG_ADDR;
		h2cParaBuf[0] = regType;
		h2cParaBuf[1] = pBtReq->pParamStart[2];
		h2cParaBuf[2] = pBtReq->pParamStart[3];
		h2cParaLen = 3;
		// execute h2c and check respond c2h from bt fw is correct or not
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
		// construct respond status code and data.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}		
	}
	else if(BT_GSET_RESET == setType)
	{
		btOpcode = BT_LO_OP_RESET;
		h2cParaLen = 0;
		// execute h2c and check respond c2h from bt fw is correct or not
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
		// construct respond status code and data.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}
	}
	else if(BT_GSET_TARGET_BD_ADDR == setType)
	{
		// fill h2c parameters
		btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_L;
		h2cParaBuf[0] = pBtReq->pParamStart[1];
		h2cParaBuf[1] = pBtReq->pParamStart[2];
		h2cParaBuf[2] = pBtReq->pParamStart[3];
		h2cParaLen = 3;
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);		
		// ckeck bt return status.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C ("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}

		btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_H;
		h2cParaBuf[0] = pBtReq->pParamStart[4];
		h2cParaBuf[1] = pBtReq->pParamStart[5];
		h2cParaBuf[2] = pBtReq->pParamStart[6];
		h2cParaLen = 3;
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);		
		// ckeck bt return status.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C ("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}
	}
	else if(BT_GSET_TX_PWR_FINETUNE == setType)
	{
		// fill h2c parameters
		btOpcode = BT_LO_OP_SET_TX_POWER_CALIBRATION;
		h2cParaBuf[0] = calVal;
		h2cParaLen = 1;
		retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
		// ckeck bt return status.
		if(BT_STATUS_BT_OP_SUCCESS != retStatus)
		{
			pBtRsp->status = ((btOpcode<<8)|retStatus);
			DBG_8192C("[MPT], Error!! status code=0x%x \n", pBtRsp->status);
			return paraLen;
		}
	}
	
	pBtRsp->status = BT_STATUS_SUCCESS;
	return paraLen;
}
void rtl8188es_set_wowlan_cmd(_adapter* padapter, u8 enable)
{
	u8		res=_SUCCESS;
	u32		test=0;
	struct recv_priv	*precvpriv = &padapter->recvpriv;
	SETWOWLAN_PARM		pwowlan_parm;
	SETAOAC_GLOBAL_INFO     paoac_global_info_parm;
	struct pwrctrl_priv	*pwrpriv = adapter_to_pwrctl(padapter);
	struct security_priv *psecpriv = &padapter->securitypriv;
#ifdef CONFIG_GPIO_WAKEUP
	u8		gpio_wake_pin = 7;
	u8		gpio_high_active = 0;	//default low active
#endif

_func_enter_;
		DBG_871X_LEVEL(_drv_always_, "+%s+\n", __func__);

		pwowlan_parm.mode =0;
		pwowlan_parm.gpio_index=0;
		pwowlan_parm.gpio_duration=0;
		pwowlan_parm.second_mode =0;
		pwowlan_parm.reserve=0;

		if(enable){

			pwowlan_parm.mode |=FW_WOWLAN_FUN_EN;
			pwrpriv->wowlan_magic =_TRUE;
			if (psecpriv->dot11PrivacyAlgrthm == _WEP40_ || psecpriv->dot11PrivacyAlgrthm == _WEP104_)
				pwrpriv->wowlan_unicast =_TRUE;

			if(pwrpriv->wowlan_pattern ==_TRUE){
				pwowlan_parm.mode |= FW_WOWLAN_PATTERN_MATCH;
				DBG_871X_LEVEL(_drv_info_, "%s 2.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
			}
			if(pwrpriv->wowlan_magic ==_TRUE){
				pwowlan_parm.mode |=FW_WOWLAN_MAGIC_PKT;
				DBG_871X_LEVEL(_drv_info_, "%s 3.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
			}
			if(pwrpriv->wowlan_unicast ==_TRUE){
				pwowlan_parm.mode |=FW_WOWLAN_UNICAST;
				DBG_871X_LEVEL(_drv_info_, "%s 4.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode );
			}

			pwowlan_parm.mode |=FW_WOWLAN_REKEY_WAKEUP;
			pwowlan_parm.mode |=FW_WOWLAN_DEAUTH_WAKEUP;

			//DataPinWakeUp
#ifdef CONFIG_USB_HCI
			pwowlan_parm.gpio_index=0x0;
#endif //CONFIG_USB_HCI

#ifdef CONFIG_SDIO_HCI
			pwowlan_parm.gpio_index = 0x80;
#endif //CONFIG_SDIO_HCI

#ifdef CONFIG_GPIO_WAKEUP
			pwowlan_parm.gpio_index = gpio_wake_pin;

			//WOWLAN_GPIO_ACTIVE means GPIO high active
			//pwowlan_parm.mode |=FW_WOWLAN_GPIO_ACTIVE;
			if (gpio_high_active)
				pwowlan_parm.mode |=FW_WOWLAN_GPIO_ACTIVE;
#endif //CONFIG_GPIO_WAKEUP

			DBG_871X_LEVEL(_drv_info_, "%s 5.pwowlan_parm.mode=0x%x \n",__FUNCTION__,pwowlan_parm.mode);
			DBG_871X_LEVEL(_drv_info_, "%s 6.pwowlan_parm.index=0x%x \n",__FUNCTION__,pwowlan_parm.gpio_index);
			res = FillH2CCmd_88E(padapter, H2C_COM_WWLAN, 2, (u8 *)&pwowlan_parm);

			rtw_msleep_os(2);

			//disconnect decision
			pwowlan_parm.mode =1;
			pwowlan_parm.gpio_index=0;
			pwowlan_parm.gpio_duration=0;
			FillH2CCmd_88E(padapter, H2C_COM_DISCNT_DECISION, 3, (u8 *)&pwowlan_parm);

			//keep alive period = 10 * 10 BCN interval
			pwowlan_parm.mode = FW_WOWLAN_KEEP_ALIVE_EN | FW_ADOPT_USER | FW_WOWLAN_KEEP_ALIVE_PKT_TYPE;
			pwowlan_parm.gpio_index = 5;
			res = FillH2CCmd_88E(padapter, H2C_COM_KEEP_ALIVE, 2, (u8 *)&pwowlan_parm);

			rtw_msleep_os(2);
			//Configure STA security information for GTK rekey wakeup event.
			paoac_global_info_parm.pairwiseEncAlg =
					padapter->securitypriv.dot11PrivacyAlgrthm;
			paoac_global_info_parm.groupEncAlg =
					padapter->securitypriv.dot118021XGrpPrivacy;
			FillH2CCmd_88E(padapter, H2C_COM_AOAC_GLOBAL_INFO, 2, (u8 *)&paoac_global_info_parm);

			rtw_msleep_os(2);
			//enable Remote wake ctrl
			pwowlan_parm.mode = FW_REMOTE_WAKE_CTRL_EN | FW_WOW_FW_UNICAST_EN | FW_ARP_EN;
			if (psecpriv->dot11PrivacyAlgrthm == _AES_ || psecpriv->dot11PrivacyAlgrthm == _NO_PRIVACY_)
			{
				pwowlan_parm.gpio_index=0;
			} else {
				pwowlan_parm.gpio_index=1;
			}
			pwowlan_parm.gpio_duration=0;

			res = FillH2CCmd_88E(padapter, H2C_COM_REMOTE_WAKE_CTRL, 3, (u8 *)&pwowlan_parm);
		} else {
			pwrpriv->wowlan_magic =_FALSE;
#ifdef CONFIG_GPIO_WAKEUP
			rtl8188es_set_output_gpio(padapter, gpio_wake_pin, !gpio_high_active);
#endif //CONFIG_GPIO_WAKEUP
			res = FillH2CCmd_88E(padapter, H2C_COM_WWLAN, 2, (u8 *)&pwowlan_parm);
			rtw_msleep_os(2);
			res = FillH2CCmd_88E(padapter, H2C_COM_REMOTE_WAKE_CTRL, 3, (u8 *)&pwowlan_parm);
		}
_func_exit_;
		DBG_871X_LEVEL(_drv_always_, "-%s res:%d-\n", __func__, res);
		return ;
}
Beispiel #23
0
void SetHwReg(_adapter *adapter, HW_VARIABLES variable, u8 *val)
{
	HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
	struct dm_priv *dm = &(hal_data->dmpriv);

	switch (variable) {
	case HW_VAR_DM_FLAG:
		dm->DMFlag = *((u8*)val);
		break;
	case HW_VAR_ENC_BMC_ENABLE:
	{
		u8 seccfg;
		struct security_priv *psecuritypriv = &adapter->securitypriv;
		//enable MC/BC hw decrypt
		seccfg = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)? 0xcc: 0xcf;
		rtw_write8(adapter, REG_SECCFG, seccfg);
		break;
	}
	case HW_VAR_ENC_BMC_DISABLE:
	{
		struct security_priv *psecuritypriv = &adapter->securitypriv;
		rtw_write8(adapter, REG_SECCFG, 0x0c|BIT(5));// enable tx enc and rx dec engine, and no key search for MC/BC
		break;
	}
	case HW_VAR_CHECK_TXBUF:
	{
		u8 retry_limit;
		u16 val16;
		u32 reg_200 = 0, reg_204 = 0;
		u32 init_reg_200 = 0, init_reg_204 = 0;
		u32 start = rtw_get_current_time();
		u32 pass_ms;
		int i = 0;

		retry_limit = 0x01;

		val16 = retry_limit << RETRY_LIMIT_SHORT_SHIFT | retry_limit << RETRY_LIMIT_LONG_SHIFT;
		rtw_write16(adapter, REG_RL, val16);

		while (rtw_get_passing_time_ms(start) < 2000
			&& !adapter->bDriverStopped && !adapter->bSurpriseRemoved
		) {
			reg_200 = rtw_read32(adapter, 0x200);
			reg_204 = rtw_read32(adapter, 0x204);

			if (i == 0) {
				init_reg_200 = reg_200;
				init_reg_204 = reg_204;
			}

			i++;
			if ((reg_200 & 0x00ffffff) != (reg_204 & 0x00ffffff)) {
				//DBG_871X("%s: (HW_VAR_CHECK_TXBUF)TXBUF NOT empty - 0x204=0x%x, 0x200=0x%x (%d)\n", __FUNCTION__, reg_204, reg_200, i);
				rtw_msleep_os(10);
			} else {
				break;
			}
		}

		pass_ms = rtw_get_passing_time_ms(start);

		if (adapter->bDriverStopped || adapter->bSurpriseRemoved) {
		} else if (pass_ms >= 2000 || (reg_200 & 0x00ffffff) != (reg_204 & 0x00ffffff)) {
			DBG_871X_LEVEL(_drv_always_, "%s:(HW_VAR_CHECK_TXBUF)NOT empty(%d) in %d ms\n", __FUNCTION__, i, pass_ms);
			DBG_871X_LEVEL(_drv_always_, "%s:(HW_VAR_CHECK_TXBUF)0x200=0x%08x, 0x204=0x%08x (0x%08x, 0x%08x)\n",
				__FUNCTION__, reg_200, reg_204, init_reg_200, init_reg_204);
			//rtw_warn_on(1);
		} else {
			DBG_871X("%s:(HW_VAR_CHECK_TXBUF)TXBUF Empty(%d) in %d ms\n", __FUNCTION__, i, pass_ms);
		}

		retry_limit = 0x30;
		val16 = retry_limit << RETRY_LIMIT_SHORT_SHIFT | retry_limit << RETRY_LIMIT_LONG_SHIFT;
		rtw_write16(adapter, REG_RL, val16);
	}
		break;
	default:
		if(0)
		DBG_871X_LEVEL(_drv_always_, "%s: [WARNING] HW_VARIABLES(%d) not defined!\n", __FUNCTION__, variable);
		break;
	}
}
Beispiel #24
0
_adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct sdio_device_id  *pdid){
	int status = _FAIL;
	struct net_device *pnetdev;
	PADAPTER padapter = NULL;
	u8 mac_addr[ETH_ALEN];
	u16 fw_ready;
	u32 i;
  
_func_enter_;
	if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) {
		DBG_871X("%s: vmalloc for padapter failed!\n", __FUNCTION__);
		goto exit;
	}
	padapter->dvobj = dvobj;
	dvobj->if1 = padapter;
	padapter->interface_type = RTW_SDIO;
	// 1. init network device data
	pnetdev = rtw_init_netdev(padapter);
	if (!pnetdev)
		goto free_adapter;
	SET_NETDEV_DEV(pnetdev, &dvobj->intf_data.func->dev);
	padapter = rtw_netdev_priv(pnetdev);

	// 2. init driver special setting, interface, OS and hardware relative
	rtw_set_hal_ops(padapter);
	
	// 3. initialize Chip version
	padapter->intf_start = &sd_intf_start;
	padapter->intf_stop = &sd_intf_stop;

	padapter->intf_init = &sdio_init;
	padapter->intf_deinit = &sdio_deinit;
	padapter->intf_alloc_irq = &sdio_alloc_irq;
	padapter->intf_free_irq = &sdio_free_irq;
	
	sdio_set_intf_ops(padapter, &padapter->io_ops);

	// 4. init driver common data
	if (rtw_init_drv_sw(padapter) == _FAIL) {
		goto free_adapter;
	}

	// 5. get MAC address
	mac_addr[0] = 0x00;
	mac_addr[1] = 0xe0;
	mac_addr[2] = 0x4c;
	mac_addr[3] = 0xB7;
	mac_addr[4] = 0x23;
	mac_addr[5] = 0x00;
	_rtw_memcpy(pnetdev->dev_addr, mac_addr, ETH_ALEN);
#ifdef CONFIG_FWDL
	// wait for the device boot code ready
	for (i=0;i<100;i++) {
		fw_ready = rtw_read16(padapter, SDIO_REG_HCPWM2);
		if (fw_ready & SDIO_INIT_DONE) {
			break;
		}
		rtw_msleep_os(10);
	}
	if (i==100) {
		DBG_871X("%s: Wait Device Firmware Ready Timeout!!SDIO_REG_HCPWM2 @ 0x%04x\n", __FUNCTION__, fw_ready);
		goto free_adapter;
	}
#else
	// wait for the device firmware ready
	for (i=0;i<100;i++) {
		fw_ready = rtw_read8(padapter, SDIO_REG_CPU_IND);
		if (fw_ready & SDIO_SYSTEM_TRX_RDY_IND) {
			break;
		}
		rtw_msleep_os(10);
	}
	if (i==100) {
		DBG_871X("%s: Wait Device Firmware Ready Timeout!!SDIO_REG_CPU_IND @ 0x%04x\n", __FUNCTION__, fw_ready);
		goto free_adapter;
	}
#endif
	rtw_hal_disable_interrupt(padapter);
	DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d\n"
		,padapter->bDriverStopped
		,padapter->bSurpriseRemoved
		,padapter->bup
	);
	status = _SUCCESS;
free_adapter:
	if (status != _SUCCESS) {
		if (pnetdev)
			rtw_free_netdev(pnetdev);
		else
			rtw_vmfree((u8*)padapter, sizeof(*padapter));
		padapter = NULL;
	}	
exit:
	_func_exit_;
	return padapter;
}
static s32 rtl8723_dequeue_writeport(PADAPTER padapter)
{
    struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
    struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
    struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
    struct xmit_buf *pxmitbuf;
    PADAPTER pri_padapter = padapter;
    u32 deviceId;
    u32 requiredPage;
    u8 PageIdx=0;
    u8 *freePage;
    _irqL irql;
    u32 n;
    s32 ret = 0;


#ifdef CONFIG_CONCURRENT_MODE
    if (padapter->adapter_type > 0)
        pri_padapter = padapter->pbuddy_adapter;

    if (rtw_buddy_adapter_up(padapter))
        ret = check_buddy_fwstate(padapter, _FW_UNDER_SURVEY);
#endif

    ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);

    if (_TRUE == ret)
        pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv);
    else
        pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);

    if (pxmitbuf == NULL)
        return _TRUE;

query_free_page:
    // check if hardware tx fifo page is enough
    if( _FALSE == rtl8723bs_query_tx_freepage(pri_padapter, pxmitbuf))
    {
        rtw_msleep_os(1);
        goto query_free_page;
    }

    if ((padapter->bSurpriseRemoved == _TRUE)
            || (padapter->bDriverStopped == _TRUE)
#ifdef CONFIG_CONCURRENT_MODE
            ||((padapter->pbuddy_adapter)
               && ((padapter->pbuddy_adapter->bSurpriseRemoved) ||(padapter->pbuddy_adapter->bDriverStopped)))
#endif
       ) {
        RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
                 ("%s: bSurpriseRemoved(wirte port)\n", __FUNCTION__));
        goto free_xmitbuf;
    }


#ifdef CONFIG_CHECK_LEAVE_LPS
    traffic_check_for_leave_lps(padapter, _TRUE, pxmitbuf->agg_num);
#endif


    rtw_write_port(padapter, ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr), pxmitbuf->len, (u8 *)pxmitbuf);

free_xmitbuf:
    //rtw_free_xmitframe(pxmitpriv, pframe);
    //pxmitbuf->priv_data = NULL;
    rtw_free_xmitbuf(pxmitpriv, pxmitbuf);

#if 0 // improve TX/RX throughput balance
    {
        PSDIO_DATA psdio;
        struct sdio_func *func;
        static u8 i = 0;
        u32 sdio_hisr;
        u8 j;

        psdio = &adapter_to_dvobj(padapter)->intf_data;
        func = psdio->func;

        if (i == 2)
        {
            j = 0;
            while (j < 10)
            {
                sdio_hisr = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HISR);
                sdio_hisr &= GET_HAL_DATA(padapter)->sdio_himr;
                if (sdio_hisr & SDIO_HISR_RX_REQUEST)
                {
                    sdio_claim_host(func);
                    sd_int_hdl(pri_padapter);
                    sdio_release_host(func);
                }
                else
                {
                    break;
                }
                j++;
            }
            i = 0;
        }
        else
        {
            i++;
        }
    }
#endif

#ifdef CONFIG_SDIO_TX_TASKLET
    tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
#endif

    return _FAIL;
}
Beispiel #26
0
void rtw_set_ps_mode(struct rtw_adapter *padapter, u8 ps_mode, u8 smart_ps)
{
	struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;

	RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
		 ("%s: PowerMode=%d Smart_PS=%d\n",
		  __func__, ps_mode, smart_ps));

	if (ps_mode > PM_Card_Disable) {
		RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
			 ("ps_mode:%d error\n", ps_mode));
		return;
	}

	if ((pwrpriv->pwr_mode == ps_mode) && (pwrpriv->smart_ps == smart_ps)) {
		return;
	}

	/* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */
	if (ps_mode == PS_MODE_ACTIVE) {
		{
#ifdef CONFIG_LPS_LCLK
			_enter_pwrlock(&pwrpriv->lock);
#endif
			DBG_8192D
			    ("rtw_set_ps_mode(): Busy Traffic , Leave 802.11 power save..\n");

			pwrpriv->smart_ps = smart_ps;
			pwrpriv->pwr_mode = ps_mode;

			rtw_set_rpwm(padapter, PS_STATE_S4);
#ifdef CONFIG_LPS_LCLK
			{
				u32 n = 0;
				while (pwrpriv->cpwm != PS_STATE_S4) {
					n++;
					if (n == 10000)
						break;
					if (padapter->bSurpriseRemoved == true)
						break;
					rtw_msleep_os(1);
				}
				if (n == 10000)
					printk(KERN_ERR
					       "%s: wait CPWM to S4 too long! cpwm=0x%02x\n",
					       __func__, pwrpriv->cpwm);
			}
#endif
			rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE,
					  (u8 *)(&ps_mode));
			pwrpriv->bFwCurrentInPSMode = false;
#ifdef CONFIG_LPS_LCLK
			_exit_pwrlock(&pwrpriv->lock);
#endif
		}
	} else {
		if (ps_rdy_check(padapter)) {
#ifdef CONFIG_LPS_LCLK
			_enter_pwrlock(&pwrpriv->lock);
#endif
			DBG_8192D
			    ("rtw_set_ps_mode(): Enter 802.11 power save mode...\n");

			pwrpriv->smart_ps = smart_ps;
			pwrpriv->pwr_mode = ps_mode;
			pwrpriv->bFwCurrentInPSMode = true;
			rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
#ifdef CONFIG_LPS_LCLK
			if (pwrpriv->alives == 0)
				rtw_set_rpwm(padapter, PS_STATE_S0);
#else
			rtw_set_rpwm(padapter, PS_STATE_S2);
#endif
#ifdef CONFIG_LPS_LCLK
			_exit_pwrlock(&pwrpriv->lock);
#endif
		}
		/* else */
		/*  */
		/*      pwrpriv->pwr_mode = PS_MODE_ACTIVE; */
		/*  */
	}

}
int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_data)
{
	unsigned int max_ap_size = 64;

#if SCAN_USE_SEMAPHORE
	rtw_bool_t result;
	if(NULL == scan_result_handler_ptr.scan_semaphore)
		rtw_init_sema(&scan_result_handler_ptr.scan_semaphore, 1);
	
	scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
	/* Initialise the semaphore that will prevent simultaneous access - cannot be a mutex, since
	* we don't want to allow the same thread to start a new scan */
	result = (rtw_bool_t)rtw_down_timeout_sema(&scan_result_handler_ptr.scan_semaphore, SCAN_LONGEST_WAIT_TIME);
	if ( result != RTW_TRUE )
	{
		/* Return error result, but set the semaphore to work the next time */
		rtw_up_sema(&scan_result_handler_ptr.scan_semaphore);
		return RTW_TIMEOUT;
	}
#else
	if(scan_result_handler_ptr.scan_running){
		int count = 100;
		while(scan_result_handler_ptr.scan_running && count > 0)
		{
			rtw_msleep_os(20);
			count --;
		}
		if(count == 0){
			printf("\n\r[%d]WiFi: Scan is running. Wait 2s timeout.", rtw_get_current_time());
			return RTW_TIMEOUT;
		}
	}
	scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
	scan_result_handler_ptr.scan_running = 1;
#endif

	scan_result_handler_ptr.gscan_result_handler = results_handler;
	
	scan_result_handler_ptr.max_ap_size = max_ap_size;
	scan_result_handler_ptr.ap_details = (rtw_scan_result_t*)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t));
	if(scan_result_handler_ptr.ap_details == NULL){
		goto error_with_result_ptr;
	}
	rtw_memset(scan_result_handler_ptr.ap_details, 0, max_ap_size*sizeof(rtw_scan_result_t));

	scan_result_handler_ptr.pap_details = (rtw_scan_result_t**)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t*));
	if(scan_result_handler_ptr.pap_details == NULL)
		return RTW_ERROR;
	rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size);
	
	scan_result_handler_ptr.scan_cnt = 0;

	scan_result_handler_ptr.scan_complete = RTW_FALSE;
	scan_result_handler_ptr.user_data = user_data;

	if (wifi_scan( RTW_SCAN_COMMAMD<<4 | RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, NULL) != RTW_SUCCESS)
	{
		goto error_with_result_ptr;
	}

	return RTW_SUCCESS;

error_with_result_ptr:
	rtw_free((u8*)scan_result_handler_ptr.pap_details);
	scan_result_handler_ptr.pap_details = NULL;
	return RTW_ERROR;
}
s32 rtl8723_dequeue_writeport(PADAPTER padapter, u8 *freePage)
{
	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
	struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
	struct xmit_buf *pxmitbuf;
	//struct xmit_frame *pframe;
	PADAPTER pri_padapter = padapter;
	u32 deviceId;
	u32 requiredPage;
	u8 PageIdx;
	_irqL irql;
	u32 n;
	s32 ret = 0;
	//HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
#ifdef CONFIG_CONCURRENT_MODE
	s32 buddy_rm_stop = _FAIL;
#endif

#ifdef CONFIG_CONCURRENT_MODE
	if(rtw_buddy_adapter_up(padapter))
		ret = check_buddy_fwstate( padapter,  _FW_UNDER_SURVEY);
#endif

	ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);

	if (_TRUE == ret)
		pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv);
	else
		pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);

	if (pxmitbuf == NULL) 
		return _TRUE;

	//pframe = (struct xmit_frame*)pxmitbuf->priv_data;
	//requiredPage = pframe->pg_num;
	requiredPage = pxmitbuf->pg_num;

	//translate queue index to sdio fifo addr
	deviceId = pdvobjpriv->Queue2Pipe[pxmitbuf->ff_hwaddr];

	// translate sdio fifo addr to tx fifo page index
	switch (deviceId)
	{
		case WLAN_TX_HIQ_DEVICE_ID:
				PageIdx = HI_QUEUE_IDX;
				break;

		case WLAN_TX_MIQ_DEVICE_ID:
				PageIdx = MID_QUEUE_IDX;
				break;

		case WLAN_TX_LOQ_DEVICE_ID:
				PageIdx = LOW_QUEUE_IDX;
				break;
	}

	// check if hardware tx fifo page is enough
	n = 0;
//	_enter_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
	do {
		if (requiredPage <= freePage[PageIdx]) {
			freePage[PageIdx] -= requiredPage;
			break;
		}
		// The number of page which public page included is available.
		if ((freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]) > (requiredPage + 1))
		{
			u8 requiredPublicPage;

			requiredPublicPage = requiredPage - freePage[PageIdx];
			freePage[PageIdx] = 0;
			freePage[PUBLIC_QUEUE_IDX] -= requiredPublicPage;
			break;
		}
//		_exit_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);

		ret = (padapter->bDriverStopped == _TRUE) || (padapter->bSurpriseRemoved == _TRUE);
		if (ret) {
			RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
				 ("%s: bSurpriseRemoved(update TX FIFO page)\n", __func__));
			goto free_xmitbuf;
		}

		n++;
		//if ((n & 0x3FF) == 0) 
		if ((n % 2) == 0) 
		{		
			if (n > 5000) {
				DBG_8192C(KERN_NOTICE "%s: FIFO starvation!(%d) len=%d agg=%d page=(R)%d(A)%d\n",
					__func__, n, pxmitbuf->len, pxmitbuf->agg_num, pxmitbuf->pg_num, freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]);
			} else {
				//RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
				//	("%s: FIFO starvation!(%d) len=%d agg=%d page=(R)%d(A)%d\n",
				//	__FUNCTION__, n, pxmitbuf->len, pxmitbuf->agg_num, pxmitbuf->pg_num, freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]));
			}
			//rtw_yield_os();
			rtw_msleep_os(1);
		}

		// Total number of page is NOT available, so update current FIFO status
#ifdef CONFIG_CONCURRENT_MODE
		if (padapter->adapter_type > 0)
			pri_padapter = padapter->pbuddy_adapter;
#endif
		HalQueryTxBufferStatus8723ASdio(pri_padapter);

	} while (1);

	if ((padapter->bSurpriseRemoved == _TRUE)
#ifdef CONFIG_CONCURRENT_MODE
		||((padapter->pbuddy_adapter)&& (padapter->pbuddy_adapter->bSurpriseRemoved))
#endif
	){
		RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
			 ("%s: bSurpriseRemoved(wirte port)\n", __FUNCTION__));
		goto free_xmitbuf;
	}
	rtw_write_port(padapter, deviceId, pxmitbuf->len, (u8 *)pxmitbuf);

free_xmitbuf:
	//rtw_free_xmitframe(pxmitpriv, pframe);
	//pxmitbuf->priv_data = NULL;
	rtw_free_xmitbuf(pxmitpriv, pxmitbuf);

	return _FAIL;
}
Beispiel #29
0
//todo: static 
s32 rtl8188es_dequeue_writeport(PADAPTER padapter)
{
	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
	struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
	struct xmit_buf *pxmitbuf;
	PADAPTER pri_padapter = padapter;
	s32 ret = 0;
	u8	PageIdx = 0;
	u32	deviceId;
#ifdef CONFIG_SDIO_TX_ENABLE_AVAL_INT
	u8	bUpdatePageNum = _FALSE;
#else
	u32	polling_num = 0;
#endif

#ifdef CONFIG_CONCURRENT_MODE
	if (padapter->adapter_type > 0)
		pri_padapter = padapter->pbuddy_adapter;

	if(rtw_buddy_adapter_up(padapter))
		ret = check_buddy_fwstate( padapter,  _FW_UNDER_SURVEY);
#endif

	ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);

	if (_TRUE == ret)
		pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv);
	else
		pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);

	if (pxmitbuf == NULL) {
		return _TRUE;
	}

	deviceId = ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr);

	// translate fifo addr to queue index
	switch (deviceId) {
		case WLAN_TX_HIQ_DEVICE_ID:
				PageIdx = HI_QUEUE_IDX;
				break;

		case WLAN_TX_MIQ_DEVICE_ID:
				PageIdx = MID_QUEUE_IDX;
				break;

		case WLAN_TX_LOQ_DEVICE_ID:
				PageIdx = LOW_QUEUE_IDX;
				break;
	}

query_free_page:
	// check if hardware tx fifo page is enough
	if( _FALSE == rtw_hal_sdio_query_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num))
	{
#ifdef CONFIG_SDIO_TX_ENABLE_AVAL_INT
		if (!bUpdatePageNum) {
			// Total number of page is NOT available, so update current FIFO status
			HalQueryTxBufferStatus8189ESdio(padapter);
			bUpdatePageNum = _TRUE;
			goto query_free_page;
		} else {
			bUpdatePageNum = _FALSE;
			enqueue_pending_xmitbuf_to_head(pxmitpriv, pxmitbuf);
			return _TRUE;
		}
#else //CONFIG_SDIO_TX_ENABLE_AVAL_INT
		polling_num++;
		if ((polling_num % 60) == 0) {//or 80
			//DBG_871X("%s: FIFO starvation!(%d) len=%d agg=%d page=(R)%d(A)%d\n",
			//	__func__, n, pxmitbuf->len, pxmitbuf->agg_num, pframe->pg_num, freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]);
			rtw_msleep_os(1);
		}

		// Total number of page is NOT available, so update current FIFO status
		HalQueryTxBufferStatus8189ESdio(padapter);
		goto query_free_page;
#endif //CONFIG_SDIO_TX_ENABLE_AVAL_INT
	}

	if ((padapter->bSurpriseRemoved == _TRUE) 
		|| (padapter->bDriverStopped == _TRUE)
#ifdef CONFIG_CONCURRENT_MODE
		||((padapter->pbuddy_adapter) 
		&& ((padapter->pbuddy_adapter->bSurpriseRemoved) ||(padapter->pbuddy_adapter->bDriverStopped)))
#endif
	){
		RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
			 ("%s: bSurpriseRemoved(wirte port)\n", __FUNCTION__));
		goto free_xmitbuf;
	}

	if (rtw_sdio_wait_enough_TxOQT_space(padapter, pxmitbuf->agg_num) == _FALSE) 
	{
		goto free_xmitbuf;
	}

	rtw_write_port(padapter, deviceId, pxmitbuf->len, (u8 *)pxmitbuf);

	rtw_hal_sdio_update_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num);

free_xmitbuf:		
	//rtw_free_xmitframe(pxmitpriv, pframe);
	//pxmitbuf->priv_data = NULL;
	rtw_free_xmitbuf(pxmitpriv, pxmitbuf);

#ifdef CONFIG_SDIO_TX_TASKLET
	tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
#endif

	return _FAIL;
}
static u8 rtl8188es_query_tx_freepage(_adapter *padapter, struct xmit_buf *pxmitbuf)
{
	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
	struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
	u8	TxRequiredPageNum = 0;
	u8	DedicatedPgNum = 0;
	u8	RequiredPublicFreePgNum = 0;
	u8	PageIdx = 0;
	u8	bResult = _TRUE;
	u32	n, deviceId;

	TxRequiredPageNum = pxmitbuf->pg_num;

	deviceId = ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr);

	// translate fifo addr to queue index
	switch (deviceId) {
		case WLAN_TX_HIQ_DEVICE_ID:
				PageIdx = HI_QUEUE_IDX;
				break;

		case WLAN_TX_MIQ_DEVICE_ID:
				PageIdx = MID_QUEUE_IDX;
				break;

		case WLAN_TX_LOQ_DEVICE_ID:
				PageIdx = LOW_QUEUE_IDX;
				break;
	}

	// check if hardware tx fifo page is enough
	n = 0;
	do {
		if ((padapter->bSurpriseRemoved == _TRUE) || (padapter->bDriverStopped == _TRUE)){
			RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
				 ("%s: bSurpriseRemoved(update TX FIFO page)\n", __FUNCTION__));
			break;
		}

		// The number of page which public page is included is available .
		if ((pHalData->SdioTxFIFOFreePage[PageIdx]+pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]) > (TxRequiredPageNum+1)) {
			DedicatedPgNum = pHalData->SdioTxFIFOFreePage[PageIdx];
			if (TxRequiredPageNum <= DedicatedPgNum) {
				pHalData->SdioTxFIFOFreePage[PageIdx] -= TxRequiredPageNum;
				break;
			} else {
				pHalData->SdioTxFIFOFreePage[PageIdx] = 0;
				RequiredPublicFreePgNum = TxRequiredPageNum - DedicatedPgNum;
				pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX] -= RequiredPublicFreePgNum;
				break;
			}
		}

		n++;
		if ((n % 60) == 0) {//or 80
			//DBG_871X("%s: FIFO starvation!(%d) len=%d agg=%d page=(R)%d(A)%d\n",
			//	__func__, n, pxmitbuf->len, pxmitbuf->agg_num, pframe->pg_num, freePage[PageIdx] + freePage[PUBLIC_QUEUE_IDX]);
			rtw_msleep_os(10);
			rtw_yield_os();
		}

		// Total number of page is NOT available, so update current FIFO status
		HalQueryTxBufferStatus8189ESdio(padapter);
	} while (1);

	return bResult;
}