1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 *******************************************************************************/
21 #include <drv_types.h>
23 #include <rtl8723a_spec.h>
24 #include <rtl8723a_hal.h>
26 //#define SDIO_DEBUG_IO 1
30 // The following mapping is for SDIO host local register space.
32 // Creadted by Roger, 2011.01.31.
34 static void HalSdioGetCmdAddr8723ASdio(
43 case SDIO_LOCAL_DEVICE_ID:
44 *pCmdAddr = ((SDIO_LOCAL_DEVICE_ID << 13) | (Addr & SDIO_LOCAL_MSK));
47 case WLAN_IOREG_DEVICE_ID:
48 *pCmdAddr = ((WLAN_IOREG_DEVICE_ID << 13) | (Addr & WLAN_IOREG_MSK));
51 case WLAN_TX_HIQ_DEVICE_ID:
52 *pCmdAddr = ((WLAN_TX_HIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
55 case WLAN_TX_MIQ_DEVICE_ID:
56 *pCmdAddr = ((WLAN_TX_MIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
59 case WLAN_TX_LOQ_DEVICE_ID:
60 *pCmdAddr = ((WLAN_TX_LOQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
63 case WLAN_RX0FF_DEVICE_ID:
64 *pCmdAddr = ((WLAN_RX0FF_DEVICE_ID << 13) | (Addr & WLAN_RX0FF_MSK));
72 static u8 get_deviceid(u32 addr)
78 pseudoId = (u16)(addr >> 16);
82 devideId = SDIO_LOCAL_DEVICE_ID;
86 devideId = WLAN_IOREG_DEVICE_ID;
90 // devideId = SDIO_FIRMWARE_FIFO;
94 devideId = WLAN_TX_HIQ_DEVICE_ID;
98 devideId = WLAN_TX_MIQ_DEVICE_ID;
102 devideId = WLAN_TX_LOQ_DEVICE_ID;
106 devideId = WLAN_RX0FF_DEVICE_ID;
110 // devideId = (u8)((addr >> 13) & 0xF);
111 devideId = WLAN_IOREG_DEVICE_ID;
120 * HalSdioGetCmdAddr8723ASdio()
122 static u32 _cvrt2ftaddr(const u32 addr, u8 *pdeviceId, u16 *poffset)
129 deviceId = get_deviceid(addr);
134 case SDIO_LOCAL_DEVICE_ID:
135 offset = addr & SDIO_LOCAL_MSK;
138 case WLAN_TX_HIQ_DEVICE_ID:
139 case WLAN_TX_MIQ_DEVICE_ID:
140 case WLAN_TX_LOQ_DEVICE_ID:
141 offset = addr & WLAN_FIFO_MSK;
144 case WLAN_RX0FF_DEVICE_ID:
145 offset = addr & WLAN_RX0FF_MSK;
148 case WLAN_IOREG_DEVICE_ID:
150 deviceId = WLAN_IOREG_DEVICE_ID;
151 offset = addr & WLAN_IOREG_MSK;
154 ftaddr = (deviceId << 13) | offset;
156 if (pdeviceId) *pdeviceId = deviceId;
157 if (poffset) *poffset = offset;
162 u8 sdio_read8(struct intf_hdl *pintfhdl, u32 addr)
168 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
169 val = sd_read8(pintfhdl, ftaddr, NULL);
176 u16 sdio_read16(struct intf_hdl *pintfhdl, u32 addr)
183 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
184 sd_cmd52_read(pintfhdl, ftaddr, 2, (u8*)&val);
185 val = le16_to_cpu(val);
192 u32 sdio_read32(struct intf_hdl *pintfhdl, u32 addr)
205 padapter = pintfhdl->padapter;
207 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
209 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
210 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
211 || (_FALSE == bMacPwrCtrlOn)
212 #ifdef CONFIG_LPS_LCLK
213 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
217 err = sd_cmd52_read(pintfhdl, ftaddr, 4, (u8*)&val);
221 val = le32_to_cpu(val);
226 DBG_8192C(KERN_ERR "%s: Mac Power off, Read FAIL(%d)! addr=0x%x\n", __func__, err, addr);
227 return SDIO_ERR_VAL32;
232 shift = ftaddr & 0x3;
234 val = sd_read32(pintfhdl, ftaddr, NULL);
238 ptmpbuf = (u8*)rtw_malloc(8);
239 if (NULL == ptmpbuf) {
240 DBG_8192C(KERN_ERR "%s: Allocate memory FAIL!(size=8) addr=0x%x\n", __func__, addr);
241 return SDIO_ERR_VAL32;
245 sd_read(pintfhdl, ftaddr, 8, ptmpbuf);
246 _rtw_memcpy(&val, ptmpbuf+shift, 4);
247 val = le32_to_cpu(val);
249 rtw_mfree(ptmpbuf, 8);
257 s32 sdio_readN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pbuf)
269 padapter = pintfhdl->padapter;
272 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
274 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
275 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
276 || (_FALSE == bMacPwrCtrlOn)
277 #ifdef CONFIG_LPS_LCLK
278 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
282 err = sd_cmd52_read(pintfhdl, ftaddr, cnt, pbuf);
287 shift = ftaddr & 0x3;
289 err = sd_read(pintfhdl, ftaddr, cnt, pbuf);
296 ptmpbuf = rtw_malloc(n);
297 if (NULL == ptmpbuf) return -1;
298 err = sd_read(pintfhdl, ftaddr, n, ptmpbuf);
300 _rtw_memcpy(pbuf, ptmpbuf+shift, cnt);
301 rtw_mfree(ptmpbuf, n);
309 s32 sdio_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
316 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
317 sd_write8(pintfhdl, ftaddr, val, &err);
324 s32 sdio_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
332 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
333 val = cpu_to_le16(val);
334 err = sd_cmd52_write(pintfhdl, ftaddr, 2, (u8*)&val);
341 s32 sdio_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
353 padapter = pintfhdl->padapter;
356 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
358 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
359 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
360 || (_FALSE == bMacPwrCtrlOn)
361 #ifdef CONFIG_LPS_LCLK
362 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
366 val = cpu_to_le32(val);
367 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8*)&val);
372 shift = ftaddr & 0x3;
376 sd_write32(pintfhdl, ftaddr, val, &err);
380 val = cpu_to_le32(val);
381 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8*)&val);
385 sd_write32(pintfhdl, ftaddr, val, &err);
389 ptmpbuf = (u8*)rtw_malloc(8);
390 if (NULL == ptmpbuf) return (-1);
393 err = sd_read(pintfhdl, ftaddr, 8, ptmpbuf);
395 rtw_mfree(ptmpbuf, 8);
398 val = cpu_to_le32(val);
399 _rtw_memcpy(ptmpbuf+shift, &val, 4);
400 err = sd_write(pintfhdl, ftaddr, 8, ptmpbuf);
402 rtw_mfree(ptmpbuf, 8);
411 s32 sdio_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8* pbuf)
423 padapter = pintfhdl->padapter;
426 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
428 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
429 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
430 || (_FALSE == bMacPwrCtrlOn)
431 #ifdef CONFIG_LPS_LCLK
432 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
436 err = sd_cmd52_write(pintfhdl, ftaddr, cnt, pbuf);
440 shift = ftaddr & 0x3;
442 err = sd_write(pintfhdl, ftaddr, cnt, pbuf);
449 ptmpbuf = rtw_malloc(n);
450 if (NULL == ptmpbuf) return -1;
451 err = sd_read(pintfhdl, ftaddr, 4, ptmpbuf);
453 rtw_mfree(ptmpbuf, n);
456 _rtw_memcpy(ptmpbuf+shift, pbuf, cnt);
457 err = sd_write(pintfhdl, ftaddr, n, ptmpbuf);
458 rtw_mfree(ptmpbuf, n);
466 void sdio_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
472 err = sdio_readN(pintfhdl, addr, cnt, rmem);
477 void sdio_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
481 sdio_writeN(pintfhdl, addr, cnt, wmem);
489 * Round read size to block size,
490 * and make sure data transfer will be done in one command.
493 * pintfhdl a pointer of intf_hdl
496 * rmem address to put data
499 * _SUCCESS(1) Success
502 static u32 sdio_read_port(
503 struct intf_hdl *pintfhdl,
512 #ifdef SDIO_DYNAMIC_ALLOC_MEM
518 padapter = pintfhdl->padapter;
519 psdio = &adapter_to_dvobj(padapter)->intf_data;
520 phal = GET_HAL_DATA(padapter);
522 HalSdioGetCmdAddr8723ASdio(padapter, addr, phal->SdioRxFIFOCnt++, &addr);
525 if (cnt > psdio->block_transfer_len)
526 cnt = _RND(cnt, psdio->block_transfer_len);
527 // cnt = sdio_align_size(cnt);
530 #ifdef SDIO_DYNAMIC_ALLOC_MEM
532 mem = rtw_malloc(cnt);
534 DBG_8192C(KERN_WARNING "%s: allocate memory %d bytes fail!\n", __func__, cnt);
539 // in this case, caller should gurante the buffer is big enough
540 // to receive data after alignment
544 err = _sd_read(pintfhdl, addr, cnt, mem);
546 #ifdef SDIO_DYNAMIC_ALLOC_MEM
547 if ((oldcnt != cnt) && (oldmem)) {
548 _rtw_memcpy(oldmem, mem, oldcnt);
553 if (err) return _FAIL;
560 * Align write size block size,
561 * and make sure data could be written in one command.
564 * pintfhdl a pointer of intf_hdl
567 * wmem data pointer to write
570 * _SUCCESS(1) Success
573 static u32 sdio_write_port(
574 struct intf_hdl *pintfhdl,
582 struct xmit_buf *xmitbuf = (struct xmit_buf *)mem;
584 padapter = pintfhdl->padapter;
585 psdio = &adapter_to_dvobj(padapter)->intf_data;
587 if(padapter->hw_init_completed == _FALSE)
589 DBG_871X("%s [addr=0x%x cnt=%d] padapter->hw_init_completed == _FALSE \n",__func__,addr,cnt);
594 HalSdioGetCmdAddr8723ASdio(padapter, addr, cnt >> 2, &addr);
596 if (cnt > psdio->block_transfer_len)
597 cnt = _RND(cnt, psdio->block_transfer_len);
598 // cnt = sdio_align_size(cnt);
600 err = sd_write(pintfhdl, addr, cnt, xmitbuf->pdata);
602 rtw_sctx_done_err(&xmitbuf->sctx,
603 err ? RTW_SCTX_DONE_WRITE_PORT_ERR : RTW_SCTX_DONE_SUCCESS);
605 if (err) return _FAIL;
609 void sdio_set_intf_ops(struct _io_ops *pops)
613 pops->_read8 = &sdio_read8;
614 pops->_read16 = &sdio_read16;
615 pops->_read32 = &sdio_read32;
616 pops->_read_mem = &sdio_read_mem;
617 pops->_read_port = &sdio_read_port;
619 pops->_write8 = &sdio_write8;
620 pops->_write16 = &sdio_write16;
621 pops->_write32 = &sdio_write32;
622 pops->_writeN = &sdio_writeN;
623 pops->_write_mem = &sdio_write_mem;
624 pops->_write_port = &sdio_write_port;
630 * Todo: align address to 4 bytes.
632 s32 _sdio_local_read(
638 struct intf_hdl * pintfhdl;
644 pintfhdl=&padapter->iopriv.intf;
646 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
648 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
649 if (_FALSE == bMacPwrCtrlOn)
651 err = _sd_cmd52_read(pintfhdl, addr, cnt, pbuf);
656 ptmpbuf = (u8*)rtw_malloc(n);
660 err = _sd_read(pintfhdl, addr, n, ptmpbuf);
662 _rtw_memcpy(pbuf, ptmpbuf, cnt);
665 rtw_mfree(ptmpbuf, n);
671 * Todo: align address to 4 bytes.
679 struct intf_hdl * pintfhdl;
685 pintfhdl=&padapter->iopriv.intf;
686 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
688 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
689 if ((_FALSE == bMacPwrCtrlOn)
690 #ifdef CONFIG_LPS_LCLK
691 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
695 err = sd_cmd52_read(pintfhdl, addr, cnt, pbuf);
700 ptmpbuf = (u8*)rtw_malloc(n);
704 err = sd_read(pintfhdl, addr, n, ptmpbuf);
706 _rtw_memcpy(pbuf, ptmpbuf, cnt);
709 rtw_mfree(ptmpbuf, n);
715 * Todo: align address to 4 bytes.
717 s32 _sdio_local_write(
723 struct intf_hdl * pintfhdl;
729 DBG_8192C("%s, address must be 4 bytes alignment\n", __FUNCTION__);
732 DBG_8192C("%s, size must be the multiple of 4 \n", __FUNCTION__);
734 pintfhdl=&padapter->iopriv.intf;
735 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
737 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
738 if ((_FALSE == bMacPwrCtrlOn)
739 #ifdef CONFIG_LPS_LCLK
740 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
744 err = _sd_cmd52_write(pintfhdl, addr, cnt, pbuf);
748 ptmpbuf = (u8*)rtw_malloc(cnt);
752 _rtw_memcpy(ptmpbuf, pbuf, cnt);
754 err = _sd_write(pintfhdl, addr, cnt, ptmpbuf);
757 rtw_mfree(ptmpbuf, cnt);
763 * Todo: align address to 4 bytes.
765 s32 sdio_local_write(
771 struct intf_hdl * pintfhdl;
777 DBG_8192C("%s, address must be 4 bytes alignment\n", __FUNCTION__);
780 DBG_8192C("%s, size must be the multiple of 4 \n", __FUNCTION__);
782 pintfhdl=&padapter->iopriv.intf;
784 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
786 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
787 if ((_FALSE == bMacPwrCtrlOn)
788 #ifdef CONFIG_LPS_LCLK
789 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
793 err = sd_cmd52_write(pintfhdl, addr, cnt, pbuf);
797 ptmpbuf = (u8*)rtw_malloc(cnt);
801 _rtw_memcpy(ptmpbuf, pbuf, cnt);
803 err = sd_write(pintfhdl, addr, cnt, ptmpbuf);
806 rtw_mfree(ptmpbuf, cnt);
811 u8 SdioLocalCmd52Read1Byte(PADAPTER padapter, u32 addr)
813 struct intf_hdl * pintfhdl;
816 pintfhdl=&padapter->iopriv.intf;
817 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
818 sd_cmd52_read(pintfhdl, addr, 1, &val);
823 u16 SdioLocalCmd52Read2Byte(PADAPTER padapter, u32 addr)
825 struct intf_hdl * pintfhdl;
828 pintfhdl=&padapter->iopriv.intf;
829 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
830 sd_cmd52_read(pintfhdl, addr, 2, (u8*)&val);
832 val = le16_to_cpu(val);
837 u32 SdioLocalCmd52Read4Byte(PADAPTER padapter, u32 addr)
839 struct intf_hdl * pintfhdl;
842 pintfhdl=&padapter->iopriv.intf;
843 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
844 sd_cmd52_read(pintfhdl, addr, 4, (u8*)&val);
846 val = le32_to_cpu(val);
851 u32 SdioLocalCmd53Read4Byte(PADAPTER padapter, u32 addr)
853 struct intf_hdl * pintfhdl;
857 pintfhdl=&padapter->iopriv.intf;
858 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
859 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
860 if ((_FALSE == bMacPwrCtrlOn)
861 #ifdef CONFIG_LPS_LCLK
862 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
866 sd_cmd52_read(pintfhdl, addr, 4, (u8*)&val);
867 val = le32_to_cpu(val);
870 val = sd_read32(pintfhdl, addr, NULL);
875 void SdioLocalCmd52Write1Byte(PADAPTER padapter, u32 addr, u8 v)
877 struct intf_hdl * pintfhdl;
879 pintfhdl=&padapter->iopriv.intf;
880 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
881 sd_cmd52_write(pintfhdl, addr, 1, &v);
884 void SdioLocalCmd52Write2Byte(PADAPTER padapter, u32 addr, u16 v)
886 struct intf_hdl * pintfhdl;
888 pintfhdl=&padapter->iopriv.intf;
889 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
891 sd_cmd52_write(pintfhdl, addr, 2, (u8*)&v);
894 void SdioLocalCmd52Write4Byte(PADAPTER padapter, u32 addr, u32 v)
896 struct intf_hdl * pintfhdl;
898 pintfhdl=&padapter->iopriv.intf;
899 HalSdioGetCmdAddr8723ASdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
901 sd_cmd52_write(pintfhdl, addr, 4, (u8*)&v);
906 DumpLoggedInterruptHistory8723Sdio(
910 HAL_DATA_TYPE *pHalData=GET_HAL_DATA(padapter);
911 u4Byte DebugLevel = DBG_LOUD;
913 if (DBG_Var.DbgPrintIsr == 0)
916 DBG_ChkDrvResource(padapter);
919 if(pHalData->InterruptLog.nISR_RX_REQUEST)
920 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RX_REQUEST[%ld]\t\n", pHalData->InterruptLog.nISR_RX_REQUEST));
922 if(pHalData->InterruptLog.nISR_AVAL)
923 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# AVAL[%ld]\t\n", pHalData->InterruptLog.nISR_AVAL));
925 if(pHalData->InterruptLog.nISR_TXERR)
926 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXERR[%ld]\t\n", pHalData->InterruptLog.nISR_TXERR));
928 if(pHalData->InterruptLog.nISR_RXERR)
929 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RXERR[%ld]\t\n", pHalData->InterruptLog.nISR_RXERR));
931 if(pHalData->InterruptLog.nISR_TXFOVW)
932 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXFOVW[%ld]\t\n", pHalData->InterruptLog.nISR_TXFOVW));
934 if(pHalData->InterruptLog.nISR_RXFOVW)
935 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RXFOVW[%ld]\t\n", pHalData->InterruptLog.nISR_RXFOVW));
937 if(pHalData->InterruptLog.nISR_TXBCNOK)
938 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXBCNOK[%ld]\t\n", pHalData->InterruptLog.nISR_TXBCNOK));
940 if(pHalData->InterruptLog.nISR_TXBCNERR)
941 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXBCNERR[%ld]\t\n", pHalData->InterruptLog.nISR_TXBCNERR));
943 if(pHalData->InterruptLog.nISR_BCNERLY_INT)
944 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# BCNERLY_INT[%ld]\t\n", pHalData->InterruptLog.nISR_BCNERLY_INT));
946 if(pHalData->InterruptLog.nISR_C2HCMD)
947 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# C2HCMD[%ld]\t\n", pHalData->InterruptLog.nISR_C2HCMD));
949 if(pHalData->InterruptLog.nISR_CPWM1)
950 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CPWM1L[%ld]\t\n", pHalData->InterruptLog.nISR_CPWM1));
952 if(pHalData->InterruptLog.nISR_CPWM2)
953 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CPWM2[%ld]\t\n", pHalData->InterruptLog.nISR_CPWM2));
955 if(pHalData->InterruptLog.nISR_HSISR_IND)
956 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# HSISR_IND[%ld]\t\n", pHalData->InterruptLog.nISR_HSISR_IND));
958 if(pHalData->InterruptLog.nISR_GTINT3_IND)
959 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# GTINT3_IND[%ld]\t\n", pHalData->InterruptLog.nISR_GTINT3_IND));
961 if(pHalData->InterruptLog.nISR_GTINT4_IND)
962 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# GTINT4_IND[%ld]\t\n", pHalData->InterruptLog.nISR_GTINT4_IND));
964 if(pHalData->InterruptLog.nISR_PSTIMEOUT)
965 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# PSTIMEOUT[%ld]\t\n", pHalData->InterruptLog.nISR_PSTIMEOUT));
967 if(pHalData->InterruptLog.nISR_OCPINT)
968 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# OCPINT[%ld]\t\n", pHalData->InterruptLog.nISR_OCPINT));
970 if(pHalData->InterruptLog.nISR_ATIMEND)
971 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# ATIMEND[%ld]\t\n", pHalData->InterruptLog.nISR_ATIMEND));
973 if(pHalData->InterruptLog.nISR_ATIMEND_E)
974 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# ATIMEND_E[%ld]\t\n", pHalData->InterruptLog.nISR_ATIMEND_E));
976 if(pHalData->InterruptLog.nISR_CTWEND)
977 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CTWEND[%ld]\t\n", pHalData->InterruptLog.nISR_CTWEND));
981 LogInterruptHistory8723Sdio(
983 PRT_ISR_CONTENT pIsrContent
986 HAL_DATA_TYPE *pHalData=GET_HAL_DATA(padapter);
988 if((pHalData->IntrMask[0] & SDIO_HIMR_RX_REQUEST_MSK) &&
989 (pIsrContent->IntArray[0] & SDIO_HISR_RX_REQUEST))
990 pHalData->InterruptLog.nISR_RX_REQUEST ++;
991 if((pHalData->IntrMask[0] & SDIO_HIMR_AVAL_MSK) &&
992 (pIsrContent->IntArray[0] & SDIO_HISR_AVAL))
993 pHalData->InterruptLog.nISR_AVAL++;
994 if((pHalData->IntrMask[0] & SDIO_HIMR_TXERR_MSK) &&
995 (pIsrContent->IntArray[0] & SDIO_HISR_TXERR))
996 pHalData->InterruptLog.nISR_TXERR++;
997 if((pHalData->IntrMask[0] & SDIO_HIMR_RXERR_MSK) &&
998 (pIsrContent->IntArray[0] & SDIO_HISR_RXERR))
999 pHalData->InterruptLog.nISR_RXERR++;
1000 if((pHalData->IntrMask[0] & SDIO_HIMR_TXFOVW_MSK) &&
1001 (pIsrContent->IntArray[0] & SDIO_HISR_TXFOVW))
1002 pHalData->InterruptLog.nISR_TXFOVW++;
1003 if((pHalData->IntrMask[0] & SDIO_HIMR_RXFOVW_MSK) &&
1004 (pIsrContent->IntArray[0] & SDIO_HISR_RXFOVW))
1005 pHalData->InterruptLog.nISR_RXFOVW++;
1006 if((pHalData->IntrMask[0] & SDIO_HIMR_TXBCNOK_MSK) &&
1007 (pIsrContent->IntArray[0] & SDIO_HISR_TXBCNOK))
1008 pHalData->InterruptLog.nISR_TXBCNOK++;
1009 if((pHalData->IntrMask[0] & SDIO_HIMR_TXBCNERR_MSK) &&
1010 (pIsrContent->IntArray[0] & SDIO_HISR_TXBCNERR))
1011 pHalData->InterruptLog.nISR_TXBCNERR++;
1012 if((pHalData->IntrMask[0] & SDIO_HIMR_BCNERLY_INT_MSK) &&
1013 (pIsrContent->IntArray[0] & SDIO_HISR_BCNERLY_INT))
1014 pHalData->InterruptLog.nISR_BCNERLY_INT ++;
1015 if((pHalData->IntrMask[0] & SDIO_HIMR_C2HCMD_MSK) &&
1016 (pIsrContent->IntArray[0] & SDIO_HISR_C2HCMD))
1017 pHalData->InterruptLog.nISR_C2HCMD++;
1018 if((pHalData->IntrMask[0] & SDIO_HIMR_CPWM1_MSK) &&
1019 (pIsrContent->IntArray[0] & SDIO_HISR_CPWM1))
1020 pHalData->InterruptLog.nISR_CPWM1++;
1021 if((pHalData->IntrMask[0] & SDIO_HIMR_CPWM2_MSK) &&
1022 (pIsrContent->IntArray[0] & SDIO_HISR_CPWM2))
1023 pHalData->InterruptLog.nISR_CPWM2++;
1024 if((pHalData->IntrMask[0] & SDIO_HIMR_HSISR_IND_MSK) &&
1025 (pIsrContent->IntArray[0] & SDIO_HISR_HSISR_IND))
1026 pHalData->InterruptLog.nISR_HSISR_IND++;
1027 if((pHalData->IntrMask[0] & SDIO_HIMR_GTINT3_IND_MSK) &&
1028 (pIsrContent->IntArray[0] & SDIO_HISR_GTINT3_IND))
1029 pHalData->InterruptLog.nISR_GTINT3_IND++;
1030 if((pHalData->IntrMask[0] & SDIO_HIMR_GTINT4_IND_MSK) &&
1031 (pIsrContent->IntArray[0] & SDIO_HISR_GTINT4_IND))
1032 pHalData->InterruptLog.nISR_GTINT4_IND++;
1033 if((pHalData->IntrMask[0] & SDIO_HIMR_PSTIMEOUT_MSK) &&
1034 (pIsrContent->IntArray[0] & SDIO_HISR_PSTIMEOUT))
1035 pHalData->InterruptLog.nISR_PSTIMEOUT++;
1036 if((pHalData->IntrMask[0] & SDIO_HIMR_OCPINT_MSK) &&
1037 (pIsrContent->IntArray[0] & SDIO_HISR_OCPINT))
1038 pHalData->InterruptLog.nISR_OCPINT++;
1039 if((pHalData->IntrMask[0] & SDIO_HIMR_ATIMEND_MSK) &&
1040 (pIsrContent->IntArray[0] & SDIO_HISR_ATIMEND))
1041 pHalData->InterruptLog.nISR_ATIMEND++;
1042 if((pHalData->IntrMask[0] & SDIO_HIMR_ATIMEND_E_MSK) &&
1043 (pIsrContent->IntArray[0] & SDIO_HISR_ATIMEND_E))
1044 pHalData->InterruptLog.nISR_ATIMEND_E++;
1045 if((pHalData->IntrMask[0] & SDIO_HIMR_CTWEND_MSK) &&
1046 (pIsrContent->IntArray[0] & SDIO_HISR_CTWEND))
1047 pHalData->InterruptLog.nISR_CTWEND++;
1052 DumpHardwareProfile8723Sdio(
1053 IN PADAPTER padapter
1056 DumpLoggedInterruptHistory8723Sdio(padapter);
1062 // Initialize SDIO Host Interrupt Mask configuration variables for future use.
1065 // Using SDIO Local register ONLY for configuration.
1067 // Created by Roger, 2011.02.11.
1069 void InitInterrupt8723ASdio(PADAPTER padapter)
1071 PHAL_DATA_TYPE pHalData;
1074 pHalData = GET_HAL_DATA(padapter);
1075 pHalData->sdio_himr = (u32)( \
1076 SDIO_HIMR_RX_REQUEST_MSK |
1077 // SDIO_HIMR_AVAL_MSK |
1078 // SDIO_HIMR_TXERR_MSK |
1079 // SDIO_HIMR_RXERR_MSK |
1080 // SDIO_HIMR_TXFOVW_MSK |
1081 // SDIO_HIMR_RXFOVW_MSK |
1082 // SDIO_HIMR_TXBCNOK_MSK |
1083 // SDIO_HIMR_TXBCNERR_MSK |
1084 // SDIO_HIMR_BCNERLY_INT_MSK |
1085 #ifndef CONFIG_DETECT_C2H_BY_POLLING
1086 #if defined( CONFIG_BT_COEXIST) || defined(CONFIG_MP_INCLUDED)
1087 SDIO_HIMR_C2HCMD_MSK |
1090 #ifndef CONFIG_DETECT_CPWM_BY_POLLING
1091 #ifdef CONFIG_LPS_LCLK
1092 SDIO_HIMR_CPWM1_MSK |
1093 // SDIO_HIMR_CPWM2_MSK |
1096 // SDIO_HIMR_HSISR_IND_MSK |
1097 // SDIO_HIMR_GTINT3_IND_MSK |
1098 // SDIO_HIMR_GTINT4_IND_MSK |
1099 // SDIO_HIMR_PSTIMEOUT_MSK |
1100 // SDIO_HIMR_OCPINT_MSK |
1101 // SDIO_HIMR_ATIMEND_MSK |
1102 // SDIO_HIMR_ATIMEND_E_MSK |
1103 // SDIO_HIMR_CTWEND_MSK |
1109 // Initialize System Host Interrupt Mask configuration variables for future use.
1111 // Created by Roger, 2011.08.03.
1113 void InitSysInterrupt8723ASdio(PADAPTER padapter)
1115 PHAL_DATA_TYPE pHalData;
1118 pHalData = GET_HAL_DATA(padapter);
1120 pHalData->SysIntrMask = ( \
1121 // HSIMR_GPIO12_0_INT_EN |
1122 // HSIMR_SPS_OCP_INT_EN |
1123 // HSIMR_RON_INT_EN |
1124 // HSIMR_PDNINT_EN |
1125 // HSIMR_GPIO9_INT_EN |
1131 // Clear corresponding SDIO Host ISR interrupt service.
1134 // Using SDIO Local register ONLY for configuration.
1136 // Created by Roger, 2011.02.11.
1138 void ClearInterrupt8723ASdio(PADAPTER padapter)
1140 PHAL_DATA_TYPE pHalData;
1144 if (_TRUE == padapter->bSurpriseRemoved)
1147 pHalData = GET_HAL_DATA(padapter);
1148 clear = rtw_zmalloc(4);
1150 // Clear corresponding HISR Content if needed
1151 *(u32*)clear = cpu_to_le32(pHalData->sdio_hisr & MASK_SDIO_HISR_CLEAR);
1154 // Perform write one clear operation
1155 sdio_local_write(padapter, SDIO_REG_HISR, 4, clear);
1158 rtw_mfree(clear, 4);
1163 // Clear corresponding system Host ISR interrupt service.
1166 // Created by Roger, 2011.02.11.
1168 void ClearSysInterrupt8723ASdio(PADAPTER padapter)
1170 PHAL_DATA_TYPE pHalData;
1174 if (_TRUE == padapter->bSurpriseRemoved)
1177 pHalData = GET_HAL_DATA(padapter);
1179 // Clear corresponding HISR Content if needed
1180 clear = pHalData->SysIntrStatus & MASK_HSISR_CLEAR;
1183 // Perform write one clear operation
1184 rtw_write32(padapter, REG_HSISR, clear);
1190 // Enalbe SDIO Host Interrupt Mask configuration on SDIO local domain.
1193 // 1. Using SDIO Local register ONLY for configuration.
1196 // Created by Roger, 2011.02.11.
1198 void EnableInterrupt8723ASdio(PADAPTER padapter)
1200 PHAL_DATA_TYPE pHalData;
1203 #ifdef CONFIG_CONCURRENT_MODE
1204 if ((padapter->isprimary == _FALSE) && padapter->pbuddy_adapter){
1205 padapter = padapter->pbuddy_adapter;
1208 pHalData = GET_HAL_DATA(padapter);
1210 himr = cpu_to_le32(pHalData->sdio_himr);
1211 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8*)&himr);
1213 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1214 ("%s: enable SDIO HIMR=0x%08X\n", __FUNCTION__, pHalData->sdio_himr));
1216 // Update current system IMR settings
1217 himr = rtw_read32(padapter, REG_HSIMR);
1218 rtw_write32(padapter, REG_HSIMR, himr|pHalData->SysIntrMask);
1220 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1221 ("%s: enable HSIMR=0x%08X\n", __FUNCTION__, pHalData->SysIntrMask));
1224 // <Roger_Notes> There are some C2H CMDs have been sent before system interrupt is enabled, e.g., C2H, CPWM.
1225 // So we need to clear all C2H events that FW has notified, otherwise FW won't schedule any commands anymore.
1228 rtw_write8(padapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE);
1233 // Disable SDIO Host IMR configuration to mask unnecessary interrupt service.
1236 // Using SDIO Local register ONLY for configuration.
1238 // Created by Roger, 2011.02.11.
1240 void DisableInterrupt8723ASdio(PADAPTER padapter)
1244 #ifdef CONFIG_CONCURRENT_MODE
1245 if ((padapter->isprimary == _FALSE) && padapter->pbuddy_adapter){
1246 padapter = padapter->pbuddy_adapter;
1249 himr = cpu_to_le32(SDIO_HIMR_DISABLED);
1250 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8*)&himr);
1256 // Update SDIO Host Interrupt Mask configuration on SDIO local domain.
1259 // 1. Using SDIO Local register ONLY for configuration.
1262 // Created by Roger, 2011.02.11.
1264 void UpdateInterruptMask8723ASdio(PADAPTER padapter, u32 AddMSR, u32 RemoveMSR)
1266 HAL_DATA_TYPE *pHalData;
1268 #ifdef CONFIG_CONCURRENT_MODE
1269 if ((padapter->isprimary == _FALSE) && padapter->pbuddy_adapter){
1270 padapter = padapter->pbuddy_adapter;
1273 pHalData = GET_HAL_DATA(padapter);
1276 pHalData->sdio_himr |= AddMSR;
1279 pHalData->sdio_himr &= (~RemoveMSR);
1281 DisableInterrupt8723ASdio(padapter);
1282 EnableInterrupt8723ASdio(padapter);
1285 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
1286 static void sd_recv_loopback(PADAPTER padapter, u32 size)
1288 PLOOPBACKDATA ploopback;
1289 u32 readsize, allocsize;
1294 DBG_8192C("%s: read size=%d\n", __func__, readsize);
1295 allocsize = _RND(readsize, adapter_to_dvobj(padapter)->intf_data.block_transfer_len);
1297 ploopback = padapter->ploopback;
1299 ploopback->rxsize = readsize;
1300 preadbuf = ploopback->rxbuf;
1303 preadbuf = rtw_malloc(allocsize);
1304 if (preadbuf == NULL) {
1305 DBG_8192C("%s: malloc fail size=%d\n", __func__, allocsize);
1310 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1311 sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1314 _rtw_up_sema(&ploopback->sema);
1318 DBG_8192C("%s: drop pkt\n", __func__);
1319 for (i = 0; i < readsize; i+=4) {
1320 DBG_8192C("%08X", *(u32*)(preadbuf + i));
1321 if ((i+4) & 0x1F) printk(" ");
1325 rtw_mfree(preadbuf, allocsize);
1328 #endif // CONFIG_MAC_LOOPBACK_DRIVER
1330 #ifdef CONFIG_SDIO_RX_COPY
1331 static struct recv_buf* sd_recv_rxfifo(PADAPTER padapter, u32 size)
1335 struct recv_priv *precvpriv;
1336 struct recv_buf *precvbuf;
1341 //3 1. alloc recvbuf
1342 precvpriv = &padapter->recvpriv;
1343 precvbuf = rtw_dequeue_recvbuf(&precvpriv->free_recv_buf_queue);
1344 if (precvbuf == NULL) {
1345 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: alloc recvbuf FAIL!\n", __FUNCTION__));
1350 if (precvbuf->pskb == NULL) {
1352 SIZE_PTR alignment=0;
1354 precvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
1358 precvbuf->pskb->dev = padapter->pnetdev;
1360 tmpaddr = (SIZE_PTR)precvbuf->pskb->data;
1361 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
1362 skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
1365 if (precvbuf->pskb == NULL) {
1366 DBG_871X("%s: alloc_skb fail! read=%d\n", __FUNCTION__, readsize);
1371 //3 3. read data from rxfifo
1372 preadbuf = precvbuf->pskb->data;
1373 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1374 ret = sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1376 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __FUNCTION__));
1382 precvbuf->len = readsize;
1383 precvbuf->phead = precvbuf->pskb->head;
1384 precvbuf->pdata = precvbuf->pskb->data;
1385 skb_set_tail_pointer(precvbuf->pskb, readsize);
1386 precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1387 precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1392 static struct recv_buf* sd_recv_rxfifo(PADAPTER padapter, u32 size)
1394 u32 readsize, allocsize, ret;
1397 struct recv_priv *precvpriv;
1398 struct recv_buf *precvbuf;
1404 // align to block size
1405 allocsize = _RND(readsize, adapter_to_dvobj(padapter)->intf_data.block_transfer_len);
1407 ppkt = rtw_skb_alloc(allocsize);
1410 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: alloc_skb fail! alloc=%d read=%d\n", __FUNCTION__, allocsize, readsize));
1414 //3 2. read data from rxfifo
1415 preadbuf = skb_put(ppkt, readsize);
1416 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1417 ret = sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1420 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __FUNCTION__));
1424 //3 3. alloc recvbuf
1425 precvpriv = &padapter->recvpriv;
1426 precvbuf = rtw_dequeue_recvbuf(&precvpriv->free_recv_buf_queue);
1427 if (precvbuf == NULL) {
1429 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: alloc recvbuf FAIL!\n", __FUNCTION__));
1434 precvbuf->pskb = ppkt;
1436 precvbuf->len = ppkt->len;
1438 precvbuf->phead = ppkt->head;
1439 precvbuf->pdata = ppkt->data;
1440 precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1441 precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1447 static void sd_rxhandler(PADAPTER padapter, struct recv_buf *precvbuf)
1449 #ifdef CONFIG_DIRECT_RECV
1450 rtl8723as_recv(padapter, precvbuf);
1451 #else //!CONFIG_DIRECT_RECV
1452 struct recv_priv *precvpriv;
1453 _queue *ppending_queue;
1456 precvpriv = &padapter->recvpriv;
1457 ppending_queue = &precvpriv->recv_buf_pending_queue;
1459 //3 1. enqueue recvbuf
1460 rtw_enqueue_recvbuf(precvbuf, ppending_queue);
1462 //3 2. schedule tasklet
1463 #ifdef PLATFORM_LINUX
1464 tasklet_schedule(&precvpriv->recv_tasklet);
1466 #endif //!CONFIG_DIRECT_RECV
1470 void sd_int_dpc(PADAPTER padapter)
1472 HAL_DATA_TYPE *phal;
1474 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1475 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
1476 phal = GET_HAL_DATA(padapter);
1478 if (phal->sdio_hisr & SDIO_HISR_CPWM1)
1480 struct reportpwrstate_parm report;
1482 #ifdef CONFIG_LPS_RPWM_TIMER
1484 _cancel_timer(&(adapter_to_pwrctl(padapter)->pwr_rpwm_timer), &bcancelled);
1485 #endif // CONFIG_LPS_RPWM_TIMER
1487 _sdio_local_read(padapter, SDIO_REG_HCPWM1, 1, &report.state);
1489 #ifdef CONFIG_LPS_LCLK
1490 //cpwm_int_hdl(padapter, &report);
1491 _set_workitem(&(adapter_to_pwrctl(padapter)->cpwm_event));
1495 if (phal->sdio_hisr & SDIO_HISR_TXERR)
1500 status = rtw_malloc(4);
1503 addr = REG_TXDMA_STATUS;
1504 HalSdioGetCmdAddr8723ASdio(padapter, WLAN_IOREG_DEVICE_ID, addr, &addr);
1505 _sd_read(pintfhdl, addr, 4, status);
1506 _sd_write(pintfhdl, addr, 4, status);
1507 DBG_8192C("%s: SDIO_HISR_TXERR (0x%08x)\n", __func__, le32_to_cpu(*(u32*)status));
1508 rtw_mfree(status, 4);
1510 DBG_8192C("%s: SDIO_HISR_TXERR, but can't allocate memory to read status!\n", __func__);
1514 if (phal->sdio_hisr & SDIO_HISR_TXBCNOK)
1516 DBG_8192C("%s: SDIO_HISR_TXBCNOK\n", __func__);
1519 if (phal->sdio_hisr & SDIO_HISR_TXBCNERR)
1521 DBG_8192C("%s: SDIO_HISR_TXBCNERR\n", __func__);
1524 if (phal->sdio_hisr & SDIO_HISR_C2HCMD)
1526 struct c2h_evt_hdr *c2h_evt;
1528 if ((c2h_evt = (struct c2h_evt_hdr *)rtw_zmalloc(16)) != NULL) {
1529 if (c2h_evt_read(padapter, (u8 *)c2h_evt) == _SUCCESS) {
1530 if (c2h_id_filter_ccx_8723a(c2h_evt->id)) {
1531 /* Handle CCX report here */
1532 rtw_hal_c2h_handler(padapter, c2h_evt);
1533 rtw_mfree((u8*)c2h_evt, 16);
1535 rtw_c2h_wk_cmd(padapter, (u8 *)c2h_evt);
1540 rtw_mfree((u8*)c2h_evt, 16);
1543 /* Error handling for malloc fail */
1544 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, (void*)NULL) != _SUCCESS)
1545 DBG_871X("%s rtw_cbuf_push fail\n", __func__);
1546 _set_workitem(&padapter->evtpriv.c2h_wk);
1550 if (phal->sdio_hisr & SDIO_HISR_RX_REQUEST)
1552 struct recv_buf *precvbuf;
1555 // DBG_8192C("%s: RX Request, size=%d\n", __func__, phal->SdioRxFIFOSize);
1556 phal->sdio_hisr ^= SDIO_HISR_RX_REQUEST;
1558 if (phal->SdioRxFIFOSize == 0)
1560 _sdio_local_read(padapter, SDIO_REG_RX0_REQ_LEN, 2, (u8*)&val);
1561 phal->SdioRxFIFOSize = le16_to_cpu(val);
1562 DBG_8192C("%s: RX_REQUEST, read RXFIFOsize again size=%d\n", __func__, phal->SdioRxFIFOSize);
1565 if (phal->SdioRxFIFOSize != 0)
1567 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
1568 sd_recv_loopback(padapter, phal->SdioRxFIFOSize);
1570 precvbuf = sd_recv_rxfifo(padapter, phal->SdioRxFIFOSize);
1572 sd_rxhandler(padapter, precvbuf);
1577 _sdio_local_read(padapter, SDIO_REG_RX0_REQ_LEN, 2, (u8*)&val);
1578 phal->SdioRxFIFOSize = le16_to_cpu(val);
1579 }while(phal->SdioRxFIFOSize !=0);
1583 void sd_int_hdl(PADAPTER padapter)
1586 HAL_DATA_TYPE *phal;
1589 if ((padapter->bDriverStopped == _TRUE) ||
1590 (padapter->bSurpriseRemoved == _TRUE))
1593 phal = GET_HAL_DATA(padapter);
1595 _sdio_local_read(padapter, SDIO_REG_HISR, 6, data);
1596 phal->sdio_hisr = le32_to_cpu(*(u32*)data);
1597 phal->SdioRxFIFOSize = le16_to_cpu(*(u16*)&data[4]);
1599 if (phal->sdio_hisr & phal->sdio_himr)
1603 phal->sdio_hisr &= phal->sdio_himr;
1606 v32 = phal->sdio_hisr & MASK_SDIO_HISR_CLEAR;
1608 v32 = cpu_to_le32(v32);
1609 _sdio_local_write(padapter, SDIO_REG_HISR, 4, (u8*)&v32);
1612 sd_int_dpc(padapter);
1614 RT_TRACE(_module_hci_ops_c_, _drv_err_,
1615 ("%s: HISR(0x%08x) and HIMR(0x%08x) not match!\n",
1616 __FUNCTION__, phal->sdio_hisr, phal->sdio_himr));
1622 // Query SDIO Local register to query current the number of Free TxPacketBuffer page.
1625 // 1. Running at PASSIVE_LEVEL
1626 // 2. RT_TX_SPINLOCK is NOT acquired.
1628 // Created by Roger, 2011.01.28.
1630 u8 HalQueryTxBufferStatus8723ASdio(PADAPTER padapter)
1632 PHAL_DATA_TYPE phal;
1637 phal = GET_HAL_DATA(padapter);
1639 NumOfFreePage = SdioLocalCmd53Read4Byte(padapter, SDIO_REG_FREE_TXPG);
1641 // _enter_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
1642 _rtw_memcpy(phal->SdioTxFIFOFreePage, &NumOfFreePage, 4);
1643 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1644 ("%s: Free page for HIQ(%#x),MIDQ(%#x),LOWQ(%#x),PUBQ(%#x)\n",
1646 phal->SdioTxFIFOFreePage[HI_QUEUE_IDX],
1647 phal->SdioTxFIFOFreePage[MID_QUEUE_IDX],
1648 phal->SdioTxFIFOFreePage[LOW_QUEUE_IDX],
1649 phal->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]));
1650 // _exit_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);