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 <rtl8723b_hal.h>
23 //#define SDIO_DEBUG_IO 1
28 // The following mapping is for SDIO host local register space.
30 // Creadted by Roger, 2011.01.31.
32 static void HalSdioGetCmdAddr8723BSdio(
41 case SDIO_LOCAL_DEVICE_ID:
42 *pCmdAddr = ((SDIO_LOCAL_DEVICE_ID << 13) | (Addr & SDIO_LOCAL_MSK));
45 case WLAN_IOREG_DEVICE_ID:
46 *pCmdAddr = ((WLAN_IOREG_DEVICE_ID << 13) | (Addr & WLAN_IOREG_MSK));
49 case WLAN_TX_HIQ_DEVICE_ID:
50 *pCmdAddr = ((WLAN_TX_HIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
53 case WLAN_TX_MIQ_DEVICE_ID:
54 *pCmdAddr = ((WLAN_TX_MIQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
57 case WLAN_TX_LOQ_DEVICE_ID:
58 *pCmdAddr = ((WLAN_TX_LOQ_DEVICE_ID << 13) | (Addr & WLAN_FIFO_MSK));
61 case WLAN_RX0FF_DEVICE_ID:
62 *pCmdAddr = ((WLAN_RX0FF_DEVICE_ID << 13) | (Addr & WLAN_RX0FF_MSK));
70 static u8 get_deviceid(u32 addr)
76 pseudoId = (u16)(addr >> 16);
80 devideId = SDIO_LOCAL_DEVICE_ID;
84 devideId = WLAN_IOREG_DEVICE_ID;
88 // devideId = SDIO_FIRMWARE_FIFO;
92 devideId = WLAN_TX_HIQ_DEVICE_ID;
96 devideId = WLAN_TX_MIQ_DEVICE_ID;
100 devideId = WLAN_TX_LOQ_DEVICE_ID;
104 devideId = WLAN_RX0FF_DEVICE_ID;
108 // devideId = (u8)((addr >> 13) & 0xF);
109 devideId = WLAN_IOREG_DEVICE_ID;
118 * HalSdioGetCmdAddr8723BSdio()
120 static u32 _cvrt2ftaddr(const u32 addr, u8 *pdeviceId, u16 *poffset)
127 deviceId = get_deviceid(addr);
132 case SDIO_LOCAL_DEVICE_ID:
133 offset = addr & SDIO_LOCAL_MSK;
136 case WLAN_TX_HIQ_DEVICE_ID:
137 case WLAN_TX_MIQ_DEVICE_ID:
138 case WLAN_TX_LOQ_DEVICE_ID:
139 offset = addr & WLAN_FIFO_MSK;
142 case WLAN_RX0FF_DEVICE_ID:
143 offset = addr & WLAN_RX0FF_MSK;
146 case WLAN_IOREG_DEVICE_ID:
148 deviceId = WLAN_IOREG_DEVICE_ID;
149 offset = addr & WLAN_IOREG_MSK;
152 ftaddr = (deviceId << 13) | offset;
154 if (pdeviceId) *pdeviceId = deviceId;
155 if (poffset) *poffset = offset;
160 u8 sdio_read8(struct intf_hdl *pintfhdl, u32 addr)
166 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
167 val = sd_read8(pintfhdl, ftaddr, NULL);
174 u16 sdio_read16(struct intf_hdl *pintfhdl, u32 addr)
180 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
182 sd_cmd52_read(pintfhdl, ftaddr, 2, (u8*)&val);
183 val = le16_to_cpu(val);
190 u32 sdio_read32(struct intf_hdl *pintfhdl, u32 addr)
203 padapter = pintfhdl->padapter;
204 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
206 bMacPwrCtrlOn = _FALSE;
207 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
208 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
209 || (_FALSE == bMacPwrCtrlOn)
210 #ifdef CONFIG_LPS_LCLK
211 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
216 err = sd_cmd52_read(pintfhdl, ftaddr, 4, (u8*)&val);
220 val = le32_to_cpu(val);
225 DBG_8192C(KERN_ERR "%s: Mac Power off, Read FAIL(%d)! addr=0x%x\n", __func__, err, addr);
226 return SDIO_ERR_VAL32;
231 shift = ftaddr & 0x3;
233 val = sd_read32(pintfhdl, ftaddr, NULL);
237 ptmpbuf = (u8*)rtw_malloc(8);
238 if (NULL == ptmpbuf) {
239 DBG_8192C(KERN_ERR "%s: Allocate memory FAIL!(size=8) addr=0x%x\n", __func__, addr);
240 return SDIO_ERR_VAL32;
244 err = sd_read(pintfhdl, ftaddr, 8, ptmpbuf);
246 return SDIO_ERR_VAL32;
247 _rtw_memcpy(&val, ptmpbuf+shift, 4);
248 val = le32_to_cpu(val);
250 rtw_mfree(ptmpbuf, 8);
258 s32 sdio_readN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pbuf)
270 padapter = pintfhdl->padapter;
273 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
275 bMacPwrCtrlOn = _FALSE;
276 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
277 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
278 || (_FALSE == bMacPwrCtrlOn)
279 #ifdef CONFIG_LPS_LCLK
280 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
284 err = sd_cmd52_read(pintfhdl, ftaddr, cnt, pbuf);
289 shift = ftaddr & 0x3;
291 err = sd_read(pintfhdl, ftaddr, cnt, pbuf);
298 ptmpbuf = rtw_malloc(n);
299 if (NULL == ptmpbuf) return -1;
300 err = sd_read(pintfhdl, ftaddr, n, ptmpbuf);
302 _rtw_memcpy(pbuf, ptmpbuf+shift, cnt);
303 rtw_mfree(ptmpbuf, n);
311 s32 sdio_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
317 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
319 sd_write8(pintfhdl, ftaddr, val, &err);
326 s32 sdio_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
333 ftaddr = _cvrt2ftaddr(addr, NULL, NULL);
334 val = cpu_to_le16(val);
335 err = sd_cmd52_write(pintfhdl, ftaddr, 2, (u8*)&val);
342 s32 sdio_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
354 padapter = pintfhdl->padapter;
357 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
359 bMacPwrCtrlOn = _FALSE;
360 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
361 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
362 || (_FALSE == bMacPwrCtrlOn)
363 #ifdef CONFIG_LPS_LCLK
364 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
368 val = cpu_to_le32(val);
369 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8*)&val);
374 shift = ftaddr & 0x3;
378 sd_write32(pintfhdl, ftaddr, val, &err);
382 val = cpu_to_le32(val);
383 err = sd_cmd52_write(pintfhdl, ftaddr, 4, (u8*)&val);
387 sd_write32(pintfhdl, ftaddr, val, &err);
391 ptmpbuf = (u8*)rtw_malloc(8);
392 if (NULL == ptmpbuf) return (-1);
395 err = sd_read(pintfhdl, ftaddr, 8, ptmpbuf);
397 rtw_mfree(ptmpbuf, 8);
400 val = cpu_to_le32(val);
401 _rtw_memcpy(ptmpbuf+shift, &val, 4);
402 err = sd_write(pintfhdl, ftaddr, 8, ptmpbuf);
404 rtw_mfree(ptmpbuf, 8);
413 s32 sdio_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8* pbuf)
425 padapter = pintfhdl->padapter;
428 ftaddr = _cvrt2ftaddr(addr, &deviceId, &offset);
430 bMacPwrCtrlOn = _FALSE;
431 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
432 if (((deviceId == WLAN_IOREG_DEVICE_ID) && (offset < 0x100))
433 || (_FALSE == bMacPwrCtrlOn)
434 #ifdef CONFIG_LPS_LCLK
435 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
439 err = sd_cmd52_write(pintfhdl, ftaddr, cnt, pbuf);
443 shift = ftaddr & 0x3;
445 err = sd_write(pintfhdl, ftaddr, cnt, pbuf);
452 ptmpbuf = rtw_malloc(n);
453 if (NULL == ptmpbuf) return -1;
454 err = sd_read(pintfhdl, ftaddr, 4, ptmpbuf);
456 rtw_mfree(ptmpbuf, n);
459 _rtw_memcpy(ptmpbuf+shift, pbuf, cnt);
460 err = sd_write(pintfhdl, ftaddr, n, ptmpbuf);
461 rtw_mfree(ptmpbuf, n);
469 u8 sdio_f0_read8(struct intf_hdl *pintfhdl, u32 addr)
475 val = sd_f0_read8(pintfhdl, addr, NULL);
482 void sdio_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
488 err = sdio_readN(pintfhdl, addr, cnt, rmem);
493 void sdio_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
497 sdio_writeN(pintfhdl, addr, cnt, wmem);
505 * Round read size to block size,
506 * and make sure data transfer will be done in one command.
509 * pintfhdl a pointer of intf_hdl
512 * rmem address to put data
515 * _SUCCESS(1) Success
518 static u32 sdio_read_port(
519 struct intf_hdl *pintfhdl,
528 #ifdef SDIO_DYNAMIC_ALLOC_MEM
534 padapter = pintfhdl->padapter;
535 psdio = &adapter_to_dvobj(padapter)->intf_data;
536 phal = GET_HAL_DATA(padapter);
538 HalSdioGetCmdAddr8723BSdio(padapter, addr, phal->SdioRxFIFOCnt++, &addr);
541 if (cnt > psdio->block_transfer_len)
542 cnt = _RND(cnt, psdio->block_transfer_len);
543 // cnt = sdio_align_size(cnt);
546 #ifdef SDIO_DYNAMIC_ALLOC_MEM
548 mem = rtw_malloc(cnt);
550 DBG_8192C(KERN_WARNING "%s: allocate memory %d bytes fail!\n", __func__, cnt);
555 // in this case, caller should gurante the buffer is big enough
556 // to receive data after alignment
560 err = _sd_read(pintfhdl, addr, cnt, mem);
562 #ifdef SDIO_DYNAMIC_ALLOC_MEM
563 if ((oldcnt != cnt) && (oldmem)) {
564 _rtw_memcpy(oldmem, mem, oldcnt);
569 if (err) return _FAIL;
576 * Align write size block size,
577 * and make sure data could be written in one command.
580 * pintfhdl a pointer of intf_hdl
583 * wmem data pointer to write
586 * _SUCCESS(1) Success
589 static u32 sdio_write_port(
590 struct intf_hdl *pintfhdl,
598 struct xmit_buf *xmitbuf = (struct xmit_buf *)mem;
600 padapter = pintfhdl->padapter;
601 psdio = &adapter_to_dvobj(padapter)->intf_data;
603 if (!rtw_is_hw_init_completed(padapter)) {
604 DBG_871X("%s [addr=0x%x cnt=%d] padapter->hw_init_completed == _FALSE\n",__func__,addr,cnt);
609 HalSdioGetCmdAddr8723BSdio(padapter, addr, cnt >> 2, &addr);
611 if (cnt > psdio->block_transfer_len)
612 cnt = _RND(cnt, psdio->block_transfer_len);
613 // cnt = sdio_align_size(cnt);
615 err = sd_write(pintfhdl, addr, cnt, xmitbuf->pdata);
617 rtw_sctx_done_err(&xmitbuf->sctx,
618 err ? RTW_SCTX_DONE_WRITE_PORT_ERR : RTW_SCTX_DONE_SUCCESS);
620 if (err) return _FAIL;
624 void sdio_set_intf_ops(_adapter *padapter, struct _io_ops *pops)
628 pops->_read8 = &sdio_read8;
629 pops->_read16 = &sdio_read16;
630 pops->_read32 = &sdio_read32;
631 pops->_read_mem = &sdio_read_mem;
632 pops->_read_port = &sdio_read_port;
634 pops->_write8 = &sdio_write8;
635 pops->_write16 = &sdio_write16;
636 pops->_write32 = &sdio_write32;
637 pops->_writeN = &sdio_writeN;
638 pops->_write_mem = &sdio_write_mem;
639 pops->_write_port = &sdio_write_port;
641 pops->_sd_f0_read8 = sdio_f0_read8;
647 * Todo: align address to 4 bytes.
649 s32 _sdio_local_read(
655 struct intf_hdl * pintfhdl;
662 pintfhdl=&padapter->iopriv.intf;
664 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
666 bMacPwrCtrlOn = _FALSE;
667 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
668 if (_FALSE == bMacPwrCtrlOn)
670 err = _sd_cmd52_read(pintfhdl, addr, cnt, pbuf);
675 ptmpbuf = (u8*)rtw_malloc(n);
679 err = _sd_read(pintfhdl, addr, n, ptmpbuf);
681 _rtw_memcpy(pbuf, ptmpbuf, cnt);
684 rtw_mfree(ptmpbuf, n);
690 * Todo: align address to 4 bytes.
698 struct intf_hdl * pintfhdl;
704 pintfhdl=&padapter->iopriv.intf;
706 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
708 bMacPwrCtrlOn = _FALSE;
709 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
710 if ((_FALSE == bMacPwrCtrlOn)
711 #ifdef CONFIG_LPS_LCLK
712 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
716 err = sd_cmd52_read(pintfhdl, addr, cnt, pbuf);
721 ptmpbuf = (u8*)rtw_malloc(n);
725 err = sd_read(pintfhdl, addr, n, ptmpbuf);
727 _rtw_memcpy(pbuf, ptmpbuf, cnt);
730 rtw_mfree(ptmpbuf, n);
736 * Todo: align address to 4 bytes.
738 s32 _sdio_local_write(
744 struct intf_hdl * pintfhdl;
750 DBG_8192C("%s, address must be 4 bytes alignment\n", __FUNCTION__);
753 DBG_8192C("%s, size must be the multiple of 4 \n", __FUNCTION__);
755 pintfhdl=&padapter->iopriv.intf;
757 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
759 bMacPwrCtrlOn = _FALSE;
760 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
761 if ((_FALSE == bMacPwrCtrlOn)
762 #ifdef CONFIG_LPS_LCLK
763 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
767 err = _sd_cmd52_write(pintfhdl, addr, cnt, pbuf);
771 ptmpbuf = (u8*)rtw_malloc(cnt);
775 _rtw_memcpy(ptmpbuf, pbuf, cnt);
777 err = _sd_write(pintfhdl, addr, cnt, ptmpbuf);
780 rtw_mfree(ptmpbuf, cnt);
786 * Todo: align address to 4 bytes.
788 s32 sdio_local_write(
794 struct intf_hdl * pintfhdl;
800 DBG_8192C("%s, address must be 4 bytes alignment\n", __FUNCTION__);
803 DBG_8192C("%s, size must be the multiple of 4 \n", __FUNCTION__);
805 pintfhdl=&padapter->iopriv.intf;
807 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
809 bMacPwrCtrlOn = _FALSE;
810 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
811 if ((_FALSE == bMacPwrCtrlOn)
812 #ifdef CONFIG_LPS_LCLK
813 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
817 err = sd_cmd52_write(pintfhdl, addr, cnt, pbuf);
821 ptmpbuf = (u8*)rtw_malloc(cnt);
825 _rtw_memcpy(ptmpbuf, pbuf, cnt);
827 err = sd_write(pintfhdl, addr, cnt, ptmpbuf);
830 rtw_mfree(ptmpbuf, cnt);
835 u8 SdioLocalCmd52Read1Byte(PADAPTER padapter, u32 addr)
838 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
840 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
841 sd_cmd52_read(pintfhdl, addr, 1, &val);
846 u16 SdioLocalCmd52Read2Byte(PADAPTER padapter, u32 addr)
849 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
851 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
852 sd_cmd52_read(pintfhdl, addr, 2, (u8*)&val);
854 val = le16_to_cpu(val);
859 u32 SdioLocalCmd52Read4Byte(PADAPTER padapter, u32 addr)
862 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
864 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
865 sd_cmd52_read(pintfhdl, addr, 4, (u8*)&val);
867 val = le32_to_cpu(val);
872 u32 SdioLocalCmd53Read4Byte(PADAPTER padapter, u32 addr)
877 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
879 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
880 bMacPwrCtrlOn = _FALSE;
881 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
882 if ((_FALSE == bMacPwrCtrlOn)
883 #ifdef CONFIG_LPS_LCLK
884 || (_TRUE == adapter_to_pwrctl(padapter)->bFwCurrentInPSMode)
888 sd_cmd52_read(pintfhdl, addr, 4, (u8*)&val);
889 val = le32_to_cpu(val);
892 val = sd_read32(pintfhdl, addr, NULL);
897 void SdioLocalCmd52Write1Byte(PADAPTER padapter, u32 addr, u8 v)
899 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
901 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
902 sd_cmd52_write(pintfhdl, addr, 1, &v);
905 void SdioLocalCmd52Write2Byte(PADAPTER padapter, u32 addr, u16 v)
907 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
909 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
911 sd_cmd52_write(pintfhdl, addr, 2, (u8*)&v);
914 void SdioLocalCmd52Write4Byte(PADAPTER padapter, u32 addr, u32 v)
916 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
917 HalSdioGetCmdAddr8723BSdio(padapter, SDIO_LOCAL_DEVICE_ID, addr, &addr);
919 sd_cmd52_write(pintfhdl, addr, 4, (u8*)&v);
924 DumpLoggedInterruptHistory8723Sdio(
928 HAL_DATA_TYPE *pHalData=GET_HAL_DATA(padapter);
929 u4Byte DebugLevel = DBG_LOUD;
931 if (DBG_Var.DbgPrintIsr == 0)
934 DBG_ChkDrvResource(padapter);
937 if(pHalData->InterruptLog.nISR_RX_REQUEST)
938 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RX_REQUEST[%ld]\t\n", pHalData->InterruptLog.nISR_RX_REQUEST));
940 if(pHalData->InterruptLog.nISR_AVAL)
941 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# AVAL[%ld]\t\n", pHalData->InterruptLog.nISR_AVAL));
943 if(pHalData->InterruptLog.nISR_TXERR)
944 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXERR[%ld]\t\n", pHalData->InterruptLog.nISR_TXERR));
946 if(pHalData->InterruptLog.nISR_RXERR)
947 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RXERR[%ld]\t\n", pHalData->InterruptLog.nISR_RXERR));
949 if(pHalData->InterruptLog.nISR_TXFOVW)
950 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXFOVW[%ld]\t\n", pHalData->InterruptLog.nISR_TXFOVW));
952 if(pHalData->InterruptLog.nISR_RXFOVW)
953 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# RXFOVW[%ld]\t\n", pHalData->InterruptLog.nISR_RXFOVW));
955 if(pHalData->InterruptLog.nISR_TXBCNOK)
956 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXBCNOK[%ld]\t\n", pHalData->InterruptLog.nISR_TXBCNOK));
958 if(pHalData->InterruptLog.nISR_TXBCNERR)
959 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# TXBCNERR[%ld]\t\n", pHalData->InterruptLog.nISR_TXBCNERR));
961 if(pHalData->InterruptLog.nISR_BCNERLY_INT)
962 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# BCNERLY_INT[%ld]\t\n", pHalData->InterruptLog.nISR_BCNERLY_INT));
964 if(pHalData->InterruptLog.nISR_C2HCMD)
965 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# C2HCMD[%ld]\t\n", pHalData->InterruptLog.nISR_C2HCMD));
967 if(pHalData->InterruptLog.nISR_CPWM1)
968 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CPWM1L[%ld]\t\n", pHalData->InterruptLog.nISR_CPWM1));
970 if(pHalData->InterruptLog.nISR_CPWM2)
971 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CPWM2[%ld]\t\n", pHalData->InterruptLog.nISR_CPWM2));
973 if(pHalData->InterruptLog.nISR_HSISR_IND)
974 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# HSISR_IND[%ld]\t\n", pHalData->InterruptLog.nISR_HSISR_IND));
976 if(pHalData->InterruptLog.nISR_GTINT3_IND)
977 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# GTINT3_IND[%ld]\t\n", pHalData->InterruptLog.nISR_GTINT3_IND));
979 if(pHalData->InterruptLog.nISR_GTINT4_IND)
980 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# GTINT4_IND[%ld]\t\n", pHalData->InterruptLog.nISR_GTINT4_IND));
982 if(pHalData->InterruptLog.nISR_PSTIMEOUT)
983 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# PSTIMEOUT[%ld]\t\n", pHalData->InterruptLog.nISR_PSTIMEOUT));
985 if(pHalData->InterruptLog.nISR_OCPINT)
986 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# OCPINT[%ld]\t\n", pHalData->InterruptLog.nISR_OCPINT));
988 if(pHalData->InterruptLog.nISR_ATIMEND)
989 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# ATIMEND[%ld]\t\n", pHalData->InterruptLog.nISR_ATIMEND));
991 if(pHalData->InterruptLog.nISR_ATIMEND_E)
992 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# ATIMEND_E[%ld]\t\n", pHalData->InterruptLog.nISR_ATIMEND_E));
994 if(pHalData->InterruptLog.nISR_CTWEND)
995 RT_TRACE(COMP_SEND|COMP_RECV, DebugLevel, ("# CTWEND[%ld]\t\n", pHalData->InterruptLog.nISR_CTWEND));
999 LogInterruptHistory8723Sdio(
1001 PRT_ISR_CONTENT pIsrContent
1004 HAL_DATA_TYPE *pHalData=GET_HAL_DATA(padapter);
1006 if((pHalData->IntrMask[0] & SDIO_HIMR_RX_REQUEST_MSK) &&
1007 (pIsrContent->IntArray[0] & SDIO_HISR_RX_REQUEST))
1008 pHalData->InterruptLog.nISR_RX_REQUEST ++;
1009 if((pHalData->IntrMask[0] & SDIO_HIMR_AVAL_MSK) &&
1010 (pIsrContent->IntArray[0] & SDIO_HISR_AVAL))
1011 pHalData->InterruptLog.nISR_AVAL++;
1012 if((pHalData->IntrMask[0] & SDIO_HIMR_TXERR_MSK) &&
1013 (pIsrContent->IntArray[0] & SDIO_HISR_TXERR))
1014 pHalData->InterruptLog.nISR_TXERR++;
1015 if((pHalData->IntrMask[0] & SDIO_HIMR_RXERR_MSK) &&
1016 (pIsrContent->IntArray[0] & SDIO_HISR_RXERR))
1017 pHalData->InterruptLog.nISR_RXERR++;
1018 if((pHalData->IntrMask[0] & SDIO_HIMR_TXFOVW_MSK) &&
1019 (pIsrContent->IntArray[0] & SDIO_HISR_TXFOVW))
1020 pHalData->InterruptLog.nISR_TXFOVW++;
1021 if((pHalData->IntrMask[0] & SDIO_HIMR_RXFOVW_MSK) &&
1022 (pIsrContent->IntArray[0] & SDIO_HISR_RXFOVW))
1023 pHalData->InterruptLog.nISR_RXFOVW++;
1024 if((pHalData->IntrMask[0] & SDIO_HIMR_TXBCNOK_MSK) &&
1025 (pIsrContent->IntArray[0] & SDIO_HISR_TXBCNOK))
1026 pHalData->InterruptLog.nISR_TXBCNOK++;
1027 if((pHalData->IntrMask[0] & SDIO_HIMR_TXBCNERR_MSK) &&
1028 (pIsrContent->IntArray[0] & SDIO_HISR_TXBCNERR))
1029 pHalData->InterruptLog.nISR_TXBCNERR++;
1030 if((pHalData->IntrMask[0] & SDIO_HIMR_BCNERLY_INT_MSK) &&
1031 (pIsrContent->IntArray[0] & SDIO_HISR_BCNERLY_INT))
1032 pHalData->InterruptLog.nISR_BCNERLY_INT ++;
1033 if((pHalData->IntrMask[0] & SDIO_HIMR_C2HCMD_MSK) &&
1034 (pIsrContent->IntArray[0] & SDIO_HISR_C2HCMD))
1035 pHalData->InterruptLog.nISR_C2HCMD++;
1036 if((pHalData->IntrMask[0] & SDIO_HIMR_CPWM1_MSK) &&
1037 (pIsrContent->IntArray[0] & SDIO_HISR_CPWM1))
1038 pHalData->InterruptLog.nISR_CPWM1++;
1039 if((pHalData->IntrMask[0] & SDIO_HIMR_CPWM2_MSK) &&
1040 (pIsrContent->IntArray[0] & SDIO_HISR_CPWM2))
1041 pHalData->InterruptLog.nISR_CPWM2++;
1042 if((pHalData->IntrMask[0] & SDIO_HIMR_HSISR_IND_MSK) &&
1043 (pIsrContent->IntArray[0] & SDIO_HISR_HSISR_IND))
1044 pHalData->InterruptLog.nISR_HSISR_IND++;
1045 if((pHalData->IntrMask[0] & SDIO_HIMR_GTINT3_IND_MSK) &&
1046 (pIsrContent->IntArray[0] & SDIO_HISR_GTINT3_IND))
1047 pHalData->InterruptLog.nISR_GTINT3_IND++;
1048 if((pHalData->IntrMask[0] & SDIO_HIMR_GTINT4_IND_MSK) &&
1049 (pIsrContent->IntArray[0] & SDIO_HISR_GTINT4_IND))
1050 pHalData->InterruptLog.nISR_GTINT4_IND++;
1051 if((pHalData->IntrMask[0] & SDIO_HIMR_PSTIMEOUT_MSK) &&
1052 (pIsrContent->IntArray[0] & SDIO_HISR_PSTIMEOUT))
1053 pHalData->InterruptLog.nISR_PSTIMEOUT++;
1054 if((pHalData->IntrMask[0] & SDIO_HIMR_OCPINT_MSK) &&
1055 (pIsrContent->IntArray[0] & SDIO_HISR_OCPINT))
1056 pHalData->InterruptLog.nISR_OCPINT++;
1057 if((pHalData->IntrMask[0] & SDIO_HIMR_ATIMEND_MSK) &&
1058 (pIsrContent->IntArray[0] & SDIO_HISR_ATIMEND))
1059 pHalData->InterruptLog.nISR_ATIMEND++;
1060 if((pHalData->IntrMask[0] & SDIO_HIMR_ATIMEND_E_MSK) &&
1061 (pIsrContent->IntArray[0] & SDIO_HISR_ATIMEND_E))
1062 pHalData->InterruptLog.nISR_ATIMEND_E++;
1063 if((pHalData->IntrMask[0] & SDIO_HIMR_CTWEND_MSK) &&
1064 (pIsrContent->IntArray[0] & SDIO_HISR_CTWEND))
1065 pHalData->InterruptLog.nISR_CTWEND++;
1070 DumpHardwareProfile8723Sdio(
1071 IN PADAPTER padapter
1074 DumpLoggedInterruptHistory8723Sdio(padapter);
1078 static s32 ReadInterrupt8723BSdio(PADAPTER padapter, u32 *phisr)
1087 himr = GET_HAL_DATA(padapter)->sdio_himr;
1089 // decide how many bytes need to be read
1098 while (hisr_len != 0)
1101 val8 = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HISR+hisr_len);
1102 hisr |= (val8 << (8*hisr_len));
1112 // Initialize SDIO Host Interrupt Mask configuration variables for future use.
1115 // Using SDIO Local register ONLY for configuration.
1117 // Created by Roger, 2011.02.11.
1119 void InitInterrupt8723BSdio(PADAPTER padapter)
1121 PHAL_DATA_TYPE pHalData;
1124 pHalData = GET_HAL_DATA(padapter);
1125 pHalData->sdio_himr = (u32)( \
1126 SDIO_HIMR_RX_REQUEST_MSK |
1127 #ifdef CONFIG_SDIO_TX_ENABLE_AVAL_INT
1128 SDIO_HIMR_AVAL_MSK |
1130 // SDIO_HIMR_TXERR_MSK |
1131 // SDIO_HIMR_RXERR_MSK |
1132 // SDIO_HIMR_TXFOVW_MSK |
1133 // SDIO_HIMR_RXFOVW_MSK |
1134 // SDIO_HIMR_TXBCNOK_MSK |
1135 // SDIO_HIMR_TXBCNERR_MSK |
1136 // SDIO_HIMR_BCNERLY_INT_MSK |
1137 // SDIO_HIMR_C2HCMD_MSK |
1138 #if defined(CONFIG_LPS_LCLK) && !defined(CONFIG_DETECT_CPWM_BY_POLLING)
1139 SDIO_HIMR_CPWM1_MSK |
1140 #endif // CONFIG_LPS_LCLK && !CONFIG_DETECT_CPWM_BY_POLLING
1141 #ifdef CONFIG_WOWLAN
1142 SDIO_HIMR_CPWM2_MSK |
1145 // SDIO_HIMR_HSISR_IND_MSK |
1146 // SDIO_HIMR_GTINT3_IND_MSK |
1147 // SDIO_HIMR_GTINT4_IND_MSK |
1148 // SDIO_HIMR_PSTIMEOUT_MSK |
1149 // SDIO_HIMR_OCPINT_MSK |
1150 // SDIO_HIMR_ATIMEND_MSK |
1151 // SDIO_HIMR_ATIMEND_E_MSK |
1152 // SDIO_HIMR_CTWEND_MSK |
1158 // Initialize System Host Interrupt Mask configuration variables for future use.
1160 // Created by Roger, 2011.08.03.
1162 void InitSysInterrupt8723BSdio(PADAPTER padapter)
1164 PHAL_DATA_TYPE pHalData;
1167 pHalData = GET_HAL_DATA(padapter);
1169 pHalData->SysIntrMask = ( \
1170 // HSIMR_GPIO12_0_INT_EN |
1171 // HSIMR_SPS_OCP_INT_EN |
1172 // HSIMR_RON_INT_EN |
1173 // HSIMR_PDNINT_EN |
1174 // HSIMR_GPIO9_INT_EN |
1178 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
1181 // Clear corresponding SDIO Host ISR interrupt service.
1184 // Using SDIO Local register ONLY for configuration.
1186 // Created by Roger, 2011.02.11.
1188 void ClearInterrupt8723BSdio(PADAPTER padapter)
1190 PHAL_DATA_TYPE pHalData;
1194 if (rtw_is_surprise_removed(padapter))
1197 pHalData = GET_HAL_DATA(padapter);
1198 clear = rtw_zmalloc(4);
1200 // Clear corresponding HISR Content if needed
1201 *(u32*)clear = cpu_to_le32(pHalData->sdio_hisr & MASK_SDIO_HISR_CLEAR);
1204 // Perform write one clear operation
1205 sdio_local_write(padapter, SDIO_REG_HISR, 4, clear);
1208 rtw_mfree(clear, 4);
1214 // Clear corresponding system Host ISR interrupt service.
1217 // Created by Roger, 2011.02.11.
1219 void ClearSysInterrupt8723BSdio(PADAPTER padapter)
1221 PHAL_DATA_TYPE pHalData;
1225 if (rtw_is_surprise_removed(padapter))
1228 pHalData = GET_HAL_DATA(padapter);
1230 // Clear corresponding HISR Content if needed
1231 clear = pHalData->SysIntrStatus & MASK_HSISR_CLEAR;
1234 // Perform write one clear operation
1235 rtw_write32(padapter, REG_HSISR, clear);
1241 // Enalbe SDIO Host Interrupt Mask configuration on SDIO local domain.
1244 // 1. Using SDIO Local register ONLY for configuration.
1247 // Created by Roger, 2011.02.11.
1249 void EnableInterrupt8723BSdio(PADAPTER padapter)
1251 PHAL_DATA_TYPE pHalData;
1254 pHalData = GET_HAL_DATA(padapter);
1256 himr = cpu_to_le32(pHalData->sdio_himr);
1257 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8*)&himr);
1259 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1260 ("%s: enable SDIO HIMR=0x%08X\n", __FUNCTION__, pHalData->sdio_himr));
1262 // Update current system IMR settings
1263 himr = rtw_read32(padapter, REG_HSIMR);
1264 rtw_write32(padapter, REG_HSIMR, himr|pHalData->SysIntrMask);
1266 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1267 ("%s: enable HSIMR=0x%08X\n", __FUNCTION__, pHalData->SysIntrMask));
1270 // <Roger_Notes> There are some C2H CMDs have been sent before system interrupt is enabled, e.g., C2H, CPWM.
1271 // So we need to clear all C2H events that FW has notified, otherwise FW won't schedule any commands anymore.
1274 rtw_write8(padapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE);
1279 // Disable SDIO Host IMR configuration to mask unnecessary interrupt service.
1282 // Using SDIO Local register ONLY for configuration.
1284 // Created by Roger, 2011.02.11.
1286 void DisableInterrupt8723BSdio(PADAPTER padapter)
1290 himr = cpu_to_le32(SDIO_HIMR_DISABLED);
1291 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8*)&himr);
1297 // Using 0x100 to check the power status of FW.
1300 // Using SDIO Local register ONLY for configuration.
1302 // Created by Isaac, 2013.09.10.
1304 u8 CheckIPSStatus(PADAPTER padapter)
1306 DBG_871X("%s(): Read 0x100=0x%02x 0x86=0x%02x\n", __func__,
1307 rtw_read8(padapter, 0x100),rtw_read8(padapter, 0x86));
1309 if (rtw_read8(padapter, 0x100) == 0xEA)
1315 #ifdef CONFIG_WOWLAN
1316 void DisableInterruptButCpwm28723BSdio(PADAPTER padapter)
1320 sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8*)&tmp);
1321 DBG_871X("DisableInterruptButCpwm28723BSdio(): Read SDIO_REG_HIMR: 0x%08x\n", tmp);
1323 himr = cpu_to_le32(SDIO_HIMR_DISABLED)|SDIO_HIMR_CPWM2_MSK;
1324 sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8*)&himr);
1326 sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8*)&tmp);
1327 DBG_871X("DisableInterruptButCpwm28723BSdio(): Read again SDIO_REG_HIMR: 0x%08x\n", tmp);
1329 #endif //CONFIG_WOWLAN
1332 // Update SDIO Host Interrupt Mask configuration on SDIO local domain.
1335 // 1. Using SDIO Local register ONLY for configuration.
1338 // Created by Roger, 2011.02.11.
1340 void UpdateInterruptMask8723BSdio(PADAPTER padapter, u32 AddMSR, u32 RemoveMSR)
1342 HAL_DATA_TYPE *pHalData;
1344 pHalData = GET_HAL_DATA(padapter);
1347 pHalData->sdio_himr |= AddMSR;
1350 pHalData->sdio_himr &= (~RemoveMSR);
1352 DisableInterrupt8723BSdio(padapter);
1353 EnableInterrupt8723BSdio(padapter);
1356 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
1357 static void sd_recv_loopback(PADAPTER padapter, u32 size)
1359 PLOOPBACKDATA ploopback;
1360 u32 readsize, allocsize;
1365 DBG_8192C("%s: read size=%d\n", __func__, readsize);
1366 allocsize = _RND(readsize, adapter_to_dvobj(padapter)->intf_data.block_transfer_len);
1368 ploopback = padapter->ploopback;
1370 ploopback->rxsize = readsize;
1371 preadbuf = ploopback->rxbuf;
1374 preadbuf = rtw_malloc(allocsize);
1375 if (preadbuf == NULL) {
1376 DBG_8192C("%s: malloc fail size=%d\n", __func__, allocsize);
1381 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1382 sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1385 _rtw_up_sema(&ploopback->sema);
1389 DBG_8192C("%s: drop pkt\n", __func__);
1390 for (i = 0; i < readsize; i+=4) {
1391 DBG_8192C("%08X", *(u32*)(preadbuf + i));
1392 if ((i+4) & 0x1F) printk(" ");
1396 rtw_mfree(preadbuf, allocsize);
1399 #endif // CONFIG_MAC_LOOPBACK_DRIVER
1401 #ifdef CONFIG_SDIO_RX_COPY
1402 static struct recv_buf* sd_recv_rxfifo(PADAPTER padapter, u32 size)
1406 struct recv_priv *precvpriv;
1407 struct recv_buf *precvbuf;
1413 // Patch for some SDIO Host 4 bytes issue
1415 readsize = RND4(size);
1418 //3 1. alloc recvbuf
1419 precvpriv = &padapter->recvpriv;
1420 precvbuf = rtw_dequeue_recvbuf(&precvpriv->free_recv_buf_queue);
1421 if (precvbuf == NULL) {
1422 DBG_871X_LEVEL(_drv_err_, "%s: alloc recvbuf FAIL!\n", __FUNCTION__);
1427 if (precvbuf->pskb == NULL) {
1429 SIZE_PTR alignment=0;
1431 precvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
1432 if (precvbuf->pskb == NULL) {
1433 DBG_871X("%s: alloc_skb fail! read=%d\n", __FUNCTION__, readsize);
1434 rtw_enqueue_recvbuf(precvbuf, &precvpriv->free_recv_buf_queue);
1438 precvbuf->pskb->dev = padapter->pnetdev;
1440 tmpaddr = (SIZE_PTR)precvbuf->pskb->data;
1441 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
1442 skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
1445 //3 3. read data from rxfifo
1446 preadbuf = precvbuf->pskb->data;
1447 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1448 ret = sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1450 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __FUNCTION__));
1451 rtw_enqueue_recvbuf(precvbuf, &precvpriv->free_recv_buf_queue);
1456 precvbuf->len = size;
1457 precvbuf->phead = precvbuf->pskb->head;
1458 precvbuf->pdata = precvbuf->pskb->data;
1459 skb_set_tail_pointer(precvbuf->pskb, size);
1460 precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1461 precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1465 #else // !CONFIG_SDIO_RX_COPY
1466 static struct recv_buf* sd_recv_rxfifo(PADAPTER padapter, u32 size)
1468 u32 sdioblksize, readsize, allocsize, ret;
1471 struct recv_priv *precvpriv;
1472 struct recv_buf *precvbuf;
1475 sdioblksize = adapter_to_dvobj(padapter)->intf_data.block_transfer_len;
1479 // Patch for some SDIO Host 4 bytes issue
1481 readsize = RND4(size);
1485 // align to block size
1486 if (readsize > sdioblksize)
1487 allocsize = _RND(readsize, sdioblksize);
1489 allocsize = readsize;
1491 ppkt = rtw_skb_alloc(allocsize);
1494 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: alloc_skb fail! alloc=%d read=%d\n", __FUNCTION__, allocsize, readsize));
1498 //3 2. read data from rxfifo
1499 preadbuf = skb_put(ppkt, size);
1500 // rtw_read_port(padapter, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1501 ret = sdio_read_port(&padapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, preadbuf);
1504 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("%s: read port FAIL!\n", __FUNCTION__));
1508 //3 3. alloc recvbuf
1509 precvpriv = &padapter->recvpriv;
1510 precvbuf = rtw_dequeue_recvbuf(&precvpriv->free_recv_buf_queue);
1511 if (precvbuf == NULL) {
1513 DBG_871X_LEVEL(_drv_err_, "%s: alloc recvbuf FAIL!\n", __FUNCTION__);
1518 precvbuf->pskb = ppkt;
1520 precvbuf->len = ppkt->len;
1522 precvbuf->phead = ppkt->head;
1523 precvbuf->pdata = ppkt->data;
1524 precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1525 precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1529 #endif // !CONFIG_SDIO_RX_COPY
1531 static void sd_rxhandler(PADAPTER padapter, struct recv_buf *precvbuf)
1533 struct recv_priv *precvpriv;
1534 _queue *ppending_queue;
1537 precvpriv = &padapter->recvpriv;
1538 ppending_queue = &precvpriv->recv_buf_pending_queue;
1540 //3 1. enqueue recvbuf
1541 rtw_enqueue_recvbuf(precvbuf, ppending_queue);
1543 //3 2. schedule tasklet
1544 #ifdef PLATFORM_LINUX
1545 tasklet_schedule(&precvpriv->recv_tasklet);
1549 void sd_int_dpc(PADAPTER padapter)
1551 PHAL_DATA_TYPE phal;
1552 struct dvobj_priv *dvobj;
1553 struct intf_hdl * pintfhdl=&padapter->iopriv.intf;
1554 struct pwrctrl_priv *pwrctl;
1557 phal = GET_HAL_DATA(padapter);
1558 dvobj = adapter_to_dvobj(padapter);
1559 pwrctl = dvobj_to_pwrctl(dvobj);
1561 #ifdef CONFIG_SDIO_TX_ENABLE_AVAL_INT
1562 if (phal->sdio_hisr & SDIO_HISR_AVAL)
1567 _sdio_local_read(padapter, SDIO_REG_FREE_TXPG, 4, freepage);
1568 //_enter_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
1569 //_rtw_memcpy(phal->SdioTxFIFOFreePage, freepage, 4);
1570 //_exit_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
1571 //DBG_871X("SDIO_HISR_AVAL, Tx Free Page = 0x%x%x%x%x\n",
1576 _rtw_up_sema(&(padapter->xmitpriv.xmit_sema));
1579 if (phal->sdio_hisr & SDIO_HISR_CPWM1)
1581 struct reportpwrstate_parm report;
1583 #ifdef CONFIG_LPS_RPWM_TIMER
1585 _cancel_timer(&(pwrctl->pwr_rpwm_timer), &bcancelled);
1586 #endif // CONFIG_LPS_RPWM_TIMER
1588 report.state = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HCPWM1_8723B);
1590 #ifdef CONFIG_LPS_LCLK
1591 //cpwm_int_hdl(padapter, &report);
1592 _set_workitem(&(pwrctl->cpwm_event));
1596 if (phal->sdio_hisr & SDIO_HISR_TXERR)
1601 status = rtw_malloc(4);
1604 addr = REG_TXDMA_STATUS;
1605 HalSdioGetCmdAddr8723BSdio(padapter, WLAN_IOREG_DEVICE_ID, addr, &addr);
1606 _sd_read(pintfhdl, addr, 4, status);
1607 _sd_write(pintfhdl, addr, 4, status);
1608 DBG_8192C("%s: SDIO_HISR_TXERR (0x%08x)\n", __func__, le32_to_cpu(*(u32*)status));
1609 rtw_mfree(status, 4);
1611 DBG_8192C("%s: SDIO_HISR_TXERR, but can't allocate memory to read status!\n", __func__);
1615 if (phal->sdio_hisr & SDIO_HISR_TXBCNOK)
1617 DBG_8192C("%s: SDIO_HISR_TXBCNOK\n", __func__);
1620 if (phal->sdio_hisr & SDIO_HISR_TXBCNERR)
1622 DBG_8192C("%s: SDIO_HISR_TXBCNERR\n", __func__);
1624 #ifndef CONFIG_C2H_PACKET_EN
1625 if (phal->sdio_hisr & SDIO_HISR_C2HCMD)
1627 struct c2h_evt_hdr_88xx *c2h_evt;
1629 DBG_8192C("%s: C2H Command\n", __func__);
1630 if ((c2h_evt = (struct c2h_evt_hdr_88xx*)rtw_zmalloc(16)) != NULL) {
1631 if (rtw_hal_c2h_evt_read(padapter, (u8 *)c2h_evt) == _SUCCESS) {
1632 if (c2h_id_filter_ccx_8723b((u8 *)c2h_evt)) {
1633 /* Handle CCX report here */
1634 rtw_hal_c2h_handler(padapter, (u8 *)c2h_evt);
1635 rtw_mfree((u8*)c2h_evt, 16);
1637 rtw_c2h_wk_cmd(padapter, (u8 *)c2h_evt);
1641 /* Error handling for malloc fail */
1642 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, (void*)NULL) != _SUCCESS)
1643 DBG_871X("%s rtw_cbuf_push fail\n", __func__);
1644 _set_workitem(&padapter->evtpriv.c2h_wk);
1649 if (phal->sdio_hisr & SDIO_HISR_RXFOVW)
1651 DBG_8192C("%s: Rx Overflow\n", __func__);
1653 if (phal->sdio_hisr & SDIO_HISR_RXERR)
1655 DBG_8192C("%s: Rx Error\n", __func__);
1658 if (phal->sdio_hisr & SDIO_HISR_RX_REQUEST)
1660 struct recv_buf *precvbuf;
1661 int alloc_fail_time=0;
1664 // DBG_8192C("%s: RX Request, size=%d\n", __func__, phal->SdioRxFIFOSize);
1665 phal->sdio_hisr ^= SDIO_HISR_RX_REQUEST;
1667 phal->SdioRxFIFOSize = SdioLocalCmd52Read2Byte(padapter, SDIO_REG_RX0_REQ_LEN);
1668 if (phal->SdioRxFIFOSize != 0)
1670 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
1671 sd_recv_loopback(padapter, phal->SdioRxFIFOSize);
1673 precvbuf = sd_recv_rxfifo(padapter, phal->SdioRxFIFOSize);
1675 sd_rxhandler(padapter, precvbuf);
1679 DBG_871X("%s: recv fail!(time=%d)\n", __func__, alloc_fail_time);
1680 if (alloc_fail_time >= 10)
1683 phal->SdioRxFIFOSize = 0;
1690 ReadInterrupt8723BSdio(padapter, &hisr);
1691 hisr &= SDIO_HISR_RX_REQUEST;
1696 if (alloc_fail_time == 10)
1697 DBG_871X("%s: exit because recv failed more than 10 times!\n", __func__);
1701 void sd_int_hdl(PADAPTER padapter)
1703 PHAL_DATA_TYPE phal;
1706 if (RTW_CANNOT_RUN(padapter))
1709 phal = GET_HAL_DATA(padapter);
1711 phal->sdio_hisr = 0;
1712 ReadInterrupt8723BSdio(padapter, &phal->sdio_hisr);
1714 if (phal->sdio_hisr & phal->sdio_himr)
1718 phal->sdio_hisr &= phal->sdio_himr;
1721 v32 = phal->sdio_hisr & MASK_SDIO_HISR_CLEAR;
1723 SdioLocalCmd52Write4Byte(padapter, SDIO_REG_HISR, v32);
1726 sd_int_dpc(padapter);
1728 RT_TRACE(_module_hci_ops_c_, _drv_err_,
1729 ("%s: HISR(0x%08x) and HIMR(0x%08x) not match!\n",
1730 __FUNCTION__, phal->sdio_hisr, phal->sdio_himr));
1736 // Query SDIO Local register to query current the number of Free TxPacketBuffer page.
1739 // 1. Running at PASSIVE_LEVEL
1740 // 2. RT_TX_SPINLOCK is NOT acquired.
1742 // Created by Roger, 2011.01.28.
1744 u8 HalQueryTxBufferStatus8723BSdio(PADAPTER padapter)
1746 PHAL_DATA_TYPE phal;
1751 phal = GET_HAL_DATA(padapter);
1753 NumOfFreePage = SdioLocalCmd53Read4Byte(padapter, SDIO_REG_FREE_TXPG);
1755 //_enter_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
1756 _rtw_memcpy(phal->SdioTxFIFOFreePage, &NumOfFreePage, 4);
1757 RT_TRACE(_module_hci_ops_c_, _drv_notice_,
1758 ("%s: Free page for HIQ(%#x),MIDQ(%#x),LOWQ(%#x),PUBQ(%#x)\n",
1760 phal->SdioTxFIFOFreePage[HI_QUEUE_IDX],
1761 phal->SdioTxFIFOFreePage[MID_QUEUE_IDX],
1762 phal->SdioTxFIFOFreePage[LOW_QUEUE_IDX],
1763 phal->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]));
1764 //_exit_critical_bh(&phal->SdioTxFIFOFreePageLock, &irql);
1771 // Query SDIO Local register to get the current number of TX OQT Free Space.
1773 u8 HalQueryTxOQTBufferStatus8723BSdio(PADAPTER padapter)
1775 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
1776 pHalData->SdioTxOQTFreeSpace = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_OQT_FREE_PG);
1780 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
1781 u8 RecvOnePkt(PADAPTER padapter, u32 size)
1783 struct recv_buf *precvbuf;
1784 struct dvobj_priv *psddev;
1785 PSDIO_DATA psdio_data;
1786 struct sdio_func *func;
1790 DBG_871X("+%s: size: %d+\n", __func__, size);
1792 if (padapter == NULL) {
1793 DBG_871X(KERN_ERR "%s: padapter is NULL!\n", __func__);
1797 psddev = adapter_to_dvobj(padapter);
1798 psdio_data = &psddev->intf_data;
1799 func = psdio_data->func;
1802 sdio_claim_host(func);
1803 precvbuf = sd_recv_rxfifo(padapter, size);
1806 //printk("Completed Recv One Pkt.\n");
1807 sd_rxhandler(padapter, precvbuf);
1812 sdio_release_host(func);
1814 DBG_871X("-%s-\n", __func__);
1817 #endif //CONFIG_WOWLAN