From 17eaf0e045fb0226f690fbffa11891b864fac810 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Tue, 16 Dec 2014 17:08:39 -0600 Subject: [PATCH] rtl8188eu: Remove some unused files Signed-off-by: Larry Finger --- core/rtw_bt_mp.c | 1735 -------------------------- core/rtw_wapi.c | 1326 -------------------- core/rtw_wapi_sms4.c | 923 -------------- os_dep/linux/custom_gpio_linux.c | 210 ---- os_dep/linux/gspi_intf.c | 945 -------------- os_dep/linux/gspi_ops_linux.c | 432 ------- os_dep/linux/pci_intf.c | 1995 ------------------------------ os_dep/linux/pci_ops_linux.c | 24 - os_dep/linux/sdio_intf.c | 1967 ----------------------------- os_dep/linux/sdio_ops_linux.c | 912 -------------- 10 files changed, 10469 deletions(-) delete mode 100755 core/rtw_bt_mp.c delete mode 100755 core/rtw_wapi.c delete mode 100755 core/rtw_wapi_sms4.c delete mode 100755 os_dep/linux/custom_gpio_linux.c delete mode 100755 os_dep/linux/gspi_intf.c delete mode 100755 os_dep/linux/gspi_ops_linux.c delete mode 100755 os_dep/linux/pci_intf.c delete mode 100755 os_dep/linux/pci_ops_linux.c delete mode 100755 os_dep/linux/sdio_intf.c delete mode 100755 os_dep/linux/sdio_ops_linux.c diff --git a/core/rtw_bt_mp.c b/core/rtw_bt_mp.c deleted file mode 100755 index e3e0f3d..0000000 --- a/core/rtw_bt_mp.c +++ /dev/null @@ -1,1735 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ - - -#include "rtw_bt_mp.h" -#include -#include - -#ifdef CONFIG_RTL8723A - -void MPh2c_timeout_handle(void *FunctionContext) -{ - _adapter *pAdapter = (_adapter *)FunctionContext; - PMPT_CONTEXT pMptCtx=&pAdapter->mppriv.MptCtx; - - DBG_8192C("[MPT], MPh2c_timeout_handle \n"); - - pMptCtx->bMPh2c_timeout=_TRUE; - - _rtw_up_sema(&pMptCtx->MPh2c_Sema); - - //_cancel_timer_ex( &pMptCtx->MPh2c_timeout_timer); - - return; -} -u32 WaitC2Hevent( PADAPTER pAdapter,BOOLEAN *C2H_event ,u32 delay_time) -{ - PMPT_CONTEXT pMptCtx=&(pAdapter->mppriv.MptCtx); - pMptCtx->bMPh2c_timeout=_FALSE; - DBG_8192C("WaitC2Hevent _set_timer \n"); - _set_timer( &pMptCtx->MPh2c_timeout_timer, delay_time ); - - _rtw_down_sema(&pMptCtx->MPh2c_Sema); - - if( pMptCtx->bMPh2c_timeout == _TRUE ) - { - C2H_event =_FALSE; - DBG_8192C("WaitC2Hevent bMPh2c_timeout _TRUE \n"); - return _FALSE; - } - - return _TRUE; - -} - -BT_CTRL_STATUS -mptbt_CheckC2hFrame( - PADAPTER Adapter, - PBT_H2C pH2c, - PBT_EXT_C2H pExtC2h - ) -{ - BT_CTRL_STATUS c2hStatus = BT_STATUS_C2H_SUCCESS; - - //DBG_8192C("[MPT], MPT rsp C2H hex: %x %x %x %x %x %x \n"), pExtC2h , pExtC2h+1 ,pExtC2h+2 ,pExtC2h+3 ,pExtC2h+4 ,pExtC2h+5); - - DBG_8192C("[MPT], statusCode = 0x%x\n", pExtC2h->statusCode); - DBG_8192C("[MPT], retLen = %d\n", pExtC2h->retLen); - DBG_8192C("[MPT], opCodeVer : req/rsp=%d/%d\n", pH2c->opCodeVer, pExtC2h->opCodeVer); - DBG_8192C("[MPT], reqNum : req/rsp=%d/%d\n", pH2c->reqNum, pExtC2h->reqNum); - if(pExtC2h->reqNum != pH2c->reqNum) - { - c2hStatus = BT_STATUS_C2H_REQNUM_MISMATCH; - DBG_8192C("[MPT], Error!! C2H reqNum Mismatch!!\n"); - } - else if(pExtC2h->opCodeVer != pH2c->opCodeVer) - { - c2hStatus = BT_STATUS_OPCODE_L_VERSION_MISMATCH; - DBG_8192C("[MPT], Error!! OPCode version L mismatch!!\n"); - } - - return c2hStatus; -} - -extern s32 FillH2CCmd(PADAPTER padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer); - -BT_CTRL_STATUS -mptbt_SendH2c( - PADAPTER Adapter, - PBT_H2C pH2c, - u2Byte h2cCmdLen - ) -{ - //KIRQL OldIrql = KeGetCurrentIrql(); - BT_CTRL_STATUS h2cStatus=BT_STATUS_H2C_SUCCESS; - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - u1Byte i; - - DBG_8192C("[MPT], mptbt_SendH2c()=========>\n"); - - //PlatformResetEvent(&pMptCtx->MptH2cRspEvent); - //PlatformResetEvent(&pMptCtx->MptBtC2hEvent); - -// if(OldIrql == PASSIVE_LEVEL) -// { - //RTPRINT_DATA(FMPBT, FMPBT_H2C_CONTENT, ("[MPT], MPT H2C hex: \n"), pH2c, h2cCmdLen); - - for(i=0; ih2cReqNum++; - pMptCtx->h2cReqNum %= 16; - - if(WaitC2Hevent(Adapter, &pMptCtx->MptH2cRspEvent, 200)) - { - DBG_8192C("[MPT], Received WiFi MptH2cRspEvent!!!\n"); - if(WaitC2Hevent(Adapter, &pMptCtx->MptBtC2hEvent, 800)) - { - DBG_8192C("[MPT], Received BT MptBtC2hEvent!!!\n"); - break; - } - else - { - DBG_8192C("[MPT], Error!!BT MptBtC2hEvent timeout!!\n"); - h2cStatus = BT_STATUS_H2C_BT_NO_RSP; - } - } - else - { - DBG_8192C("[MPT], Error!!WiFi MptH2cRspEvent timeout!!\n"); - h2cStatus = BT_STATUS_H2C_TIMTOUT; - } - } -// } -// else -// { -// RT_ASSERT(FALSE, ("[MPT], mptbt_SendH2c() can only run under PASSIVE_LEVEL!!\n")); -// h2cStatus = BT_STATUS_WRONG_LEVEL; -// } - - DBG_8192C("[MPT], mptbt_SendH2c()<=========\n"); - return h2cStatus; -} - - - -BT_CTRL_STATUS -mptbt_CheckBtRspStatus( - PADAPTER Adapter, - PBT_EXT_C2H pExtC2h - ) -{ - BT_CTRL_STATUS retStatus=BT_OP_STATUS_SUCCESS; - - switch(pExtC2h->statusCode) - { - case BT_OP_STATUS_SUCCESS: - retStatus = BT_STATUS_BT_OP_SUCCESS; - DBG_8192C("[MPT], BT status : BT_STATUS_SUCCESS\n"); - break; - case BT_OP_STATUS_VERSION_MISMATCH: - retStatus = BT_STATUS_OPCODE_L_VERSION_MISMATCH; - DBG_8192C("[MPT], BT status : BT_STATUS_OPCODE_L_VERSION_MISMATCH\n"); - break; - case BT_OP_STATUS_UNKNOWN_OPCODE: - retStatus = BT_STATUS_UNKNOWN_OPCODE_L; - DBG_8192C("[MPT], BT status : BT_STATUS_UNKNOWN_OPCODE_L\n"); - break; - case BT_OP_STATUS_ERROR_PARAMETER: - retStatus = BT_STATUS_PARAMETER_FORMAT_ERROR_L; - DBG_8192C("[MPT], BT status : BT_STATUS_PARAMETER_FORMAT_ERROR_L\n"); - break; - default: - retStatus = BT_STATUS_UNKNOWN_STATUS_L; - DBG_8192C("[MPT], BT status : BT_STATUS_UNKNOWN_STATUS_L\n"); - break; - } - - return retStatus; -} - - - -BT_CTRL_STATUS -mptbt_BtFwOpCodeProcess( - PADAPTER Adapter, - u1Byte btFwOpCode, - u1Byte opCodeVer, - pu1Byte pH2cPar, - u1Byte h2cParaLen - ) -{ - u1Byte H2C_Parameter[6] ={0}; - PBT_H2C pH2c=(PBT_H2C)&H2C_Parameter[0]; - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - PBT_EXT_C2H pExtC2h=(PBT_EXT_C2H)&pMptCtx->c2hBuf[0]; - u2Byte paraLen=0,i; - BT_CTRL_STATUS h2cStatus=BT_STATUS_H2C_SUCCESS, c2hStatus=BT_STATUS_C2H_SUCCESS; - BT_CTRL_STATUS retStatus=BT_STATUS_H2C_BT_NO_RSP; - - pH2c->opCode = btFwOpCode; - pH2c->opCodeVer = opCodeVer; - pH2c->reqNum = pMptCtx->h2cReqNum; - //PlatformMoveMemory(&pH2c->buf[0], pH2cPar, h2cParaLen); - //_rtw_memcpy(&pH2c->buf[0], pH2cPar, h2cParaLen); - _rtw_memcpy(pH2c->buf, pH2cPar, h2cParaLen); - - DBG_8192C("[MPT], pH2c->opCode=%d\n", pH2c->opCode); - DBG_8192C("[MPT], pH2c->opCodeVer=%d\n", pH2c->opCodeVer); - DBG_8192C("[MPT], pH2c->reqNum=%d\n", pH2c->reqNum); - DBG_8192C("[MPT], h2c parameter length=%d\n", h2cParaLen); - if(h2cParaLen) - { - DBG_8192C("[MPT], parameters(hex): \n"); - for(i=0;ibuf[i]); - } - } - - h2cStatus = mptbt_SendH2c(Adapter, pH2c, h2cParaLen+2); - if(BT_STATUS_H2C_SUCCESS == h2cStatus) - { - // if reach here, it means H2C get the correct c2h response, - c2hStatus = mptbt_CheckC2hFrame(Adapter, pH2c, pExtC2h); - if(BT_STATUS_C2H_SUCCESS == c2hStatus) - { - retStatus = mptbt_CheckBtRspStatus(Adapter, pExtC2h); - } - else - { - DBG_8192C("[MPT], Error!! C2H failed for pH2c->opCode=%d\n", pH2c->opCode); - // check c2h status error, return error status code to upper layer. - retStatus = c2hStatus; - } - } - else - { - DBG_8192C("[MPT], Error!! H2C failed for pH2c->opCode=%d\n", pH2c->opCode); - // check h2c status error, return error status code to upper layer. - retStatus = h2cStatus; - } - - return retStatus; -} - - - - -u2Byte -mptbt_BtReady( - PADAPTER Adapter, - PBT_REQ_CMD pBtReq, - 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; - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - PBT_EXT_C2H pExtC2h=(PBT_EXT_C2H)&pMptCtx->c2hBuf[0]; - u1Byte i; - u1Byte btFwVer=0, bdAddr[6]={0}; - u2Byte btRealFwVer=0; - pu2Byte pu2Tmp=NULL; - - // - // check upper layer parameters - // - - // 1. 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; - } - - pBtRsp->pParamStart[0] = MP_BT_NOT_READY; - paraLen = 10; - // - // execute lower layer opcodes - // - - // Get BT FW version - // fill h2c parameters - btOpcode = BT_LO_OP_GET_BT_VERSION; - // execute h2c and check respond c2h from bt fw is correct or not - 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 - { - pu2Tmp = (pu2Byte)&pExtC2h->buf[0]; - btRealFwVer = *pu2Tmp; - btFwVer = pExtC2h->buf[1]; - DBG_8192C("[MPT], btRealFwVer=0x%x, btFwVer=0x%x\n", btRealFwVer, btFwVer); - } - - // Get BD Address - // fill h2c parameters - btOpcode = BT_LO_OP_GET_BD_ADDR_L; - // execute h2c and check respond c2h from bt fw is correct or not - 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 - { - bdAddr[5] = pExtC2h->buf[0]; - bdAddr[4] = pExtC2h->buf[1]; - bdAddr[3] = pExtC2h->buf[2]; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_GET_BD_ADDR_H; - // execute h2c and check respond c2h from bt fw is correct or not - 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 - { - bdAddr[2] = pExtC2h->buf[0]; - bdAddr[1] = pExtC2h->buf[1]; - bdAddr[0] = pExtC2h->buf[2]; - } - DBG_8192C("[MPT], Local BDAddr:"); - for(i=0; i<6; i++) - { - DBG_8192C(" 0x%x ", bdAddr[i]); - } - pBtRsp->status = BT_STATUS_SUCCESS; - pBtRsp->pParamStart[0] = MP_BT_READY; - pu2Tmp = (pu2Byte)&pBtRsp->pParamStart[1]; - *pu2Tmp = btRealFwVer; - pBtRsp->pParamStart[3] = btFwVer; - for(i=0; i<6; i++) - { - pBtRsp->pParamStart[4+i] = bdAddr[5-i]; - } - - return paraLen; -} - -void mptbt_close_WiFiRF(PADAPTER Adapter) -{ - PHY_SetBBReg(Adapter, 0x824, 0xF, 0x0); - PHY_SetBBReg(Adapter, 0x824, 0x700000, 0x0); - PHY_SetRFReg(Adapter, RF90_PATH_A, 0x0, 0xF0000, 0x0); -} - -void mptbt_open_WiFiRF(PADAPTER Adapter) -{ - PHY_SetBBReg(Adapter, 0x824, 0x700000, 0x3); - PHY_SetBBReg(Adapter, 0x824, 0xF, 0x2); - PHY_SetRFReg(Adapter, RF90_PATH_A, 0x0, 0xF0000, 0x3); -} - -u4Byte mptbt_switch_RF(PADAPTER Adapter, u1Byte Enter) -{ - u2Byte tmp_2byte = 0; - - //Enter test mode - if (Enter) { - ////1>. close WiFi RF - mptbt_close_WiFiRF(Adapter); - - ////2>. change ant switch to BT - tmp_2byte = rtw_read16(Adapter, 0x860); - tmp_2byte = tmp_2byte | BIT(9); - tmp_2byte = tmp_2byte & (~BIT(8)); - rtw_write16(Adapter, 0x860, tmp_2byte); - rtw_write16(Adapter, 0x870, 0x300); - } else { - ////1>. Open WiFi RF - mptbt_open_WiFiRF(Adapter); - - ////2>. change ant switch back - tmp_2byte = rtw_read16(Adapter, 0x860); - tmp_2byte = tmp_2byte | BIT(8); - tmp_2byte = tmp_2byte & (~BIT(9)); - rtw_write16(Adapter, 0x860, tmp_2byte); - rtw_write16(Adapter, 0x870, 0x300); - } - - return 0; -} - -u2Byte -mptbt_BtSetMode( - PADAPTER Adapter, - PBT_REQ_CMD pBtReq, - 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 btModeToSet=0; - - // - // check upper layer parameters - // - // 1. 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; - } - // 2. check upper layer parameter length - if(1 == pBtReq->paraLength) - { - btModeToSet = pBtReq->pParamStart[0]; - DBG_8192C("[MPT], BtTestMode=%d \n", btModeToSet); - } - else - { - DBG_8192C("[MPT], Error!! wrong parameter length=%d (should be 1)\n", pBtReq->paraLength); - pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U; - return paraLen; - } - - // - // execute lower layer opcodes - // - - // 1. fill h2c parameters - // check bt mode - btOpcode = BT_LO_OP_SET_BT_MODE; - if(btModeToSet >= MP_BT_MODE_MAX) - { - pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - mptbt_switch_RF(Adapter, 1); - - h2cParaBuf[0] = btModeToSet; - h2cParaLen = 1; - // 2. execute h2c and check respond c2h from bt fw is correct or not - retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen); - } - - // 3. construct respond status code and data. - if(BT_STATUS_BT_OP_SUCCESS == retStatus) - { - pBtRsp->status = BT_STATUS_SUCCESS; - } - else - { - pBtRsp->status = ((btOpcode<<8)|retStatus); - DBG_8192C("[MPT], Error!! status code=0x%x \n", pBtRsp->status); - } - - return paraLen; -} - - -VOID -MPTBT_FwC2hBtMpCtrl( - PADAPTER Adapter, - pu1Byte tmpBuf, - u1Byte length - ) -{ - u32 i; - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - PBT_EXT_C2H pExtC2h=(PBT_EXT_C2H)tmpBuf; - - if(Adapter->bBTFWReady == _FALSE || Adapter->registrypriv.mp_mode == 0 ) - { - DBG_8192C("[MPT], %s,bBTFWReady == _FALSE\n",__func__); - return; - } - //cancel_timeout for h2c handle - _cancel_timer_ex( &pMptCtx->MPh2c_timeout_timer); - - DBG_8192C("[MPT], MPTBT_FwC2hBtMpCtrl(), hex: \n"); - for(i=0;i<=length;i++) - { - //DBG_8192C("[MPT], MPTBT_FwC2hBtMpCtrl(), hex: \n",tmpBuf[i], length); - DBG_8192C(" 0x%x ",tmpBuf[i]); - } - DBG_8192C("\n [MPT], pExtC2h->extendId=0x%x\n", pExtC2h->extendId); - - switch(pExtC2h->extendId) - { - case EXT_C2H_WIFI_FW_ACTIVE_RSP: - DBG_8192C("[MPT], EXT_C2H_WIFI_FW_ACTIVE_RSP\n"); - DBG_8192C("[MPT], pExtC2h->buf hex: \n"); - if( length > 32 || length < 3 ) - break ; - for(i=0;i<=(length-3);i++) - DBG_8192C(" 0x%x ",pExtC2h->buf[i]); - //PlatformSetEvent(&pMptCtx->MptH2cRspEvent); - pMptCtx->MptH2cRspEvent=_TRUE; - _rtw_up_sema(&pMptCtx->MPh2c_Sema); - break; - case EXT_C2H_TRIG_BY_BT_FW: - DBG_8192C("[MPT], EXT_C2H_TRIG_BY_BT_FW\n"); - //PlatformMoveMemory(&pMptCtx->c2hBuf[0], tmpBuf, length); - _rtw_memcpy(&pMptCtx->c2hBuf[0], tmpBuf, length); - DBG_8192C("[MPT], pExtC2h->statusCode=0x%x\n", pExtC2h->statusCode); - DBG_8192C("[MPT], pExtC2h->retLen=0x%x\n", pExtC2h->retLen); - DBG_8192C("[MPT], pExtC2h->opCodeVer=0x%x\n", pExtC2h->opCodeVer); - DBG_8192C("[MPT], pExtC2h->reqNum=0x%x\n", pExtC2h->reqNum); - DBG_8192C("[MPT], pExtC2h->buf hex: \n"); - for(i=0;i<=(length-3);i++) - DBG_8192C(" 0x%x ",pExtC2h->buf[0]); - //PlatformSetEvent(&pMptCtx->MptBtC2hEvent); - pMptCtx->MptBtC2hEvent=_TRUE; - _rtw_up_sema(&pMptCtx->MPh2c_Sema); - break; - default: - DBG_8192C("[MPT], EXT_C2H Target not found,pExtC2h->extendId =%d ,pExtC2h->reqNum=%d\n",pExtC2h->extendId,pExtC2h->reqNum); - break; - } - - - -} - - -u2Byte -mptbt_BtGetGeneral( - IN PADAPTER Adapter, - IN PBT_REQ_CMD pBtReq, - IN PBT_RSP_CMD pBtRsp - ) -{ - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - PBT_EXT_C2H pExtC2h=(PBT_EXT_C2H)&pMptCtx->c2hBuf[0]; - u1Byte h2cParaBuf[6] ={0}; - u1Byte h2cParaLen=0; - u2Byte paraLen=0; - u1Byte retStatus=BT_STATUS_BT_OP_SUCCESS; - u1Byte btOpcode, bdAddr[6]={0}; - u1Byte btOpcodeVer=0; - u1Byte getType=0, i; - u2Byte getParaLen=0, validParaLen=0; - u1Byte regType=0, reportType=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; - } - getParaLen = pBtReq->paraLength - 1; - getType = pBtReq->pParamStart[0]; - - DBG_8192C("[MPT], getType=%d, getParaLen=%d\n", getType, getParaLen); - - // check parameter first - switch(getType) - { - case BT_GGET_REG: - DBG_8192C("[MPT], [BT_GGET_REG]\n"); - validParaLen = 5; - if(getParaLen == validParaLen) - { - btOpcode = BT_LO_OP_READ_REG; - regType = pBtReq->pParamStart[1]; - pu4Tmp = (pu4Byte)&pBtReq->pParamStart[2]; - regAddr = *pu4Tmp; - DBG_8192C("[MPT], BT_GGET_REG regType=0x%x, regAddr=0x%x!!\n", - regType, regAddr); - 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_GGET_STATUS: - DBG_8192C("[MPT], [BT_GGET_STATUS]\n"); - validParaLen = 0; - break; - case BT_GGET_REPORT: - DBG_8192C("[MPT], [BT_GGET_REPORT]\n"); - validParaLen = 1; - if(getParaLen == validParaLen) - { - reportType = pBtReq->pParamStart[1]; - DBG_8192C("[MPT], BT_GGET_REPORT reportType=0x%x!!\n", reportType); - if(reportType >= BT_REPORT_MAX) - { - pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - } - break; - default: - { - DBG_8192C("[MPT], Error!! getType=%d, out of range\n", getType); - pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - break; - } - if(getParaLen != validParaLen) - { - DBG_8192C("[MPT], Error!! wrong parameter length=%d for BT_GET_GEN_CMD cmd id=0x%x, paraLen should=0x%x\n", - getParaLen, getType, validParaLen); - pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U; - return paraLen; - } - - // - // execute lower layer opcodes - // - if(BT_GGET_REG == getType) - { - // fill h2c parameters - // here we should write reg value first then write the address, adviced by Austin - btOpcode = BT_LO_OP_READ_REG; - 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; - } - - pu2Tmp = (pu2Byte)&pExtC2h->buf[0]; - regValue = *pu2Tmp; - DBG_8192C("[MPT], read reg regType=0x%x, regAddr=0x%x, regValue=0x%x\n", - regType, regAddr, regValue); - - pu4Tmp = (pu4Byte)&pBtRsp->pParamStart[0]; - *pu4Tmp = regValue; - paraLen = 4; - } - else if(BT_GGET_STATUS == getType) - { - btOpcode = BT_LO_OP_GET_BT_STATUS; - 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; - } - - pBtRsp->pParamStart[0] = pExtC2h->buf[0]; - pBtRsp->pParamStart[1] = pExtC2h->buf[1]; - DBG_8192C("[MPT], read bt status, testMode=0x%x, testStatus=0x%x\n", - pBtRsp->pParamStart[0], pBtRsp->pParamStart[1]); - paraLen = 2; - } - else if(BT_GGET_REPORT == getType) - { - switch(reportType) - { - case BT_REPORT_RX_PACKET_CNT: - { - DBG_8192C("[MPT], [Rx Packet Counts]\n"); - btOpcode = BT_LO_OP_GET_RX_PKT_CNT_L; - 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; - } - pBtRsp->pParamStart[0] = pExtC2h->buf[0]; - pBtRsp->pParamStart[1] = pExtC2h->buf[1]; - - btOpcode = BT_LO_OP_GET_RX_PKT_CNT_H; - 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; - } - pBtRsp->pParamStart[2] = pExtC2h->buf[0]; - pBtRsp->pParamStart[3] = pExtC2h->buf[1]; - paraLen = 4; - } - break; - case BT_REPORT_RX_ERROR_BITS: - { - DBG_8192C("[MPT], [Rx Error Bits]\n"); - btOpcode = BT_LO_OP_GET_RX_ERROR_BITS_L; - 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; - } - pBtRsp->pParamStart[0] = pExtC2h->buf[0]; - pBtRsp->pParamStart[1] = pExtC2h->buf[1]; - - btOpcode = BT_LO_OP_GET_RX_ERROR_BITS_H; - 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; - } - pBtRsp->pParamStart[2] = pExtC2h->buf[0]; - pBtRsp->pParamStart[3] = pExtC2h->buf[1]; - paraLen = 4; - } - break; - case BT_REPORT_RSSI: - { - DBG_8192C("[MPT], [RSSI]\n"); - btOpcode = BT_LO_OP_GET_RSSI; - 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; - } - pBtRsp->pParamStart[0] = pExtC2h->buf[0]; - pBtRsp->pParamStart[1] = pExtC2h->buf[1]; - paraLen = 2; - } - break; - case BT_REPORT_CFO_HDR_QUALITY: - { - DBG_8192C("[MPT], [CFO & Header Quality]\n"); - btOpcode = BT_LO_OP_GET_CFO_HDR_QUALITY_L; - 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; - } - pBtRsp->pParamStart[0] = pExtC2h->buf[0]; - pBtRsp->pParamStart[1] = pExtC2h->buf[1]; - - btOpcode = BT_LO_OP_GET_CFO_HDR_QUALITY_H; - 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; - } - pBtRsp->pParamStart[2] = pExtC2h->buf[0]; - pBtRsp->pParamStart[3] = pExtC2h->buf[1]; - paraLen = 4; - } - break; - case BT_REPORT_CONNECT_TARGET_BD_ADDR: - { - DBG_8192C("[MPT], [Connected Target BD ADDR]\n"); - btOpcode = BT_LO_OP_GET_TARGET_BD_ADDR_L; - 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; - } - bdAddr[5] = pExtC2h->buf[0]; - bdAddr[4] = pExtC2h->buf[1]; - bdAddr[3] = pExtC2h->buf[2]; - - btOpcode = BT_LO_OP_GET_TARGET_BD_ADDR_H; - 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; - } - bdAddr[2] = pExtC2h->buf[0]; - bdAddr[1] = pExtC2h->buf[1]; - bdAddr[0] = pExtC2h->buf[2]; - - DBG_8192C("[MPT], Connected Target BDAddr:%s", bdAddr); - for(i=0; i<6; i++) - { - pBtRsp->pParamStart[i] = bdAddr[5-i]; - } - paraLen = 6; - } - break; - default: - pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - break; - } - } - - pBtRsp->status = BT_STATUS_SUCCESS; - return paraLen; -} - - - -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:%x,%x,%x,%x,%x,%x\n", - bdAddr[0],bdAddr[1],bdAddr[2],bdAddr[3],bdAddr[4],bdAddr[5]); - } - 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_SET_TRACKING_INTERVAL: - DBG_871X("[MPT], [BT_SET_TRACKING_INTERVAL] setParaLen =%d \n",setParaLen); - - validParaLen = 1; - if(setParaLen == validParaLen) - calVal = pBtReq->pParamStart[1]; - break; - case BT_SET_THERMAL_METER: - DBG_871X("[MPT], [BT_SET_THERMAL_METER] setParaLen =%d \n",setParaLen); - validParaLen = 1; - if(setParaLen == validParaLen) - calVal = pBtReq->pParamStart[1]; - break; - case BT_ENABLE_CFO_TRACKING: - DBG_871X("[MPT], [BT_ENABLE_CFO_TRACKING] setParaLen =%d \n",setParaLen); - validParaLen = 1; - if(setParaLen == validParaLen) - calVal = pBtReq->pParamStart[1]; - 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; - } - } - else if(BT_SET_TRACKING_INTERVAL == setType) - { - // BT_LO_OP_SET_TRACKING_INTERVAL = 0x22, - // BT_LO_OP_SET_THERMAL_METER = 0x23, - // BT_LO_OP_ENABLE_CFO_TRACKING = 0x24, - btOpcode = BT_LO_OP_SET_TRACKING_INTERVAL; - 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; - } - } - else if(BT_SET_THERMAL_METER == setType) - { - btOpcode = BT_LO_OP_SET_THERMAL_METER; - 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; - } - } - else if(BT_ENABLE_CFO_TRACKING == setType) - { - btOpcode = BT_LO_OP_ENABLE_CFO_TRACKING; - 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; -} - - - -u2Byte -mptbt_BtSetTxRxPars( - 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; - PBT_TXRX_PARAMETERS pTxRxPars=(PBT_TXRX_PARAMETERS)&pBtReq->pParamStart[0]; - u2Byte lenTxRx=sizeof(BT_TXRX_PARAMETERS); - u1Byte i; - u1Byte bdAddr[6]={0}; - - // - // check upper layer parameters - // - - // 1. 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; - } - // 2. check upper layer parameter length - if(pBtReq->paraLength == sizeof(BT_TXRX_PARAMETERS)) - { - DBG_8192C ("[MPT], pTxRxPars->txrxChannel=0x%x \n", pTxRxPars->txrxChannel); - DBG_8192C ("[MPT], pTxRxPars->txrxTxPktCnt=0x%8x \n", pTxRxPars->txrxTxPktCnt); - DBG_8192C ("[MPT], pTxRxPars->txrxTxPktInterval=0x%x \n", pTxRxPars->txrxTxPktInterval); - DBG_8192C ("[MPT], pTxRxPars->txrxPayloadType=0x%x \n", pTxRxPars->txrxPayloadType); - DBG_8192C ("[MPT], pTxRxPars->txrxPktType=0x%x \n", pTxRxPars->txrxPktType); - DBG_8192C ("[MPT], pTxRxPars->txrxPayloadLen=0x%x \n", pTxRxPars->txrxPayloadLen); - DBG_8192C ("[MPT], pTxRxPars->txrxPktHeader=0x%x \n", pTxRxPars->txrxPktHeader); - DBG_8192C ("[MPT], pTxRxPars->txrxWhitenCoeff=0x%x \n", pTxRxPars->txrxWhitenCoeff); - bdAddr[0] = pTxRxPars->txrxBdaddr[5]; - bdAddr[1] = pTxRxPars->txrxBdaddr[4]; - bdAddr[2] = pTxRxPars->txrxBdaddr[3]; - bdAddr[3] = pTxRxPars->txrxBdaddr[2]; - bdAddr[4] = pTxRxPars->txrxBdaddr[1]; - bdAddr[5] = pTxRxPars->txrxBdaddr[0]; - DBG_8192C ("[MPT], pTxRxPars->txrxBdaddr: %s", &bdAddr[0]); - DBG_8192C ("[MPT], pTxRxPars->txrxTxGainIndex=0x%x \n", pTxRxPars->txrxTxGainIndex); - } - else - { - DBG_8192C ("[MPT], Error!! pBtReq->paraLength=%d, correct Len=%d\n", pBtReq->paraLength, lenTxRx); - pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U; - return paraLen; - } - - // - // execute lower layer opcodes - // - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_PKT_HEADER; - if(pTxRxPars->txrxPktHeader > 0x3ffff) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxPktHeader=0x%x is out of range, (should be between 0x0~0x3ffff)\n", pTxRxPars->txrxPktHeader); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - h2cParaBuf[0] = (u1Byte)(pTxRxPars->txrxPktHeader&0xff); - h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxPktHeader&0xff00)>>8); - h2cParaBuf[2] = (u1Byte)((pTxRxPars->txrxPktHeader&0xff0000)>>16); - 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; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_PKT_TYPE_LEN; - { - u2Byte payloadLenLimit=0; - switch(pTxRxPars->txrxPktType) - { - case MP_BT_PKT_DH1: - payloadLenLimit = 27*8; - break; - case MP_BT_PKT_DH3: - payloadLenLimit = 183*8; - break; - case MP_BT_PKT_DH5: - payloadLenLimit = 339*8; - break; - case MP_BT_PKT_2DH1: - payloadLenLimit = 54*8; - break; - case MP_BT_PKT_2DH3: - payloadLenLimit = 367*8; - break; - case MP_BT_PKT_2DH5: - payloadLenLimit = 679*8; - break; - case MP_BT_PKT_3DH1: - payloadLenLimit = 83*8; - break; - case MP_BT_PKT_3DH3: - payloadLenLimit = 552*8; - break; - case MP_BT_PKT_3DH5: - payloadLenLimit = 1021*8; - break; - case MP_BT_PKT_LE: - payloadLenLimit = 39*8; - break; - default: - { - DBG_8192C ("[MPT], Error!! Unknown pTxRxPars->txrxPktType=0x%x\n", pTxRxPars->txrxPktType); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - break; - } - - if(pTxRxPars->txrxPayloadLen > payloadLenLimit) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxPayloadLen=0x%x, (should smaller than %d)\n", - pTxRxPars->txrxPayloadLen, payloadLenLimit); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - - h2cParaBuf[0] = pTxRxPars->txrxPktType; - h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxPayloadLen&0xff)); - h2cParaBuf[2] = (u1Byte)((pTxRxPars->txrxPayloadLen&0xff00)>>8); - 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; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_PKT_CNT_L_PL_TYPE; - if(pTxRxPars->txrxPayloadType > MP_BT_PAYLOAD_MAX) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxPayloadType=0x%x, (should be between 0~4)\n", pTxRxPars->txrxPayloadType); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - h2cParaBuf[0] = (u1Byte)((pTxRxPars->txrxTxPktCnt&0xff)); - h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxTxPktCnt&0xff00)>>8); - h2cParaBuf[2] = pTxRxPars->txrxPayloadType; - 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; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_PKT_CNT_H_PKT_INTV; - if(pTxRxPars->txrxTxPktInterval > 15) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxTxPktInterval=0x%x, (should be between 0~15)\n", pTxRxPars->txrxTxPktInterval); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - h2cParaBuf[0] = (u1Byte)((pTxRxPars->txrxTxPktCnt&0xff0000)>>16); - h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxTxPktCnt&0xff000000)>>24); - h2cParaBuf[2] = pTxRxPars->txrxTxPktInterval; - 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; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_WHITENCOEFF; - { - h2cParaBuf[0] = pTxRxPars->txrxWhitenCoeff; - 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; - } - - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_CHNL_TX_GAIN; - if( (pTxRxPars->txrxChannel > 78) || - (pTxRxPars->txrxTxGainIndex > 7) ) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxChannel=0x%x, (should be between 0~78)\n", pTxRxPars->txrxChannel); - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxTxGainIndex=0x%x, (should be between 0~7)\n", pTxRxPars->txrxTxGainIndex); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - h2cParaBuf[0] = pTxRxPars->txrxChannel; - h2cParaBuf[1] = pTxRxPars->txrxTxGainIndex; - h2cParaLen = 2; - 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; - } - - // fill h2c parameters - btOpcode = BT_LO_OP_SET_BD_ADDR_L; - if( (pTxRxPars->txrxBdaddr[0]==0) && - (pTxRxPars->txrxBdaddr[1]==0) && - (pTxRxPars->txrxBdaddr[2]==0) && - (pTxRxPars->txrxBdaddr[3]==0) && - (pTxRxPars->txrxBdaddr[4]==0) && - (pTxRxPars->txrxBdaddr[5]==0) ) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxBdaddr=all zero\n"); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - if( (pTxRxPars->txrxBdaddr[0]==0xff) && - (pTxRxPars->txrxBdaddr[1]==0xff) && - (pTxRxPars->txrxBdaddr[2]==0xff) && - (pTxRxPars->txrxBdaddr[3]==0xff) && - (pTxRxPars->txrxBdaddr[4]==0xff) && - (pTxRxPars->txrxBdaddr[5]==0xff) ) - { - DBG_8192C ("[MPT], Error!! pTxRxPars->txrxBdaddr=all 0xf\n"); - pBtRsp->status = (btOpcode<<8)|BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - - { - h2cParaBuf[0] = pTxRxPars->txrxBdaddr[0]; - h2cParaBuf[1] = pTxRxPars->txrxBdaddr[1]; - h2cParaBuf[2] = pTxRxPars->txrxBdaddr[2]; - 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_BD_ADDR_H; - { - h2cParaBuf[0] = pTxRxPars->txrxBdaddr[3]; - h2cParaBuf[1] = pTxRxPars->txrxBdaddr[4]; - h2cParaBuf[2] = pTxRxPars->txrxBdaddr[5]; - 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; - } - - pBtRsp->status = BT_STATUS_SUCCESS; - return paraLen; -} - - - -u2Byte -mptbt_BtTestCtrl( - 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 testCtrl=0; - - // - // check upper layer parameters - // - - // 1. 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; - } - // 2. check upper layer parameter length - if(1 == pBtReq->paraLength) - { - testCtrl = pBtReq->pParamStart[0]; - DBG_8192C("[MPT], testCtrl=%d \n", testCtrl); - } - else - { - DBG_8192C("[MPT], Error!! wrong parameter length=%d (should be 1)\n", pBtReq->paraLength); - pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U; - return paraLen; - } - - // - // execute lower layer opcodes - // - - // 1. fill h2c parameters - // check bt mode - btOpcode = BT_LO_OP_TEST_CTRL; - if(testCtrl >= MP_BT_TEST_MAX) - { - DBG_8192C("[MPT], Error!! testCtrl=0x%x, (should be between smaller or equal to 0x%x)\n", - testCtrl, MP_BT_TEST_MAX-1); - pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U; - return paraLen; - } - else - { - h2cParaBuf[0] = testCtrl; - h2cParaLen = 1; - retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen); - } - - // 3. 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; - } - - pBtRsp->status = BT_STATUS_SUCCESS; - return paraLen; -} - - -u2Byte -mptbt_TestBT( - 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 testCtrl=0; - - // 1. fill h2c parameters - btOpcode = 0x11; - h2cParaBuf[0] = 0x11; - h2cParaBuf[1] = 0x0; - h2cParaBuf[2] = 0x0; - h2cParaBuf[3] = 0x0; - h2cParaBuf[4] = 0x0; - h2cParaLen = 1; - // retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen); - retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, h2cParaBuf, h2cParaLen); - - - // 3. 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; - } - - pBtRsp->status = BT_STATUS_SUCCESS; - return paraLen; -} - -VOID -mptbt_BtControlProcess( - PADAPTER Adapter, - PVOID pInBuf - ) -{ - u1Byte H2C_Parameter[6] ={0}; - PBT_H2C pH2c=(PBT_H2C)&H2C_Parameter[0]; - PMPT_CONTEXT pMptCtx=&(Adapter->mppriv.MptCtx); - PBT_REQ_CMD pBtReq=(PBT_REQ_CMD)pInBuf; - PBT_RSP_CMD pBtRsp=(PBT_RSP_CMD)&pMptCtx->mptOutBuf[0]; - u1Byte i; - - DBG_8192C("[MPT], mptbt_BtControlProcess()=========>\n"); - - DBG_8192C("[MPT], input opCodeVer=%d\n", pBtReq->opCodeVer); - DBG_8192C("[MPT], input OpCode=%d\n", pBtReq->OpCode); - DBG_8192C("[MPT], paraLength=%d \n", pBtReq->paraLength); - if(pBtReq->paraLength) - { - //DBG_8192C("[MPT], parameters(hex):0x%x %d \n",&pBtReq->pParamStart[0], pBtReq->paraLength); - } - - // The following we should maintain the User OP codes sent by upper layer - - pBtRsp->status = BT_STATUS_SUCCESS; - pMptCtx->mptOutLen = 4; //length of (BT_RSP_CMD.status+BT_RSP_CMD.paraLength) - pBtRsp->paraLength = 0x0; - - _rtw_memset((PVOID)&pMptCtx->mptOutBuf[0], '\0',100); - - switch(pBtReq->OpCode) - { - case BT_UP_OP_BT_READY: - DBG_8192C("[MPT], OPcode : [BT_READY]\n"); - pBtRsp->paraLength = mptbt_BtReady(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_BT_SET_MODE: - DBG_8192C("[MPT], OPcode : [BT_SET_MODE]\n"); - pBtRsp->paraLength = mptbt_BtSetMode(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_BT_SET_TX_RX_PARAMETER: - DBG_8192C("[MPT], OPcode : [BT_SET_TXRX_PARAMETER]\n"); - pBtRsp->paraLength = mptbt_BtSetTxRxPars(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_BT_SET_GENERAL: - DBG_8192C("[MPT], OPcode : [BT_SET_GENERAL]\n"); - pBtRsp->paraLength = mptbt_BtSetGeneral(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_BT_GET_GENERAL: - DBG_8192C("[MPT], OPcode : [BT_GET_GENERAL]\n"); - pBtRsp->paraLength = mptbt_BtGetGeneral(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_BT_TEST_CTRL: - DBG_8192C("[MPT], OPcode : [BT_TEST_CTRL]\n"); - pBtRsp->paraLength = mptbt_BtTestCtrl(Adapter, pBtReq, pBtRsp); - break; - case BT_UP_OP_TEST_BT: - DBG_8192C("[MPT], OPcode : [TEST_BT]\n"); - pBtRsp->paraLength = mptbt_TestBT(Adapter, pBtReq, pBtRsp); - break; - default: - DBG_8192C("[MPT], Error!! OPcode : UNDEFINED!!!!\n"); - pBtRsp->status = BT_STATUS_UNKNOWN_OPCODE_U; - pBtRsp->paraLength = 0x0; - break; - } - - DBG_8192C("pBtRsp->paraLength =%d \n",pBtRsp->paraLength); - - pMptCtx->mptOutLen += pBtRsp->paraLength; - - DBG_8192C("\n [MPT], OUT to DLL pMptCtx->mptOutLen=%d ,pBtRsp->paraLength =%d ",pMptCtx->mptOutLen,pBtRsp->paraLength); - - DBG_8192C("\n [MPT], mptbt_BtControlProcess()<=========\n"); -} - -#endif - diff --git a/core/rtw_wapi.c b/core/rtw_wapi.c deleted file mode 100755 index 6c6268c..0000000 --- a/core/rtw_wapi.c +++ /dev/null @@ -1,1326 +0,0 @@ -#ifdef CONFIG_WAPI_SUPPORT - -#include -#include -#include -#include - - -u32 wapi_debug_component = -// WAPI_INIT | -// WAPI_API | -// WAPI_TX | -// WAPI_RX | - WAPI_ERR ; //always open err flags on - -void WapiFreeAllStaInfo(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo; - PRT_WAPI_BKID pWapiBkid; - - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__); - pWapiInfo = &padapter->wapiInfo; - - //Pust to Idle List - rtw_wapi_return_all_sta_info(padapter); - - //Sta Info List - while(!list_empty(&(pWapiInfo->wapiSTAIdleList))) - { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiStaInfo->list); - } - - //BKID List - while(!list_empty(&(pWapiInfo->wapiBKIDIdleList))) - { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - } - WAPI_TRACE(WAPI_INIT, "<=========== %s\n", __FUNCTION__); - return; -} - -void WapiSetIE(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - //PRT_WAPI_BKID pWapiBkid; - u16 protocolVer = 1; - u16 akmCnt = 1; - u16 suiteCnt = 1; - u16 capability = 0; - u8 OUI[3]; - - OUI[0] = 0x00; - OUI[1] = 0x14; - OUI[2] = 0x72; - - pWapiInfo->wapiIELength = 0; -//protocol version - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &protocolVer, 2); - pWapiInfo->wapiIELength +=2; -//akm - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &akmCnt, 2); - pWapiInfo->wapiIELength +=2; - - if(pWapiInfo->bWapiPSK){ - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3); - pWapiInfo->wapiIELength +=3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x2; - pWapiInfo->wapiIELength +=1; - }else{ - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3); - pWapiInfo->wapiIELength +=3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength +=1; - } - -//usk - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &suiteCnt, 2); - pWapiInfo->wapiIELength +=2; - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3); - pWapiInfo->wapiIELength +=3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength +=1; - -//msk - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3); - pWapiInfo->wapiIELength +=3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength +=1; - -//Capbility - memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &capability, 2); - pWapiInfo->wapiIELength +=2; -} - - -/* PN1 > PN2, return 1, - * else return 0. - */ -u32 WapiComparePN(u8 *PN1, u8 *PN2) -{ - char i; - - if ((NULL == PN1) || (NULL == PN2)) - return 1; - - // overflow case - if ((PN2[15] - PN1[15]) & 0x80) - return 1; - - for (i=16; i>0; i--) - { - if(PN1[i-1] == PN2[i-1]) - continue; - else if(PN1[i-1] > PN2[i-1]) - return 1; - else - return 0; - } - - return 0; -} - -u8 -WapiGetEntryForCamWrite(_adapter *padapter,u8 *pMacAddr,u8 KID,BOOLEAN IsMsk) -{ - PRT_WAPI_T pWapiInfo=NULL; - //PRT_WAPI_CAM_ENTRY pEntry=NULL; - u8 i=0; - u8 ret = 0xff; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - pWapiInfo = &padapter->wapiInfo; - - //exist? - for(i=0;iwapiCamEntry[i].IsUsed - && (_rtw_memcmp(pMacAddr, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE) - && pWapiInfo->wapiCamEntry[i].keyidx == KID - && pWapiInfo->wapiCamEntry[i].type == IsMsk) - { - ret = pWapiInfo->wapiCamEntry[i].entry_idx; //cover it - break; - } - } - - if(i == WAPI_CAM_ENTRY_NUM) //not found - { - for(i=0;iwapiCamEntry[i].IsUsed == 0) - { - pWapiInfo->wapiCamEntry[i].IsUsed = 1; - pWapiInfo->wapiCamEntry[i].type = IsMsk; - pWapiInfo->wapiCamEntry[i].keyidx = KID; - _rtw_memcpy(pWapiInfo->wapiCamEntry[i].PeerMacAddr, pMacAddr,ETH_ALEN); - ret = pWapiInfo->wapiCamEntry[i].entry_idx; - break; - } - } - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); - return ret; - -/* - if(RTIsListEmpty(&pWapiInfo->wapiCamIdleList)){ - RT_TRACE(COMP_SEC,DBG_LOUD,("No Entry for wapi!!!\n")); - return 0; - } - - pEntry = (PRT_WAPI_CAM_ENTRY)RTRemoveHeadList(&pWapiInfo->wapiCamIdleList); - RTInsertTailList(&pWapiInfo->wapiCamUsedList, &pEntry->list); - - RT_TRACE(COMP_SEC,DBG_LOUD,("<====WapiGetCamEntry(),Get Entry Idx:%d.but we just return 4 for test\n",pEntry->entry_idx)); - - return pEntry->entry_idx;*/ -} - -u8 WapiGetEntryForCamClear(_adapter *padapter,u8 *pPeerMac,u8 keyid,u8 IsMsk) -{ - PRT_WAPI_T pWapiInfo=NULL; - u8 i=0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - pWapiInfo = &padapter->wapiInfo; - - for(i=0;iwapiCamEntry[i].IsUsed - && (_rtw_memcmp(pPeerMac, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE) - && pWapiInfo->wapiCamEntry[i].keyidx == keyid - && pWapiInfo->wapiCamEntry[i].type == IsMsk) - { - pWapiInfo->wapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; - _rtw_memset(pWapiInfo->wapiCamEntry[i].PeerMacAddr,0,ETH_ALEN); - - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); - return pWapiInfo->wapiCamEntry[i].entry_idx; - } - } - - WAPI_TRACE(WAPI_API,"<====WapiGetReturnCamEntry(), No this cam entry.\n"); - return 0xff; -/* - if(RTIsListEmpty(&pWapiInfo->wapiCamUsedList)){ - RT_TRACE(COMP_SEC,DBG_LOUD,("No Entry for wapi!!!\n")); - return FALSE; - } - - pList = &pWapiInfo->wapiCamUsedList; - while(pList->Flink != &pWapiInfo->wapiCamUsedList) - { - pEntry = (PRT_WAPI_CAM_ENTRY)pList->Flink; - if(PlatformCompareMemory(pPeerMac,pEntry->PeerMacAddr, ETHER_ADDRLEN)== 0 - && keyid == pEntry->keyidx) - { - RTRemoveEntryList(pList); - RTInsertHeadList(&pWapiInfo->wapiCamIdleList, pList); - return pEntry->entry_idx; - } - pList = pList->Flink; - } - - return 0; -*/ -} - -void -WapiResetAllCamEntry(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - int i; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - pWapiInfo = &padapter->wapiInfo; - - for (i=0;iwapiCamEntry[i].PeerMacAddr, 0, ETH_ALEN); - pWapiInfo->wapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; //invalid - pWapiInfo->wapiCamEntry[i].entry_idx = 4+i*2; - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); - - return; -} - -u8 WapiWriteOneCamEntry( - _adapter *padapter, - u8 *pMacAddr, - u8 KeyId, - u8 EntryId, - u8 EncAlg, - u8 bGroupKey, - u8 *pKey -) -{ - u8 retVal = 0; - u16 usConfig = 0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - if(EntryId >= 32) - { - WAPI_TRACE(WAPI_ERR, "<=== CamAddOneEntry(): ulKeyId exceed!\n"); - return retVal; - } - - usConfig=usConfig|(0x01<<15)|((u16)(EncAlg)<<2)|(KeyId); - - if(EncAlg == _SMS4_ ) - { - if(bGroupKey == 1) - usConfig |= (0x01<<6); - if((EntryId % 2)==1) // ==0 sec key; == 1mic key - usConfig |= (0x01<<5); - } - - write_cam(padapter, EntryId, usConfig, pMacAddr, pKey); - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - return 1; -} - -void rtw_wapi_init(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - int i; - - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) - { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - pWapiInfo = &padapter->wapiInfo; - pWapiInfo->bWapiEnable = false; - - //Init BKID List - INIT_LIST_HEAD(&pWapiInfo->wapiBKIDIdleList); - INIT_LIST_HEAD(&pWapiInfo->wapiBKIDStoreList); - for(i=0;iwapiBKID[i].list, &pWapiInfo->wapiBKIDIdleList); - } - - //Init STA List - INIT_LIST_HEAD(&pWapiInfo->wapiSTAIdleList); - INIT_LIST_HEAD(&pWapiInfo->wapiSTAUsedList); - for(i=0;iwapiSta[i].list, &pWapiInfo->wapiSTAIdleList); - } - - for (i=0;iwapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; //invalid - pWapiInfo->wapiCamEntry[i].entry_idx = 4+i*2; - } - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__); -} - -void rtw_wapi_free(_adapter *padapter) -{ - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) - { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - WapiFreeAllStaInfo(padapter); - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__); -} - -void rtw_wapi_disable_tx(_adapter *padapter) -{ - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) - { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - padapter->wapiInfo.wapiTxMsk.bTxEnable = false; - padapter->wapiInfo.wapiTxMsk.bSet = false; - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__); -} - -u8 rtw_wapi_is_wai_packet(_adapter* padapter,u8 *pkt_data) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 WaiPkt = 0, *pTaddr, bFind = false; - u8 Offset_TypeWAI = 0 ; // (mac header len + llc length) - - WAPI_TRACE(WAPI_TX|WAPI_RX, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return 0; - } - - Offset_TypeWAI = 24 + 6 ; - - //YJ,add,091103. Data frame may also have skb->data[30]=0x88 and skb->data[31]=0xb4. - if ((pkt_data[1]&0x40) !=0) - { - DBG_871X("data is privacy \n"); - return 0; - } - - pTaddr = GetAddr2Ptr(pkt_data); - if(list_empty(&pWapiInfo->wapiSTAUsedList)){ - bFind = false; - }else{ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){ - if (_rtw_memcmp(pTaddr, pWapiSta->PeerMacAddr, 6) == _TRUE) { - bFind = true; - break; - } - } - } - - WAPI_TRACE(WAPI_TX|WAPI_RX, "%s: bFind=%d pTaddr="MAC_FMT"\n", __FUNCTION__, bFind, MAC_ARG(pTaddr)); - - if (pkt_data[0] == WIFI_QOS_DATA_TYPE) - { - Offset_TypeWAI += 2; - } - - // 88b4? - if( (pkt_data[Offset_TypeWAI]==0x88) && (pkt_data[Offset_TypeWAI+1]==0xb4) ){ - WaiPkt = pkt_data[Offset_TypeWAI+5]; - - psecuritypriv->hw_decrypted = _TRUE; - }else{ - WAPI_TRACE(WAPI_TX|WAPI_RX, "%s(): non wai packet\n",__FUNCTION__); - } - - WAPI_TRACE(WAPI_TX|WAPI_RX, "%s(): Recvd WAI frame. IsWAIPkt(%d)\n",__FUNCTION__, WaiPkt); - - return WaiPkt; -} - - -void rtw_wapi_update_info(_adapter *padapter, union recv_frame *precv_frame) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - struct recv_frame_hdr *precv_hdr; - u8 *ptr; - u8 *pTA; - u8 *pRecvPN; - - - WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - precv_hdr = &precv_frame->u.hdr; - ptr = precv_hdr->rx_data; - - if (precv_hdr->attrib.qos == 1) - { - precv_hdr->UserPriority = GetTid(ptr); - } - else - { - precv_hdr->UserPriority = 0; - } - - pTA = GetAddr2Ptr(ptr); - _rtw_memcpy((u8 *)precv_hdr->WapiSrcAddr, pTA, 6); - pRecvPN = ptr + precv_hdr->attrib.hdrlen + 2; - _rtw_memcpy((u8 *)precv_hdr->WapiTempPN, pRecvPN, 16); - - WAPI_TRACE(WAPI_RX, "<========== %s\n", __FUNCTION__); -} - -/**************************************************************************** -TRUE-----------------Drop -FALSE---------------- handle -add to support WAPI to N-mode -*****************************************************************************/ -u8 rtw_wapi_check_for_drop( - _adapter *padapter, - union recv_frame *precv_frame -) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 *pLastRecvPN = NULL; - u8 bFind = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 bDrop = false; - struct recv_frame_hdr *precv_hdr = &precv_frame->u.hdr; - u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - u8 *ptr = precv_frame->u.hdr.rx_data; - int i; - - WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return false; - } - - if(precv_hdr->bIsWaiPacket !=0) - { - if(precv_hdr->bIsWaiPacket== 0x8) - { - - DBG_871X("rtw_wapi_check_for_drop: dump packet \n"); - for(i=0;i<50;i++) - { - DBG_871X("%02X ",ptr[i]); - if((i+1) %8 ==0) - DBG_871X("\n"); - } - DBG_871X("\n rtw_wapi_check_for_drop: dump packet \n"); - - for(i=0;i<16;i++) - { - if(ptr[i+27] !=0) - break; - } - - if(i== 16) - { - WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: drop with zero BKID \n"); - return true; - } - else - { - return false; - } - } - else - return false; - } - - if(list_empty(&pWapiInfo->wapiSTAUsedList)){ - bFind = false; - }else{ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (_rtw_memcmp(precv_hdr->WapiSrcAddr, pWapiSta->PeerMacAddr, ETH_ALEN) == _TRUE) { - bFind = true; - break; - } - } - } - WAPI_TRACE(WAPI_RX, "%s: bFind=%d prxb->WapiSrcAddr="MAC_FMT"\n", __FUNCTION__, bFind, MAC_ARG(precv_hdr->WapiSrcAddr)); - - if(bFind) - { - if(IS_MCAST(precv_hdr->attrib.ra)) - { - WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: multicast case \n"); - pLastRecvPN = pWapiSta->lastRxMulticastPN; - } - else - { - WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: unicast case \n"); - switch(precv_hdr->UserPriority) - { - case 0: - case 3: - pLastRecvPN = pWapiSta->lastRxUnicastPNBEQueue; - break; - case 1: - case 2: - pLastRecvPN = pWapiSta->lastRxUnicastPNBKQueue; - break; - case 4: - case 5: - pLastRecvPN = pWapiSta->lastRxUnicastPNVIQueue; - break; - case 6: - case 7: - pLastRecvPN = pWapiSta->lastRxUnicastPNVOQueue; - break; - default: - WAPI_TRACE(WAPI_ERR,"%s: Unknown TID \n",__FUNCTION__); - break; - } - } - - if(!WapiComparePN(precv_hdr->WapiTempPN,pLastRecvPN)) - { - WAPI_TRACE(WAPI_RX,"%s: Equal PN!!\n",__FUNCTION__); - if(IS_MCAST(precv_hdr->attrib.ra)) - _rtw_memcpy(pLastRecvPN,WapiAEMultiCastPNInitialValueSrc,16); - else - _rtw_memcpy(pLastRecvPN,WapiAEPNInitialValueSrc,16); - bDrop = true; - } - else - { - _rtw_memcpy(pLastRecvPN,precv_hdr->WapiTempPN,16); - } - } - - WAPI_TRACE(WAPI_RX, "<========== %s\n", __FUNCTION__); - return bDrop; -} - -void rtw_build_probe_resp_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength+2; - pattrib->pktlen += WapiIELength+2; - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__); -} - -void rtw_build_beacon_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength+2; - pattrib->pktlen += WapiIELength+2; - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__); -} - -void rtw_build_assoc_req_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_BKID pWapiBKID; - u16 bkidNum; - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - bkidNum = 0; - if(!list_empty(&(pWapiInfo->wapiBKIDStoreList))){ - list_for_each_entry(pWapiBKID, &pWapiInfo->wapiBKIDStoreList, list) { - bkidNum ++; - _rtw_memcpy(pWapiInfo->wapiIE+WapiIELength+2, pWapiBKID->bkid,16); - WapiIELength += 16; - } - } - _rtw_memcpy(pWapiInfo->wapiIE+WapiIELength, &bkidNum, 2); - WapiIELength += 2; - - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength+2; - pattrib->pktlen += WapiIELength+2; - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__); -} - -void rtw_wapi_on_assoc_ok(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - PRT_WAPI_STA_INFO pWapiSta; - u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - //u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - pWapiSta =(PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiSta->list); - list_add_tail(&pWapiSta->list, &pWapiInfo->wapiSTAUsedList); - _rtw_memcpy(pWapiSta->PeerMacAddr,padapter->mlmeextpriv.mlmext_info.network.MacAddress,6); - _rtw_memcpy(pWapiSta->lastRxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16); - _rtw_memcpy(pWapiSta->lastRxUnicastPN, WapiAEPNInitialValueSrc, 16); - - //For chenk PN error with Qos Data after s3: add by ylb 20111114 - _rtw_memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiAEPNInitialValueSrc,16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiAEPNInitialValueSrc,16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiAEPNInitialValueSrc,16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiAEPNInitialValueSrc,16); - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__); -} - - -void rtw_wapi_return_one_sta_info(_adapter *padapter, u8 *MacAddr) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo = NULL; - PRT_WAPI_BKID pWapiBkid = NULL; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - pWapiInfo = &padapter->wapiInfo; - - WAPI_TRACE(WAPI_API, "==========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - if(check_fwstate(pmlmepriv, WIFI_STATION_STATE)) - { - while(!list_empty(&(pWapiInfo->wapiBKIDStoreList))) - { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - _rtw_memset(pWapiBkid->bkid,0,16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList); - } - } - - - WAPI_TRACE(WAPI_API, " %s: after clear bkid \n", __FUNCTION__); - - - //Remove STA info - if(list_empty(&(pWapiInfo->wapiSTAUsedList))){ - WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is null \n", __FUNCTION__); - return; - }else{ - - WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is not null \n", __FUNCTION__); -#if 0 - pWapiStaInfo=(PRT_WAPI_STA_INFO)list_entry((pWapiInfo->wapiSTAUsedList.next),RT_WAPI_STA_INFO,list); - - list_for_each_entry(pWapiStaInfo, &(pWapiInfo->wapiSTAUsedList), list) { - - DBG_871X("MAC Addr %02x-%02x-%02x-%02x-%02x-%02x \n",MacAddr[0],MacAddr[1],MacAddr[2],MacAddr[3],MacAddr[4],MacAddr[5]); - - - DBG_871X("peer Addr %02x-%02x-%02x-%02x-%02x-%02x \n",pWapiStaInfo->PeerMacAddr[0],pWapiStaInfo->PeerMacAddr[1],pWapiStaInfo->PeerMacAddr[2],pWapiStaInfo->PeerMacAddr[3],pWapiStaInfo->PeerMacAddr[4],pWapiStaInfo->PeerMacAddr[5]); - - if(pWapiStaInfo == NULL) - { - WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo == NULL Case \n", __FUNCTION__); - return; - } - - if(pWapiStaInfo->PeerMacAddr == NULL) - { - WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo->PeerMacAddr == NULL Case \n", __FUNCTION__); - return; - } - - if(MacAddr == NULL) - { - WAPI_TRACE(WAPI_API, " %s: MacAddr == NULL Case \n", __FUNCTION__); - return; - } - - if (_rtw_memcmp(pWapiStaInfo->PeerMacAddr, MacAddr, ETH_ALEN) == _TRUE) { - pWapiStaInfo->bAuthenticateInProgress = false; - pWapiStaInfo->bSetkeyOk = false; - _rtw_memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN); - list_del_init(&pWapiStaInfo->list); - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - break; - } - - } -#endif - - while(!list_empty(&(pWapiInfo->wapiSTAUsedList))) - { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list); - - DBG_871X("peer Addr %02x-%02x-%02x-%02x-%02x-%02x \n",pWapiStaInfo->PeerMacAddr[0],pWapiStaInfo->PeerMacAddr[1],pWapiStaInfo->PeerMacAddr[2],pWapiStaInfo->PeerMacAddr[3],pWapiStaInfo->PeerMacAddr[4],pWapiStaInfo->PeerMacAddr[5]); - - list_del_init(&pWapiStaInfo->list); - memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN); - pWapiStaInfo->bSetkeyOk = 0; - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - } - - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); - return; -} - -void rtw_wapi_return_all_sta_info(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo; - PRT_WAPI_BKID pWapiBkid; - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - pWapiInfo = &padapter->wapiInfo; - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - //Sta Info List - while(!list_empty(&(pWapiInfo->wapiSTAUsedList))) - { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiStaInfo->list); - memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN); - pWapiStaInfo->bSetkeyOk = 0; - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - } - - //BKID List - while(!list_empty(&(pWapiInfo->wapiBKIDStoreList))) - { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - memset(pWapiBkid->bkid,0,16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList); - } - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); -} - -void rtw_wapi_clear_cam_entry(_adapter *padapter, u8 *pMacAddr) -{ - u8 UcIndex = 0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 0); - if(UcIndex != 0xff){ - //CAM_mark_invalid(Adapter, UcIndex); - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 0); - if(UcIndex != 0xff){ - //CAM_mark_invalid(Adapter, UcIndex); - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 1); - if(UcIndex != 0xff){ - //CAM_mark_invalid(Adapter, UcIndex); - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 1); - if(UcIndex != 0xff){ - //CAM_mark_invalid(padapter, UcIndex); - CAM_empty_entry(padapter, UcIndex); - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__); -} - -void rtw_wapi_clear_all_cam_entry(_adapter *padapter) -{ - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) - { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - invalidate_cam_all(padapter); // is this ok? - WapiResetAllCamEntry(padapter); - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); -} - -void rtw_wapi_set_key(_adapter *padapter, RT_WAPI_KEY *pWapiKey, RT_WAPI_STA_INFO *pWapiSta, u8 bGroupKey, u8 bUseDefaultKey) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - u8 *pMacAddr = pWapiSta->PeerMacAddr; - u32 EntryId = 0; - BOOLEAN IsPairWise = false ; - u8 EncAlgo; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) - { - WAPI_TRACE(WAPI_API, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__); - return; - } - - EncAlgo = _SMS4_; - - //For Tx bc/mc pkt,use defualt key entry - if(bUseDefaultKey) - { - // when WAPI update key, keyid will be 0 or 1 by turns. - if (pWapiKey->keyId == 0) - EntryId = 0; - else - EntryId = 2; - } - else - { - // tx/rx unicast pkt, or rx broadcast, find the key entry by peer's MacAddr - EntryId = WapiGetEntryForCamWrite(padapter,pMacAddr,pWapiKey->keyId,bGroupKey); - } - - if(EntryId == 0xff){ - WAPI_TRACE(WAPI_API, "===>No entry for WAPI setkey! !!\n"); - return; - } - - //EntryId is also used to diff Sec key and Mic key - //Sec Key - WapiWriteOneCamEntry(padapter, - pMacAddr, - pWapiKey->keyId, //keyid - EntryId, //entry - EncAlgo, //type - bGroupKey, //pairwise or group key - pWapiKey->dataKey); - //MIC key - WapiWriteOneCamEntry(padapter, - pMacAddr, - pWapiKey->keyId, //keyid - EntryId+1, //entry - EncAlgo, //type - bGroupKey, //pairwise or group key - pWapiKey->micKey); - - WAPI_TRACE(WAPI_API, "Set Wapi Key :KeyId:%d,EntryId:%d,PairwiseKey:%d.\n",pWapiKey->keyId,EntryId,!bGroupKey); - WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__); - -} - -#if 0 -//YJ,test,091013 -void wapi_test_set_key(struct _adapter *padapter, u8* buf) -{ /*Data: keyType(1) + bTxEnable(1) + bAuthenticator(1) + bUpdate(1) + PeerAddr(6) + DataKey(16) + MicKey(16) + KeyId(1)*/ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_BKID pWapiBkid; - PRT_WAPI_STA_INFO pWapiSta; - u8 data[43]; - bool bTxEnable; - bool bUpdate; - bool bAuthenticator; - u8 PeerAddr[6]; - u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; - - WAPI_TRACE(WAPI_INIT, "===========>%s\n", __FUNCTION__); - - if (!padapter->WapiSupport){ - return; - } - - copy_from_user(data, buf, 43); - bTxEnable = data[1]; - bAuthenticator = data[2]; - bUpdate = data[3]; - memcpy(PeerAddr,data+4,6); - - if(data[0] == 0x3){ - if(!list_empty(&(pWapiInfo->wapiBKIDIdleList))){ - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - memcpy(pWapiBkid->bkid, data+10, 16); - WAPI_DATA(WAPI_INIT, "SetKey - BKID", pWapiBkid->bkid, 16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDStoreList); - } - }else{ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if(!memcmp(pWapiSta->PeerMacAddr,PeerAddr,6)){ - pWapiSta->bAuthenticatorInUpdata = false; - switch(data[0]){ - case 1: //usk - if(bAuthenticator){ //authenticator - memcpy(pWapiSta->lastTxUnicastPN,WapiAEPNInitialValueSrc,16); - if(!bUpdate) { //first - WAPI_TRACE(WAPI_INIT,"AE fisrt set usk \n"); - pWapiSta->wapiUsk.bSet = true; - memcpy(pWapiSta->wapiUsk.dataKey,data+10,16); - memcpy(pWapiSta->wapiUsk.micKey,data+26,16); - pWapiSta->wapiUsk.keyId = *(data+42); - pWapiSta->wapiUsk.bTxEnable = true; - WAPI_DATA(WAPI_INIT, "SetKey - AE USK Data Key", pWapiSta->wapiUsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - AE USK Mic Key", pWapiSta->wapiUsk.micKey, 16); - } - else //update - { - WAPI_TRACE(WAPI_INIT, "AE update usk \n"); - pWapiSta->wapiUskUpdate.bSet = true; - pWapiSta->bAuthenticatorInUpdata = true; - memcpy(pWapiSta->wapiUskUpdate.dataKey,data+10,16); - memcpy(pWapiSta->wapiUskUpdate.micKey,data+26,16); - memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPN,WapiASUEPNInitialValueSrc,16); - pWapiSta->wapiUskUpdate.keyId = *(data+42); - pWapiSta->wapiUskUpdate.bTxEnable = true; - } - } - else{ - if(!bUpdate){ - WAPI_TRACE(WAPI_INIT,"ASUE fisrt set usk \n"); - if(bTxEnable){ - pWapiSta->wapiUsk.bTxEnable = true; - memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16); - }else{ - pWapiSta->wapiUsk.bSet = true; - memcpy(pWapiSta->wapiUsk.dataKey,data+10,16); - memcpy(pWapiSta->wapiUsk.micKey,data+26,16); - pWapiSta->wapiUsk.keyId = *(data+42); - pWapiSta->wapiUsk.bTxEnable = false; - } - }else{ - WAPI_TRACE(WAPI_INIT,"ASUE update usk \n"); - if(bTxEnable){ - pWapiSta->wapiUskUpdate.bTxEnable = true; - if(pWapiSta->wapiUskUpdate.bSet){ - memcpy(pWapiSta->wapiUsk.dataKey,pWapiSta->wapiUskUpdate.dataKey,16); - memcpy(pWapiSta->wapiUsk.micKey,pWapiSta->wapiUskUpdate.micKey,16); - pWapiSta->wapiUsk.keyId=pWapiSta->wapiUskUpdate.keyId; - memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiASUEPNInitialValueSrc,16); - memcpy(pWapiSta->lastRxUnicastPN,WapiASUEPNInitialValueSrc,16); - pWapiSta->wapiUskUpdate.bTxEnable = false; - pWapiSta->wapiUskUpdate.bSet = false; - } - memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16); - }else{ - pWapiSta->wapiUskUpdate.bSet = true; - memcpy(pWapiSta->wapiUskUpdate.dataKey,data+10,16); - memcpy(pWapiSta->wapiUskUpdate.micKey,data+26,16); - pWapiSta->wapiUskUpdate.keyId = *(data+42); - pWapiSta->wapiUskUpdate.bTxEnable = false; - } - } - } - break; - case 2: //msk - if(bAuthenticator){ //authenticator - pWapiInfo->wapiTxMsk.bSet = true; - memcpy(pWapiInfo->wapiTxMsk.dataKey,data+10,16); - memcpy(pWapiInfo->wapiTxMsk.micKey,data+26,16); - pWapiInfo->wapiTxMsk.keyId = *(data+42); - pWapiInfo->wapiTxMsk.bTxEnable = true; - memcpy(pWapiInfo->lastTxMulticastPN,WapiAEMultiCastPNInitialValueSrc,16); - - if(!bUpdate){ //first - WAPI_TRACE(WAPI_INIT, "AE fisrt set msk \n"); - if(!pWapiSta->bSetkeyOk) - pWapiSta->bSetkeyOk = true; - pWapiInfo->bFirstAuthentiateInProgress= false; - }else{ //update - WAPI_TRACE(WAPI_INIT,"AE update msk \n"); - } - - WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Data Key", pWapiInfo->wapiTxMsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Mic Key", pWapiInfo->wapiTxMsk.micKey, 16); - } - else{ - if(!bUpdate){ - WAPI_TRACE(WAPI_INIT,"ASUE fisrt set msk \n"); - pWapiSta->wapiMsk.bSet = true; - memcpy(pWapiSta->wapiMsk.dataKey,data+10,16); - memcpy(pWapiSta->wapiMsk.micKey,data+26,16); - pWapiSta->wapiMsk.keyId = *(data+42); - pWapiSta->wapiMsk.bTxEnable = false; - if(!pWapiSta->bSetkeyOk) - pWapiSta->bSetkeyOk = true; - pWapiInfo->bFirstAuthentiateInProgress= false; - WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Data Key", pWapiSta->wapiMsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Mic Key", pWapiSta->wapiMsk.micKey, 16); - }else{ - WAPI_TRACE(WAPI_INIT,"ASUE update msk \n"); - pWapiSta->wapiMskUpdate.bSet = true; - memcpy(pWapiSta->wapiMskUpdate.dataKey,data+10,16); - memcpy(pWapiSta->wapiMskUpdate.micKey,data+26,16); - pWapiSta->wapiMskUpdate.keyId = *(data+42); - pWapiSta->wapiMskUpdate.bTxEnable = false; - } - } - break; - default: - WAPI_TRACE(WAPI_ERR,"Unknown Flag \n"); - break; - } - } - } - } - WAPI_TRACE(WAPI_INIT, "<===========%s\n", __FUNCTION__); -} - - -void wapi_test_init(struct _adapter *padapter) -{ - u8 keybuf[100]; - u8 mac_addr[6]={0x00,0xe0,0x4c,0x72,0x04,0x70}; - u8 UskDataKey[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}; - u8 UskMicKey[16]={0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f}; - u8 UskId = 0; - u8 MskDataKey[16]={0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f}; - u8 MskMicKey[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f}; - u8 MskId = 0; - - WAPI_TRACE(WAPI_INIT, "===========>%s\n", __FUNCTION__); - - //Enable Wapi - WAPI_TRACE(WAPI_INIT, "%s: Enable wapi!!!!\n", __FUNCTION__); - padapter->wapiInfo.bWapiEnable = true; - padapter->pairwise_key_type = KEY_TYPE_SMS4; - ieee->group_key_type = KEY_TYPE_SMS4; - padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN; - padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN; - - //set usk - WAPI_TRACE(WAPI_INIT, "%s: Set USK!!!!\n", __FUNCTION__); - memset(keybuf,0,100); - keybuf[0] = 1; //set usk - keybuf[1] = 1; //enable tx - keybuf[2] = 1; //AE - keybuf[3] = 0; //not update - - memcpy(keybuf+4,mac_addr,6); - memcpy(keybuf+10,UskDataKey,16); - memcpy(keybuf+26,UskMicKey,16); - keybuf[42]=UskId; - wapi_test_set_key(padapter, keybuf); - - memset(keybuf,0,100); - keybuf[0] = 1; //set usk - keybuf[1] = 1; //enable tx - keybuf[2] = 0; //AE - keybuf[3] = 0; //not update - - memcpy(keybuf+4,mac_addr,6); - memcpy(keybuf+10,UskDataKey,16); - memcpy(keybuf+26,UskMicKey,16); - keybuf[42]=UskId; - wapi_test_set_key(padapter, keybuf); - - //set msk - WAPI_TRACE(WAPI_INIT, "%s: Set MSK!!!!\n", __FUNCTION__); - memset(keybuf,0,100); - keybuf[0] = 2; //set msk - keybuf[1] = 1; //Enable TX - keybuf[2] = 1; //AE - keybuf[3] = 0; //not update - memcpy(keybuf+4,mac_addr,6); - memcpy(keybuf+10,MskDataKey,16); - memcpy(keybuf+26,MskMicKey,16); - keybuf[42] = MskId; - wapi_test_set_key(padapter, keybuf); - - memset(keybuf,0,100); - keybuf[0] = 2; //set msk - keybuf[1] = 1; //Enable TX - keybuf[2] = 0; //AE - keybuf[3] = 0; //not update - memcpy(keybuf+4,mac_addr,6); - memcpy(keybuf+10,MskDataKey,16); - memcpy(keybuf+26,MskMicKey,16); - keybuf[42] = MskId; - wapi_test_set_key(padapter, keybuf); - WAPI_TRACE(WAPI_INIT, "<===========%s\n", __FUNCTION__); -} -#endif - -void rtw_wapi_get_iv(_adapter *padapter,u8 *pRA, u8*IV) -{ - PWLAN_HEADER_WAPI_EXTENSION pWapiExt = NULL; - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - bool bPNOverflow = false; - bool bFindMatchPeer = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - - pWapiExt = (PWLAN_HEADER_WAPI_EXTENSION)IV; - - WAPI_DATA(WAPI_RX,"wapi_get_iv: pra",pRA,6); - - if(IS_MCAST(pRA)){ - if(!pWapiInfo->wapiTxMsk.bTxEnable){ - WAPI_TRACE(WAPI_ERR,"%s: bTxEnable = 0!!\n",__FUNCTION__); - return; - } - - if(pWapiInfo->wapiTxMsk.keyId <= 1){ - pWapiExt->KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiInfo->lastTxMulticastPN, 1); - memcpy(pWapiExt->PN, pWapiInfo->lastTxMulticastPN, 16); - } - } - else - { - if(list_empty(&pWapiInfo->wapiSTAUsedList)){ - WAPI_TRACE(WAPI_RX,"rtw_wapi_get_iv: list is empty \n"); - _rtw_memset(IV,10,18); - return; - } - else{ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){ - WAPI_DATA(WAPI_RX,"rtw_wapi_get_iv: peermacaddr ",pWapiSta->PeerMacAddr,6); - if (_rtw_memcmp((u8*)pWapiSta->PeerMacAddr, pRA, 6) == _TRUE) { - bFindMatchPeer = true; - break; - } - } - - WAPI_TRACE(WAPI_RX,"bFindMatchPeer: %d \n",bFindMatchPeer); - WAPI_DATA(WAPI_RX,"Addr",pRA,6); - - if (bFindMatchPeer){ - if((!pWapiSta->wapiUskUpdate.bTxEnable) && (!pWapiSta->wapiUsk.bTxEnable)) - return; - - if (pWapiSta->wapiUsk.keyId <= 1){ - if(pWapiSta->wapiUskUpdate.bTxEnable) - pWapiExt->KeyIdx = pWapiSta->wapiUskUpdate.keyId; - else - pWapiExt->KeyIdx = pWapiSta->wapiUsk.keyId; - - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiSta->lastTxUnicastPN, 2); - _rtw_memcpy(pWapiExt->PN, pWapiSta->lastTxUnicastPN, 16); - - } - } - } - - } - -} - -bool rtw_wapi_drop_for_key_absent(_adapter *padapter,u8 *pRA) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - bool bFindMatchPeer = false; - bool bDrop = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - struct security_priv *psecuritypriv = &padapter->securitypriv; - - WAPI_DATA(WAPI_RX,"rtw_wapi_drop_for_key_absent: ra ",pRA,6); - - if(psecuritypriv->dot11PrivacyAlgrthm == _SMS4_) - { - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - return true; - - if(IS_MCAST(pRA)){ - if(!pWapiInfo->wapiTxMsk.bTxEnable){ - bDrop = true; - WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: multicast key is absent \n"); - return bDrop; - } - } - else{ - if(!list_empty(&pWapiInfo->wapiSTAUsedList)){ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){ - WAPI_DATA(WAPI_RX,"rtw_wapi_drop_for_key_absent: pWapiSta->PeerMacAddr ",pWapiSta->PeerMacAddr,6); - if (_rtw_memcmp(pRA, pWapiSta->PeerMacAddr, 6) == _TRUE){ - bFindMatchPeer = true; - break; - } - } - if (bFindMatchPeer) { - if (!pWapiSta->wapiUsk.bTxEnable){ - bDrop = true; - WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: unicast key is absent \n"); - return bDrop; - } - } - else{ - bDrop = true; - WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: no peer find \n"); - return bDrop; - } - - } - else{ - bDrop = true; - WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: no sta exist \n"); - return bDrop; - } - } - } - else - { - return bDrop; - } - - return bDrop; -} - -#endif diff --git a/core/rtw_wapi_sms4.c b/core/rtw_wapi_sms4.c deleted file mode 100755 index 6126ed9..0000000 --- a/core/rtw_wapi_sms4.c +++ /dev/null @@ -1,923 +0,0 @@ -#ifdef CONFIG_WAPI_SUPPORT - -#include -#include -#include -#include - - -#ifdef CONFIG_WAPI_SW_SMS4 - -#define WAPI_LITTLE_ENDIAN -//#define BIG_ENDIAN -#define ENCRYPT 0 -#define DECRYPT 1 - - -/********************************************************** - **********************************************************/ -const u8 Sbox[256] = { -0xd6,0x90,0xe9,0xfe,0xcc,0xe1,0x3d,0xb7,0x16,0xb6,0x14,0xc2,0x28,0xfb,0x2c,0x05, -0x2b,0x67,0x9a,0x76,0x2a,0xbe,0x04,0xc3,0xaa,0x44,0x13,0x26,0x49,0x86,0x06,0x99, -0x9c,0x42,0x50,0xf4,0x91,0xef,0x98,0x7a,0x33,0x54,0x0b,0x43,0xed,0xcf,0xac,0x62, -0xe4,0xb3,0x1c,0xa9,0xc9,0x08,0xe8,0x95,0x80,0xdf,0x94,0xfa,0x75,0x8f,0x3f,0xa6, -0x47,0x07,0xa7,0xfc,0xf3,0x73,0x17,0xba,0x83,0x59,0x3c,0x19,0xe6,0x85,0x4f,0xa8, -0x68,0x6b,0x81,0xb2,0x71,0x64,0xda,0x8b,0xf8,0xeb,0x0f,0x4b,0x70,0x56,0x9d,0x35, -0x1e,0x24,0x0e,0x5e,0x63,0x58,0xd1,0xa2,0x25,0x22,0x7c,0x3b,0x01,0x21,0x78,0x87, -0xd4,0x00,0x46,0x57,0x9f,0xd3,0x27,0x52,0x4c,0x36,0x02,0xe7,0xa0,0xc4,0xc8,0x9e, -0xea,0xbf,0x8a,0xd2,0x40,0xc7,0x38,0xb5,0xa3,0xf7,0xf2,0xce,0xf9,0x61,0x15,0xa1, -0xe0,0xae,0x5d,0xa4,0x9b,0x34,0x1a,0x55,0xad,0x93,0x32,0x30,0xf5,0x8c,0xb1,0xe3, -0x1d,0xf6,0xe2,0x2e,0x82,0x66,0xca,0x60,0xc0,0x29,0x23,0xab,0x0d,0x53,0x4e,0x6f, -0xd5,0xdb,0x37,0x45,0xde,0xfd,0x8e,0x2f,0x03,0xff,0x6a,0x72,0x6d,0x6c,0x5b,0x51, -0x8d,0x1b,0xaf,0x92,0xbb,0xdd,0xbc,0x7f,0x11,0xd9,0x5c,0x41,0x1f,0x10,0x5a,0xd8, -0x0a,0xc1,0x31,0x88,0xa5,0xcd,0x7b,0xbd,0x2d,0x74,0xd0,0x12,0xb8,0xe5,0xb4,0xb0, -0x89,0x69,0x97,0x4a,0x0c,0x96,0x77,0x7e,0x65,0xb9,0xf1,0x09,0xc5,0x6e,0xc6,0x84, -0x18,0xf0,0x7d,0xec,0x3a,0xdc,0x4d,0x20,0x79,0xee,0x5f,0x3e,0xd7,0xcb,0x39,0x48 -}; - -const u32 CK[32] = { - 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, - 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, - 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, - 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, - 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, - 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, - 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, - 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279 }; - -#define Rotl(_x, _y) (((_x) << (_y)) | ((_x) >> (32 - (_y)))) - -#define ByteSub(_A) (Sbox[(_A) >> 24 & 0xFF] << 24 | \ - Sbox[(_A) >> 16 & 0xFF] << 16 | \ - Sbox[(_A) >> 8 & 0xFF] << 8 | \ - Sbox[(_A) & 0xFF]) - -#define L1(_B) ((_B) ^ Rotl(_B, 2) ^ Rotl(_B, 10) ^ Rotl(_B, 18) ^ Rotl(_B, 24)) -#define L2(_B) ((_B) ^ Rotl(_B, 13) ^ Rotl(_B, 23)) - -static void -xor_block(void *dst, void *src1, void *src2) -/* 128-bit xor: *dst = *src1 xor *src2. Pointers must be 32-bit aligned */ -{ - ((u32 *)dst)[0] = ((u32 *)src1)[0] ^ ((u32 *)src2)[0]; - ((u32 *)dst)[1] = ((u32 *)src1)[1] ^ ((u32 *)src2)[1]; - ((u32 *)dst)[2] = ((u32 *)src1)[2] ^ ((u32 *)src2)[2]; - ((u32 *)dst)[3] = ((u32 *)src1)[3] ^ ((u32 *)src2)[3]; -} - - -void SMS4Crypt(u8 *Input, u8 *Output, u32 *rk) -{ - u32 r, mid, x0, x1, x2, x3, *p; - p = (u32 *)Input; - x0 = p[0]; - x1 = p[1]; - x2 = p[2]; - x3 = p[3]; -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); x0 = ((x0 & 0x00FF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); x1 = ((x1 & 0x00FF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); x2 = ((x2 & 0x00FF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); x3 = ((x3 & 0x00FF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - for (r = 0; r < 32; r += 4) - { - mid = x1 ^ x2 ^ x3 ^ rk[r + 0]; - mid = ByteSub(mid); - x0 ^= L1(mid); - mid = x2 ^ x3 ^ x0 ^ rk[r + 1]; - mid = ByteSub(mid); - x1 ^= L1(mid); - mid = x3 ^ x0 ^ x1 ^ rk[r + 2]; - mid = ByteSub(mid); - x2 ^= L1(mid); - mid = x0 ^ x1 ^ x2 ^ rk[r + 3]; - mid = ByteSub(mid); - x3 ^= L1(mid); - } -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); x0 = ((x0 & 0x00FF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); x1 = ((x1 & 0x00FF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); x2 = ((x2 & 0x00FF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); x3 = ((x3 & 0x00FF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - p = (u32 *)Output; - p[0] = x3; - p[1] = x2; - p[2] = x1; - p[3] = x0; -} - - - -void SMS4KeyExt(u8 *Key, u32 *rk, u32 CryptFlag) -{ - u32 r, mid, x0, x1, x2, x3, *p; - - p = (u32 *)Key; - x0 = p[0]; - x1 = p[1]; - x2 = p[2]; - x3 = p[3]; -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); x0 = ((x0 & 0xFF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); x1 = ((x1 & 0xFF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); x2 = ((x2 & 0xFF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); x3 = ((x3 & 0xFF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - - x0 ^= 0xa3b1bac6; - x1 ^= 0x56aa3350; - x2 ^= 0x677d9197; - x3 ^= 0xb27022dc; - for (r = 0; r < 32; r += 4) - { - mid = x1 ^ x2 ^ x3 ^ CK[r + 0]; - mid = ByteSub(mid); - rk[r + 0] = x0 ^= L2(mid); - mid = x2 ^ x3 ^ x0 ^ CK[r + 1]; - mid = ByteSub(mid); - rk[r + 1] = x1 ^= L2(mid); - mid = x3 ^ x0 ^ x1 ^ CK[r + 2]; - mid = ByteSub(mid); - rk[r + 2] = x2 ^= L2(mid); - mid = x0 ^ x1 ^ x2 ^ CK[r + 3]; - mid = ByteSub(mid); - rk[r + 3] = x3 ^= L2(mid); - } - if (CryptFlag == DECRYPT) - { - for (r = 0; r < 16; r++) - mid = rk[r], rk[r] = rk[31 - r], rk[31 - r] = mid; - } -} - - -void WapiSMS4Cryption(u8 *Key, u8 *IV, u8 *Input, u16 InputLength, - u8 *Output, u16 *OutputLength, u32 CryptFlag) -{ - u32 blockNum,i,j, rk[32]; - u16 remainder; - u8 blockIn[16],blockOut[16], tempIV[16], k; - - *OutputLength = 0; - remainder = InputLength & 0x0F; - blockNum = InputLength >> 4; - if(remainder !=0) - blockNum++; - else - remainder = 16; - - for(k=0;k<16;k++) - tempIV[k] = IV[15-k]; - - memcpy(blockIn, tempIV, 16); - - SMS4KeyExt((u8 *)Key, rk,CryptFlag); - - for(i=0; i> 4; - - for(k=0;k<16;k++) - tempIV[k] = IV[15-k]; - - memcpy(BlockIn, tempIV, 16); - - SMS4KeyExt((u8 *)Key, rk, ENCRYPT); - - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - - for(i=0; i> 4; - - for(i=0; i%s\n", __FUNCTION__); - - header = (struct ieee80211_hdr_3addr_qos *)pHeader; - memset(TempBuf, 0, 34); - memcpy(TempBuf, pHeader, 2); //FrameCtrl - pTemp = (u16*)TempBuf; - *pTemp &= 0xc78f; //bit4,5,6,11,12,13 - - memcpy((TempBuf+2), (pHeader+4), 12); //Addr1, Addr2 - memcpy((TempBuf+14), (pHeader+22), 2); // SeqCtrl - pTemp = (u16*)(TempBuf + 14); - *pTemp &= 0x000f; - - memcpy((TempBuf+16), (pHeader+16), 6); //Addr3 - - fc = le16_to_cpu(header->frame_ctl); - - - - if (GetFrDs((u16*)&fc) && GetToDs((u16 *)&fc)) - { - memcpy((TempBuf+22), (pHeader+24), 6); - QosOffset = 30; - }else{ - memset((TempBuf+22), 0, 6); - QosOffset = 24; - } - - if((fc & 0x0088) == 0x0088){ - memcpy((TempBuf+28), (pHeader+QosOffset), 2); - TempLen += 2; - //IV = pHeader + QosOffset + 2 + SNAP_SIZE + sizeof(u16) + 2; - IV = pHeader + QosOffset + 2 + 2; - }else{ - IV = pHeader + QosOffset + 2; - //IV = pHeader + QosOffset + SNAP_SIZE + sizeof(u16) + 2; - } - - TempBuf[TempLen-1] = (u8)(DataLen & 0xff); - TempBuf[TempLen-2] = (u8)((DataLen & 0xff00)>>8); - TempBuf[TempLen-4] = KeyIdx; - - WAPI_DATA(WAPI_TX, "CalculateMic - KEY", MicKey, 16); - WAPI_DATA(WAPI_TX, "CalculateMic - IV", IV, 16); - WAPI_DATA(WAPI_TX, "CalculateMic - TempBuf", TempBuf, TempLen); - WAPI_DATA(WAPI_TX, "CalculateMic - pData", pData, DataLen); - - WapiSMS4CalculateMic(MicKey, IV, TempBuf, TempLen, - pData, DataLen, MicBuffer, &MicLen); - - if (MicLen != 16) - WAPI_TRACE(WAPI_ERR,"%s: MIC Length Error!!\n",__FUNCTION__); - - WAPI_TRACE(WAPI_TX|WAPI_RX, "<=========%s\n", __FUNCTION__); -#endif -} - -/* AddCount: 1 or 2. - * If overflow, return 1, - * else return 0. - */ -u8 WapiIncreasePN(u8 *PN, u8 AddCount) -{ - u8 i; - - if (NULL == PN) - return 1; - //YJ,test,091102 - /* - if(AddCount == 2){ - DBG_8192C("############################%s(): PN[0]=0x%x\n", __FUNCTION__, PN[0]); - if(PN[0] == 0x48){ - PN[0] += AddCount; - return 1; - }else{ - PN[0] += AddCount; - return 0; - } - } - */ - //YJ,test,091102,end - - for (i=0; i<16; i++) - { - if (PN[i] + AddCount <= 0xff) - { - PN[i] += AddCount; - return 0; - } - else - { - PN[i] += AddCount; - AddCount = 1; - } - } - return 1; -} - - -void WapiGetLastRxUnicastPNForQoSData( - u8 UserPriority, - PRT_WAPI_STA_INFO pWapiStaInfo, - u8 *PNOut -) -{ - WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__); - switch(UserPriority) - { - case 0: - case 3: - memcpy(PNOut,pWapiStaInfo->lastRxUnicastPNBEQueue,16); - break; - case 1: - case 2: - memcpy(PNOut,pWapiStaInfo->lastRxUnicastPNBKQueue,16); - break; - case 4: - case 5: - memcpy(PNOut,pWapiStaInfo->lastRxUnicastPNVIQueue,16); - break; - case 6: - case 7: - memcpy(PNOut,pWapiStaInfo->lastRxUnicastPNVOQueue,16); - break; - default: - WAPI_TRACE(WAPI_ERR, "%s: Unknown TID \n", __FUNCTION__); - break; - } - WAPI_TRACE(WAPI_RX, "<=========== %s\n", __FUNCTION__); -} - - -void WapiSetLastRxUnicastPNForQoSData( - u8 UserPriority, - u8 *PNIn, - PRT_WAPI_STA_INFO pWapiStaInfo -) -{ - WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__); - switch(UserPriority) - { - case 0: - case 3: - memcpy(pWapiStaInfo->lastRxUnicastPNBEQueue,PNIn,16); - break; - case 1: - case 2: - memcpy(pWapiStaInfo->lastRxUnicastPNBKQueue,PNIn,16); - break; - case 4: - case 5: - memcpy(pWapiStaInfo->lastRxUnicastPNVIQueue,PNIn,16); - break; - case 6: - case 7: - memcpy(pWapiStaInfo->lastRxUnicastPNVOQueue,PNIn,16); - break; - default: - WAPI_TRACE(WAPI_ERR, "%s: Unknown TID \n", __FUNCTION__); - break; - } - WAPI_TRACE(WAPI_RX, "<=========== %s\n", __FUNCTION__); -} - - -/**************************************************************************** - FALSE not RX-Reorder - TRUE do RX Reorder -add to support WAPI to N-mode -*****************************************************************************/ -u8 WapiCheckPnInSwDecrypt( - _adapter *padapter, - struct sk_buff *pskb -) -{ - u8 ret = false; - -#if 0 - struct ieee80211_hdr_3addr_qos *header; - u16 fc; - u8 *pDaddr, *pTaddr, *pRaddr; - - header = (struct ieee80211_hdr_3addr_qos *)pskb->data; - pTaddr = header->addr2; - pRaddr = header->addr1; - fc = le16_to_cpu(header->frame_ctl); - - if(GetToDs(&fc)) - pDaddr = header->addr3; - else - pDaddr = header->addr1; - - if ((_rtw_memcmp(pRaddr, padapter->pnetdev->dev_addr, ETH_ALEN) == 0) - && ! (pDaddr) - && (GetFrameType(&fc) == WIFI_QOS_DATA_TYPE)) - //&& ieee->pHTInfo->bCurrentHTSupport && - //ieee->pHTInfo->bCurRxReorderEnable) - ret = false; - else - ret = true; -#endif - WAPI_TRACE(WAPI_RX, "%s: return %d\n", __FUNCTION__, ret); - return ret; -} - -int SecSMS4HeaderFillIV(_adapter *padapter, u8 *pxmitframe) -{ - struct pkt_attrib *pattrib = &((struct xmit_frame*)pxmitframe)->attrib; - u8 * frame = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET; - u8 *pSecHeader = NULL, *pos = NULL, *pRA = NULL; - u8 bPNOverflow = false, bFindMatchPeer = false, hdr_len = 0; - PWLAN_HEADER_WAPI_EXTENSION pWapiExt = NULL; - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_STA_INFO pWapiSta = NULL; - int ret = 0; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __FUNCTION__); - - return ret; -#if 0 - hdr_len = sMacHdrLng; - if (GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE) - { - hdr_len += 2; - } - //hdr_len += SNAP_SIZE + sizeof(u16); - - pos = skb_push(pskb, padapter->wapiInfo.extra_prefix_len); - memmove(pos, pos+padapter->wapiInfo.extra_prefix_len, hdr_len); - - pSecHeader = pskb->data + hdr_len; - pWapiExt = (PWLAN_HEADER_WAPI_EXTENSION)pSecHeader; - pRA = pskb->data + 4; - - WAPI_DATA(WAPI_TX, "FillIV - Before Fill IV", pskb->data, pskb->len); - - //Address 1 is always receiver's address - if( IS_MCAST(pRA) ){ - if(!pWapiInfo->wapiTxMsk.bTxEnable){ - WAPI_TRACE(WAPI_ERR,"%s: bTxEnable = 0!!\n",__FUNCTION__); - return -2; - } - if(pWapiInfo->wapiTxMsk.keyId <= 1){ - pWapiExt->KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiInfo->lastTxMulticastPN, 1); - memcpy(pWapiExt->PN, pWapiInfo->lastTxMulticastPN, 16); - if (bPNOverflow){ - // Update MSK Notification. - WAPI_TRACE(WAPI_ERR,"===============>%s():multicast PN overflow\n",__FUNCTION__); - rtw_wapi_app_event_handler(padapter,NULL,0,pRA, false, false, true, 0, false); - } - }else{ - WAPI_TRACE(WAPI_ERR,"%s: Invalid Wapi Multicast KeyIdx!!\n",__FUNCTION__); - ret = -3; - } - } - else{ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if(!memcmp(pWapiSta->PeerMacAddr,pRA,6)){ - bFindMatchPeer = true; - break; - } - } - if (bFindMatchPeer){ - if((!pWapiSta->wapiUskUpdate.bTxEnable) && (!pWapiSta->wapiUsk.bTxEnable)){ - WAPI_TRACE(WAPI_ERR,"%s: bTxEnable = 0!!\n",__FUNCTION__); - return -4; - } - if (pWapiSta->wapiUsk.keyId <= 1){ - if(pWapiSta->wapiUskUpdate.bTxEnable) - pWapiExt->KeyIdx = pWapiSta->wapiUskUpdate.keyId; - else - pWapiExt->KeyIdx = pWapiSta->wapiUsk.keyId; - - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiSta->lastTxUnicastPN, 2); - memcpy(pWapiExt->PN, pWapiSta->lastTxUnicastPN, 16); - if (bPNOverflow){ - // Update USK Notification. - WAPI_TRACE(WAPI_ERR,"===============>%s():unicast PN overflow\n",__FUNCTION__); - rtw_wapi_app_event_handler(padapter,NULL,0,pWapiSta->PeerMacAddr, false, true, false, 0, false); - } - }else{ - WAPI_TRACE(WAPI_ERR,"%s: Invalid Wapi Unicast KeyIdx!!\n",__FUNCTION__); - ret = -5; - } - } - else{ - WAPI_TRACE(WAPI_ERR,"%s: Can not find Peer Sta "MAC_FMT"!!\n",__FUNCTION__, MAC_ARG(pRA)); - ret = -6; - } - } - - WAPI_DATA(WAPI_TX, "FillIV - After Fill IV", pskb->data, pskb->len); - WAPI_TRACE(WAPI_TX, "<=========%s\n", __FUNCTION__); - return ret; -#endif -} - -// WAPI SW Enc: must have done Coalesce! -void SecSWSMS4Encryption( - _adapter *padapter, - u8 * pxmitframe - ) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 *pframe = ((struct xmit_frame*)pxmitframe)->buf_addr + TXDESC_SIZE; - struct pkt_attrib *pattrib = &((struct xmit_frame*)pxmitframe)->attrib; - - u8 *SecPtr = NULL, *pRA, *pMicKey = NULL, *pDataKey = NULL, *pIV = NULL; - u8 IVOffset, DataOffset, bFindMatchPeer = false, KeyIdx = 0, MicBuffer[16]; - u16 OutputLength; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __FUNCTION__); - - WAPI_TRACE(WAPI_TX,"hdrlen: %d \n",pattrib->hdrlen); - - return; - - DataOffset = pattrib->hdrlen + pattrib->iv_len; - - pRA = pframe + 4; - - - if( IS_MCAST(pRA) ){ - KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pIV = pWapiInfo->lastTxMulticastPN; - pMicKey = pWapiInfo->wapiTxMsk.micKey; - pDataKey = pWapiInfo->wapiTxMsk.dataKey; - }else{ - if (!list_empty(&(pWapiInfo->wapiSTAUsedList))){ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (0 == memcmp(pWapiSta->PeerMacAddr, pRA, 6)){ - bFindMatchPeer = true; - break; - } - } - - if (bFindMatchPeer){ - if (pWapiSta->wapiUskUpdate.bTxEnable){ - KeyIdx = pWapiSta->wapiUskUpdate.keyId; - WAPI_TRACE(WAPI_TX, "%s(): Use update USK!! KeyIdx=%d\n", __FUNCTION__, KeyIdx); - pIV = pWapiSta->lastTxUnicastPN; - pMicKey = pWapiSta->wapiUskUpdate.micKey; - pDataKey = pWapiSta->wapiUskUpdate.dataKey; - }else{ - KeyIdx = pWapiSta->wapiUsk.keyId; - WAPI_TRACE(WAPI_TX, "%s(): Use USK!! KeyIdx=%d\n", __FUNCTION__, KeyIdx); - pIV = pWapiSta->lastTxUnicastPN; - pMicKey = pWapiSta->wapiUsk.micKey; - pDataKey = pWapiSta->wapiUsk.dataKey; - } - }else{ - WAPI_TRACE(WAPI_ERR,"%s: Can not find Peer Sta!!\n",__FUNCTION__); - return; - } - }else{ - WAPI_TRACE(WAPI_ERR,"%s: wapiSTAUsedList is empty!!\n",__FUNCTION__); - return; - } - } - - SecPtr = pframe; - SecCalculateMicSMS4(KeyIdx, pMicKey, SecPtr, (SecPtr+DataOffset), pattrib->pktlen, MicBuffer); - - WAPI_DATA(WAPI_TX, "Encryption - MIC", MicBuffer, padapter->wapiInfo.extra_postfix_len); - - memcpy(pframe+pattrib->hdrlen+pattrib->iv_len+pattrib->pktlen-pattrib->icv_len, - (u8 *)MicBuffer, - padapter->wapiInfo.extra_postfix_len - ); - - - WapiSMS4Encryption(pDataKey, pIV, (SecPtr+DataOffset),pattrib->pktlen+pattrib->icv_len, (SecPtr+DataOffset), &OutputLength); - - WAPI_DATA(WAPI_TX, "Encryption - After SMS4 encryption",pframe,pattrib->hdrlen+pattrib->iv_len+pattrib->pktlen); - - WAPI_TRACE(WAPI_TX, "<=========%s\n", __FUNCTION__); -} - -u8 SecSWSMS4Decryption( - _adapter *padapter, - u8 *precv_frame, - struct recv_priv *precv_priv - ) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - struct recv_frame_hdr *precv_hdr; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 IVOffset, DataOffset, bFindMatchPeer = false, bUseUpdatedKey = false; - u8 KeyIdx, MicBuffer[16], lastRxPNforQoS[16]; - u8 *pRA, *pTA, *pMicKey, *pDataKey, *pLastRxPN, *pRecvPN, *pSecData, *pRecvMic, *pos; - u8 TID = 0; - u16 OutputLength, DataLen; - u8 bQosData; - struct sk_buff * pskb; - - WAPI_TRACE(WAPI_RX, "=========>%s\n", __FUNCTION__); - - return 0; - - precv_hdr = &((union recv_frame*)precv_frame)->u.hdr; - pskb = (struct sk_buff *)(precv_hdr->rx_data); - precv_hdr->bWapiCheckPNInDecrypt = WapiCheckPnInSwDecrypt(padapter, pskb); - WAPI_TRACE(WAPI_RX, "=========>%s: check PN %d\n", __FUNCTION__,precv_hdr->bWapiCheckPNInDecrypt); - WAPI_DATA(WAPI_RX, "Decryption - Before decryption", pskb->data, pskb->len); - - IVOffset = sMacHdrLng; - bQosData = GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE; - if (bQosData){ - IVOffset += 2; - } - - //if(GetHTC()) - // IVOffset += 4; - - //IVOffset += SNAP_SIZE + sizeof(u16); - - DataOffset = IVOffset + padapter->wapiInfo.extra_prefix_len; - - pRA = pskb->data + 4; - pTA = pskb->data + 10; - KeyIdx = *(pskb->data + IVOffset); - pRecvPN = pskb->data + IVOffset + 2; - pSecData = pskb->data + DataOffset; - DataLen = pskb->len - DataOffset; - pRecvMic = pskb->data + pskb->len - padapter->wapiInfo.extra_postfix_len; - TID = GetTid(pskb->data); - - if (!list_empty(&(pWapiInfo->wapiSTAUsedList))){ - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (0 == memcmp(pWapiSta->PeerMacAddr, pTA, 6)){ - bFindMatchPeer = true; - break; - } - } - } - - if (!bFindMatchPeer){ - WAPI_TRACE(WAPI_ERR, "%s: Can not find Peer Sta "MAC_FMT" for Key Info!!!\n", __FUNCTION__, MAC_ARG(pTA)); - return false; - } - - if( IS_MCAST(pRA) ){ - WAPI_TRACE(WAPI_RX, "%s: Multicast decryption !!!\n", __FUNCTION__); - if (pWapiSta->wapiMsk.keyId == KeyIdx && pWapiSta->wapiMsk.bSet){ - pLastRxPN = pWapiSta->lastRxMulticastPN; - if (!WapiComparePN(pRecvPN, pLastRxPN)){ - WAPI_TRACE(WAPI_ERR, "%s: MSK PN is not larger than last, Dropped!!!\n", __FUNCTION__); - WAPI_DATA(WAPI_ERR, "pRecvPN:", pRecvPN, 16); - WAPI_DATA(WAPI_ERR, "pLastRxPN:", pLastRxPN, 16); - return false; - } - - memcpy(pLastRxPN, pRecvPN, 16); - pMicKey = pWapiSta->wapiMsk.micKey; - pDataKey = pWapiSta->wapiMsk.dataKey; - }else if (pWapiSta->wapiMskUpdate.keyId == KeyIdx && pWapiSta->wapiMskUpdate.bSet){ - WAPI_TRACE(WAPI_RX, "%s: Use Updated MSK for Decryption !!!\n", __FUNCTION__); - bUseUpdatedKey = true; - memcpy(pWapiSta->lastRxMulticastPN, pRecvPN, 16); - pMicKey = pWapiSta->wapiMskUpdate.micKey; - pDataKey = pWapiSta->wapiMskUpdate.dataKey; - }else{ - WAPI_TRACE(WAPI_ERR, "%s: Can not find MSK with matched KeyIdx(%d), Dropped !!!\n", __FUNCTION__,KeyIdx); - return false; - } - } - else{ - WAPI_TRACE(WAPI_RX, "%s: Unicast decryption !!!\n", __FUNCTION__); - if (pWapiSta->wapiUsk.keyId == KeyIdx && pWapiSta->wapiUsk.bSet){ - WAPI_TRACE(WAPI_RX, "%s: Use USK for Decryption!!!\n", __FUNCTION__); - if(precv_hdr->bWapiCheckPNInDecrypt){ - if(GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE){ - WapiGetLastRxUnicastPNForQoSData(TID, pWapiSta, lastRxPNforQoS); - pLastRxPN = lastRxPNforQoS; - }else{ - pLastRxPN = pWapiSta->lastRxUnicastPN; - } - if (!WapiComparePN(pRecvPN, pLastRxPN)){ - return false; - } - if(bQosData){ - WapiSetLastRxUnicastPNForQoSData(TID, pRecvPN, pWapiSta); - }else{ - memcpy(pWapiSta->lastRxUnicastPN, pRecvPN, 16); - } - }else{ - memcpy(precv_hdr->WapiTempPN,pRecvPN,16); - } - - if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) - { - if ((pRecvPN[0] & 0x1) == 0){ - WAPI_TRACE(WAPI_ERR, "%s: Rx USK PN is not odd when Infra STA mode, Dropped !!!\n", __FUNCTION__); - return false; - } - } - - pMicKey = pWapiSta->wapiUsk.micKey; - pDataKey = pWapiSta->wapiUsk.dataKey; - } - else if (pWapiSta->wapiUskUpdate.keyId == KeyIdx && pWapiSta->wapiUskUpdate.bSet ){ - WAPI_TRACE(WAPI_RX, "%s: Use Updated USK for Decryption!!!\n", __FUNCTION__); - if(pWapiSta->bAuthenticatorInUpdata) - bUseUpdatedKey = true; - else - bUseUpdatedKey = false; - - if(bQosData){ - WapiSetLastRxUnicastPNForQoSData(TID, pRecvPN, pWapiSta); - }else{ - memcpy(pWapiSta->lastRxUnicastPN, pRecvPN, 16); - } - pMicKey = pWapiSta->wapiUskUpdate.micKey; - pDataKey = pWapiSta->wapiUskUpdate.dataKey; - }else{ - WAPI_TRACE(WAPI_ERR, "%s: No valid USK!!!KeyIdx=%d pWapiSta->wapiUsk.keyId=%d pWapiSta->wapiUskUpdate.keyId=%d\n", __FUNCTION__, KeyIdx, pWapiSta->wapiUsk.keyId, pWapiSta->wapiUskUpdate.keyId); - //dump_buf(pskb->data,pskb->len); - return false; - } - } - - WAPI_DATA(WAPI_RX, "Decryption - DataKey", pDataKey, 16); - WAPI_DATA(WAPI_RX, "Decryption - IV", pRecvPN, 16); - WapiSMS4Decryption(pDataKey, pRecvPN, pSecData, DataLen, pSecData, &OutputLength); - - if (OutputLength != DataLen) - WAPI_TRACE(WAPI_ERR, "%s: Output Length Error!!!!\n", __FUNCTION__); - - WAPI_DATA(WAPI_RX, "Decryption - After decryption", pskb->data, pskb->len); - - DataLen -= padapter->wapiInfo.extra_postfix_len; - - SecCalculateMicSMS4(KeyIdx, pMicKey, pskb->data, pSecData, DataLen, MicBuffer); - - WAPI_DATA(WAPI_RX, "Decryption - MIC received", pRecvMic, SMS4_MIC_LEN); - WAPI_DATA(WAPI_RX, "Decryption - MIC calculated", MicBuffer, SMS4_MIC_LEN); - - if (0 == memcmp(MicBuffer, pRecvMic, padapter->wapiInfo.extra_postfix_len)){ - WAPI_TRACE(WAPI_RX, "%s: Check MIC OK!!\n", __FUNCTION__); - if (bUseUpdatedKey){ - // delete the old key - if ( IS_MCAST(pRA) ){ - WAPI_TRACE(WAPI_API, "%s(): AE use new update MSK!!\n", __FUNCTION__); - pWapiSta->wapiMsk.keyId = pWapiSta->wapiMskUpdate.keyId; - memcpy(pWapiSta->wapiMsk.dataKey, pWapiSta->wapiMskUpdate.dataKey, 16); - memcpy(pWapiSta->wapiMsk.micKey, pWapiSta->wapiMskUpdate.micKey, 16); - pWapiSta->wapiMskUpdate.bTxEnable = pWapiSta->wapiMskUpdate.bSet = false; - }else{ - WAPI_TRACE(WAPI_API, "%s(): AE use new update USK!!\n", __FUNCTION__); - pWapiSta->wapiUsk.keyId = pWapiSta->wapiUskUpdate.keyId; - memcpy(pWapiSta->wapiUsk.dataKey, pWapiSta->wapiUskUpdate.dataKey, 16); - memcpy(pWapiSta->wapiUsk.micKey, pWapiSta->wapiUskUpdate.micKey, 16); - pWapiSta->wapiUskUpdate.bTxEnable = pWapiSta->wapiUskUpdate.bSet = false; - } - } - }else{ - WAPI_TRACE(WAPI_ERR, "%s: Check MIC Error, Dropped !!!!\n", __FUNCTION__); - return false; - } - - pos = pskb->data; - memmove(pos+padapter->wapiInfo.extra_prefix_len, pos, IVOffset); - skb_pull(pskb, padapter->wapiInfo.extra_prefix_len); - - WAPI_TRACE(WAPI_RX, "<=========%s\n", __FUNCTION__); - - return true; -} - -u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe) -{ - - u8 *pframe; - u32 res = _SUCCESS; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) - { - WAPI_TRACE(WAPI_TX, "<========== %s, WAPI not supported or enabled!\n", __FUNCTION__); - return _FAIL; - } - - if(((struct xmit_frame*)pxmitframe)->buf_addr==NULL) - return _FAIL; - - pframe = ((struct xmit_frame*)pxmitframe)->buf_addr + TXDESC_OFFSET; - - SecSWSMS4Encryption(padapter, pxmitframe); - - WAPI_TRACE(WAPI_TX, "<=========%s\n", __FUNCTION__); - return res; -} - -u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe) -{ - u8 *pframe; - u32 res = _SUCCESS; - - WAPI_TRACE(WAPI_RX, "=========>%s\n", __FUNCTION__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) - { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or enabled!\n", __FUNCTION__); - return _FAIL; - } - - - //drop packet when hw decrypt fail - //return tempraily - return _FAIL; - - //pframe=(unsigned char *)((union recv_frame*)precvframe)->u.hdr.rx_data; - - if (false == SecSWSMS4Decryption(padapter, precvframe, &padapter->recvpriv)) - { - WAPI_TRACE(WAPI_ERR, "%s():SMS4 decrypt frame error\n",__FUNCTION__); - return _FAIL; - } - - WAPI_TRACE(WAPI_RX, "<=========%s\n", __FUNCTION__); - return res; -} - -#else - -u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe) -{ - WAPI_TRACE(WAPI_TX, "=========>Dummy %s\n", __FUNCTION__); - WAPI_TRACE(WAPI_TX, "<=========Dummy %s\n", __FUNCTION__); - return _SUCCESS; -} - -u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe) -{ - WAPI_TRACE(WAPI_RX, "=========>Dummy %s\n", __FUNCTION__); - WAPI_TRACE(WAPI_RX, "<=========Dummy %s\n", __FUNCTION__); - return _SUCCESS; -} - -#endif - -#endif diff --git a/os_dep/linux/custom_gpio_linux.c b/os_dep/linux/custom_gpio_linux.c deleted file mode 100755 index eaf2e14..0000000 --- a/os_dep/linux/custom_gpio_linux.c +++ /dev/null @@ -1,210 +0,0 @@ -/****************************************************************************** - * Customer code to add GPIO control during WLAN start/stop - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#include "osdep_service.h" -#include "drv_types.h" -#include "custom_gpio.h" - -#ifdef CONFIG_PLATFORM_SPRD - -//gspi func & GPIO define -#include //0915 -#include - -#if !(defined ANDROID_2X) - -#ifdef CONFIG_RTL8188E -#include -#include -#endif // CONFIG_RTL8188E - -#ifndef GPIO_WIFI_POWER -#define GPIO_WIFI_POWER -1 -#endif // !GPIO_WIFI_POWER - -#ifndef GPIO_WIFI_RESET -#define GPIO_WIFI_RESET -1 -#endif // !GPIO_WIFI_RESET - -#ifndef GPIO_WIFI_PWDN -#define GPIO_WIFI_PWDN -1 -#endif // !GPIO_WIFI_RESET -#ifdef CONFIG_GSPI_HCI -extern unsigned int oob_irq; -#endif // CONFIG_GSPI_HCI - -#ifdef CONFIG_SDIO_HCI -extern int rtw_mp_mode; -#else // !CONFIG_SDIO_HCI -#endif // !CONFIG_SDIO_HCI - -int rtw_wifi_gpio_init(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) { - gpio_request(GPIO_WIFI_IRQ, "oob_irq"); - gpio_direction_input(GPIO_WIFI_IRQ); - - oob_irq = gpio_to_irq(GPIO_WIFI_IRQ); - - DBG_8192C("%s oob_irq:%d\n", __func__, oob_irq); - } -#endif - - if (GPIO_WIFI_RESET > 0) - gpio_request(GPIO_WIFI_RESET , "wifi_rst"); - - return 0; -} - -int rtw_wifi_gpio_deinit(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) { - gpio_free(GPIO_WIFI_IRQ); -#endif - if (GPIO_WIFI_RESET > 0) - gpio_free(GPIO_WIFI_RESET ); - - return 0; -} - -/* Customer function to control hw specific wlan gpios */ -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ - switch (onoff) { - case WLAN_PWDN_OFF: - DBG_8192C("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n", - __FUNCTION__, GPIO_WIFI_RESET); - - if (GPIO_WIFI_RESET > 0) - gpio_direction_output(GPIO_WIFI_RESET , 0); - break; - - case WLAN_PWDN_ON: - DBG_8192C("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n", - __FUNCTION__, GPIO_WIFI_RESET); - - if (GPIO_WIFI_RESET > 0) - gpio_direction_output(GPIO_WIFI_RESET , 1); - break; - - case WLAN_POWER_OFF: - DBG_8192C("%s: call customer specific GPIO to turn off wifi power\n", - __FUNCTION__); - break; - case WLAN_POWER_ON: - DBG_8192C("%s: call customer specific GPIO to turn on wifi power\n", - __FUNCTION__); - break; - } -} -#else //ANDROID_2X -//gspi func & GPIO define -#include //0915 -#include -#ifdef CONFIG_RTL8188E -extern int sprd_3rdparty_gpio_wifi_power; -#endif -extern int sprd_3rdparty_gpio_wifi_pwd; -#ifdef CONFIG_RTL8723A -extern int sprd_3rdparty_gpio_bt_reset; -#endif - -int rtw_wifi_gpio_init(void) -{ -#ifdef CONFIG_RTL8723A - if (sprd_3rdparty_gpio_bt_reset > 0) - gpio_direction_output(sprd_3rdparty_gpio_bt_reset, 1); -#endif - - return 0; -} - -int rtw_wifi_gpio_deinit(void) -{ - return 0; -} - -/* Customer function to control hw specific wlan gpios */ -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ - switch (onoff) { - case WLAN_PWDN_OFF: - DBG_8192C("%s: call customer specific GPIO to set wifi power down pin to 0\n", - __FUNCTION__); - if (sprd_3rdparty_gpio_wifi_pwd > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0); - break; - - case WLAN_PWDN_ON: - DBG_8192C("%s: callc customer specific GPIO to set wifi power down pin to 1\n", - __FUNCTION__); - if (sprd_3rdparty_gpio_wifi_pwd > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1); - break; - - case WLAN_POWER_OFF: - DBG_8192C("%s: call customer specific GPIO to turn off wifi power\n", - __FUNCTION__); -#ifdef CONFIG_RTL8188E - if (sprd_3rdparty_gpio_wifi_power > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0); -#endif - break; - case WLAN_POWER_ON: - DBG_8192C("%s: call customer specific GPIO to turn on wifi power\n", - __FUNCTION__); -#ifdef CONFIG_RTL8188E - if (sprd_3rdparty_gpio_wifi_power > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1); -#endif - - case WLAN_BT_PWDN_OFF: - DBG_8192C("%s: call customer specific GPIO to set bt power down pin to 0\n", - __FUNCTION__); -#ifdef CONFIG_RTL8723A - if (sprd_3rdparty_gpio_bt_reset > 0) - gpio_set_value(sprd_3rdparty_gpio_bt_reset, 0); -#endif - break; - - case WLAN_BT_PWDN_ON: - DBG_8192C("%s: callc customer specific GPIO to set bt power down pin to 1\n", - __FUNCTION__); -#ifdef CONFIG_RTL8723A - if (sprd_3rdparty_gpio_bt_reset > 0) - gpio_set_value(sprd_3rdparty_gpio_bt_reset, 1); -#endif - break; - break; - } -} -#endif //ANDROID_2X -#else //CONFIG_PLATFORM_SPRD -int rtw_wifi_gpio_init(void) -{ - return 0; -} - -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ -} -#endif //CONFIG_PLATFORM_SPRD diff --git a/os_dep/linux/gspi_intf.c b/os_dep/linux/gspi_intf.c deleted file mode 100755 index aa08f2b..0000000 --- a/os_dep/linux/gspi_intf.c +++ /dev/null @@ -1,945 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _HCI_INTF_C_ - -#include -#include -#include -#include -#include -#include - -#ifndef CONFIG_GSPI_HCI -#error "CONFIG_GSPI_HCI should be on!\n" -#endif - -#include -#include -#include -//#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_RTL8723A -#include -#include -#include -#endif - -#ifdef CONFIG_RTL8188E -#include -#endif - -#include -#include -#include - -#include - - -extern char* ifname; - -typedef struct _driver_priv { - int drv_registered; -} drv_priv, *pdrv_priv; - -unsigned int oob_irq; -static drv_priv drvpriv = { - -}; - -static void decide_chip_type_by_device_id(PADAPTER padapter) -{ - padapter->chip_type = NULL_CHIP_TYPE; - -#if defined(CONFIG_RTL8723A) - padapter->chip_type = RTL8723A; - padapter->HardwareType = HARDWARE_TYPE_RTL8723AS; -#elif defined(CONFIG_RTL8188E) - padapter->chip_type = RTL8188E; - padapter->HardwareType = HARDWARE_TYPE_RTL8188ES; -#endif -} - -static irqreturn_t spi_interrupt_thread(int irq, void *data) -{ - struct dvobj_priv *dvobj; - PGSPI_DATA pgspi_data; - - - dvobj = (struct dvobj_priv*)data; - pgspi_data = &dvobj->intf_data; - - //spi_int_hdl(padapter); - if (pgspi_data->priv_wq) - queue_delayed_work(pgspi_data->priv_wq, &pgspi_data->irq_work, 0); - - return IRQ_HANDLED; -} - -static u8 gspi_alloc_irq(struct dvobj_priv *dvobj) -{ - PGSPI_DATA pgspi_data; - struct spi_device *spi; - int err; - - - pgspi_data = &dvobj->intf_data; - spi = pgspi_data->func; - - err = request_irq(oob_irq, spi_interrupt_thread, - IRQF_TRIGGER_FALLING,//IRQF_TRIGGER_HIGH;//|IRQF_ONESHOT, - DRV_NAME, dvobj); - //err = request_threaded_irq(oob_irq, NULL, spi_interrupt_thread, - // IRQF_TRIGGER_FALLING, - // DRV_NAME, dvobj); - if (err < 0) { - DBG_871X("Oops: can't allocate irq %d err:%d\n", oob_irq, err); - goto exit; - } - enable_irq_wake(oob_irq); - disable_irq(oob_irq); - -exit: - return err?_FAIL:_SUCCESS; -} - -static u8 gspi_init(struct dvobj_priv *dvobj) -{ - PGSPI_DATA pgspi_data; - int err = 0; - -_func_enter_; - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+gspi_init\n")); - - if (NULL == dvobj) { - DBG_8192C(KERN_ERR "%s: driver object is NULL!\n", __func__); - err = -1; - goto exit; - } - - pgspi_data = &dvobj->intf_data; - - pgspi_data->block_transfer_len = 512; - pgspi_data->tx_block_mode = 0; - pgspi_data->rx_block_mode = 0; - -exit: - _func_exit_; - - if (err) return _FAIL; - return _SUCCESS; -} - -static void gspi_deinit(struct dvobj_priv *dvobj) -{ - PGSPI_DATA pgspi_data; - struct spi_device *spi; - int err; - - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+gspi_deinit\n")); - - if (NULL == dvobj) { - DBG_8192C(KERN_ERR "%s: driver object is NULL!\n", __FUNCTION__); - return; - } - - pgspi_data = &dvobj->intf_data; - spi = pgspi_data->func; - - if (spi) { - free_irq(oob_irq, dvobj); - } -} - -static struct dvobj_priv *gspi_dvobj_init(struct spi_device *spi) -{ - int status = _FAIL; - struct dvobj_priv *dvobj = NULL; - PGSPI_DATA pgspi; - -_func_enter_; - - dvobj = (struct dvobj_priv*)rtw_zmalloc(sizeof(*dvobj)); - if (NULL == dvobj) { - goto exit; - } - - _rtw_mutex_init(&dvobj->hw_init_mutex); - _rtw_mutex_init(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_init(&dvobj->setch_mutex); - _rtw_mutex_init(&dvobj->setbw_mutex); - dvobj->processing_dev_remove = _FALSE; - //spi init - /* This is the only SPI value that we need to set here, the rest - * comes from the board-peripherals file */ - spi->bits_per_word = 32; - spi->max_speed_hz = 48 * 1000 * 1000; - //here mode 0 and 3 all ok, - //3 can run under 48M clock when SPI_CTL4 bit14 IS_FST set to 1 - //0 can run under 24M clock, but can run under 48M when SPI_CTL4 bit14 IS_FST set to 1 and Ctl0_reg[1:0] set to 3. - spi->mode = SPI_MODE_3; - spi_setup(spi); - -#if 1 - //DBG_8192C("set spi ==========================%d \n", spi_setup(spi)); - - DBG_871X("%s, mode = %d \n", __func__, spi->mode); - DBG_871X("%s, bit_per_word = %d \n", __func__, spi->bits_per_word); - DBG_871X("%s, speed = %d \n", __func__, spi->max_speed_hz); - DBG_871X("%s, chip_select = %d \n", __func__, spi->chip_select); - DBG_871X("%s, controller_data = %d \n", __func__, *(int *)spi->controller_data); - DBG_871X("%s, irq= %d \n", __func__, oob_irq); -#endif - - spi_set_drvdata(spi, dvobj); - pgspi = &dvobj->intf_data; - pgspi->func = spi; - - if (gspi_init(dvobj) != _SUCCESS) { - DBG_871X("%s: initialize GSPI Failed!\n", __FUNCTION__); - goto free_dvobj; - } - rtw_reset_continual_io_error(dvobj); - status = _SUCCESS; - -free_dvobj: - if (status != _SUCCESS && dvobj) { - spi_set_drvdata(spi, NULL); - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - dvobj = NULL; - } - -exit: -_func_exit_; - - return dvobj; -} - -static void gspi_dvobj_deinit(struct spi_device *spi) -{ - struct dvobj_priv *dvobj = spi_get_drvdata(spi); - -_func_enter_; - - spi_set_drvdata(spi, NULL); - if (dvobj) { - gspi_deinit(dvobj); - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - } - -_func_exit_; -} - -static void spi_irq_work(void *data) -{ - struct delayed_work *dwork; - PGSPI_DATA pgspi; - struct dvobj_priv *dvobj; - - - dwork = container_of(data, struct delayed_work, work); - pgspi = container_of(dwork, GSPI_DATA, irq_work); - - dvobj = spi_get_drvdata(pgspi->func); - if (!dvobj->if1) { - DBG_871X("%s if1 == NULL !!\n", __FUNCTION__); - return; - } - spi_int_hdl(dvobj->if1); -} - -static void gspi_intf_start(PADAPTER padapter) -{ - PGSPI_DATA pgspi; - - - if (padapter == NULL) { - DBG_871X(KERN_ERR "%s: padapter is NULL!\n", __FUNCTION__); - return; - } - - pgspi = &adapter_to_dvobj(padapter)->intf_data; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) - pgspi->priv_wq = alloc_workqueue("spi_wq", 0, 0); -#else - pgspi->priv_wq = create_workqueue("spi_wq"); -#endif - INIT_DELAYED_WORK(&pgspi->irq_work, (void*)spi_irq_work); - - enable_irq(oob_irq); - //hal dep - rtw_hal_enable_interrupt(padapter); -} - -static void gspi_intf_stop(PADAPTER padapter) -{ - PGSPI_DATA pgspi; - - - if (padapter == NULL) { - DBG_871X(KERN_ERR "%s: padapter is NULL!\n", __FUNCTION__); - return; - } - - pgspi = &adapter_to_dvobj(padapter)->intf_data; - - if (pgspi->priv_wq) { - cancel_delayed_work_sync(&pgspi->irq_work); - flush_workqueue(pgspi->priv_wq); - destroy_workqueue(pgspi->priv_wq); - pgspi->priv_wq = NULL; - } - - //hal dep - rtw_hal_disable_interrupt(padapter); - disable_irq(oob_irq); -} - -/* - * Do deinit job corresponding to netdev_open() - */ -void rtw_dev_unload(PADAPTER padapter) -{ - struct net_device *pnetdev = (struct net_device*)padapter->pnetdev; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_unload\n")); - - padapter->bDriverStopped = _TRUE; - #ifdef CONFIG_XMIT_ACK - if (padapter->xmitpriv.ack_tx) - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP); - #endif - - if (padapter->bup == _TRUE) - { -#if 0 - if (padapter->intf_stop) - padapter->intf_stop(padapter); -#else - gspi_intf_stop(padapter); -#endif - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop intf complete!\n")); - - if (!adapter_to_pwrctl(padapter)->bInternalAutoSuspend) - rtw_stop_drv_threads(padapter); - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop thread complete!\n")); - - if (padapter->bSurpriseRemoved == _FALSE) - { -#ifdef CONFIG_WOWLAN - if (adapter_to_pwrctl(padapter)->bSupportRemoteWakeup == _TRUE) { - DBG_871X("%s bSupportRemoteWakeup==_TRUE do not run rtw_hal_deinit()\n",__FUNCTION__); - } - else -#endif - { - rtw_hal_deinit(padapter); - } - padapter->bSurpriseRemoved = _TRUE; - } - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: deinit hal complelt!\n")); - - padapter->bup = _FALSE; - } - else { - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("rtw_dev_unload: bup==_FALSE\n")); - } - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_unload\n")); -} - -static PADAPTER rtw_gspi_if1_init(struct dvobj_priv *dvobj) -{ - int status = _FAIL; - struct net_device *pnetdev; - PADAPTER padapter = NULL; - - - padapter = (PADAPTER)rtw_zvmalloc(sizeof(*padapter)); - if (NULL == padapter) { - goto exit; - } - - padapter->dvobj = dvobj; - dvobj->if1 = padapter; - - padapter->bDriverStopped = _TRUE; - - dvobj->padapters[dvobj->iface_nums++] = padapter; - padapter->iface_id = IFACE_ID0; - -#if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT) - //set adapter_type/iface type for primary padapter - padapter->isprimary = _TRUE; - padapter->adapter_type = PRIMARY_ADAPTER; - #ifndef CONFIG_HWPORT_SWAP - padapter->iface_type = IFACE_PORT0; - #else - padapter->iface_type = IFACE_PORT1; - #endif -#endif - - padapter->interface_type = RTW_GSPI; - decide_chip_type_by_device_id(padapter); - - //3 1. init network device data - pnetdev = rtw_init_netdev(padapter); - if (!pnetdev) - goto free_adapter; - - SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj)); - -#ifdef CONFIG_IOCTL_CFG80211 - rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)); -#endif - - - //3 3. init driver special setting, interface, OS and hardware relative - //4 3.1 set hardware operation functions - hal_set_hal_ops(padapter); - - - //3 5. initialize Chip version - padapter->intf_start = &gspi_intf_start; - padapter->intf_stop = &gspi_intf_stop; - - if (rtw_init_io_priv(padapter, spi_set_intf_ops) == _FAIL) - { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, - ("rtw_drv_init: Can't init io_priv\n")); - goto free_hal_data; - } - - { - u32 ret = 0; - DBG_8192C("read start:\n"); - //spi_write8_endian(padapter, SPI_LOCAL_OFFSET | 0xF0, 0x01, 1); - rtw_write8(padapter, SPI_LOCAL_OFFSET | 0xF0, 0x03); - ret = rtw_read32(padapter, SPI_LOCAL_OFFSET | 0xF0); - DBG_8192C("read end 0xF0 read32:%x:\n", ret); - DBG_8192C("read end 0xF0 read8:%x:\n", rtw_read8(padapter, SPI_LOCAL_OFFSET | 0xF0)); - - } - - rtw_hal_read_chip_version(padapter); - - rtw_hal_chip_configure(padapter); - - - //3 6. read efuse/eeprom data - rtw_hal_read_chip_info(padapter); - - - //3 7. init driver common data - if (rtw_init_drv_sw(padapter) == _FAIL) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, - ("rtw_drv_init: Initialize driver software resource Failed!\n")); - goto free_hal_data; - } - - - //3 8. get WLan MAC address - // set mac addr - rtw_macaddr_cfg(padapter->eeprompriv.mac_addr); - rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr); - - rtw_hal_disable_interrupt(padapter); - - DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n" - ,padapter->bDriverStopped - ,padapter->bSurpriseRemoved - ,padapter->bup - ,padapter->hw_init_completed - ); - - status = _SUCCESS; - -free_hal_data: - if (status != _SUCCESS && padapter->HalData) - rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData))); - -free_wdev: - if (status != _SUCCESS) { - #ifdef CONFIG_IOCTL_CFG80211 - rtw_wdev_unregister(padapter->rtw_wdev); - rtw_wdev_free(padapter->rtw_wdev); - #endif - } - -free_adapter: - if (status != _SUCCESS) { - if (pnetdev) - rtw_free_netdev(pnetdev); - else if (padapter) - rtw_vmfree((u8*)padapter, sizeof(*padapter)); - padapter = NULL; - } - -exit: - return padapter; -} - -static void rtw_gspi_if1_deinit(PADAPTER if1) -{ - struct net_device *pnetdev = if1->pnetdev; - struct mlme_priv *pmlmepriv = &if1->mlmepriv; - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_disassoc_cmd(if1, 0, _FALSE); - -#ifdef CONFIG_AP_MODE - free_mlme_ap_info(if1); - #ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_unload(if1); -#endif -#endif -/* - if(if1->DriverState != DRIVER_DISAPPEAR) { - if(pnetdev) { - unregister_netdev(pnetdev); //will call netdev_close() - rtw_proc_remove_one(pnetdev); - } - } -*/ - rtw_cancel_all_timer(if1); - - rtw_dev_unload(if1); - DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", if1->hw_init_completed); - - rtw_handle_dualmac(if1, 0); - -#ifdef CONFIG_IOCTL_CFG80211 - if (if1->rtw_wdev) - { - //rtw_wdev_unregister(if1->rtw_wdev); - rtw_wdev_free(if1->rtw_wdev); - } -#endif - - rtw_free_drv_sw(if1); - - if(pnetdev) - rtw_free_netdev(pnetdev); -} - -/* - * drv_init() - a device potentially for us - * - * notes: drv_init() is called when the bus driver has located a card for us to support. - * We accept the new device by returning 0. - */ -static int /*__devinit*/ rtw_drv_probe(struct spi_device *spi) -{ - int status = _FAIL; - struct dvobj_priv *dvobj; - struct net_device *pnetdev; - PADAPTER if1 = NULL, if2 = NULL; - - - DBG_8192C("RTW: %s line:%d", __FUNCTION__, __LINE__); - - if ((dvobj = gspi_dvobj_init(spi)) == NULL) { - DBG_871X("%s: Initialize device object priv Failed!\n", __FUNCTION__); - goto exit; - } - - if ((if1 = rtw_gspi_if1_init(dvobj)) == NULL) { - DBG_871X("rtw_init_primary_adapter Failed!\n"); - goto free_dvobj; - } - -#ifdef CONFIG_CONCURRENT_MODE - if ((if2 = rtw_drv_if2_init(if1, NULL, spi_set_intf_ops)) == NULL) { - goto free_if1; - } -#endif - - //dev_alloc_name && register_netdev - if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) { - goto free_if2; - } - -#ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_init(if1); -#endif - -#ifdef CONFIG_PLATFORM_RTD2880B - DBG_871X("wlan link up\n"); - rtd2885_wlan_netlink_sendMsg("linkup", "8712"); -#endif - -#ifdef RTK_DMP_PLATFORM - rtw_proc_init_one(if1->pnetdev); -#endif - - if (gspi_alloc_irq(dvobj) != _SUCCESS) - goto free_if2; - -#ifdef CONFIG_GLOBAL_UI_PID - if(ui_pid[1]!=0) { - DBG_871X("ui_pid[1]:%d\n",ui_pid[1]); - rtw_signal_process(ui_pid[1], SIGUSR2); - } -#endif - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n")); - - status = _SUCCESS; - -free_if2: - if (status != _SUCCESS && if2) { - #ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(if2); - rtw_drv_if2_free(if2); - #endif - } - -free_if1: - if (status != _SUCCESS && if1) { - rtw_gspi_if1_deinit(if1); - } - -free_dvobj: - if (status != _SUCCESS) - gspi_dvobj_deinit(spi); - -exit: - return status == _SUCCESS?0:-ENODEV; -} -extern void rtw_unregister_netdevs(struct dvobj_priv *dvobj); -static int /*__devexit*/ rtw_dev_remove(struct spi_device *spi) -{ - struct dvobj_priv *dvobj = spi_get_drvdata(spi); - PADAPTER padapter = dvobj->if1; - -_func_enter_; - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_remove\n")); - - dvobj->processing_dev_remove = _TRUE; - rtw_unregister_netdevs(dvobj); - -#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER) - rtw_unregister_early_suspend(dvobj_to_pwrctl(dvobj)); -#endif - - rtw_pm_set_ips(padapter, IPS_NONE); - rtw_pm_set_lps(padapter, PS_MODE_ACTIVE); - - LeaveAllPowerSaveMode(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(dvobj->if2); -#endif - - rtw_gspi_if1_deinit(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_free(dvobj->if2); -#endif - - gspi_dvobj_deinit(spi); - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_remove\n")); - -_func_exit_; - - return 0; -} - -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 = dvobj_to_pwrctl(dvobj); - 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 - pwrpriv->bSupportRemoteWakeup=_TRUE; -#else - //s2. - rtw_disassoc_cmd(padapter, 0, _FALSE); -#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); - - rtw_set_roaming(padapter, 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; -} - -extern int pm_netdev_open(struct net_device *pnetdev,u8 bnormal); -int rtw_resume_process(_adapter *padapter) -{ - struct net_device *pnetdev; - struct pwrctrl_priv *pwrpriv; - u8 is_pwrlock_hold_by_caller; - u8 is_directly_called_by_auto_resume; - int ret = 0; - u32 start_time = rtw_get_current_time(); - - _func_enter_; - - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_ON); - rtw_mdelay_os(1); - - { - u32 ret = 0; - DBG_8192C("read start:\n"); - //spi_write8_endian(padapter, SPI_LOCAL_OFFSET | 0xF0, 0x01, 1); - rtw_write8(padapter, SPI_LOCAL_OFFSET | 0xF0, 0x03); - ret = rtw_read32(padapter, SPI_LOCAL_OFFSET | 0xF0); - DBG_8192C("read end 0xF0 read32:%x:\n", ret); - DBG_8192C("read end 0xF0 read8:%x:\n", rtw_read8(padapter, SPI_LOCAL_OFFSET | 0xF0)); - - } - - if (padapter) { - pnetdev = padapter->pnetdev; - pwrpriv = adapter_to_pwrctl(padapter); - } else { - ret = -1; - goto exit; - } - - // interface init - if (gspi_init(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __FUNCTION__)); - goto exit; - } - rtw_hal_disable_interrupt(padapter); - if (gspi_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: gspi_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_reset_drv_sw(padapter); - pwrpriv->bkeepfwalive = _FALSE; - - DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive); - if(pm_netdev_open(pnetdev,_TRUE) != 0) { - ret = -1; - goto exit; - } - - netif_device_attach(pnetdev); - netif_carrier_on(pnetdev); - - if( padapter->pid[1]!=0) { - DBG_871X("pid[1]:%d\n",padapter->pid[1]); - rtw_signal_process(padapter->pid[1], SIGUSR2); - } - - #ifdef CONFIG_LAYER2_ROAMING_RESUME - rtw_roaming(padapter, NULL); - #endif - - #ifdef CONFIG_RESUME_IN_WORKQUEUE - rtw_unlock_suspend(); - #endif //CONFIG_RESUME_IN_WORKQUEUE - -exit: - pwrpriv->bInSuspend = _FALSE; - DBG_871X("<=== %s return %d.............. in %dms\n", __FUNCTION__ - , ret, rtw_get_passing_time_ms(start_time)); - - _func_exit_; - - return ret; -} - -static int rtw_gspi_resume(struct spi_device *spi) -{ - struct dvobj_priv *dvobj = spi_get_drvdata(spi); - PADAPTER padapter = dvobj->if1; - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); - int ret = 0; - - - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - if(pwrpriv->bInternalAutoSuspend ){ - ret = rtw_resume_process(padapter); - } else { -#ifdef CONFIG_RESUME_IN_WORKQUEUE - rtw_resume_in_workqueue(pwrpriv); -#else - if(rtw_is_earlysuspend_registered(pwrpriv)) { - /* jeff: bypass resume here, do in late_resume */ - rtw_set_do_late_resume(pwrpriv, _TRUE); - } else { - ret = rtw_resume_process(padapter); - } -#endif /* CONFIG_RESUME_IN_WORKQUEUE */ - } - - DBG_871X("<======== %s return %d\n", __FUNCTION__, ret); - return ret; - -} - - -static struct spi_driver rtw_spi_drv = { - .probe = rtw_drv_probe, - .remove = rtw_dev_remove, - .suspend = rtw_gspi_suspend, - .resume = rtw_gspi_resume, - .driver = { - .name = "wlan_spi", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - } - -}; - -static int __init rtw_drv_entry(void) -{ - int ret; - - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_drv_entry\n")); - DBG_8192C("RTW: rtw_drv_entry enter\n"); - - rtw_suspend_lock_init(); - - drvpriv.drv_registered = _TRUE; - - rtw_wifi_gpio_init(); - rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_ON); - ret = spi_register_driver(&rtw_spi_drv); - - DBG_8192C("RTW: rtw_drv_entry exit %d\n", ret); - - return 0; -} - -static void __exit rtw_drv_halt(void) -{ - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_drv_halt\n")); - DBG_8192C("RTW: rtw_drv_halt enter\n"); - - drvpriv.drv_registered = _FALSE; - - spi_unregister_driver(&rtw_spi_drv); - - - rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_OFF); - rtw_wifi_gpio_deinit(); - - rtw_suspend_lock_uninit(); - DBG_8192C("RTW: rtw_drv_halt enter\n"); - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_drv_halt\n")); - - rtw_mstat_dump(); -} -module_init(rtw_drv_entry); -module_exit(rtw_drv_halt); diff --git a/os_dep/linux/gspi_ops_linux.c b/os_dep/linux/gspi_ops_linux.c deleted file mode 100755 index 8600f05..0000000 --- a/os_dep/linux/gspi_ops_linux.c +++ /dev/null @@ -1,432 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - *******************************************************************************/ -#define _GSPI_OPS_LINUX_C_ - -#include -#include - -#include "rtl8723a_hal.h" -#include "rtl8723a_spec.h" -#include "gspi_ops.h" - -int spi_send_msg(PADAPTER Adapter, struct spi_transfer xfers[], u32 IoAction) -{ - struct dvobj_priv *psddev; - struct spi_device *spi; - struct spi_message msg; - int ret = 1; - - if (Adapter == NULL) { - DBG_8192C(KERN_ERR "%s: padapter is NULL!\n", __func__); - return 1; - } - - psddev = adapter_to_dvobj(Adapter); - spi = psddev->intf_data.func; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - spi_message_add_tail(&xfers[2], &msg); - ret = spi_sync(spi, &msg); - if (ret) { - DBG_8192C("%s: FAIL!\n", __func__); - } - - return ret; -} - -int addr_convert(u32 addr) -{ - u32 domain_id = 0 ; - u32 temp_addr = addr&0xffff0000; - - if (temp_addr == 0 ) { - domain_id = WLAN_IOREG_DOMAIN; - return domain_id; - } - - switch (temp_addr) { - case SPI_LOCAL_OFFSET: - domain_id = SPI_LOCAL_DOMAIN; - break; - case WLAN_IOREG_OFFSET: - domain_id = WLAN_IOREG_DOMAIN; - break; - case FW_FIFO_OFFSET: - domain_id = FW_FIFO_DOMAIN; - break; - case TX_HIQ_OFFSET: - domain_id = TX_HIQ_DOMAIN; - break; - case TX_MIQ_OFFSET: - domain_id = TX_MIQ_DOMAIN; - break; - case TX_LOQ_OFFSET: - domain_id = TX_LOQ_DOMAIN; - break; - case RX_RXOFF_OFFSET: - domain_id = RX_RXFIFO_DOMAIN; - break; - default: - break; - } - //sys_mib.Spi_Transation_record.domain_id =domain_id; - return domain_id; -} - -static u32 buf_endian_reverse(u32 src) -{ - return (((src&0x000000ff)<<24)|((src&0x0000ff00)<<8)| - ((src&0x00ff0000)>>8)|((src&0xff000000)>>24)); -} - -void spi_get_status_info(ADAPTER* Adapter, unsigned char *status) -{ - HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter); - - pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX] = GET_STATUS_PUB_PAGE_NUM(status); - pHalData->SdioTxFIFOFreePage[HI_QUEUE_IDX] = GET_STATUS_HI_PAGE_NUM(status); - pHalData->SdioTxFIFOFreePage[MID_QUEUE_IDX] = GET_STATUS_MID_PAGE_NUM(status); - pHalData->SdioTxFIFOFreePage[LOW_QUEUE_IDX] = GET_STATUS_LOW_PAGE_NUM(status); - - //DBG_8192C("%s: Free page for HIQ(%#x),MIDQ(%#x),LOWQ(%#x),PUBQ(%#x)\n", - // __FUNCTION__, - // pHalData->SdioTxFIFOFreePage[HI_QUEUE_IDX], - // pHalData->SdioTxFIFOFreePage[MID_QUEUE_IDX], - // pHalData->SdioTxFIFOFreePage[LOW_QUEUE_IDX], - // pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]); -} - -int spi_read_write_reg(PADAPTER pAdapter, int write_flag, u32 addr, char * buf, int len, u32 eddien) -{ - int fun = 1, domain_id = 0x0; //LOCAL - unsigned int cmd = 0 ; - int byte_en = 0 ;//,i = 0 ; - int ret = 0; - unsigned char status[8] = {0}; - unsigned int data_tmp = 0; - //u32 force_bigendian = !eddien; - u32 force_bigendian = eddien; - - if (len!=1 && len!=2 && len != 4) { - return -1; - } - - domain_id = addr_convert(addr); - - addr &= 0x7fff; - len &= 0xff; - if (write_flag) //write register - { - int remainder = addr % 4; - u32 val32 = *(u32 *)buf; - switch(len) { - case 1: - byte_en = (0x1 << remainder); - data_tmp = (val32& 0xff)<< (remainder*8); - break; - case 2: - byte_en = (0x3 << remainder); - data_tmp = (val32 & 0xffff)<< (remainder*8); - break; - case 4: - byte_en = 0xf; - data_tmp = val32 & 0xffffffff; - break; - default: - byte_en = 0xf; - data_tmp = val32 & 0xffffffff; - break; - } - } - else //read register - { - switch(len) { - case 1: - byte_en = 0x1; - break; - case 2: - byte_en = 0x3; - break; - case 4: - byte_en = 0xf; - break; - default: - byte_en = 0xf; - break; - } - } - - //addr = 0xF0 4byte: 0x2800f00f - REG_LEN_FORMAT(&cmd, byte_en); - REG_ADDR_FORMAT(&cmd, (addr&0xfffffffc)); - REG_DOMAIN_ID_FORMAT(&cmd, domain_id); - REG_FUN_FORMAT(&cmd, fun); - REG_RW_FORMAT(&cmd, write_flag); - - //DBG_8192C("spi_read_write_reg cmd1: %x, data_tmp is %x\n",cmd, data_tmp); - - if (force_bigendian) { - cmd = buf_endian_reverse(cmd); - } - - //io is one by one, so we do not need fwps_lock here - //rtw_spin_lock(&padapter->halpriv.fwps_lock); - //padapter->io_fifo_processing = _TRUE; - if (!write_flag && (domain_id!= RX_RXFIFO_DOMAIN)) { - u32 read_data = 0; - struct spi_transfer xfers[3]; - _rtw_memset(xfers, 0x00, 3*sizeof(struct spi_transfer)); - _rtw_memset(buf, 0x0, len); - - xfers[0].tx_buf = &cmd; - xfers[0].len = 4; - - xfers[1].rx_buf = status; - xfers[1].len = 8; - - xfers[2].rx_buf = &read_data; - xfers[2].len = 4; - - //DBG_8192C("spi_read_write_reg: read_data is %x\n", read_data); - ret = spi_send_msg(pAdapter, xfers, 0); - if (ret) { - DBG_8192C(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, ret, addr); - read_data = 0; - _rtw_memset(status, 0, 8); - } - - //DBG_8192C("spi_read_write_reg: read_data is %x\n", read_data); - read_data = EF4Byte(read_data); - //add for 8810 -#ifdef CONFIG_BIG_ENDIAN - if (!force_bigendian) - read_data = buf_endian_reverse(read_data); -#else - if (force_bigendian) - read_data = buf_endian_reverse(read_data); -#endif - *(u32*)buf = read_data; - //DBG_8192C("spi_read_write_reg: read: buf is %x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); - } else if (write_flag ) { - struct spi_transfer xfers[3]; - _rtw_memset(xfers, 0x00, 3*sizeof(struct spi_transfer)); - - xfers[0].tx_buf = &cmd; - xfers[0].len = 4; - - xfers[1].tx_buf = &data_tmp; - xfers[1].len = 4; - - xfers[2].rx_buf = status; - xfers[2].len = 8; - - //DBG_8192C("spi_read_write_reg data_tmp 111: %x\n",data_tmp); -#ifdef CONFIG_BIG_ENDIAN - if (!force_bigendian) - data_tmp = buf_endian_reverse(data_tmp); -#else - if (force_bigendian) - data_tmp = buf_endian_reverse(data_tmp); -#endif - ret = spi_send_msg(pAdapter, xfers, 0); - if (ret) { - DBG_8192C(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, ret, addr); - _rtw_memset(status, 0, 8); - } - } - - //padapter->io_fifo_processing = _FALSE; - - spi_get_status_info(pAdapter, (unsigned char*)status); - - return ret; -} - -u8 spi_read8(ADAPTER *Adapter, unsigned int addr, s32 *err) -{ - unsigned int ret = 0; - int val32 = 0 , remainder = 0 ; - s32 _err = 0; - - _err = spi_read_write_reg(Adapter,0,addr&0xFFFFFFFC,(char *)&ret,4,0); - remainder = addr % 4; - val32 = ret; - val32 = (val32& (0xff<< (remainder<<3)))>>(remainder<<3); - - if (err) - *err = _err; - - return (u8)val32; - -} - -u16 spi_read16(ADAPTER *Adapter, u32 addr, s32 *err) -{ - unsigned int ret = 0; - int val32 = 0 , remainder = 0 ; - s32 _err = 0; - - _err = spi_read_write_reg(Adapter,0,addr&0xFFFFFFFC,(char *)&ret,4,0); - remainder = addr % 4; - val32 = ret; - val32 = (val32& (0xffff<< (remainder<<3)))>>(remainder<<3); - - if (err) - *err = _err; - - return (u16)val32; -} - -u32 spi_read32(ADAPTER *Adapter, u32 addr, s32 *err) -{ - unsigned int ret = 0; - s32 _err = 0; - - _err = spi_read_write_reg(Adapter,0,addr&0xFFFFFFFC,(char *)&ret,4,0); - if (err) - *err = _err; - - return ret; -} - -void spi_write8(ADAPTER *Adapter, u32 addr, u8 buf, s32 *err) -{ - int ret = 0; - - ret = spi_read_write_reg(Adapter,1,addr,(char *)&buf,1,0); - if (err) - *err = ret; -} - -void spi_write16(ADAPTER *Adapter, u32 addr, u16 buf, s32 *err) -{ - int ret = 0; - - ret = spi_read_write_reg(Adapter,1,addr,(char *)&buf,2,0); - if (err) - *err = ret; -} - -void spi_write32(ADAPTER *Adapter, u32 addr, u32 buf, s32 *err) -{ - int ret = 0; - - ret = spi_read_write_reg(Adapter, 1,addr,(char *)&buf,4,0); - if (err) - *err = ret; -} - -unsigned int spi_write8_endian(ADAPTER *Adapter, unsigned int addr, unsigned int buf, u32 big) -{ - int ret = 0; - - ret = spi_read_write_reg(Adapter,1,addr,(char *)&buf,1, big); - return ret; -} - -void spi_write_tx_fifo(ADAPTER *Adapter, u8 *buf, int len, u32 fifo) -{ - int fun =1; //TX_HIQ_FIFO - unsigned int cmd = 0; - unsigned char status[8]; - u8 more_data = 0; - int ret = 0; - - struct spi_transfer xfers[3]; - _rtw_memset(xfers, 0x00, 3*sizeof(struct spi_transfer)); - - xfers[0].tx_buf = &cmd; - xfers[0].len = 4; - - xfers[1].tx_buf = buf; - xfers[1].len = len;//len/4; - - xfers[2].rx_buf = status; - xfers[2].len = 8; - -_func_enter_; - - FIFO_LEN_FORMAT(&cmd, len); //TX Agg len - FIFO_DOMAIN_ID_FORMAT(&cmd, fifo); - FIFO_FUN_FORMAT(&cmd, fun); - FIFO_RW_FORMAT(&cmd, (unsigned int)1); //write - - _rtw_memset(status, 0x00, 8); - - ret = spi_send_msg(Adapter, xfers, 1); - if (ret) { - DBG_8192C("%s: FAIL!(%d)\n", __func__, ret); - _rtw_memset(status, 0, 8); - } - - spi_get_status_info(Adapter, status); - - more_data = GET_STATUS_HISR_LOW8BIT(status) & BIT(0); - //if(more_data) { - // rtw_queue_delayed_work(Adapter->recv_wq, &Adapter->recv_work, 0, (void*)Adapter); - //} - -_func_exit_; - - return; -} - -int spi_read_rx_fifo(ADAPTER *Adapter, unsigned char *buf, int len, struct spi_more_data *pmore_data) -{ - int fun =1, domain_id = 0x1f; //RX_FIFO - unsigned int cmd = 0; - unsigned char status[8]; - int ret = 0; - struct spi_transfer xfers[3]; - - _rtw_memset(xfers, 0x00, 3*sizeof(struct spi_transfer)); - - xfers[0].tx_buf = &cmd; - xfers[0].len = 4; - - xfers[1].rx_buf = buf; - xfers[1].len = len; - - xfers[2].rx_buf = status; - xfers[2].len = 8; - - FIFO_LEN_FORMAT(&cmd, len); //TX Agg len - FIFO_DOMAIN_ID_FORMAT(&cmd, domain_id); - FIFO_FUN_FORMAT(&cmd, fun); - FIFO_RW_FORMAT(&cmd, 0); //read - - _rtw_memset(status, 0x00, 8); - _rtw_memset(buf, 0x0, len); - - ret = spi_send_msg(Adapter, xfers, 1); - if (ret) { - DBG_8192C(KERN_ERR "%s: FAIL!(%d)\n", __func__, ret); - _rtw_memset(status, 0x00, 8); - _rtw_memset(buf, 0x0, len); - return _FAIL; - } - - spi_get_status_info(Adapter, (unsigned char*)status); - pmore_data->more_data = GET_STATUS_HISR_LOW8BIT(status) & BIT(0); - pmore_data->len = GET_STATUS_RX_LENGTH(status); - - return _SUCCESS; -} diff --git a/os_dep/linux/pci_intf.c b/os_dep/linux/pci_intf.c deleted file mode 100755 index ccd3800..0000000 --- a/os_dep/linux/pci_intf.c +++ /dev/null @@ -1,1995 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _HCI_INTF_C_ - -#include -#include -#include -#include -#include -#include -#include - -#ifndef CONFIG_PCI_HCI - -#error "CONFIG_PCI_HCI shall be on!\n" - -#endif - -#include -#include -#include - -#ifdef CONFIG_80211N_HT -extern int rtw_ht_enable; -extern int rtw_cbw40_enable; -extern int rtw_ampdu_enable;//for enable tx_ampdu -#endif - -#ifdef CONFIG_PM -extern int pm_netdev_open(struct net_device *pnetdev); -static int rtw_suspend(struct pci_dev *pdev, pm_message_t state); -static int rtw_resume(struct pci_dev *pdev); -#endif - - -static int rtw_drv_init(struct pci_dev *pdev, const struct pci_device_id *pdid); -static void rtw_dev_remove(struct pci_dev *pdev); - -static struct specific_device_id specific_device_id_tbl[] = { - {.idVendor=0x0b05, .idProduct=0x1791, .flags=SPEC_DEV_ID_DISABLE_HT}, - {.idVendor=0x13D3, .idProduct=0x3311, .flags=SPEC_DEV_ID_DISABLE_HT}, - {} -}; - -struct pci_device_id rtw_pci_id_tbl[] = { -#ifdef CONFIG_RTL8188E - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8179)}, -#endif -#ifdef CONFIG_RTL8192C - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8191)}, - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8178)}, - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8177)}, - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8176)}, -#endif -#ifdef CONFIG_RTL8192D - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8193)}, - {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x002B)}, -#endif - {}, -}; - -struct pci_drv_priv { - struct pci_driver rtw_pci_drv; - int drv_registered; -}; - - -static struct pci_drv_priv pci_drvpriv = { - .rtw_pci_drv.name = (char*)DRV_NAME, - .rtw_pci_drv.probe = rtw_drv_init, - .rtw_pci_drv.remove = rtw_dev_remove, - .rtw_pci_drv.id_table = rtw_pci_id_tbl, -#ifdef CONFIG_PM - .rtw_pci_drv.suspend = rtw_suspend, - .rtw_pci_drv.resume = rtw_resume, -#else - .rtw_pci_drv.suspend = NULL, - .rtw_pci_drv.resume = NULL, -#endif -}; - - -MODULE_DEVICE_TABLE(pci, rtw_pci_id_tbl); - - -static u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = { - INTEL_VENDOR_ID, - ATI_VENDOR_ID, - AMD_VENDOR_ID, - SIS_VENDOR_ID -}; - -static u8 rtw_pci_platform_switch_device_pci_aspm(_adapter *padapter, u8 value) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - u8 bresult = _SUCCESS; - int error; - - value |= 0x40; - - error = pci_write_config_byte(pdvobjpriv->ppcidev, 0x80, value); - - if(error != 0) - { - bresult = _FALSE; - DBG_871X("rtw_pci_platform_switch_device_pci_aspm error (%d)\n",error); - } - - return bresult; -} - -// -// When we set 0x01 to enable clk request. Set 0x0 to disable clk req. -// -static u8 rtw_pci_switch_clk_req(_adapter *padapter, u8 value) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - u8 buffer, bresult = _SUCCESS; - int error; - - buffer = value; - - if(!padapter->hw_init_completed) - return bresult; - - error = pci_write_config_byte(pdvobjpriv->ppcidev, 0x81, value); - - if(error != 0) - { - bresult = _FALSE; - DBG_871X("rtw_pci_switch_clk_req error (%d)\n",error); - } - - return bresult; -} - -#if 0 -//Description: -//Disable RTL8192SE ASPM & Disable Pci Bridge ASPM -void rtw_pci_disable_aspm(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv); - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u32 pcicfg_addrport = 0; - u8 num4bytes; - u8 linkctrl_reg; - u16 pcibridge_linkctrlreg, aspmlevel = 0; - - // When there exists anyone's busnum, devnum, and funcnum that are set to 0xff, - // we do not execute any action and return. - // if it is not intel bus then don't enable ASPM. - if ((pcipriv->busnumber == 0xff - && pcipriv->devnumber == 0xff - && pcipriv->funcnumber == 0xff) - || (pcipriv->pcibridge_busnum == 0xff - && pcipriv->pcibridge_devnum == 0xff - && pcipriv->pcibridge_funcnum == 0xff)) - { - DBG_871X("PlatformEnableASPM(): Fail to enable ASPM. Cannot find the Bus of PCI(Bridge).\n"); - return; - } - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { - DBG_871X("%s(): Disable ASPM. Recognize the Bus of PCI(Bridge) as UNKNOWN.\n", __func__); - } - - if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { - RT_CLEAR_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ); - rtw_pci_switch_clk_req(padapter, 0x0); - } - - { - // Suggested by SD1 for promising device will in L0 state after an I/O. - u8 tmp_u1b; - - pci_read_config_byte(pdvobjpriv->ppcidev, 0x80, &tmp_u1b); - } - - // Retrieve original configuration settings. - linkctrl_reg = pcipriv->linkctrl_reg; - pcibridge_linkctrlreg = pcipriv->pcibridge_linkctrlreg; - - // Set corresponding value. - aspmlevel |= BIT(0) | BIT(1); - linkctrl_reg &= ~aspmlevel; - pcibridge_linkctrlreg &= ~(BIT(0) | BIT(1)); - - rtw_pci_platform_switch_device_pci_aspm(padapter, linkctrl_reg); - rtw_udelay_os(50); - - //When there exists anyone's busnum, devnum, and funcnum that are set to 0xff, - // we do not execute any action and return. - if ((pcipriv->busnumber == 0xff && - pcipriv->devnumber == 0xff && - pcipriv->funcnumber == 0xff) || - (pcipriv->pcibridge_busnum == 0xff && - pcipriv->pcibridge_devnum == 0xff - && pcipriv->pcibridge_funcnum == 0xff)) - { - //Do Nothing!! - } - else - { - //4 //Disable Pci Bridge ASPM - pcicfg_addrport = (pcipriv->pcibridge_busnum << 16) | - (pcipriv->pcibridge_devnum << 11) | - (pcipriv->pcibridge_funcnum << 8) | (1 << 31); - num4bytes = (pcipriv->pcibridge_pciehdr_offset + 0x10) / 4; - - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - - // now grab data port with device|vendor 4 byte dword - NdisRawWritePortUchar(PCI_CONF_DATA, pcibridge_linkctrlreg); - - DBG_871X("rtw_pci_disable_aspm():PciBridge busnumber[%x], DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n", - pcipriv->pcibridge_busnum, pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum, - (pcipriv->pcibridge_pciehdr_offset+0x10), pcibridge_linkctrlreg); - - rtw_udelay_os(50); - } -} - -//[ASPM] -//Description: -// Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for power saving -// We should follow the sequence to enable RTL8192SE first then enable Pci Bridge ASPM -// or the system will show bluescreen. -void rtw_pci_enable_aspm(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv); - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u16 aspmlevel = 0; - u32 pcicfg_addrport = 0; - u8 num4bytes; - u8 u_pcibridge_aspmsetting = 0; - u8 u_device_aspmsetting = 0; - - // When there exists anyone's busnum, devnum, and funcnum that are set to 0xff, - // we do not execute any action and return. - // if it is not intel bus then don't enable ASPM. - - if ((pcipriv->busnumber == 0xff - && pcipriv->devnumber == 0xff - && pcipriv->funcnumber == 0xff) - || (pcipriv->pcibridge_busnum == 0xff - && pcipriv->pcibridge_devnum == 0xff - && pcipriv->pcibridge_funcnum == 0xff)) - { - DBG_871X("PlatformEnableASPM(): Fail to enable ASPM. Cannot find the Bus of PCI(Bridge).\n"); - return; - } - - //4 Enable Pci Bridge ASPM - pcicfg_addrport = (pcipriv->pcibridge_busnum << 16) - | (pcipriv->pcibridge_devnum << 11) - | (pcipriv->pcibridge_funcnum << 8) | (1 << 31); - num4bytes = (pcipriv->pcibridge_pciehdr_offset + 0x10) / 4; - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - // now grab data port with device|vendor 4 byte dword - - u_pcibridge_aspmsetting = pcipriv->pcibridge_linkctrlreg | pdvobjpriv->const_hostpci_aspm_setting; - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL || - pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_SIS) - u_pcibridge_aspmsetting &= ~BIT(0); - - NdisRawWritePortUchar(PCI_CONF_DATA, u_pcibridge_aspmsetting); - - DBG_871X("PlatformEnableASPM():PciBridge busnumber[%x], DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n", - pcipriv->pcibridge_busnum, - pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum, - (pcipriv->pcibridge_pciehdr_offset+0x10), - u_pcibridge_aspmsetting); - - rtw_udelay_os(50); - - // Get ASPM level (with/without Clock Req) - aspmlevel |= pdvobjpriv->const_devicepci_aspm_setting; - u_device_aspmsetting = pcipriv->linkctrl_reg; - u_device_aspmsetting |= aspmlevel; - - rtw_pci_platform_switch_device_pci_aspm(padapter, u_device_aspmsetting); //(priv->linkctrl_reg | ASPMLevel)); - - if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { - rtw_pci_switch_clk_req(padapter, (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0); - RT_SET_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ); - } - - rtw_udelay_os(50); -} - -// -//Description: -//To get link control field by searching from PCIe capability lists. -// -static u8 -rtw_get_link_control_field(_adapter *padapter, u8 busnum, u8 devnum, - u8 funcnum) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - struct rt_pci_capabilities_header capability_hdr; - u8 capability_offset, num4bytes; - u32 pcicfg_addrport = 0; - u8 linkctrl_reg; - u8 status = _FALSE; - - //If busnum, devnum, funcnum are set to 0xff. - if (busnum == 0xff && devnum == 0xff && funcnum == 0xff) { - DBG_871X("GetLinkControlField(): Fail to find PCIe Capability\n"); - return _FALSE; - } - - pcicfg_addrport = (busnum << 16) | (devnum << 11) | (funcnum << 8) | (1 << 31); - - //2PCIeCap - - // The device supports capability lists. Find the capabilities. - num4bytes = 0x34 / 4; - //get capability_offset - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - // now grab data port with device|vendor 4 byte dword - NdisRawReadPortUchar(PCI_CONF_DATA, &capability_offset); - - // Loop through the capabilities in search of the power management capability. - // The list is NULL-terminated, so the last offset will always be zero. - - while (capability_offset != 0) { - // First find the number of 4 Byte. - num4bytes = capability_offset / 4; - - // Read the header of the capability at this offset. If the retrieved capability is not - // the power management capability that we are looking for, follow the link to the - // next capability and continue looping. - - //4 get capability_hdr - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - // now grab data port with device|vendor 4 byte dword - NdisRawReadPortUshort(PCI_CONF_DATA, (u16 *) & capability_hdr); - - // Found the PCI express capability - if (capability_hdr.capability_id == PCI_CAPABILITY_ID_PCI_EXPRESS) - { - break; - } - else - { - // This is some other capability. Keep looking for the PCI express capability. - capability_offset = capability_hdr.next; - } - } - - if (capability_hdr.capability_id == PCI_CAPABILITY_ID_PCI_EXPRESS) // - { - num4bytes = (capability_offset + 0x10) / 4; - - //4 Read Link Control Register - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - // now grab data port with device|vendor 4 byte dword - NdisRawReadPortUchar(PCI_CONF_DATA, &linkctrl_reg); - - pcipriv->pcibridge_pciehdr_offset = capability_offset; - pcipriv->pcibridge_linkctrlreg = linkctrl_reg; - - status = _TRUE; - } - else - { - // We didn't find a PCIe capability. - DBG_871X("GetLinkControlField(): Cannot Find PCIe Capability\n"); - } - - return status; -} - -// -//Description: -//To get PCI bus infomation and return busnum, devnum, and funcnum about -//the bus(bridge) which the device binds. -// -static u8 -rtw_get_pci_bus_info(_adapter *padapter, - u16 vendorid, - u16 deviceid, - u8 irql, u8 basecode, u8 subclass, u8 filed19val, - u8 * busnum, u8 * devnum, u8 * funcnum) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pci_dev *pdev = pdvobjpriv->ppcidev; - u8 busnum_idx, devicenum_idx, functionnum_idx; - u32 pcicfg_addrport = 0; - u32 dev_venid = 0, classcode, field19, headertype; - u16 venId, devId; - u8 basec, subc, irqline; - u16 regoffset; - u8 b_singlefunc = _FALSE; - u8 b_bridgechk = _FALSE; - - *busnum = 0xFF; - *devnum = 0xFF; - *funcnum = 0xFF; - - //DBG_871X("==============>vendorid:%x,deviceid:%x,irql:%x\n", vendorid,deviceid,irql); - if ((basecode == PCI_CLASS_BRIDGE_DEV) && - (subclass == PCI_SUBCLASS_BR_PCI_TO_PCI) - && (filed19val == U1DONTCARE)) - b_bridgechk = _TRUE; - - // perform a complete pci bus scan operation - for (busnum_idx = 0; busnum_idx < PCI_MAX_BRIDGE_NUMBER; busnum_idx++) //255 - { - for (devicenum_idx = 0; devicenum_idx < PCI_MAX_DEVICES; devicenum_idx++) //32 - { - b_singlefunc = _FALSE; - for (functionnum_idx = 0; functionnum_idx < PCI_MAX_FUNCTION; functionnum_idx++) //8 - { - // - // We have to skip redundant Bus scan to prevent unexpected system hang - // if single function is present in this device. - // 2009.02.26. - // - if (functionnum_idx == 0) { - //4 get header type (DWORD #3) - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (3 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &headertype); - headertype = ((headertype >> 16) & 0x0080) >> 7; // address 0x0e[7]. - if (headertype == 0) //Single function - b_singlefunc = _TRUE; - } - else - {//By pass the following scan process. - if (b_singlefunc == _TRUE) - break; - } - - // Set access enable control. - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - - //4 // Get vendorid/ deviceid - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport); - // now grab data port with device|vendor 4 byte dword - NdisRawReadPortUlong(PCI_CONF_DATA, &dev_venid); - - // if data port is full of 1s, no device is present - // some broken boards return 0 if a slot is empty: - if (dev_venid == 0xFFFFFFFF || dev_venid == 0) - continue; //PCI_INVALID_VENDORID - - // 4 // Get irql - regoffset = 0x3C; - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31) | (regoffset & 0xFFFFFFFC); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport); - NdisRawReadPortUchar((PCI_CONF_DATA +(regoffset & 0x3)), &irqline); - - venId = (u16) (dev_venid >> 0) & 0xFFFF; - devId = (u16) (dev_venid >> 16) & 0xFFFF; - - // Check Vendor ID - if (!b_bridgechk && (venId != vendorid) && (vendorid != U2DONTCARE)) - continue; - - // Check Device ID - if (!b_bridgechk && (devId != deviceid) && (deviceid != U2DONTCARE)) - continue; - - // Check irql - if (!b_bridgechk && (irqline != irql) && (irql != U1DONTCARE)) - continue; - - //4 get Class Code - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (2 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &classcode); - classcode = classcode >> 8; - - basec = (u8) (classcode >> 16) & 0xFF; - subc = (u8) (classcode >> 8) & 0xFF; - if (b_bridgechk && (venId != vendorid) && (basec == basecode) && (subc == subclass)) - return _TRUE; - - // Check Vendor ID - if (b_bridgechk && (venId != vendorid) && (vendorid != U2DONTCARE)) - continue; - - // Check Device ID - if (b_bridgechk && (devId != deviceid) && (deviceid != U2DONTCARE)) - continue; - - // Check irql - if (b_bridgechk && (irqline != irql) && (irql != U1DONTCARE)) - continue; - - //4 get field 0x19 value (DWORD #6) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (6 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &field19); - field19 = (field19 >> 8) & 0xFF; - - //4 Matching Class Code and filed19. - if ((basec == basecode) && (subc == subclass) && ((field19 == filed19val) || (filed19val == U1DONTCARE))) { - *busnum = busnum_idx; - *devnum = devicenum_idx; - *funcnum = functionnum_idx; - - DBG_871X("GetPciBusInfo(): Find Device(%X:%X) bus=%d dev=%d, func=%d\n", - vendorid, deviceid, busnum_idx, devicenum_idx, functionnum_idx); - return _TRUE; - } - } - } - } - - DBG_871X("GetPciBusInfo(): Cannot Find Device(%X:%X:%X)\n", vendorid, deviceid, dev_venid); - - return _FALSE; -} - -static u8 -rtw_get_pci_brideg_info(_adapter *padapter, - u8 basecode, - u8 subclass, - u8 filed19val, u8 * busnum, u8 * devnum, - u8 * funcnum, u16 * vendorid, u16 * deviceid) -{ - u8 busnum_idx, devicenum_idx, functionnum_idx; - u32 pcicfg_addrport = 0; - u32 dev_venid, classcode, field19, headertype; - u16 venId, devId; - u8 basec, subc, irqline; - u16 regoffset; - u8 b_singlefunc = _FALSE; - - *busnum = 0xFF; - *devnum = 0xFF; - *funcnum = 0xFF; - - // perform a complete pci bus scan operation - for (busnum_idx = 0; busnum_idx < PCI_MAX_BRIDGE_NUMBER; busnum_idx++) //255 - { - for (devicenum_idx = 0; devicenum_idx < PCI_MAX_DEVICES; devicenum_idx++) //32 - { - b_singlefunc = _FALSE; - for (functionnum_idx = 0; functionnum_idx < PCI_MAX_FUNCTION; functionnum_idx++) //8 - { - // - // We have to skip redundant Bus scan to prevent unexpected system hang - // if single function is present in this device. - // 2009.02.26. - // - if (functionnum_idx == 0) - { - //4 get header type (DWORD #3) - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - //NdisRawWritePortUlong((ULONG_PTR)PCI_CONF_ADDRESS , pcicfg_addrport + (3 << 2)); - //NdisRawReadPortUlong((ULONG_PTR)PCI_CONF_DATA, &headertype); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (3 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &headertype); - headertype = ((headertype >> 16) & 0x0080) >> 7; // address 0x0e[7]. - if (headertype == 0) //Single function - b_singlefunc = _TRUE; - } - else - {//By pass the following scan process. - if (b_singlefunc == _TRUE) - break; - } - - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - - //4 // Get vendorid/ deviceid - // set up address port at 0xCF8 offset field= 0 (dev|vend) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport); - // now grab data port with device|vendor 4 byte dword - NdisRawReadPortUlong(PCI_CONF_DATA, &dev_venid); - - //4 Get irql - regoffset = 0x3C; - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31) | (regoffset & 0xFFFFFFFC); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport); - NdisRawReadPortUchar((PCI_CONF_DATA + (regoffset & 0x3)), &irqline); - - venId = (u16) (dev_venid >> 0) & 0xFFFF; - devId = (u16) (dev_venid >> 16) & 0xFFFF; - - //4 get Class Code - pcicfg_addrport = (busnum_idx << 16) | (devicenum_idx << 11) | (functionnum_idx << 8) | (1 << 31); - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (2 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &classcode); - classcode = classcode >> 8; - - basec = (u8) (classcode >> 16) & 0xFF; - subc = (u8) (classcode >> 8) & 0xFF; - - //4 get field 0x19 value (DWORD #6) - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (6 << 2)); - NdisRawReadPortUlong(PCI_CONF_DATA, &field19); - field19 = (field19 >> 8) & 0xFF; - - //4 Matching Class Code and filed19. - if ((basec == basecode) && (subc == subclass) && ((field19 == filed19val) || (filed19val == U1DONTCARE))) { - *busnum = busnum_idx; - *devnum = devicenum_idx; - *funcnum = functionnum_idx; - *vendorid = venId; - *deviceid = devId; - - DBG_871X("GetPciBridegInfo : Find Device(%X:%X) bus=%d dev=%d, func=%d\n", - venId, devId, busnum_idx, devicenum_idx, functionnum_idx); - - return _TRUE; - } - } - } - } - - DBG_871X("GetPciBridegInfo(): Cannot Find PciBridge for Device\n"); - - return _FALSE; -} // end of GetPciBridegInfo - -// -//Description: -//To find specific bridge information. -// -static void rtw_find_bridge_info(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u8 pcibridge_busnum = 0xff; - u8 pcibridge_devnum = 0xff; - u8 pcibridge_funcnum = 0xff; - u16 pcibridge_vendorid = 0xff; - u16 pcibridge_deviceid = 0xff; - u8 tmp = 0; - - rtw_get_pci_brideg_info(padapter, - PCI_CLASS_BRIDGE_DEV, - PCI_SUBCLASS_BR_PCI_TO_PCI, - pcipriv->busnumber, - &pcibridge_busnum, - &pcibridge_devnum, &pcibridge_funcnum, - &pcibridge_vendorid, &pcibridge_deviceid); - - // match the array of vendor id and regonize which chipset is used. - pcipriv->pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN; - - for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) { - if (pcibridge_vendorid == pcibridge_vendors[tmp]) { - pcipriv->pcibridge_vendor = tmp; - DBG_871X("Pci Bridge Vendor is found index: %d\n", tmp); - break; - } - } - DBG_871X("Pci Bridge Vendor is %x\n", pcibridge_vendors[tmp]); - - // Update corresponding PCI bus info. - pcipriv->pcibridge_busnum = pcibridge_busnum; - pcipriv->pcibridge_devnum = pcibridge_devnum; - pcipriv->pcibridge_funcnum = pcibridge_funcnum; - pcipriv->pcibridge_vendorid = pcibridge_vendorid; - pcipriv->pcibridge_deviceid = pcibridge_deviceid; - -} - -static u8 -rtw_get_amd_l1_patch(_adapter *padapter, u8 busnum, u8 devnum, - u8 funcnum) -{ - u8 status = _FALSE; - u8 offset_e0; - unsigned offset_e4; - u32 pcicfg_addrport = 0; - - pcicfg_addrport = (busnum << 16) | (devnum << 11) | (funcnum << 8) | (1 << 31); - - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + 0xE0); - NdisRawWritePortUchar(PCI_CONF_DATA, 0xA0); - - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + 0xE0); - NdisRawReadPortUchar(PCI_CONF_DATA, &offset_e0); - - if (offset_e0 == 0xA0) - { - NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + 0xE4); - NdisRawReadPortUlong(PCI_CONF_DATA, &offset_e4); - //DbgPrint("Offset E4 %x\n", offset_e4); - if (offset_e4 & BIT(23)) - status = _TRUE; - } - - return status; -} -#else -/*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/ -void rtw_pci_disable_aspm(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv); - struct pci_dev *pdev = pdvobjpriv->ppcidev; - struct pci_dev *bridge_pdev = pdev->bus->self; - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u8 linkctrl_reg; - u16 pcibridge_linkctrlreg; - u16 aspmlevel = 0; - - // We do not diable/enable ASPM by driver, in the future, the BIOS will enable host and NIC ASPM. - // Advertised by SD1 victorh. Added by tynli. 2009.11.23. - if(pdvobjpriv->const_pci_aspm == 0) - return; - - if(!padapter->hw_init_completed) - return; - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s(): PCI(Bridge) UNKNOWN.\n", __FUNCTION__)); - return; - } - - linkctrl_reg = pcipriv->linkctrl_reg; - pcibridge_linkctrlreg = pcipriv->pcibridge_linkctrlreg; - - // Set corresponding value. - aspmlevel |= BIT(0) | BIT(1); - linkctrl_reg &=~aspmlevel; - pcibridge_linkctrlreg &=~aspmlevel; - - if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { - RT_CLEAR_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ); - rtw_pci_switch_clk_req(padapter, 0x0); - } - - { - /*for promising device will in L0 state after an I/O.*/ - u8 tmp_u1b; - pci_read_config_byte(pdev, 0x80, &tmp_u1b); - } - - rtw_pci_platform_switch_device_pci_aspm(padapter, linkctrl_reg); - rtw_udelay_os(50); - - //When there exists anyone's BusNum, DevNum, and FuncNum that are set to 0xff, - // we do not execute any action and return. Added by tynli. - if( (pcipriv->busnumber == 0xff && pcipriv->devnumber == 0xff && pcipriv->funcnumber == 0xff) || - (pcipriv->pcibridge_busnum == 0xff && pcipriv->pcibridge_devnum == 0xff && pcipriv->pcibridge_funcnum == 0xff) ) - { - // Do Nothing!! - } - else - { - /*Disable Pci Bridge ASPM*/ - //NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + (num4bytes << 2)); - //NdisRawWritePortUchar(PCI_CONF_DATA, pcibridge_linkctrlreg); - pci_write_config_byte(bridge_pdev, pcipriv->pcibridge_pciehdr_offset + 0x10, pcibridge_linkctrlreg); - - DBG_871X("rtw_pci_disable_aspm():PciBridge busnumber[%x], DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n", - pcipriv->pcibridge_busnum, pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum, - (pcipriv->pcibridge_pciehdr_offset+0x10), pcibridge_linkctrlreg); - - rtw_udelay_os(50); - } - -} - -/*Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for -power saving We should follow the sequence to enable -RTL8192SE first then enable Pci Bridge ASPM -or the system will show bluescreen.*/ -void rtw_pci_enable_aspm(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv); - struct pci_dev *pdev = pdvobjpriv->ppcidev; - struct pci_dev *bridge_pdev = pdev->bus->self; - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u16 aspmlevel = 0; - u8 u_pcibridge_aspmsetting = 0; - u8 u_device_aspmsetting = 0; - u32 u_device_aspmsupportsetting = 0; - - // We do not diable/enable ASPM by driver, in the future, the BIOS will enable host and NIC ASPM. - // Advertised by SD1 victorh. Added by tynli. 2009.11.23. - if(pdvobjpriv->const_pci_aspm == 0) - return; - - //When there exists anyone's BusNum, DevNum, and FuncNum that are set to 0xff, - // we do not execute any action and return. Added by tynli. - if( (pcipriv->busnumber == 0xff && pcipriv->devnumber == 0xff && pcipriv->funcnumber == 0xff) || - (pcipriv->pcibridge_busnum == 0xff && pcipriv->pcibridge_devnum == 0xff && pcipriv->pcibridge_funcnum == 0xff) ) - { - DBG_871X("rtw_pci_enable_aspm(): Fail to enable ASPM. Cannot find the Bus of PCI(Bridge).\n"); - return; - } - -//Get Bridge ASPM Support -//not to enable bridge aspm if bridge does not support -//Added by sherry 20100803 - if (IS_HARDWARE_TYPE_8192DE(padapter)) - { - //PciCfgAddrPort = (pcipriv->pcibridge_busnum << 16)|(pcipriv->pcibridge_devnum<< 11)|(pcipriv->pcibridge_funcnum << 8)|(1 << 31); - //Num4Bytes = (pcipriv->pcibridge_pciehdr_offset+0x0C)/4; - //NdisRawWritePortUlong((ULONG_PTR)PCI_CONF_ADDRESS , PciCfgAddrPort+(Num4Bytes << 2)); - //NdisRawReadPortUlong((ULONG_PTR)PCI_CONF_DATA,&uDeviceASPMSupportSetting); - pci_read_config_dword(bridge_pdev, (pcipriv->pcibridge_pciehdr_offset+0x0C), &u_device_aspmsupportsetting); - DBG_871X("rtw_pci_enable_aspm(): Bridge ASPM support %x \n",u_device_aspmsupportsetting); - if(((u_device_aspmsupportsetting & BIT(11)) != BIT(11)) || ((u_device_aspmsupportsetting & BIT(10)) != BIT(10))) - { - if(pdvobjpriv->const_devicepci_aspm_setting == 3) - { - DBG_871X("rtw_pci_enable_aspm(): Bridge not support L0S or L1\n"); - return; - } - else if(pdvobjpriv->const_devicepci_aspm_setting == 2) - { - if((u_device_aspmsupportsetting & BIT(11)) != BIT(11)) - { - DBG_871X("rtw_pci_enable_aspm(): Bridge not support L1 \n"); - return; - } - } - else if(pdvobjpriv->const_devicepci_aspm_setting == 1) - { - if((u_device_aspmsupportsetting & BIT(10)) != BIT(10)) - { - DBG_871X("rtw_pci_enable_aspm(): Bridge not support L0s \n"); - return; - } - - } - } - else - { - DBG_871X("rtw_pci_enable_aspm(): Bridge support L0s and L1 \n"); - } - } - - - /*Enable Pci Bridge ASPM*/ - //PciCfgAddrPort = (pcipriv->pcibridge_busnum << 16)|(pcipriv->pcibridge_devnum<< 11) |(pcipriv->pcibridge_funcnum << 8)|(1 << 31); - //Num4Bytes = (pcipriv->pcibridge_pciehdr_offset+0x10)/4; - // set up address port at 0xCF8 offset field= 0 (dev|vend) - //NdisRawWritePortUlong(PCI_CONF_ADDRESS, PciCfgAddrPort + (Num4Bytes << 2)); - // now grab data port with device|vendor 4 byte dword - - u_pcibridge_aspmsetting = pcipriv->pcibridge_linkctrlreg; - u_pcibridge_aspmsetting |= pdvobjpriv->const_hostpci_aspm_setting; - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL || - pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_SIS ) - u_pcibridge_aspmsetting &= ~BIT(0); // for intel host 42 device 43 - - //NdisRawWritePortUchar(PCI_CONF_DATA, u_pcibridge_aspmsetting); - pci_write_config_byte(bridge_pdev, (pcipriv->pcibridge_pciehdr_offset+0x10), u_pcibridge_aspmsetting); - - DBG_871X("PlatformEnableASPM():PciBridge busnumber[%x], DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n", - pcipriv->pcibridge_busnum, pcipriv->pcibridge_devnum, pcipriv->pcibridge_funcnum, - (pcipriv->pcibridge_pciehdr_offset+0x10), - u_pcibridge_aspmsetting); - - rtw_udelay_os(50); - - /*Get ASPM level (with/without Clock Req)*/ - aspmlevel |= pdvobjpriv->const_devicepci_aspm_setting; - u_device_aspmsetting = pcipriv->linkctrl_reg; - u_device_aspmsetting |= aspmlevel; // device 43 - - rtw_pci_platform_switch_device_pci_aspm(padapter, u_device_aspmsetting); - - if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { - rtw_pci_switch_clk_req(padapter, (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0); - RT_SET_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ); - } - - rtw_udelay_os(50); -} - -static u8 rtw_pci_get_amd_l1_patch(struct dvobj_priv *pdvobjpriv) -{ - struct pci_dev *pdev = pdvobjpriv->ppcidev; - struct pci_dev *bridge_pdev = pdev->bus->self; - u8 status = _FALSE; - u8 offset_e0; - u32 offset_e4; - - //NdisRawWritePortUlong(PCI_CONF_ADDRESS,pcicfg_addrport + 0xE0); - //NdisRawWritePortUchar(PCI_CONF_DATA, 0xA0); - pci_write_config_byte(bridge_pdev, 0xE0, 0xA0); - - //NdisRawWritePortUlong(PCI_CONF_ADDRESS,pcicfg_addrport + 0xE0); - //NdisRawReadPortUchar(PCI_CONF_DATA, &offset_e0); - pci_read_config_byte(bridge_pdev, 0xE0, &offset_e0); - - if (offset_e0 == 0xA0) { - //NdisRawWritePortUlong(PCI_CONF_ADDRESS, pcicfg_addrport + 0xE4); - //NdisRawReadPortUlong(PCI_CONF_DATA, &offset_e4); - pci_read_config_dword(bridge_pdev, 0xE4, &offset_e4); - if (offset_e4 & BIT(23)) - status = _TRUE; - } - - return status; -} - -static void rtw_pci_get_linkcontrol_field(struct dvobj_priv *pdvobjpriv) -{ - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - struct pci_dev *pdev = pdvobjpriv->ppcidev; - struct pci_dev *bridge_pdev = pdev->bus->self; - u8 capabilityoffset = pcipriv->pcibridge_pciehdr_offset; - u8 linkctrl_reg; - - /*Read Link Control Register*/ - pci_read_config_byte(bridge_pdev, capabilityoffset + PCI_EXP_LNKCTL, &linkctrl_reg); - - pcipriv->pcibridge_linkctrlreg = linkctrl_reg; -} -#endif - -static void rtw_pci_parse_configuration(struct pci_dev *pdev, struct dvobj_priv *pdvobjpriv) -{ - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - u8 tmp; - int pos; - u8 linkctrl_reg; - - //Link Control Register - pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); - pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &linkctrl_reg); - pcipriv->linkctrl_reg = linkctrl_reg; - - //DBG_871X("Link Control Register = %x\n", pcipriv->linkctrl_reg); - - pci_read_config_byte(pdev, 0x98, &tmp); - tmp |= BIT(4); - pci_write_config_byte(pdev, 0x98, tmp); - - //tmp = 0x17; - //pci_write_config_byte(pdev, 0x70f, tmp); -} - -// -// Update PCI dependent default settings. -// -static void rtw_pci_update_default_setting(_adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv); - - //reset pPSC->reg_rfps_level & priv->b_support_aspm - pwrpriv->reg_rfps_level = 0; - pwrpriv->b_support_aspm = 0; - - // Dynamic Mechanism, - //rtw_hal_set_def_var(pAdapter, HAL_DEF_INIT_GAIN, &(pDevice->InitGainState)); - - // Update PCI ASPM setting - pwrpriv->const_amdpci_aspm = pdvobjpriv->const_amdpci_aspm; - switch (pdvobjpriv->const_pci_aspm) { - case 0: // No ASPM - break; - - case 1: // ASPM dynamically enabled/disable. - pwrpriv->reg_rfps_level |= RT_RF_LPS_LEVEL_ASPM; - break; - - case 2: // ASPM with Clock Req dynamically enabled/disable. - pwrpriv->reg_rfps_level |= (RT_RF_LPS_LEVEL_ASPM | RT_RF_OFF_LEVL_CLK_REQ); - break; - - case 3: // Always enable ASPM and Clock Req from initialization to halt. - pwrpriv->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM); - pwrpriv->reg_rfps_level |= (RT_RF_PS_LEVEL_ALWAYS_ASPM | RT_RF_OFF_LEVL_CLK_REQ); - break; - - case 4: // Always enable ASPM without Clock Req from initialization to halt. - pwrpriv->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM | RT_RF_OFF_LEVL_CLK_REQ); - pwrpriv->reg_rfps_level |= RT_RF_PS_LEVEL_ALWAYS_ASPM; - break; - } - - pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC; - - // Update Radio OFF setting - switch (pdvobjpriv->const_hwsw_rfoff_d3) { - case 1: - if (pwrpriv->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM) - pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM; - break; - - case 2: - if (pwrpriv->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM) - pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM; - pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC; - break; - - case 3: - pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_PCI_D3; - break; - } - - // Update Rx 2R setting - //pPSC->reg_rfps_level |= ((pDevice->RegLPS2RDisable) ? RT_RF_LPS_DISALBE_2R : 0); - - // - // Set HW definition to determine if it supports ASPM. - // - switch (pdvobjpriv->const_support_pciaspm) { - case 0: // Not support ASPM. - { - u8 b_support_aspm = _FALSE; - pwrpriv->b_support_aspm = b_support_aspm; - } - break; - - case 1: // Support ASPM. - { - u8 b_support_aspm = _TRUE; - u8 b_support_backdoor = _TRUE; - - pwrpriv->b_support_aspm = b_support_aspm; - - /*if(pAdapter->MgntInfo.CustomerID == RT_CID_TOSHIBA && - pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_AMD && - !pcipriv->amd_l1_patch) - b_support_backdoor = _FALSE;*/ - - pwrpriv->b_support_backdoor = b_support_backdoor; - } - break; - - case 2: // Set by Chipset. - // ASPM value set by chipset. - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) { - u8 b_support_aspm = _TRUE; - pwrpriv->b_support_aspm = b_support_aspm; - } - break; - - default: - // Do nothing. Set when finding the chipset. - break; - } -} - -static void rtw_pci_initialize_adapter_common(_adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - rtw_pci_update_default_setting(padapter); - - if (pwrpriv->reg_rfps_level & RT_RF_PS_LEVEL_ALWAYS_ASPM) { - // Always enable ASPM & Clock Req. - rtw_pci_enable_aspm(padapter); - RT_SET_PS_LEVEL(pwrpriv, RT_RF_PS_LEVEL_ALWAYS_ASPM); - } - -} - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) || (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)) -#define rtw_pci_interrupt(x,y,z) rtw_pci_interrupt(x,y) -#endif - -static irqreturn_t rtw_pci_interrupt(int irq, void *priv, struct pt_regs *regs) -{ - struct dvobj_priv *dvobj = (struct dvobj_priv *)priv; - _adapter *adapter = dvobj->if1; - - if (dvobj->irq_enabled == 0) { - return IRQ_HANDLED; - } - - if(rtw_hal_interrupt_handler(adapter) == _FAIL) - return IRQ_HANDLED; - //return IRQ_NONE; - - return IRQ_HANDLED; -} - -#ifdef RTK_DMP_PLATFORM -#define pci_iounmap(x,y) iounmap(y) -#endif - -int pci_alloc_irq(struct dvobj_priv *dvobj) -{ - int err; - struct pci_dev *pdev = dvobj->ppcidev; - -#if defined(IRQF_SHARED) - err = request_irq(pdev->irq, &rtw_pci_interrupt, IRQF_SHARED, DRV_NAME, dvobj); -#else - err = request_irq(pdev->irq, &rtw_pci_interrupt, SA_SHIRQ, DRV_NAME, dvobj); -#endif - if (err) { - DBG_871X("Error allocating IRQ %d",pdev->irq); - } else { - dvobj->irq_alloc = 1; - DBG_871X("Request_irq OK, IRQ %d\n",pdev->irq); - } - - return err?_FAIL:_SUCCESS; -} - -static struct dvobj_priv *pci_dvobj_init(struct pci_dev *pdev) -{ - int err; - u32 status = _FAIL; - struct dvobj_priv *dvobj = NULL; - struct pci_priv *pcipriv = NULL; - struct pci_dev *bridge_pdev = pdev->bus->self; - unsigned long pmem_start, pmem_len, pmem_flags; - u8 tmp; - -_func_enter_; - - if ((dvobj = (struct dvobj_priv*)rtw_zmalloc(sizeof(*dvobj))) == NULL) { - goto exit; - } - dvobj->ppcidev = pdev; - pcipriv = &(dvobj->pcipriv); - pci_set_drvdata(pdev, dvobj); - - _rtw_mutex_init(&dvobj->hw_init_mutex); - _rtw_mutex_init(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_init(&dvobj->setch_mutex); - _rtw_mutex_init(&dvobj->setbw_mutex); - - dvobj->processing_dev_remove = _FALSE; - if ( (err = pci_enable_device(pdev)) != 0) { - DBG_871X(KERN_ERR "%s : Cannot enable new PCI device\n", pci_name(pdev)); - goto free_dvobj; - } - -#ifdef CONFIG_64BIT_DMA - if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { - DBG_871X("RTL819xCE: Using 64bit DMA\n"); - if ((err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) != 0) { - DBG_871X(KERN_ERR "Unable to obtain 64bit DMA for consistent allocations\n"); - goto disable_picdev; - } - dvobj->bdma64 = _TRUE; - } else -#endif - { - if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { - if ((err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) != 0) { - DBG_871X(KERN_ERR "Unable to obtain 32bit DMA for consistent allocations\n"); - goto disable_picdev; - } - } - } - - pci_set_master(pdev); - - if ((err = pci_request_regions(pdev, DRV_NAME)) != 0) { - DBG_871X(KERN_ERR "Can't obtain PCI resources\n"); - goto disable_picdev; - } - //MEM map - pmem_start = pci_resource_start(pdev, 2); - pmem_len = pci_resource_len(pdev, 2); - pmem_flags = pci_resource_flags(pdev, 2); - -#ifdef RTK_DMP_PLATFORM - dvobj->pci_mem_start = (unsigned long)ioremap_nocache(pmem_start, pmem_len); -#else - dvobj->pci_mem_start = (unsigned long)pci_iomap(pdev, 2, pmem_len); /* shared mem start */ -#endif - if (dvobj->pci_mem_start == 0) { - DBG_871X(KERN_ERR "Can't map PCI mem\n"); - goto release_regions; - } - - DBG_871X("Memory mapped space start: 0x%08lx len:%08lx flags:%08lx, after map:0x%08lx\n", - pmem_start, pmem_len, pmem_flags, dvobj->pci_mem_start); - - // Disable Clk Request */ - pci_write_config_byte(pdev, 0x81, 0); - // leave D3 mode */ - pci_write_config_byte(pdev, 0x44, 0); - pci_write_config_byte(pdev, 0x04, 0x06); - pci_write_config_byte(pdev, 0x04, 0x07); - -#if 1 - /*find bus info*/ - pcipriv->busnumber = pdev->bus->number; - pcipriv->devnumber = PCI_SLOT(pdev->devfn); - pcipriv->funcnumber = PCI_FUNC(pdev->devfn); - - /*find bridge info*/ - pcipriv->pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN; - if(bridge_pdev){ - pcipriv->pcibridge_vendorid = bridge_pdev->vendor; - for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) { - if (bridge_pdev->vendor == pcibridge_vendors[tmp]) { - pcipriv->pcibridge_vendor = tmp; - DBG_871X("Pci Bridge Vendor is found index: %d, %x\n", tmp, pcibridge_vendors[tmp]); - break; - } - } - } - - //if (pcipriv->pcibridge_vendor != PCI_BRIDGE_VENDOR_UNKNOWN) { - if(bridge_pdev){ - pcipriv->pcibridge_busnum = bridge_pdev->bus->number; - pcipriv->pcibridge_devnum = PCI_SLOT(bridge_pdev->devfn); - pcipriv->pcibridge_funcnum = PCI_FUNC(bridge_pdev->devfn); - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)) - pcipriv->pcibridge_pciehdr_offset = pci_find_capability(bridge_pdev, PCI_CAP_ID_EXP); -#else - pcipriv->pcibridge_pciehdr_offset = bridge_pdev->pcie_cap; -#endif - - rtw_pci_get_linkcontrol_field(dvobj); - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_AMD) { - pcipriv->amd_l1_patch = rtw_pci_get_amd_l1_patch(dvobj); - } - } -#else - // - // Find bridge related info. - // - rtw_get_pci_bus_info(padapter, - pdev->vendor, - pdev->device, - (u8) pdvobjpriv->irqline, - 0x02, 0x80, U1DONTCARE, - &pcipriv->busnumber, - &pcipriv->devnumber, - &pcipriv->funcnumber); - - rtw_find_bridge_info(padapter); - - if (pcipriv->pcibridge_vendor != PCI_BRIDGE_VENDOR_UNKNOWN) { - rtw_get_link_control_field(padapter, - pcipriv->pcibridge_busnum, - pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum); - - if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_AMD) { - pcipriv->amd_l1_patch = - rtw_get_amd_l1_patch(padapter, - pcipriv->pcibridge_busnum, - pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum); - } - } -#endif - - // - // Allow the hardware to look at PCI config information. - // - rtw_pci_parse_configuration(pdev, dvobj); - - DBG_871X("pcidev busnumber:devnumber:funcnumber:" - "vendor:link_ctl %d:%d:%d:%x:%x\n", - pcipriv->busnumber, - pcipriv->devnumber, - pcipriv->funcnumber, - pdev->vendor, - pcipriv->linkctrl_reg); - - DBG_871X("pci_bridge busnumber:devnumber:funcnumber:vendor:" - "pcie_cap:link_ctl_reg: %d:%d:%d:%x:%x:%x:%x\n", - pcipriv->pcibridge_busnum, - pcipriv->pcibridge_devnum, - pcipriv->pcibridge_funcnum, - pcibridge_vendors[pcipriv->pcibridge_vendor], - pcipriv->pcibridge_pciehdr_offset, - pcipriv->pcibridge_linkctrlreg, - pcipriv->amd_l1_patch); - - status = _SUCCESS; - -iounmap: - if (status != _SUCCESS && dvobj->pci_mem_start != 0) { - pci_iounmap(pdev, (void *)dvobj->pci_mem_start); - dvobj->pci_mem_start = 0; - } -release_regions: - if (status != _SUCCESS) - pci_release_regions(pdev); -disable_picdev: - if (status != _SUCCESS) - pci_disable_device(pdev); -free_dvobj: - if (status != _SUCCESS && dvobj) { - pci_set_drvdata(pdev, NULL); - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - dvobj = NULL; - } -exit: -_func_exit_; - return dvobj; -} - - -static void pci_dvobj_deinit(struct pci_dev *pdev) -{ - struct dvobj_priv *dvobj = pci_get_drvdata(pdev); -_func_enter_; - - pci_set_drvdata(pdev, NULL); - if (dvobj) { - if (dvobj->irq_alloc) { - free_irq(pdev->irq, dvobj); - dvobj->irq_alloc = 0; - } - - if (dvobj->pci_mem_start != 0) { - pci_iounmap(pdev, (void *)dvobj->pci_mem_start); - dvobj->pci_mem_start = 0; - } - - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - } - - pci_release_regions(pdev); - pci_disable_device(pdev); - -_func_exit_; -} - - -static void decide_chip_type_by_pci_device_id(_adapter *padapter, struct pci_dev *pdev) -{ - u16 venderid, deviceid, irqline; - u8 revisionid; - struct dvobj_priv *pdvobjpriv=adapter_to_dvobj(padapter); - - - venderid = pdev->vendor; - deviceid = pdev->device; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)) - pci_read_config_byte(pdev, PCI_REVISION_ID, &revisionid); // PCI_REVISION_ID 0x08 -#else - revisionid = pdev->revision; -#endif - pci_read_config_word(pdev, PCI_INTERRUPT_LINE, &irqline); // PCI_INTERRUPT_LINE 0x3c - pdvobjpriv->irqline = irqline; - - - // - // Decide hardware type here. - // - if( deviceid == HAL_HW_PCI_8185_DEVICE_ID || - deviceid == HAL_HW_PCI_8188_DEVICE_ID || - deviceid == HAL_HW_PCI_8198_DEVICE_ID) - { - DBG_871X("Adapter (8185/8185B) is found- VendorID/DeviceID=%x/%x\n", venderid, deviceid); - padapter->HardwareType=HARDWARE_TYPE_RTL8185; - } - else if (deviceid == HAL_HW_PCI_8190_DEVICE_ID || - deviceid == HAL_HW_PCI_0045_DEVICE_ID || - deviceid == HAL_HW_PCI_0046_DEVICE_ID || - deviceid == HAL_HW_PCI_DLINK_DEVICE_ID) - { - DBG_871X("Adapter(8190 PCI) is found - vendorid/deviceid=%x/%x\n", venderid, deviceid); - padapter->HardwareType = HARDWARE_TYPE_RTL8190P; - } - else if (deviceid == HAL_HW_PCI_8192_DEVICE_ID || - deviceid == HAL_HW_PCI_0044_DEVICE_ID || - deviceid == HAL_HW_PCI_0047_DEVICE_ID || - deviceid == HAL_HW_PCI_8192SE_DEVICE_ID || - deviceid == HAL_HW_PCI_8174_DEVICE_ID || - deviceid == HAL_HW_PCI_8173_DEVICE_ID || - deviceid == HAL_HW_PCI_8172_DEVICE_ID || - deviceid == HAL_HW_PCI_8171_DEVICE_ID) - { - // 8192e and and 8192se may have the same device ID 8192. However, their Revision - // ID is different - // Added for 92DE. We deferentiate it from SVID,SDID. - if( pdev->subsystem_vendor == 0x10EC && pdev->subsystem_device == 0xE020){ - padapter->HardwareType = HARDWARE_TYPE_RTL8192DE; - DBG_871X("Adapter(8192DE) is found - VendorID/DeviceID/RID=%X/%X/%X\n", venderid, deviceid, revisionid); - }else{ - switch (revisionid) { - case HAL_HW_PCI_REVISION_ID_8192PCIE: - DBG_871X("Adapter(8192 PCI-E) is found - vendorid/deviceid=%x/%x\n", venderid, deviceid); - padapter->HardwareType = HARDWARE_TYPE_RTL8192E; - break; - case HAL_HW_PCI_REVISION_ID_8192SE: - DBG_871X("Adapter(8192SE) is found - vendorid/deviceid=%x/%x\n", venderid, deviceid); - padapter->HardwareType = HARDWARE_TYPE_RTL8192SE; - break; - default: - DBG_871X("Err: Unknown device - vendorid/deviceid=%x/%x\n", venderid, deviceid); - padapter->HardwareType = HARDWARE_TYPE_RTL8192SE; - break; - } - } - } - else if(deviceid==HAL_HW_PCI_8723E_DEVICE_ID ) - {//RTL8723E may have the same device ID with RTL8192CET - padapter->HardwareType = HARDWARE_TYPE_RTL8723AE; - DBG_871X("Adapter(8723 PCI-E) is found - VendorID/DeviceID=%x/%x\n", venderid, deviceid); - } - else if (deviceid == HAL_HW_PCI_8192CET_DEVICE_ID || - deviceid == HAL_HW_PCI_8192CE_DEVICE_ID || - deviceid == HAL_HW_PCI_8191CE_DEVICE_ID || - deviceid == HAL_HW_PCI_8188CE_DEVICE_ID) - { - DBG_871X("Adapter(8192C PCI-E) is found - vendorid/deviceid=%x/%x\n", venderid, deviceid); - padapter->HardwareType = HARDWARE_TYPE_RTL8192CE; - } - else if (deviceid == HAL_HW_PCI_8192DE_DEVICE_ID || - deviceid == HAL_HW_PCI_002B_DEVICE_ID ){ - padapter->HardwareType = HARDWARE_TYPE_RTL8192DE; - DBG_871X("Adapter(8192DE) is found - VendorID/DeviceID/RID=%X/%X/%X\n", venderid, deviceid, revisionid); - } - else if (deviceid == HAL_HW_PCI_8188EE_DEVICE_ID){ - padapter->HardwareType = HARDWARE_TYPE_RTL8188EE; - padapter->chip_type = RTL8188E; - DBG_871X("Adapter(8188EE) is found - VendorID/DeviceID/RID=%X/%X/%X\n", venderid, deviceid, revisionid); - } - - else - { - DBG_871X("Err: Unknown device - vendorid/deviceid=%x/%x\n", venderid, deviceid); - //padapter->HardwareType = HAL_DEFAULT_HARDWARE_TYPE; - } - - - padapter->chip_type = NULL_CHIP_TYPE; - - //TODO: -#ifdef CONFIG_RTL8192C - padapter->chip_type = RTL8188C_8192C; - padapter->HardwareType = HARDWARE_TYPE_RTL8192CE; -#endif -#ifdef CONFIG_RTL8192D - pdvobjpriv->InterfaceNumber = revisionid; - - padapter->chip_type = RTL8192D; - padapter->HardwareType = HARDWARE_TYPE_RTL8192DE; -#endif - -} - -static void pci_intf_start(_adapter *padapter) -{ - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+pci_intf_start\n")); - DBG_871X("+pci_intf_start\n"); - - //Enable hw interrupt - rtw_hal_enable_interrupt(padapter); - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-pci_intf_start\n")); - DBG_871X("-pci_intf_start\n"); -} - -static void pci_intf_stop(_adapter *padapter) -{ - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+pci_intf_stop\n")); - - //Disable hw interrupt - if(padapter->bSurpriseRemoved == _FALSE) - { - //device still exists, so driver can do i/o operation - rtw_hal_disable_interrupt(padapter); - tasklet_disable(&(padapter->recvpriv.recv_tasklet)); - tasklet_disable(&(padapter->recvpriv.irq_prepare_beacon_tasklet)); - tasklet_disable(&(padapter->xmitpriv.xmit_tasklet)); - -#ifdef CONFIG_CONCURRENT_MODE - /* This function only be called at driver removing. disable buddy_adapter too - don't disable interrupt of buddy_adapter because it is same as primary. - */ - if (padapter->pbuddy_adapter){ - tasklet_disable(&(padapter->pbuddy_adapter->recvpriv.recv_tasklet)); - tasklet_disable(&(padapter->pbuddy_adapter->recvpriv.irq_prepare_beacon_tasklet)); - tasklet_disable(&(padapter->pbuddy_adapter->xmitpriv.xmit_tasklet)); - } -#endif - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("pci_intf_stop: SurpriseRemoved==_FALSE\n")); - } - else - { - // Clear irq_enabled to prevent handle interrupt function. - adapter_to_dvobj(padapter)->irq_enabled = 0; - } - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-pci_intf_stop\n")); - -} - - -void rtw_dev_unload(_adapter *padapter) -{ - struct net_device *pnetdev= (struct net_device*)padapter->pnetdev; - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_dev_unload\n")); - - if(padapter->bup == _TRUE) - { - DBG_871X("+rtw_dev_unload\n"); - - padapter->bDriverStopped = _TRUE; - #ifdef CONFIG_XMIT_ACK - if (padapter->xmitpriv.ack_tx) - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP); - #endif - - //s3. - if(padapter->intf_stop) - { - padapter->intf_stop(padapter); - } - - //s4. - rtw_stop_drv_threads(padapter); - - - //s5. - if(padapter->bSurpriseRemoved == _FALSE) - { - DBG_871X("r871x_dev_unload()->rtl871x_hal_deinit()\n"); - rtw_hal_deinit(padapter); - - padapter->bSurpriseRemoved = _TRUE; - } - - padapter->bup = _FALSE; - - } - else - { - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("r871x_dev_unload():padapter->bup == _FALSE\n" )); - } - - DBG_871X("-rtw_dev_unload\n"); - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-rtw_dev_unload\n")); - -} - -static void disable_ht_for_spec_devid(const struct pci_device_id *pdid) -{ -#ifdef CONFIG_80211N_HT - u16 vid, pid; - u32 flags; - int i; - int num = sizeof(specific_device_id_tbl)/sizeof(struct specific_device_id); - - for(i=0; ivendor==vid) && (pdid->device==pid) && (flags&SPEC_DEV_ID_DISABLE_HT)) - { - rtw_ht_enable = 0; - rtw_cbw40_enable = 0; - rtw_ampdu_enable = 0; - } - - } -#endif -} - -#ifdef CONFIG_PM -static int rtw_suspend(struct pci_dev *pdev, pm_message_t state) -{ - _func_enter_; - - - _func_exit_; - return 0; -} - -static int rtw_resume(struct pci_dev *pdev) -{ - _func_enter_; - - - _func_exit_; - - return 0; -} -#endif - -_adapter *rtw_pci_if1_init(struct dvobj_priv * dvobj, struct pci_dev *pdev, const struct pci_device_id *pdid) -{ - _adapter *padapter = NULL; - struct net_device *pnetdev = NULL; - int status = _FAIL; - - if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) { - goto exit; - } - padapter->dvobj = dvobj; - dvobj->if1 = padapter; - - padapter->bDriverStopped=_TRUE; - - dvobj->padapters[dvobj->iface_nums++] = padapter; - padapter->iface_id = IFACE_ID0; - -#if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT) - //set adapter_type/iface type for primary padapter - padapter->isprimary = _TRUE; - padapter->adapter_type = PRIMARY_ADAPTER; - #ifndef CONFIG_HWPORT_SWAP - padapter->iface_type = IFACE_PORT0; - #else - padapter->iface_type = IFACE_PORT1; - #endif -#endif - - #ifndef RTW_DVOBJ_CHIP_HW_TYPE - //step 1-1., decide the chip_type via vid/pid - padapter->interface_type = RTW_PCIE; - decide_chip_type_by_pci_device_id(padapter, pdev); - #endif - - if((pnetdev = rtw_init_netdev(padapter)) == NULL) { - goto free_adapter; - } - - #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) - SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj)); - #endif - if (dvobj->bdma64) - pnetdev->features |= NETIF_F_HIGHDMA; - pnetdev->irq = pdev->irq; - - padapter = rtw_netdev_priv(pnetdev); - -#ifdef CONFIG_IOCTL_CFG80211 - if(rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)) != 0) { - goto free_adapter; - } -#endif //CONFIG_IOCTL_CFG80211 - - - //step 2. hook HalFunc, allocate HalData - hal_set_hal_ops(padapter); - - - //step 3. - padapter->intf_start=&pci_intf_start; - padapter->intf_stop=&pci_intf_stop; - - - //.2 - rtw_init_io_priv(padapter, pci_set_intf_ops); - - //.3 - rtw_hal_read_chip_version(padapter); - - //.4 - rtw_hal_chip_configure(padapter); - - - //step 4. read efuse/eeprom data and get mac_addr - rtw_hal_read_chip_info(padapter); - - //step 5. - if(rtw_init_drv_sw(padapter) ==_FAIL) { - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize driver software resource Failed!\n")); - goto free_hal_data; - } - - if(rtw_hal_inirp_init(padapter) ==_FAIL) { - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize PCI desc ring Failed!\n")); - goto free_hal_data; - } - rtw_macaddr_cfg(padapter->eeprompriv.mac_addr); - rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr); - - rtw_hal_disable_interrupt(padapter); - - //step 6. Init pci related configuration - rtw_pci_initialize_adapter_common(padapter); - - DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n" - ,padapter->bDriverStopped - ,padapter->bSurpriseRemoved - ,padapter->bup - ,padapter->hw_init_completed - ); - - status = _SUCCESS; - -free_hal_data: - if(status != _SUCCESS && padapter->HalData) - rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData))); - -free_wdev: - if(status != _SUCCESS) { - #ifdef CONFIG_IOCTL_CFG80211 - rtw_wdev_unregister(padapter->rtw_wdev); - rtw_wdev_free(padapter->rtw_wdev); - #endif - } - -free_adapter: - if (status != _SUCCESS) { - if (pnetdev) - rtw_free_netdev(pnetdev); - else if (padapter) - rtw_vmfree((u8*)padapter, sizeof(*padapter)); - padapter = NULL; - } -exit: - return padapter; -} - -static void rtw_pci_if1_deinit(_adapter *if1) -{ - struct net_device *pnetdev = if1->pnetdev; - struct mlme_priv *pmlmepriv= &if1->mlmepriv; - - // padapter->intf_stop(padapter); - - if(check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_disassoc_cmd(if1, 0, _FALSE); - -#ifdef CONFIG_AP_MODE - free_mlme_ap_info(if1); - #ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_unload(if1); - #endif -#endif - - if (if1->DriverState != DRIVER_DISAPPEAR) { - if(pnetdev) { - unregister_netdev(pnetdev); //will call netdev_close() - rtw_proc_remove_one(pnetdev); - } - } - - rtw_cancel_all_timer(if1); -#ifdef CONFIG_WOWLAN - adapter_to_pwrctl(if1)->wowlan_mode=_FALSE; -#endif //CONFIG_WOWLAN - rtw_dev_unload(if1); - - DBG_871X("%s, hw_init_completed=%d\n", __func__, if1->hw_init_completed); - - //s6. - rtw_handle_dualmac(if1, 0); - -#ifdef CONFIG_IOCTL_CFG80211 - if(if1->rtw_wdev) - { - rtw_wdev_unregister(if1->rtw_wdev); - rtw_wdev_free(if1->rtw_wdev); - } -#endif //CONFIG_IOCTL_CFG80211 - - rtw_hal_inirp_deinit(if1); - rtw_free_drv_sw(if1); - - if(pnetdev) - rtw_free_netdev(pnetdev); - -#ifdef CONFIG_PLATFORM_RTD2880B - DBG_871X("wlan link down\n"); - rtd2885_wlan_netlink_sendMsg("linkdown", "8712"); -#endif -} - -/* - * drv_init() - a device potentially for us - * - * notes: drv_init() is called when the bus driver has located a card for us to support. - * We accept the new device by returning 0. -*/ -static int rtw_drv_init(struct pci_dev *pdev, const struct pci_device_id *pdid) -{ - int i, err = -ENODEV; - - int status; - _adapter *if1 = NULL, *if2 = NULL; - struct dvobj_priv *dvobj; - - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n")); - //DBG_871X("+rtw_drv_init\n"); - - //step 0. - disable_ht_for_spec_devid(pdid); - - /* Initialize dvobj_priv */ - if ((dvobj = pci_dvobj_init(pdev)) == NULL) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n")); - goto exit; - } - - /* Initialize if1 */ - if ((if1 = rtw_pci_if1_init(dvobj, pdev, pdid)) == NULL) { - DBG_871X("rtw_pci_if1_init Failed!\n"); - goto free_dvobj; - } - - /* Initialize if2 */ -#ifdef CONFIG_CONCURRENT_MODE - if((if2 = rtw_drv_if2_init(if1, pci_set_intf_ops)) == NULL) { - goto free_if1; - } -#endif - - //dev_alloc_name && register_netdev - if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) { - goto free_if2; - } - -#ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_init(if1); -#endif - -#ifdef CONFIG_PLATFORM_RTD2880B - DBG_871X("wlan link up\n"); - rtd2885_wlan_netlink_sendMsg("linkup", "8712"); -#endif - -#ifdef RTK_DMP_PLATFORM - rtw_proc_init_one(if1->pnetdev); -#endif - - /* alloc irq */ - if (pci_alloc_irq(dvobj) != _SUCCESS) - goto free_if2; - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n")); - //DBG_871X("-871x_drv - drv_init, success!\n"); - - status = _SUCCESS; - -free_if2: - if(status != _SUCCESS && if2) { - #ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(if2); - rtw_drv_if2_free(if2); - #endif - } -free_if1: - if (status != _SUCCESS && if1) { - rtw_pci_if1_deinit(if1); - } -free_dvobj: - if (status != _SUCCESS) - pci_dvobj_deinit(pdev); -exit: - return status == _SUCCESS?0:-ENODEV; -} - -extern void rtw_unregister_netdevs(struct dvobj_priv *dvobj); -/* - * dev_remove() - our device is being removed -*/ -//rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both -static void rtw_dev_remove(struct pci_dev *pdev) -{ - struct dvobj_priv *pdvobjpriv = pci_get_drvdata(pdev); - _adapter *padapter = pdvobjpriv->if1; - struct net_device *pnetdev = padapter->pnetdev; - -_func_exit_; - - DBG_871X("+rtw_dev_remove\n"); - - pdvobjpriv->processing_dev_remove = _TRUE; - rtw_unregister_netdevs(pdvobjpriv); - - if (unlikely(!padapter)) { - return; - } - - #if 0 -#ifdef RTK_DMP_PLATFORM - padapter->bSurpriseRemoved = _FALSE; // always trate as device exists - // this will let the driver to disable it's interrupt -#else - if(pci_drvpriv.drv_registered == _TRUE) - { - //DBG_871X("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n"); - padapter->bSurpriseRemoved = _TRUE; - } - /*else - { - //DBG_871X("r871xu_dev_remove():module removed\n"); - padapter->hw_init_completed = _FALSE; - }*/ -#endif - #endif - -#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER) - rtw_unregister_early_suspend(dvobj_to_pwrctl(pdvobjpriv)); -#endif - - rtw_pm_set_ips(padapter, IPS_NONE); - rtw_pm_set_lps(padapter, PS_MODE_ACTIVE); - - LeaveAllPowerSaveMode(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(pdvobjpriv->if2); -#endif - - rtw_pci_if1_deinit(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_free(pdvobjpriv->if2); -#endif - - pci_dvobj_deinit(pdev); - - DBG_871X("-r871xu_dev_remove, done\n"); - -_func_exit_; - return; -} - - -static int __init rtw_drv_entry(void) -{ - int ret = 0; - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_drv_entry\n")); - DBG_871X("rtw driver version=%s\n", DRIVERVERSION); - DBG_871X("Build at: %s %s\n", __DATE__, __TIME__); - pci_drvpriv.drv_registered = _TRUE; - - rtw_suspend_lock_init(); - - ret = pci_register_driver(&pci_drvpriv.rtw_pci_drv); - if (ret) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, (": No device found\n")); - } - - return ret; -} - -static void __exit rtw_drv_halt(void) -{ - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_drv_halt\n")); - DBG_871X("+rtw_drv_halt\n"); - - pci_drvpriv.drv_registered = _FALSE; - - pci_unregister_driver(&pci_drvpriv.rtw_pci_drv); - - rtw_suspend_lock_uninit(); - - DBG_871X("-rtw_drv_halt\n"); - - rtw_mstat_dump(); -} - - -module_init(rtw_drv_entry); -module_exit(rtw_drv_halt); - diff --git a/os_dep/linux/pci_ops_linux.c b/os_dep/linux/pci_ops_linux.c deleted file mode 100755 index 12c6c68..0000000 --- a/os_dep/linux/pci_ops_linux.c +++ /dev/null @@ -1,24 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - *******************************************************************************/ -#define _PCI_OPS_LINUX_C_ - -#include - - - diff --git a/os_dep/linux/sdio_intf.c b/os_dep/linux/sdio_intf.c deleted file mode 100755 index 0e1b1ab..0000000 --- a/os_dep/linux/sdio_intf.c +++ /dev/null @@ -1,1967 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _HCI_INTF_C_ - -#include -#include -#include -#include -#include -#include - -#ifndef CONFIG_SDIO_HCI -#error "CONFIG_SDIO_HCI shall be on!\n" -#endif - -#include -#include - -#if defined(CONFIG_WOWLAN) || defined(CONFIG_PLATFORM_SPRD) -#include -#include -#endif - -#ifdef CONFIG_PLATFORM_SPRD -#include -#endif // CONFIG_PLATFORM_SPRD - -#include -#include -#include - -#include - -#ifdef CONFIG_PLATFORM_SPRD -#ifdef CONFIG_PM_RUNTIME -#include -#endif -#endif - -#ifdef CONFIG_PLATFORM_ARM_SUNxI -#if defined(CONFIG_MMC_SUNXI_POWER_CONTROL) - -#ifdef CONFIG_WITS_EVB_V13 -#define SDIOID 0 -#else -#define SDIOID (CONFIG_CHIP_ID==1123 ? 3 : 1) -#endif - -#define SUNXI_SDIO_WIFI_NUM_RTL8189ES 10 -extern void sunximmc_rescan_card(unsigned id, unsigned insert); -extern int mmc_pm_get_mod_type(void); -extern int mmc_pm_gpio_ctrl(char* name, int level); -/* -* rtl8189es_shdn = port:PH09<1><0> -* rtl8189es_wakeup = port:PH10<1><1> -* rtl8189es_vdd_en = port:PH11<1><0> -* rtl8189es_vcc_en = port:PH12<1><0> -*/ - -int rtl8189es_sdio_powerup(void) -{ - mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 1); - udelay(100); - mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 1); - udelay(50); - mmc_pm_gpio_ctrl("rtl8189es_shdn", 1); - return 0; -} -int rtl8189es_sdio_poweroff(void) -{ - mmc_pm_gpio_ctrl("rtl8189es_shdn", 0); - mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 0); - mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 0); - return 0; -} -#endif //defined(CONFIG_MMC_SUNXI_POWER_CONTROL) -#endif //CONFIG_PLATFORM_ARM_SUNxI - -#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) -#ifdef CONFIG_MMC -#include -static unsigned sdc_id = 0; -extern void sw_mci_rescan_card(unsigned id, unsigned insert); -extern int wifi_pm_get_mod_type(void); -extern void wifi_pm_power(int on); -#endif //CONFIG_MMC -#endif //#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) - -#ifndef dev_to_sdio_func -#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev) -#endif - -#ifdef CONFIG_WOWLAN -static struct mmc_host *mmc_host = NULL; -#endif - -static const struct sdio_device_id sdio_ids[] = { -#ifdef CONFIG_RTL8723A - { SDIO_DEVICE(0x024c, 0x8723) }, -#endif //CONFIG_RTL8723A - -#ifdef CONFIG_RTL8188E - { SDIO_DEVICE(0x024c, 0x8179) }, -#endif //CONFIG_RTL8188E - -#if defined(RTW_ENABLE_WIFI_CONTROL_FUNC) /* temporarily add this to accept all sdio wlan id */ - { SDIO_DEVICE_CLASS(SDIO_CLASS_WLAN) }, -#endif -// { /* end: all zeroes */ }, -}; - -static int rtw_drv_init(struct sdio_func *func, const struct sdio_device_id *id); -static void rtw_dev_remove(struct sdio_func *func); -static int rtw_sdio_resume(struct device *dev); -static int rtw_sdio_suspend(struct device *dev); -#ifdef CONFIG_PM_RUNTIME -static void rtw_start_runtime(struct sdio_func *func); -#endif - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) -static const struct dev_pm_ops rtw_sdio_pm_ops = { - .suspend = rtw_sdio_suspend, - .resume = rtw_sdio_resume, -}; -#endif - -struct sdio_drv_priv { - struct sdio_driver r871xs_drv; - int drv_registered; -}; - -static struct sdio_drv_priv sdio_drvpriv = { - .r871xs_drv.probe = rtw_drv_init, - .r871xs_drv.remove = rtw_dev_remove, - .r871xs_drv.name = (char*)DRV_NAME, - .r871xs_drv.id_table = sdio_ids, - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) - .r871xs_drv.drv = { - .pm = &rtw_sdio_pm_ops, - } - #endif -}; - -static void sd_sync_int_hdl(struct sdio_func *func) -{ - struct dvobj_priv *psdpriv; - - - psdpriv = sdio_get_drvdata(func); - - if (!psdpriv->if1) { - DBG_871X("%s if1 == NULL\n", __func__); - return; - } - - rtw_sdio_set_irq_thd(psdpriv, current); - sd_int_hdl(psdpriv->if1); - rtw_sdio_set_irq_thd(psdpriv, NULL); -} - -int sdio_alloc_irq(struct dvobj_priv *dvobj) -{ - PSDIO_DATA psdio_data; - struct sdio_func *func; - int err; - - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - sdio_claim_host(func); - - err = sdio_claim_irq(func, &sd_sync_int_hdl); - if (err) - printk(KERN_CRIT "%s: sdio_claim_irq FAIL(%d)!\n", __func__, err); - else - dvobj->irq_alloc = 1; - - sdio_release_host(func); - - return err?_FAIL:_SUCCESS; -} - -void sdio_free_irq(struct dvobj_priv *dvobj) -{ - PSDIO_DATA psdio_data; - struct sdio_func *func; - int err; - - if (dvobj->irq_alloc) { - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - if (func) { - sdio_claim_host(func); - err = sdio_release_irq(func); - if (err) - DBG_871X_LEVEL(_drv_err_,"%s: sdio_release_irq FAIL(%d)!\n", __func__, err); - sdio_release_host(func); - } - dvobj->irq_alloc = 0; - } -} - -#ifdef CONFIG_GPIO_WAKEUP -extern unsigned int oob_irq; -static irqreturn_t gpio_hostwakeup_irq_thread(int irq, void *data) -{ - PADAPTER padapter = (PADAPTER)data; - DBG_871X_LEVEL(_drv_always_, "gpio_hostwakeup_irq_thread\n"); - /* Disable interrupt before calling handler */ - //disable_irq_nosync(oob_irq); - rtw_lock_suspend_timeout(HZ/2); - return IRQ_HANDLED; -} - -static u8 gpio_hostwakeup_alloc_irq(PADAPTER padapter) -{ - int err; - if (oob_irq == 0) - return _FAIL; - /* dont set it IRQF_TRIGGER_LOW, or wowlan */ - /* power is high after suspend */ - /* and failing can prevent can not sleep issue if */ - /* wifi gpio12 pin is not linked with CPU */ - err = request_threaded_irq(oob_irq, gpio_hostwakeup_irq_thread, NULL, - //IRQF_TRIGGER_LOW | IRQF_ONESHOT, - IRQF_TRIGGER_FALLING, - "rtw_wifi_gpio_wakeup", padapter); - if (err < 0) { - DBG_871X("Oops: can't allocate gpio irq %d err:%d\n", oob_irq, err); - return _FALSE; - } else { - DBG_871X("allocate gpio irq %d ok\n", oob_irq); -} - - enable_irq_wake(oob_irq); - return _SUCCESS; -} - -static void gpio_hostwakeup_free_irq(PADAPTER padapter) -{ - if (oob_irq == 0) - return; - disable_irq_wake(oob_irq); - free_irq(oob_irq, padapter); -} -#endif - -static u32 sdio_init(struct dvobj_priv *dvobj) -{ - PSDIO_DATA psdio_data; - struct sdio_func *func; - int err; - -_func_enter_; - - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - //3 1. init SDIO bus - sdio_claim_host(func); - - err = sdio_enable_func(func); - if (err) { - DBG_8192C(KERN_CRIT "%s: sdio_enable_func FAIL(%d)!\n", __func__, err); - goto release; - } - - err = sdio_set_block_size(func, 512); - if (err) { - DBG_8192C(KERN_CRIT "%s: sdio_set_block_size FAIL(%d)!\n", __func__, err); - goto release; - } - psdio_data->block_transfer_len = 512; - psdio_data->tx_block_mode = 1; - psdio_data->rx_block_mode = 1; - -release: - sdio_release_host(func); - -exit: -_func_exit_; - - if (err) return _FAIL; - return _SUCCESS; -} - -static void sdio_deinit(struct dvobj_priv *dvobj) -{ - struct sdio_func *func; - int err; - - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+sdio_deinit\n")); - - func = dvobj->intf_data.func; - - if (func) { - sdio_claim_host(func); - err = sdio_disable_func(func); - if (err) - DBG_8192C(KERN_ERR "%s: sdio_disable_func(%d)\n", __func__, err); - - if (dvobj->irq_alloc) { - err = sdio_release_irq(func); - if (err) - DBG_8192C(KERN_ERR "%s: sdio_release_irq(%d)\n", __func__, err); - } - - sdio_release_host(func); - } -} -static struct dvobj_priv *sdio_dvobj_init(struct sdio_func *func) -{ - int status = _FAIL; - struct dvobj_priv *dvobj = NULL; - PSDIO_DATA psdio; -_func_enter_; - - if ((dvobj = (struct dvobj_priv*)rtw_zmalloc(sizeof(*dvobj))) == NULL) { - goto exit; - } - - _rtw_mutex_init(&dvobj->hw_init_mutex); - _rtw_mutex_init(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_init(&dvobj->setch_mutex); - _rtw_mutex_init(&dvobj->setbw_mutex); - - sdio_set_drvdata(func, dvobj); - dvobj->processing_dev_remove = _FALSE; - -#ifdef CONFIG_WOWLAN - sdio_claim_host(func); - mmc_host = func->card->host; - sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); - sdio_release_host(func); -#endif - - psdio = &dvobj->intf_data; - psdio->func = func; - - if (sdio_init(dvobj) != _SUCCESS) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!\n", __FUNCTION__)); - goto free_dvobj; - } - rtw_reset_continual_io_error(dvobj); - status = _SUCCESS; - -free_dvobj: - if (status != _SUCCESS && dvobj) { - sdio_set_drvdata(func, NULL); - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - dvobj = NULL; - } -exit: -_func_exit_; - return dvobj; -} - -static void sdio_dvobj_deinit(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); -_func_enter_; - - sdio_set_drvdata(func, NULL); - if (dvobj) { - sdio_deinit(dvobj); - _rtw_mutex_free(&dvobj->hw_init_mutex); - _rtw_mutex_free(&dvobj->h2c_fwcmd_mutex); - _rtw_mutex_free(&dvobj->setch_mutex); - _rtw_mutex_free(&dvobj->setbw_mutex); - rtw_mfree((u8*)dvobj, sizeof(*dvobj)); - } - -_func_exit_; - return; -} -static void decide_chip_type_by_device_id(PADAPTER padapter, u32 id) -{ - padapter->chip_type = NULL_CHIP_TYPE; - -#if 0 - switch (id) - { - case 0x8723: - padapter->chip_type = RTL8723A; - padapter->HardwareType = HARDWARE_TYPE_RTL8723AS; - break; - case 0x8179: - padapter->chip_type = RTL8188E; - padapter->HardwareType = HARDWARE_TYPE_RTL8188ES; - break; - } -#else -#if defined(CONFIG_RTL8723A) - padapter->chip_type = RTL8723A; - padapter->HardwareType = HARDWARE_TYPE_RTL8723AS; -#elif defined(CONFIG_RTL8188E) - padapter->chip_type = RTL8188E; - padapter->HardwareType = HARDWARE_TYPE_RTL8188ES; -#endif -#endif -} - -static void sd_intf_start(PADAPTER padapter) -{ - if (padapter == NULL) { - DBG_8192C(KERN_ERR "%s: padapter is NULL!\n", __func__); - return; - } - - // hal dep - rtw_hal_enable_interrupt(padapter); -} - -static void sd_intf_stop(PADAPTER padapter) -{ - if (padapter == NULL) { - DBG_8192C(KERN_ERR "%s: padapter is NULL!\n", __func__); - return; - } - - // hal dep - rtw_hal_disable_interrupt(padapter); -} - -/* - * Do deinit job corresponding to netdev_open() - */ -void rtw_dev_unload(PADAPTER padapter) -{ - struct net_device *pnetdev = (struct net_device*)padapter->pnetdev; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter); - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_unload\n")); - - padapter->bDriverStopped = _TRUE; - #ifdef CONFIG_XMIT_ACK - if (padapter->xmitpriv.ack_tx) - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP); - #endif - - if (padapter->bup == _TRUE) - { - // stop TX -// val8 = 0xFF; -// rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE,&val8); - -#if 0 - if (padapter->intf_stop) - padapter->intf_stop(padapter); -#else - sd_intf_stop(padapter); -#endif - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop intf complete!\n")); - - if (!pwrctl->bInternalAutoSuspend) - rtw_stop_drv_threads(padapter); - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop thread complete!\n")); - - if (padapter->bSurpriseRemoved == _FALSE) - { -#ifdef CONFIG_WOWLAN - if (pwrctl->bSupportRemoteWakeup == _TRUE && - pwrctl->wowlan_mode ==_TRUE) { - DBG_871X_LEVEL(_drv_always_, "%s bSupportRemoteWakeup==_TRUE do not run rtw_hal_deinit()\n",__FUNCTION__); - } - else -#endif - { - //amy modify 20120221 for power seq is different between driver open and ips - rtw_hal_deinit(padapter); - } - padapter->bSurpriseRemoved = _TRUE; - } - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: deinit hal complelt!\n")); - - padapter->bup = _FALSE; - } - else { - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("rtw_dev_unload: bup==_FALSE\n")); - } - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_unload\n")); -} - -_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; - - if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) { - goto exit; - } - padapter->dvobj = dvobj; - dvobj->if1 = padapter; - - padapter->bDriverStopped=_TRUE; - - dvobj->padapters[dvobj->iface_nums++] = padapter; - padapter->iface_id = IFACE_ID0; - -#if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT) - //set adapter_type/iface type for primary padapter - padapter->isprimary = _TRUE; - padapter->adapter_type = PRIMARY_ADAPTER; - #ifndef CONFIG_HWPORT_SWAP - padapter->iface_type = IFACE_PORT0; - #else - padapter->iface_type = IFACE_PORT1; - #endif -#endif - - padapter->interface_type = RTW_SDIO; - decide_chip_type_by_device_id(padapter, (u32)pdid->device); - - //3 1. init network device data - pnetdev = rtw_init_netdev(padapter); - if (!pnetdev) - goto free_adapter; - - SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj)); - - padapter = rtw_netdev_priv(pnetdev); - -#ifdef CONFIG_IOCTL_CFG80211 - rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)); -#endif - - //3 3. init driver special setting, interface, OS and hardware relative - - //4 3.1 set hardware operation functions - hal_set_hal_ops(padapter); - - - //3 5. initialize Chip version - padapter->intf_start = &sd_intf_start; - padapter->intf_stop = &sd_intf_stop; - - if (rtw_init_io_priv(padapter, sdio_set_intf_ops) == _FAIL) - { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, - ("rtw_drv_init: Can't init io_priv\n")); - goto free_hal_data; - } - - rtw_hal_read_chip_version(padapter); - - rtw_hal_chip_configure(padapter); - - - //3 6. read efuse/eeprom data - rtw_hal_read_chip_info(padapter); - - //3 7. init driver common data - if (rtw_init_drv_sw(padapter) == _FAIL) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, - ("rtw_drv_init: Initialize driver software resource Failed!\n")); - goto free_hal_data; - } - - //3 8. get WLan MAC address - // set mac addr - rtw_macaddr_cfg(padapter->eeprompriv.mac_addr); - rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr); - - rtw_hal_disable_interrupt(padapter); - - DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n" - ,padapter->bDriverStopped - ,padapter->bSurpriseRemoved - ,padapter->bup - ,padapter->hw_init_completed - ); - - status = _SUCCESS; - -free_hal_data: - if(status != _SUCCESS && padapter->HalData) - rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData))); - -free_wdev: - if(status != _SUCCESS) { - #ifdef CONFIG_IOCTL_CFG80211 - rtw_wdev_unregister(padapter->rtw_wdev); - rtw_wdev_free(padapter->rtw_wdev); - #endif - } - -free_adapter: - if (status != _SUCCESS) { - if (pnetdev) - rtw_free_netdev(pnetdev); - else if (padapter) - rtw_vmfree((u8*)padapter, sizeof(*padapter)); - padapter = NULL; - } -exit: - return padapter; -} - -static void rtw_sdio_if1_deinit(_adapter *if1) -{ - struct net_device *pnetdev = if1->pnetdev; - struct mlme_priv *pmlmepriv= &if1->mlmepriv; - - if(check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_disassoc_cmd(if1, 0, _FALSE); - -#ifdef CONFIG_AP_MODE - free_mlme_ap_info(if1); - #ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_unload(if1); - #endif -#endif - -#ifdef CONFIG_GPIO_WAKEUP - gpio_hostwakeup_free_irq(if1); -#endif -/* - if(if1->DriverState != DRIVER_DISAPPEAR) { - if(pnetdev) { - unregister_netdev(pnetdev); //will call netdev_close() - rtw_proc_remove_one(pnetdev); - } - } -*/ - rtw_cancel_all_timer(if1); - -#ifdef CONFIG_WOWLAN - adapter_to_pwrctl(if1)->wowlan_mode=_FALSE; - DBG_871X_LEVEL(_drv_always_, "%s wowlan_mode:%d\n", __func__, adapter_to_pwrctl(if1)->wowlan_mode); -#endif //CONFIG_WOWLAN - - rtw_dev_unload(if1); - DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", if1->hw_init_completed); - - rtw_handle_dualmac(if1, 0); - -#ifdef CONFIG_IOCTL_CFG80211 - if (if1->rtw_wdev) - { - //rtw_wdev_unregister(if1->rtw_wdev); - rtw_wdev_free(if1->rtw_wdev); - } -#endif - - rtw_free_drv_sw(if1); - - if(pnetdev) - rtw_free_netdev(pnetdev); - -#ifdef CONFIG_PLATFORM_RTD2880B - DBG_871X("wlan link down\n"); - rtd2885_wlan_netlink_sendMsg("linkdown", "8712"); -#endif - -} - -#ifdef CONFIG_PLATFORM_SPRD -#ifdef CONFIG_PM_RUNTIME -#include -static void rtw_start_runtime(struct sdio_func *func) -{ - unsigned long flags; - struct mmc_card *card = func->card; - struct mmc_host *host = card->host; - - DBG_871X("%s \n", __func__); - - pm_runtime_no_callbacks(&func->dev); - pm_suspend_ignore_children(&func->dev, true); - pm_runtime_set_autosuspend_delay(&func->dev, 50); - pm_runtime_use_autosuspend(&func->dev); - pm_runtime_put_autosuspend(&func->dev); -} -#endif -#endif - -/* - * drv_init() - a device potentially for us - * - * notes: drv_init() is called when the bus driver has located a card for us to support. - * We accept the new device by returning 0. - */ -static int rtw_drv_init( - struct sdio_func *func, - const struct sdio_device_id *id) -{ - int status = _FAIL; - struct net_device *pnetdev; - PADAPTER if1 = NULL, if2 = NULL; - struct dvobj_priv *dvobj; - - RT_TRACE(_module_hci_intfs_c_, _drv_info_, - ("+rtw_drv_init: vendor=0x%04x device=0x%04x class=0x%02x\n", - func->vendor, func->device, func->class)); - - if ((dvobj = sdio_dvobj_init(func)) == NULL) { - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n")); - goto exit; - } - - if ((if1 = rtw_sdio_if1_init(dvobj, id)) == NULL) { - DBG_871X("rtw_init_primary_adapter Failed!\n"); - goto free_dvobj; - } - -#ifdef CONFIG_CONCURRENT_MODE - if ((if2 = rtw_drv_if2_init(if1, sdio_set_intf_ops)) == NULL) { - goto free_if1; - } -#endif - - //dev_alloc_name && register_netdev - if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) { - goto free_if2; - } - -#ifdef CONFIG_HOSTAPD_MLME - hostapd_mode_init(if1); -#endif - -#ifdef CONFIG_PLATFORM_RTD2880B - DBG_871X("wlan link up\n"); - rtd2885_wlan_netlink_sendMsg("linkup", "8712"); -#endif - -#ifdef RTK_DMP_PLATFORM - rtw_proc_init_one(if1->pnetdev); -#endif - - if (sdio_alloc_irq(dvobj) != _SUCCESS) - goto free_if2; - -#ifdef CONFIG_GPIO_WAKEUP - gpio_hostwakeup_alloc_irq(if1); -#endif - -#ifdef CONFIG_GLOBAL_UI_PID - if(ui_pid[1]!=0) { - DBG_871X("ui_pid[1]:%d\n",ui_pid[1]); - rtw_signal_process(ui_pid[1], SIGUSR2); - } -#endif - -#ifdef CONFIG_PLATFORM_SPRD -#ifdef CONFIG_PM_RUNTIME - rtw_start_runtime(func); -#endif -#endif - - RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n")); - - status = _SUCCESS; - -free_if2: - if(status != _SUCCESS && if2) { - #ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(if2); - rtw_drv_if2_free(if2); - #endif - } -free_if1: - if (status != _SUCCESS && if1) { - rtw_sdio_if1_deinit(if1); - } -free_dvobj: - if (status != _SUCCESS) - sdio_dvobj_deinit(func); -exit: - return status == _SUCCESS?0:-ENODEV; -} -extern void rtw_unregister_netdevs(struct dvobj_priv *dvobj); -static void rtw_dev_remove(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); - PADAPTER padapter = dvobj->if1; - -_func_enter_; - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_remove\n")); - - dvobj->processing_dev_remove = _TRUE; - rtw_unregister_netdevs(dvobj); - - if (padapter->bSurpriseRemoved == _FALSE) { - int err; - - /* test surprise remove */ - sdio_claim_host(func); - sdio_readb(func, 0, &err); - sdio_release_host(func); - if (err == -ENOMEDIUM) { - padapter->bSurpriseRemoved = _TRUE; - DBG_871X(KERN_NOTICE "%s: device had been removed!\n", __func__); - } - } -#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER) - rtw_unregister_early_suspend(dvobj_to_pwrctl(dvobj)); -#endif - - rtw_pm_set_ips(padapter, IPS_NONE); - rtw_pm_set_lps(padapter, PS_MODE_ACTIVE); - - LeaveAllPowerSaveMode(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_stop(dvobj->if2); -#endif - - rtw_sdio_if1_deinit(padapter); - -#ifdef CONFIG_CONCURRENT_MODE - rtw_drv_if2_free(dvobj->if2); -#endif - - sdio_dvobj_deinit(func); - - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_remove\n")); - -_func_exit_; -} - -#if 1 - -#ifdef CONFIG_WOWLAN -static int rtw_suspend_wow(_adapter *padapter) -{ - _adapter *pbuddy_adapter = padapter->pbuddy_adapter; - - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct net_device *pnetdev = padapter->pnetdev; - struct wifidirect_info* pwdinfo = &padapter->wdinfo; - int ret = 0; - - struct wowlan_ioctl_param poidparam; - u8 ps_mode; - - _func_enter_; - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - pwrpriv->wowlan_mode = _TRUE; - else - pwrpriv->wowlan_mode = _FALSE; - - rtw_cancel_all_timer(padapter); - - if (pwrpriv->wowlan_mode == _TRUE) { - // 1. stop thread - padapter->bDriverStopped = _TRUE; //for stop thread - rtw_stop_drv_threads(padapter); - padapter->bDriverStopped = _FALSE; //for 32k command -#ifdef CONFIG_POWER_SAVING - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0); -#endif - // 2. disable interrupt - rtw_hal_disable_interrupt(padapter); // It need wait for leaving 32K. - - // 2.1 clean interupt - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - // 2.2 free irq - sdio_free_irq(adapter_to_dvobj(padapter)); - } - else { - LeaveAllPowerSaveMode(padapter); - } - - if(pnetdev){ - if(pwrpriv->wowlan_mode == _TRUE) { - rtw_netif_stop_queue(pnetdev); - } else { - netif_carrier_off(pnetdev); - rtw_netif_stop_queue(pnetdev); - } - } - - DBG_871X("wowlan_mode: %d\n", pwrpriv->wowlan_mode); - - if ((pwrpriv->bSupportRemoteWakeup == _TRUE) && - (pwrpriv->wowlan_mode == _TRUE)) { - poidparam.subcode = WOWLAN_ENABLE; - padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam); - } else { - //s2-1. issue rtw_disassoc_cmd to fw - rtw_disassoc_cmd(padapter, 0, _FALSE); - } - - -#ifdef CONFIG_LAYER2_ROAMING_RESUME - if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED) && rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) ) - { - 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); - - if (pwrpriv->wowlan_mode != _TRUE) - rtw_set_roaming(padapter, 1); - else - rtw_set_roaming(padapter, 0); - } -#endif //CONFIG_LAYER2_ROAMING_RESUME - - if (pwrpriv->wowlan_mode == _FALSE) - { - //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)){ - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__); - rtw_indicate_scan_done(padapter, 1); - } - - if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING)){ - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_linking\n", __func__); - rtw_indicate_disconnect(padapter); - } - - sdio_deinit(adapter_to_dvobj(padapter)); - } - else - { - DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) - { - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__); - rtw_indicate_scan_done(padapter, 1); - clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY); - } -#ifdef CONFIG_POWER_SAVING - rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0); -#endif - } - -exit: - - _func_exit_; - return ret; -} -#endif //#ifdef CONFIG_WOWLAN - -static int rtw_sdio_suspend(struct device *dev) -{ - struct sdio_func *func =dev_to_sdio_func(dev); - struct dvobj_priv *psdpriv = sdio_get_drvdata(func); - _adapter *padapter = psdpriv->if1; - - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct net_device *pnetdev = padapter->pnetdev; - int ret = 0; -#ifdef CONFIG_PLATFORM_SPRD - u32 value; -#endif // CONFIG_PLATFORM_SPRD - - u32 start_time = rtw_get_current_time(); - - _func_enter_; - - DBG_871X_LEVEL(_drv_always_, "sdio suspend start\n"); - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - pwrpriv->bInSuspend = _TRUE; - -#if (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD)) - if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) { - //we should not suspend softap, bcm also do like this - DBG_871X("%s should not suspend hw and system in AP mode\n",__FUNCTION__); - goto exit; - } -#endif - - while (pwrpriv->bips_processing == _TRUE) - rtw_msleep_os(1); - -#ifdef CONFIG_IOL_READ_EFUSE_MAP - if(!padapter->bup){ - u8 bMacPwrCtrlOn = _FALSE; - rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); - if(bMacPwrCtrlOn) - rtw_hal_power_off(padapter); - } -#endif - - 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; - } - - -#ifdef CONFIG_WOWLAN - rtw_suspend_wow(padapter); -#else - rtw_suspend_common(padapter); -#endif - - // interface deinit - sdio_deinit(adapter_to_dvobj(padapter)); - - DBG_871X_LEVEL(_drv_always_, "sdio suspend success in %d ms\n", - rtw_get_passing_time_ms(start_time)); - -exit: - -#ifdef CONFIG_MMC_PM_KEEP_POWER - //Android 4.0 don't support WIFI close power - //or power down or clock will close after wifi resume, - //this is sprd's bug in Android 4.0, but sprd don't - //want to fix it. - //we have test power under 8723as, power consumption is ok - if (func) { - mmc_pm_flag_t pm_flag = 0; - pm_flag = sdio_get_host_pm_caps(func); - DBG_871X("cmd: %s: suspend: PM flag = 0x%x\n", sdio_func_id(func), pm_flag); - if (!(pm_flag & MMC_PM_KEEP_POWER)) { - DBG_871X("%s: cannot remain alive while host is suspended\n", sdio_func_id(func)); - return -ENOSYS; - } else { - DBG_871X("cmd: suspend with MMC_PM_KEEP_POWER\n"); - sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); - } - } -#endif - -#ifdef CONFIG_PLATFORM_SPRD -#ifndef CONFIG_WOWLAN -#ifdef CONFIG_RTL8188E -#ifdef ANDROID_2X - /* - * Pull down wifi power pin here - * Pull up wifi power pin before sdio resume. - */ - rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_OFF); -#endif // ANDROID_2X -#endif // CONFIG_RTL8188E -#endif // CONFIG_WOWLAN -#endif // CONFIG_PLATFORM_SPRD - - DBG_871X("<=== %s return %d.............. in %dms\n", __FUNCTION__ - , ret, rtw_get_passing_time_ms(start_time)); - - _func_exit_; - return ret; -} - - -#else -static int rtw_sdio_suspend(struct device *dev) -{ - struct sdio_func *func =dev_to_sdio_func(dev); - struct dvobj_priv *psdpriv = sdio_get_drvdata(func); - _adapter *padapter = psdpriv->if1; - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct net_device *pnetdev = padapter->pnetdev; - int ret = 0; -#ifdef CONFIG_PLATFORM_SPRD - u32 value; -#endif // CONFIG_PLATFORM_SPRD - -#ifdef CONFIG_WOWLAN - struct wowlan_ioctl_param poidparam; - u8 ps_mode; -#endif //CONFIG_WOWLAN - - u32 start_time = rtw_get_current_time(); - - _func_enter_; - - DBG_871X_LEVEL(_drv_always_, "sdio suspend start\n"); - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - pwrpriv->bInSuspend = _TRUE; - -#if (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD)) - if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) { - //we should not suspend softap, bcm also do like this - DBG_871X("%s should not suspend hw and system in AP mode\n",__FUNCTION__); - goto exit; - } -#endif - -#ifdef CONFIG_WOWLAN - if (check_fwstate(pmlmepriv, _FW_LINKED)) - pwrpriv->wowlan_mode = _TRUE; - else - pwrpriv->wowlan_mode = _FALSE; -#endif - - //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); - -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_mode == _TRUE) { - // 1. stop thread - padapter->bDriverStopped = _TRUE; //for stop thread - rtw_stop_drv_threads(padapter); - padapter->bDriverStopped = _FALSE; //for 32k command -#ifdef CONFIG_POWER_SAVING - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0); -#endif - // 2. disable interrupt - rtw_hal_disable_interrupt(padapter); // It need wait for leaving 32K. - - // 2.1 clean interupt - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - // 2.2 free irq - sdio_free_irq(adapter_to_dvobj(padapter)); - } else { - LeaveAllPowerSaveMode(padapter); - } - - if(pnetdev){ - if(pwrpriv->wowlan_mode == _TRUE) { - rtw_netif_stop_queue(pnetdev); - } else { - netif_carrier_off(pnetdev); - rtw_netif_stop_queue(pnetdev); - } - } - - DBG_871X("wowlan_mode: %d\n", pwrpriv->wowlan_mode); - - if ((pwrpriv->bSupportRemoteWakeup == _TRUE) && - (pwrpriv->wowlan_mode == _TRUE)) { - poidparam.subcode = WOWLAN_ENABLE; - padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam); - } else { - //s2-1. issue rtw_disassoc_cmd to fw - rtw_disassoc_cmd(padapter, 0, _FALSE); - } -#else // !CONFIG_WOWLAN - LeaveAllPowerSaveMode(padapter); - - if(pnetdev) - { - netif_carrier_off(pnetdev); - rtw_netif_stop_queue(pnetdev); - } - - rtw_disassoc_cmd(padapter, 0, _FALSE); -#endif // !CONFIG_WOWLAN - - //for power down during suspend, need leave ips mode before entering power down. - //pwrpriv->bInSuspend = _TRUE; - - //padapter->net_closed = _TRUE; - //s1. - -#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); -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_mode != _TRUE) - rtw_set_roaming(padapter, 1); - else - rtw_set_roaming(padapter, 0); -#else //CONFIG_WOWLAN - rtw_set_roaming(padapter, 1); -#endif // !CONFIG_WOWLAN - } -#endif //CONFIG_LAYER2_ROAMING_RESUME - -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_mode == _FALSE) - { - //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)){ - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__); - rtw_indicate_scan_done(padapter, 1); - } - - if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING)){ - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_linking\n", __func__); - rtw_indicate_disconnect(padapter); - } - - sdio_deinit(adapter_to_dvobj(padapter)); - } - else - { - DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) - { - DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__); - rtw_indicate_scan_done(padapter, 1); - clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY); - } -#ifdef CONFIG_POWER_SAVING - rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0); -#endif - } -#else - //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 - sdio_deinit(adapter_to_dvobj(padapter)); -#endif - DBG_871X_LEVEL(_drv_always_, "sdio suspend success in %d ms\n", - rtw_get_passing_time_ms(start_time)); - -exit: - -//#if (defined CONFIG_WOWLAN) || (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD)) -#if (defined CONFIG_WOWLAN) -#if (!(defined ANDROID_2X)) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) - //Android 4.0 don't support WIFI close power - //or power down or clock will close after wifi resume, - //this is sprd's bug in Android 4.0, but sprd don't - //want to fix it. - //we have test power under 8723as, power consumption is ok - if (func) { - mmc_pm_flag_t pm_flag = 0; - pm_flag = sdio_get_host_pm_caps(func); - DBG_871X("cmd: %s: suspend: PM flag = 0x%x\n", sdio_func_id(func), pm_flag); - if (!(pm_flag & MMC_PM_KEEP_POWER)) { - DBG_871X("%s: cannot remain alive while host is suspended\n", sdio_func_id(func)); - return -ENOSYS; - } else { - DBG_871X("cmd: suspend with MMC_PM_KEEP_POWER\n"); - sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); - } - } -#endif -#endif - -#ifdef CONFIG_PLATFORM_SPRD -#ifndef CONFIG_WOWLAN -#ifdef CONFIG_RTL8188E -#ifdef ANDROID_2X - /* - * Pull down wifi power pin here - * Pull up wifi power pin before sdio resume. - */ - rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_OFF); -#endif // ANDROID_2X -#endif // CONFIG_RTL8188E -#endif // CONFIG_WOWLAN -#endif // CONFIG_PLATFORM_SPRD - - DBG_871X("<=== %s return %d.............. in %dms\n", __FUNCTION__ - , ret, rtw_get_passing_time_ms(start_time)); - - _func_exit_; - return ret; -} -#endif -extern int pm_netdev_open(struct net_device *pnetdev,u8 bnormal); - -#if 1 -#ifdef CONFIG_WOWLAN -int rtw_resume_process_wow(_adapter *padapter) -{ - struct net_device *pnetdev = padapter->pnetdev; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - int ret = 0; - - u32 value = 0; - struct wowlan_ioctl_param poidparam; - struct sta_info *psta = NULL; - - _func_enter_; - - if (pwrpriv->wowlan_mode == _FALSE){ - - // interface init - if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_hal_disable_interrupt(padapter); - - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_reset_drv_sw(padapter); - pwrpriv->bkeepfwalive = _FALSE; - - DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive); - - if(pm_netdev_open(pnetdev,_TRUE) != 0) { - ret = -1; - goto exit; - } - - netif_device_attach(pnetdev); - netif_carrier_on(pnetdev); - } - else //pwrpriv->wowlan_mode == _TRUE - { - -#ifdef CONFIG_POWER_SAVING -#ifdef CONFIG_LPS - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0); -#endif //CONFIG_LPS -#endif - - pwrpriv->bFwCurrentInPSMode = _FALSE; - - rtw_hal_disable_interrupt(padapter); - - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - //Disable WOW, set H2C command - poidparam.subcode=WOWLAN_DISABLE; - padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam); - - psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv)); - if (psta) { - set_sta_rate(padapter, psta); - } - - padapter->bDriverStopped = _FALSE; - - DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped); - rtw_start_drv_threads(padapter); - - rtw_hal_enable_interrupt(padapter); - - // start netif queue - if(pnetdev) { - if(!rtw_netif_queue_stopped(pnetdev)) - rtw_netif_start_queue(pnetdev); - else - rtw_netif_wake_queue(pnetdev); - } - } - - -#ifdef CONFIG_LAYER2_ROAMING_RESUME - - if (pwrpriv->wowlan_wake_reason == FWDecisionDisconnect || - pwrpriv->wowlan_wake_reason == Rx_DisAssoc || - pwrpriv->wowlan_wake_reason == Rx_DeAuth) { - - DBG_871X("%s: disconnect reason: %02x\n", __func__, - pwrpriv->wowlan_wake_reason); - rtw_indicate_disconnect(padapter); - rtw_sta_media_status_rpt(padapter, rtw_get_stainfo(&padapter->stapriv, - get_bssid(&padapter->mlmepriv)), 0); - rtw_free_assoc_resources(padapter, 1); - } else { - DBG_871X("%s: do roaming\n", __func__); - rtw_roaming(padapter, NULL); - } - -#endif //CONFIG_LAYER2_ROAMING_RESUME - - if (pwrpriv->wowlan_wake_reason == Rx_GTK || - pwrpriv->wowlan_wake_reason == Rx_DisAssoc || - pwrpriv->wowlan_wake_reason == Rx_DeAuth) { - DBG_871X("%s: set ext wake lock\n", __func__); - rtw_lock_ext_suspend_timeout(1500); - } - - if (pwrpriv->wowlan_mode == _TRUE) { - pwrpriv->bips_processing = _FALSE; - _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000); - rtw_set_pwr_state_check_timer(pwrpriv); - pwrpriv->bips_processing = _FALSE; - rtw_unlock_suspend(); - } else { - DBG_871X_LEVEL(_drv_always_, "do not reset timer\n"); - } - - pwrpriv->wowlan_mode =_FALSE; - -exit: - - _func_exit_; - - return ret; -} -#endif //CONFIG_WOWLAN - -int rtw_resume_process_normal(_adapter *padapter) -{ - struct net_device *pnetdev= padapter->pnetdev; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - struct mlme_priv *mlmepriv = &padapter->mlmepriv; - int ret = 0; - - _func_enter_; - // interface init - if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __FUNCTION__)); - goto exit; - } - rtw_hal_disable_interrupt(padapter); - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - if(rtw_resume_common(padapter)!= 0) { - DBG_871X("%s rtw_resume_common failed\n",__FUNCTION__); - goto exit; - } - _func_exit_; -exit: - return ret; -} - -int rtw_resume_process(_adapter *padapter) -{ - struct net_device *pnetdev; - struct pwrctrl_priv *pwrpriv = NULL; - - int ret = 0; - u32 start_time = rtw_get_current_time(); - - _func_enter_; - - DBG_871X_LEVEL(_drv_always_, "sdio resume start\n"); - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - if (padapter) { - pnetdev = padapter->pnetdev; - pwrpriv = adapter_to_pwrctl(padapter); - } else { - ret = -1; - goto exit; - } - -#ifdef CONFIG_WOWLAN - rtw_resume_process_wow( padapter); -#else //!CONFIG_WOWLAN - rtw_resume_process_normal( padapter); -#endif - - if( padapter->pid[1]!=0) { - DBG_871X("pid[1]:%d\n",padapter->pid[1]); - rtw_signal_process(padapter->pid[1], SIGUSR2); - } - - #ifdef CONFIG_RESUME_IN_WORKQUEUE - rtw_unlock_suspend(); - #endif //CONFIG_RESUME_IN_WORKQUEUE - -exit: - if (pwrpriv) - pwrpriv->bInSuspend = _FALSE; - DBG_871X_LEVEL(_drv_always_, "sdio resume ret:%d in %d ms\n", ret, - rtw_get_passing_time_ms(start_time)); - - _func_exit_; - - return ret; -} -#else -int rtw_resume_process(_adapter *padapter) -{ - struct net_device *pnetdev; - struct pwrctrl_priv *pwrpriv = NULL; - u8 is_pwrlock_hold_by_caller; - u8 is_directly_called_by_auto_resume; - int ret = 0; - u32 start_time = rtw_get_current_time(); -#ifdef CONFIG_WOWLAN - u32 value = 0; - struct wowlan_ioctl_param poidparam; - struct sta_info *psta = NULL; -#endif // CONFIG_WOWLAN - - _func_enter_; - - DBG_871X_LEVEL(_drv_always_, "sdio resume start\n"); - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - if (padapter) { - pnetdev = padapter->pnetdev; - pwrpriv = adapter_to_pwrctl(padapter); - } else { - ret = -1; - goto exit; - } - -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_mode == _FALSE){ - - // interface init - if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_hal_disable_interrupt(padapter); - - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_reset_drv_sw(padapter); - pwrpriv->bkeepfwalive = _FALSE; - - DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive); - - if(pm_netdev_open(pnetdev,_TRUE) != 0) { - ret = -1; - goto exit; - } - - netif_device_attach(pnetdev); - netif_carrier_on(pnetdev); - } else { - -#ifdef CONFIG_POWER_SAVING -#ifdef CONFIG_LPS - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0); -#endif //CONFIG_LPS -#endif - - pwrpriv->bFwCurrentInPSMode = _FALSE; - - rtw_hal_disable_interrupt(padapter); - - if (padapter->HalFunc.clear_interrupt) - padapter->HalFunc.clear_interrupt(padapter); - - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - //Disable WOW, set H2C command - poidparam.subcode=WOWLAN_DISABLE; - padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam); - - psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv)); - if (psta) { - set_sta_rate(padapter, psta); - } - - padapter->bDriverStopped = _FALSE; - - DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped); - rtw_start_drv_threads(padapter); - - rtw_hal_enable_interrupt(padapter); - - // start netif queue - if(pnetdev) { - if(!rtw_netif_queue_stopped(pnetdev)) - rtw_netif_start_queue(pnetdev); - else - rtw_netif_wake_queue(pnetdev); - } - } -#else //!CONFIG_WOWLAN - - // interface init - if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __FUNCTION__)); - goto exit; - } - rtw_hal_disable_interrupt(padapter); - if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) - { - ret = -1; - RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __FUNCTION__)); - goto exit; - } - - rtw_reset_drv_sw(padapter); - pwrpriv->bkeepfwalive = _FALSE; - - DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive); - if(pm_netdev_open(pnetdev,_TRUE) != 0) { - ret = -1; - goto exit; - } - - netif_device_attach(pnetdev); - netif_carrier_on(pnetdev); -#endif - if( padapter->pid[1]!=0) { - DBG_871X("pid[1]:%d\n",padapter->pid[1]); - rtw_signal_process(padapter->pid[1], SIGUSR2); - } - -#ifdef CONFIG_LAYER2_ROAMING_RESUME -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_wake_reason == FWDecisionDisconnect || - pwrpriv->wowlan_wake_reason == Rx_DisAssoc || - pwrpriv->wowlan_wake_reason == Rx_DeAuth) { - - DBG_871X("%s: disconnect reason: %02x\n", __func__, - pwrpriv->wowlan_wake_reason); - rtw_indicate_disconnect(padapter); - rtw_sta_media_status_rpt(padapter, rtw_get_stainfo(&padapter->stapriv, - get_bssid(&padapter->mlmepriv)), 0); - rtw_free_assoc_resources(padapter, 1); - } else { - DBG_871X("%s: do roaming\n", __func__); - rtw_roaming(padapter, NULL); - } -#else - rtw_roaming(padapter, NULL); -#endif //CONFOG_WOWLAN -#endif //CONFIG_LAYER2_ROAMING_RESUME - - #ifdef CONFIG_RESUME_IN_WORKQUEUE - rtw_unlock_suspend(); - #endif //CONFIG_RESUME_IN_WORKQUEUE - -#ifdef CONFIG_WOWLAN - if (pwrpriv->wowlan_wake_reason == Rx_GTK || - pwrpriv->wowlan_wake_reason == Rx_DisAssoc || - pwrpriv->wowlan_wake_reason == Rx_DeAuth) { - DBG_871X("%s: set ext wake lock\n", __func__); - rtw_lock_ext_suspend_timeout(1500); - } - - if (pwrpriv->wowlan_mode == _TRUE) { - pwrpriv->bips_processing = _FALSE; - _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000); - rtw_set_pwr_state_check_timer(pwrpriv); - pwrpriv->bips_processing = _FALSE; - rtw_unlock_suspend(); - } else { - DBG_871X_LEVEL(_drv_always_, "do not reset timer\n"); - } - - pwrpriv->wowlan_mode =_FALSE; -#endif //CONFIG_WOWLAN - -exit: - if (pwrpriv) - pwrpriv->bInSuspend = _FALSE; - DBG_871X_LEVEL(_drv_always_, "sdio resume ret:%d in %d ms\n", ret, - rtw_get_passing_time_ms(start_time)); - - _func_exit_; - - return ret; -} -#endif - - -static int rtw_sdio_resume(struct device *dev) -{ - struct sdio_func *func =dev_to_sdio_func(dev); - struct dvobj_priv *psdpriv = sdio_get_drvdata(func); - _adapter *padapter = psdpriv->if1; - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); - int ret = 0; - - DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid); - - if(pwrpriv->bInternalAutoSuspend ){ - ret = rtw_resume_process(padapter); - } else { -#ifdef CONFIG_RESUME_IN_WORKQUEUE - rtw_resume_in_workqueue(pwrpriv); -#else - if (rtw_is_earlysuspend_registered(pwrpriv) - #ifdef CONFIG_WOWLAN - && !pwrpriv->wowlan_mode - #endif /* CONFIG_WOWLAN */ - ) { - /* jeff: bypass resume here, do in late_resume */ - rtw_set_do_late_resume(pwrpriv, _TRUE); - } else { - rtw_set_do_late_resume(pwrpriv, _FALSE); - #ifdef CONFIG_WOWLAN - //rtw_lock_suspend_timeout(4000); - rtw_lock_suspend(); - #endif - ret = rtw_resume_process(padapter); - } -#endif /* CONFIG_RESUME_IN_WORKQUEUE */ - } - - DBG_871X("<======== %s return %d\n", __FUNCTION__, ret); - return ret; - -} - - - - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)) -extern int console_suspend_enabled; -#endif - - -#ifdef CONFIG_PLATFORM_SPRD -extern void sdhci_bus_scan(void); -#ifndef ANDROID_2X -extern int sdhci_device_attached(void); -#endif -#endif // CONFIG_PLATFORM_SPRD - -static int __init rtw_drv_entry(void) -{ - int ret = 0; - -#ifdef CONFIG_PLATFORM_ARM_SUNxI -/*depends on sunxi power control */ -#if defined CONFIG_MMC_SUNXI_POWER_CONTROL - unsigned int mod_sel = mmc_pm_get_mod_type(); - - if(mod_sel == SUNXI_SDIO_WIFI_NUM_RTL8189ES) - { - rtl8189es_sdio_powerup(); - sunximmc_rescan_card(SDIOID, 1); - DBG_8192C("[rtl8189es] %s: power up, rescan card.\n", __FUNCTION__); - } - else - { - ret = -1; - DBG_8192C("[rtl8189es] %s: mod_sel = %d is incorrect.\n", __FUNCTION__, mod_sel); - } -#endif // defined CONFIG_MMC_SUNXI_POWER_CONTROL - if(ret != 0) - goto exit; - -#endif //CONFIG_PLATFORM_ARM_SUNxI - -#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) -#ifdef CONFIG_MMC - script_item_value_type_e type; - script_item_u item; - - unsigned int mod_sel = wifi_pm_get_mod_type(); - - type = script_get_item("wifi_para", "wifi_sdc_id", &item); - if (SCIRPT_ITEM_VALUE_TYPE_INT != type) - { - DBG_871X("ERR: script_get_item wifi_sdc_id failed\n"); - ret = -1; - } - else - { - sdc_id = item.val; - DBG_871X("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel); - wifi_pm_power(1); - mdelay(10); - sw_mci_rescan_card(sdc_id, 1); - DBG_871X("[rtw_sdio] %s: power up, rescan card.\n", __FUNCTION__); - } -#endif //CONFIG_MMC - if(ret != 0) - goto exit; - -#endif //#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) - - DBG_871X_LEVEL(_drv_always_, "module init start version:"DRIVERVERSION"\n"); - -// DBG_871X(KERN_INFO "+%s", __func__); - RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_drv_entry\n")); - DBG_871X(DRV_NAME " driver version=%s\n", DRIVERVERSION); - DBG_871X("build time: %s %s\n", __DATE__, __TIME__); - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)) - //console_suspend_enabled=0; -#endif - -#ifdef CONFIG_PLATFORM_SPRD - rtw_wifi_gpio_init(); - -#ifdef ANDROID_2X -#ifdef CONFIG_RTL8188E - rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_ON); -#endif //CONFIG_RTL8188E -#endif //ANDROID_2X - - /* Pull up pwd pin, make wifi leave power down mode. */ - rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_ON); - -#if defined(CONFIG_RTL8723A) && (MP_DRIVER == 1) - // Pull up BT reset pin. - rtw_wifi_gpio_wlan_ctrl(WLAN_BT_PWDN_ON); -#endif - rtw_mdelay_os(5); - - sdhci_bus_scan(); -#if (defined ANDROID_2X) - rtw_mdelay_os(200); -#endif //ANDROID_2X - -#endif // CONFIG_PLATFORM_SPRD - - rtw_suspend_lock_init(); - - - sdio_drvpriv.drv_registered = _TRUE; - - ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv); - -exit: - DBG_871X_LEVEL(_drv_always_, "module init ret=%d\n", ret); - - rtw_android_wifictrl_func_add(); - - return ret; -} - -static void __exit rtw_drv_halt(void) -{ - DBG_871X_LEVEL(_drv_always_, "module exit start\n"); - - rtw_android_wifictrl_func_del(); - sdio_drvpriv.drv_registered = _FALSE; - - sdio_unregister_driver(&sdio_drvpriv.r871xs_drv); - -#ifdef CONFIG_PLATFORM_SPRD - /* Pull down pwd pin, make wifi enter power down mode. */ - rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_OFF); - rtw_mdelay_os(5); - rtw_wifi_gpio_deinit(); - -#ifdef ANDROID_2X -#ifdef CONFIG_RTL8188E - rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_OFF); -#endif // CONFIG_RTL8188E -#endif // ANDROID_2X - -#endif // CONFIG_PLATFORM_SPRD - -#ifdef CONFIG_PLATFORM_ARM_SUNxI -#if defined(CONFIG_MMC_SUNXI_POWER_CONTROL) - sunximmc_rescan_card(SDIOID, 0); -#ifdef CONFIG_RTL8188E - rtl8189es_sdio_poweroff(); - DBG_8192C("[rtl8189es] %s: remove card, power off.\n", __FUNCTION__); -#endif //CONFIG_RTL8188E -#endif //defined(CONFIG_MMC_SUNXI_POWER_CONTROL) -#endif //CONFIG_PLATFORM_ARM_SUNxI - -#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) -#ifdef CONFIG_MMC - wifi_pm_power(0); - sw_mci_rescan_card(sdc_id, 0); - printk("[rtl8723as] %s: remove card, power off.\n", __FUNCTION__); -#endif //CONFIG_MMC -#endif //#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) - rtw_suspend_lock_uninit(); - DBG_871X_LEVEL(_drv_always_, "module exit success\n"); - - rtw_mstat_dump(); -} - - -module_init(rtw_drv_entry); -module_exit(rtw_drv_halt); - diff --git a/os_dep/linux/sdio_ops_linux.c b/os_dep/linux/sdio_ops_linux.c deleted file mode 100755 index 4a10789..0000000 --- a/os_dep/linux/sdio_ops_linux.c +++ /dev/null @@ -1,912 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - *******************************************************************************/ -#define _SDIO_OPS_LINUX_C_ - -#include - -#include - -static bool rtw_sdio_claim_host_needed(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); - PSDIO_DATA sdio_data = &dvobj->intf_data; - - if (sdio_data->sys_sdio_irq_thd && sdio_data->sys_sdio_irq_thd == current) - return _FALSE; - return _TRUE; -} - -inline void rtw_sdio_set_irq_thd(struct dvobj_priv *dvobj, _thread_hdl_ thd_hdl) -{ - PSDIO_DATA sdio_data = &dvobj->intf_data; - - sdio_data->sys_sdio_irq_thd = thd_hdl; -} - -u8 sd_f0_read8(struct intf_hdl *pintfhdl,u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u8 v=0; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_f0_readb(func, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, *err, addr); - -_func_exit_; - - return v; -} - -void sd_f0_write8(struct intf_hdl *pintfhdl, u32 addr, u8 v, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_f0_writeb(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%02x\n", __func__, *err, addr, v); - -_func_exit_; -} - -/* - * Return: - * 0 Success - * others Fail - */ -s32 _sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - int err=0, i; - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - - for (i = 0; i < cnt; i++) { - pdata[i] = sdio_readb(func, addr+i, &err); - if (err) { - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, err, addr+i); - break; - } - } - -_func_exit_; - - return err; -} - -/* - * Return: - * 0 Success - * others Fail - */ -s32 sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - int err=0, i; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_cmd52_read(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - -_func_exit_; - - return err; -} - -/* - * Return: - * 0 Success - * others Fail - */ -s32 _sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - int err=0, i; - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved)!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - - for (i = 0; i < cnt; i++) { - sdio_writeb(func, pdata[i], addr+i, &err); - if (err) { - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%02x\n", __func__, err, addr+i, pdata[i]); - break; - } - } - -_func_exit_; - - return err; -} - -/* - * Return: - * 0 Success - * others Fail - */ -s32 sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - int err=0, i; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_cmd52_write(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - -_func_exit_; - - return err; -} - -u8 _sd_read8(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u8 v=0; - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved)!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - - v = sdio_readb(func, addr, err); - - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, *err, addr); - -_func_exit_; - - return v; -} - -u8 sd_read8(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u8 v; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_readb(func, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, *err, addr); - -_func_exit_; - - return v; -} - -u16 sd_read16(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u16 v=0; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_readw(func, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, *err, addr); - -_func_exit_; - - return v; -} - -u32 _sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u32 v=0; - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - - v = sdio_readl(func, addr, err); - - if (err && *err) - { - int i; - - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x, val=0x%x\n", __func__, *err, addr, v); - - *err = 0; - for(i=0; ibSurpriseRemoved = _TRUE; - } - - if(rtw_inc_and_chk_continual_io_error(psdiodev) == _TRUE ){ - padapter->bSurpriseRemoved = _TRUE; - break; - } - - } - } - - if (i==SD_IO_TRY_CNT) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x, val=0x%x, try_cnt=%d\n", __func__, *err, addr, v, i); - else - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x, val=0x%x, try_cnt=%d\n", __func__, *err, addr, v, i); - - } - -_func_exit_; - - return v; -} - -u32 sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - u32 v=0; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return v; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_readl(func, addr, err); - if (claim_needed) - sdio_release_host(func); - - if (err && *err) - { - int i; - - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x, val=0x%x\n", __func__, *err, addr, v); - - *err = 0; - for(i=0; ibSurpriseRemoved = _TRUE; - } - - if(rtw_inc_and_chk_continual_io_error(psdiodev) == _TRUE ){ - padapter->bSurpriseRemoved = _TRUE; - break; - } - } - } - - if (i==SD_IO_TRY_CNT) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x, val=0x%x, try_cnt=%d\n", __func__, *err, addr, v, i); - else - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x, val=0x%x, try_cnt=%d\n", __func__, *err, addr, v, i); - - } - -_func_exit_; - - return v; -} - -void sd_write8(struct intf_hdl *pintfhdl, u32 addr, u8 v, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return ; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_writeb(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%02x\n", __func__, *err, addr, v); - -_func_exit_; -} - -void sd_write16(struct intf_hdl *pintfhdl, u32 addr, u16 v, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return ; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_writew(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - if (err && *err) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%04x\n", __func__, *err, addr, v); - -_func_exit_; -} - -void _sd_write32(struct intf_hdl *pintfhdl, u32 addr, u32 v, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return ; - } - - func = psdio->func; - - sdio_writel(func, v, addr, err); - - if (err && *err) - { - int i; - - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x val=0x%08x\n", __func__, *err, addr, v); - - *err = 0; - for(i=0; ibSurpriseRemoved = _TRUE; - } - - if(rtw_inc_and_chk_continual_io_error(psdiodev) == _TRUE ){ - padapter->bSurpriseRemoved = _TRUE; - break; - } - } - } - - if (i==SD_IO_TRY_CNT) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%08x, try_cnt=%d\n", __func__, *err, addr, v, i); - else - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x val=0x%08x, try_cnt=%d\n", __func__, *err, addr, v, i); - - } - -_func_exit_; -} - -void sd_write32(struct intf_hdl *pintfhdl, u32 addr, u32 v, s32 *err) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - struct sdio_func *func; - bool claim_needed; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved)!!!\n",__FUNCTION__); - return ; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_writel(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - - if (err && *err) - { - int i; - - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x val=0x%08x\n", __func__, *err, addr, v); - - *err = 0; - for(i=0; ibSurpriseRemoved = _TRUE; - } - - if(rtw_inc_and_chk_continual_io_error(psdiodev) == _TRUE ){ - padapter->bSurpriseRemoved = _TRUE; - break; - } - } - } - - if (i==SD_IO_TRY_CNT) - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%08x, try_cnt=%d\n", __func__, *err, addr, v, i); - else - DBG_871X(KERN_ERR "%s: (%d) addr=0x%05x val=0x%08x, try_cnt=%d\n", __func__, *err, addr, v, i); - } - -_func_exit_; -} - -/* - * Use CMD53 to read data from SDIO device. - * This function MUST be called after sdio_claim_host() or - * in SDIO ISR(host had been claimed). - * - * Parameters: - * psdio pointer of SDIO_DATA - * addr address to read - * cnt amount to read - * pdata pointer to put data, this should be a "DMA:able scratch buffer"! - * - * Return: - * 0 Success - * others Fail - */ -s32 _sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - int err= -EPERM; - struct sdio_func *func; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - - if (unlikely((cnt==1) || (cnt==2))) - { - int i; - u8 *pbuf = (u8*)pdata; - - for (i = 0; i < cnt; i++) - { - *(pbuf+i) = sdio_readb(func, addr+i, &err); - - if (err) { - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x\n", __func__, err, addr); - break; - } - } - return err; - } - - err = sdio_memcpy_fromio(func, pdata, addr, cnt); - if (err) { - DBG_871X(KERN_ERR "%s: FAIL(%d)! ADDR=%#x Size=%d\n", __func__, err, addr, cnt); - } - -_func_exit_; - - return err; -} - -/* - * Use CMD53 to read data from SDIO device. - * - * Parameters: - * psdio pointer of SDIO_DATA - * addr address to read - * cnt amount to read - * pdata pointer to put data, this should be a "DMA:able scratch buffer"! - * - * Return: - * 0 Success - * others Fail - */ -s32 sd_read(struct intf_hdl * pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - bool claim_needed; - s32 err= -EPERM; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_read(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); -_func_exit_; - return err; -} - -/* - * Use CMD53 to write data to SDIO device. - * This function MUST be called after sdio_claim_host() or - * in SDIO ISR(host had been claimed). - * - * Parameters: - * psdio pointer of SDIO_DATA - * addr address to write - * cnt amount to write - * pdata data pointer, this should be a "DMA:able scratch buffer"! - * - * Return: - * 0 Success - * others Fail - */ -s32 _sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - u32 size; - s32 err=-EPERM; - -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; -// size = sdio_align_size(func, cnt); - - if (unlikely((cnt==1) || (cnt==2))) - { - int i; - u8 *pbuf = (u8*)pdata; - - for (i = 0; i < cnt; i++) - { - sdio_writeb(func, *(pbuf+i), addr+i, &err); - if (err) { - DBG_871X(KERN_ERR "%s: FAIL!(%d) addr=0x%05x val=0x%02x\n", __func__, err, addr, *(pbuf+i)); - break; - } - } - - return err; - } - - size = cnt; - err = sdio_memcpy_toio(func, addr, pdata, size); - if (err) { - DBG_871X(KERN_ERR "%s: FAIL(%d)! ADDR=%#x Size=%d(%d)\n", __func__, err, addr, cnt, size); - } - -_func_exit_; - - return err; -} - -/* - * Use CMD53 to write data to SDIO device. - * - * Parameters: - * psdio pointer of SDIO_DATA - * addr address to write - * cnt amount to write - * pdata data pointer, this should be a "DMA:able scratch buffer"! - * - * Return: - * 0 Success - * others Fail - */ -s32 sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - PADAPTER padapter; - struct dvobj_priv *psdiodev; - PSDIO_DATA psdio; - - struct sdio_func *func; - bool claim_needed; - s32 err=-EPERM; -_func_enter_; - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if(padapter->bSurpriseRemoved){ - //DBG_871X(" %s (padapter->bSurpriseRemoved )!!!\n",__FUNCTION__); - return err; - } - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_write(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); -_func_exit_; - return err; -} -