static bool _rtl92s_firmware_checkready( struct ieee80211_hw *hw, u8 loadfw_status ) { struct rtl_priv *rtlpriv = rtl_priv( hw ); struct rtl_hal *rtlhal = rtl_hal( rtl_priv( hw ) ); struct rt_firmware *pfirmware = ( struct rt_firmware * )rtlhal->pfirmware; u32 tmpu4b; u8 cpustatus = 0; short pollingcnt = 1000; bool rtstatus = true; RT_TRACE( COMP_INIT, DBG_LOUD, ( "LoadStaus(%d)\n", loadfw_status ) ); pfirmware->fwstatus = ( enum fw_status )loadfw_status; switch ( loadfw_status ) { case FW_STATUS_LOAD_IMEM: /* Polling IMEM code done. */ do { cpustatus = rtl_read_byte( rtlpriv, TCR ); if ( cpustatus & IMEM_CODE_DONE ) break; udelay( 5 ); } while ( pollingcnt-- ); if ( !( cpustatus & IMEM_CHK_RPT ) || ( pollingcnt <= 0 ) ) { RT_TRACE( COMP_ERR, DBG_EMERG, ( "FW_STATUS_LOAD_IMEM" " FAIL CPU, Status=%x\r\n", cpustatus ) ); goto status_check_fail; } break; case FW_STATUS_LOAD_EMEM: /* Check Put Code OK and Turn On CPU */ /* Polling EMEM code done. */ do { cpustatus = rtl_read_byte( rtlpriv, TCR ); if ( cpustatus & EMEM_CODE_DONE ) break; udelay( 5 ); } while ( pollingcnt-- ); if ( !( cpustatus & EMEM_CHK_RPT ) || ( pollingcnt <= 0 ) ) { RT_TRACE( COMP_ERR, DBG_EMERG, ( "FW_STATUS_LOAD_EMEM" " FAIL CPU, Status=%x\r\n", cpustatus ) ); goto status_check_fail; } /* Turn On CPU */ rtstatus = _rtl92s_firmware_enable_cpu( hw ); if ( rtstatus != true ) { RT_TRACE( COMP_ERR, DBG_EMERG, ( "Enable CPU fail ! \n" ) ); goto status_check_fail; } break; case FW_STATUS_LOAD_DMEM: /* Polling DMEM code done */ do { cpustatus = rtl_read_byte( rtlpriv, TCR ); if ( cpustatus & DMEM_CODE_DONE ) break; udelay( 5 ); } while ( pollingcnt-- ); if ( !( cpustatus & DMEM_CODE_DONE ) || ( pollingcnt <= 0 ) ) { RT_TRACE( COMP_ERR, DBG_EMERG, ( "Polling DMEM code done" " fail ! cpustatus(%#x)\n", cpustatus ) ); goto status_check_fail; } RT_TRACE( COMP_INIT, DBG_LOUD, ( "DMEM code download success," " cpustatus(%#x)\n", cpustatus ) ); /* Prevent Delay too much and being scheduled out */ /* Polling Load Firmware ready */ pollingcnt = 2000; do { cpustatus = rtl_read_byte( rtlpriv, TCR ); if( cpustatus & FWRDY ) break; udelay( 40 ); } while ( pollingcnt-- ); RT_TRACE( COMP_INIT, DBG_LOUD, ( "Polling Load Firmware ready," " cpustatus(%x)\n", cpustatus ) ); if ( ( ( cpustatus & LOAD_FW_READY ) != LOAD_FW_READY ) || ( pollingcnt <= 0 ) ) { RT_TRACE( COMP_ERR, DBG_EMERG, ( "Polling Load Firmware" " ready fail ! cpustatus(%x)\n", cpustatus ) ); goto status_check_fail; } /* If right here, we can set TCR/RCR to desired value */ /* and config MAC lookback mode to normal mode */ tmpu4b = rtl_read_dword( rtlpriv, TCR ); rtl_write_dword( rtlpriv, TCR, ( tmpu4b & ( ~TCR_ICV ) ) ); tmpu4b = rtl_read_dword( rtlpriv, RCR ); rtl_write_dword( rtlpriv, RCR, ( tmpu4b | RCR_APPFCS | RCR_APP_ICV | RCR_APP_MIC ) ); RT_TRACE( COMP_INIT, DBG_LOUD, ( "Current RCR settings(%#x)\n", tmpu4b ) ); /* Set to normal mode. */ rtl_write_byte( rtlpriv, LBKMD_SEL, LBK_NORMAL ); break; default : RT_TRACE( COMP_INIT, DBG_EMERG, ( "Unknown status check!\n" ) ); rtstatus = false; break; } status_check_fail: RT_TRACE( COMP_INIT, DBG_LOUD, ( "loadfw_status(%d), " "rtstatus(%x)\n", loadfw_status, rtstatus ) ); return rtstatus; }
static int _rtl92s_firmware_checkready(struct ieee80211_hw *hw, u8 loadfw_status) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); struct rt_firmware *firmware = (struct rt_firmware *)rtlhal->pfirmware; u32 tmpu4b; u8 cpustatus = 0; int err = 0; int pollingcnt = 1000; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "LoadStaus(%d)\n", loadfw_status); firmware->fwstatus = (enum fw_status)loadfw_status; switch (loadfw_status) { case FW_STATUS_LOAD_IMEM: /* Polling IMEM code done. */ do { cpustatus = rtl_read_byte(rtlpriv, REG_TCR); if (cpustatus & IMEM_CODE_DONE) break; udelay(5); } while (pollingcnt--); if (!(cpustatus & IMEM_CHK_RPT) || (pollingcnt <= 0)) { RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "FW_STATUS_LOAD_IMEM FAIL CPU, Status=%x\n", cpustatus); err = -EAGAIN; goto status_check_fail; } break; case FW_STATUS_LOAD_EMEM: /* Check Put Code OK and Turn On CPU */ /* Polling EMEM code done. */ do { cpustatus = rtl_read_byte(rtlpriv, REG_TCR); if (cpustatus & EMEM_CODE_DONE) break; udelay(5); } while (pollingcnt--); if (!(cpustatus & EMEM_CHK_RPT) || (pollingcnt <= 0)) { RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "FW_STATUS_LOAD_EMEM FAIL CPU, Status=%x\n", cpustatus); err = -EAGAIN; goto status_check_fail; } /* Turn On CPU */ err = _rtl92s_firmware_enable_cpu(hw); if (err) { RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Enable CPU fail!\n"); err = -EAGAIN; goto status_check_fail; } break; case FW_STATUS_LOAD_DMEM: /* Polling DMEM code done */ do { cpustatus = rtl_read_byte(rtlpriv, REG_TCR); if (cpustatus & DMEM_CODE_DONE) break; udelay(5); } while (pollingcnt--); if (!(cpustatus & DMEM_CODE_DONE) || (pollingcnt <= 0)) { RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Polling DMEM code done fail ! cpustatus(%#x)\n", cpustatus); err = -EAGAIN; goto status_check_fail; } RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "DMEM code download success, cpustatus(%#x)\n", cpustatus); /* Prevent Delay too much and being scheduled out */ /* Polling Load Firmware ready */ pollingcnt = 30; do { cpustatus = rtl_read_byte(rtlpriv, REG_TCR); if (cpustatus & FWRDY) break; msleep(100); } while (pollingcnt--); RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Polling Load Firmware ready, cpustatus(%x)\n", cpustatus); if (((cpustatus & LOAD_FW_READY) != LOAD_FW_READY) || (pollingcnt <= 0)) { RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Polling Load Firmware ready fail ! cpustatus(%x)\n", cpustatus); err = -EAGAIN; goto status_check_fail; } /* If right here, we can set TCR/RCR to desired value */ /* and config MAC lookback mode to normal mode */ tmpu4b = rtl_read_dword(rtlpriv, REG_TCR); rtl_write_dword(rtlpriv, REG_TCR, (tmpu4b & (~TCR_ICV))); tmpu4b = rtl_read_dword(rtlpriv, REG_RCR); rtl_write_dword(rtlpriv, REG_RCR, (tmpu4b | RCR_APP_PHYST_RXFF | RCR_APP_ICV | RCR_APP_MIC)); RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Current RCR settings(%#x)\n", tmpu4b); /* Set to normal mode. */ rtl_write_byte(rtlpriv, REG_LBKMD_SEL, LBK_NORMAL); break; default: RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Unknown status check!\n"); err = -EINVAL; break; } status_check_fail: if (err) { RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "loadfw_status(%d), err(%d)\n", loadfw_status, err); } return err; }