162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright(c) 2009-2014 Realtek Corporation.*/ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include "../wifi.h" 562306a36Sopenharmony_ci#include "../pci.h" 662306a36Sopenharmony_ci#include "../base.h" 762306a36Sopenharmony_ci#include "../core.h" 862306a36Sopenharmony_ci#include "../efuse.h" 962306a36Sopenharmony_ci#include "reg.h" 1062306a36Sopenharmony_ci#include "def.h" 1162306a36Sopenharmony_ci#include "fw.h" 1262306a36Sopenharmony_ci#include "dm.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistatic void _rtl92ee_enable_fw_download(struct ieee80211_hw *hw, bool enable) 1562306a36Sopenharmony_ci{ 1662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1762306a36Sopenharmony_ci u8 tmp; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci if (enable) { 2062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x05); 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL + 2); 2362306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MCUFWDL + 2, tmp & 0xf7); 2462306a36Sopenharmony_ci } else { 2562306a36Sopenharmony_ci tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL); 2662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp & 0xfe); 2762306a36Sopenharmony_ci } 2862306a36Sopenharmony_ci} 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistatic void _rtl92ee_write_fw(struct ieee80211_hw *hw, 3162306a36Sopenharmony_ci enum version_8192e version, 3262306a36Sopenharmony_ci u8 *buffer, u32 size) 3362306a36Sopenharmony_ci{ 3462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3562306a36Sopenharmony_ci u8 *bufferptr = (u8 *)buffer; 3662306a36Sopenharmony_ci u32 pagenums, remainsize; 3762306a36Sopenharmony_ci u32 page, offset; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "FW size is %d bytes,\n", size); 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci rtl_fill_dummy(bufferptr, &size); 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci pagenums = size / FW_8192C_PAGE_SIZE; 4462306a36Sopenharmony_ci remainsize = size % FW_8192C_PAGE_SIZE; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci if (pagenums > 8) 4762306a36Sopenharmony_ci pr_err("Page numbers should not greater then 8\n"); 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci for (page = 0; page < pagenums; page++) { 5062306a36Sopenharmony_ci offset = page * FW_8192C_PAGE_SIZE; 5162306a36Sopenharmony_ci rtl_fw_page_write(hw, page, (bufferptr + offset), 5262306a36Sopenharmony_ci FW_8192C_PAGE_SIZE); 5362306a36Sopenharmony_ci udelay(2); 5462306a36Sopenharmony_ci } 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci if (remainsize) { 5762306a36Sopenharmony_ci offset = pagenums * FW_8192C_PAGE_SIZE; 5862306a36Sopenharmony_ci page = pagenums; 5962306a36Sopenharmony_ci rtl_fw_page_write(hw, page, (bufferptr + offset), remainsize); 6062306a36Sopenharmony_ci } 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic int _rtl92ee_fw_free_to_go(struct ieee80211_hw *hw) 6462306a36Sopenharmony_ci{ 6562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 6662306a36Sopenharmony_ci int err = -EIO; 6762306a36Sopenharmony_ci u32 counter = 0; 6862306a36Sopenharmony_ci u32 value32; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci do { 7162306a36Sopenharmony_ci value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); 7262306a36Sopenharmony_ci } while ((counter++ < FW_8192C_POLLING_TIMEOUT_COUNT) && 7362306a36Sopenharmony_ci (!(value32 & FWDL_CHKSUM_RPT))); 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci if (counter >= FW_8192C_POLLING_TIMEOUT_COUNT) { 7662306a36Sopenharmony_ci pr_err("chksum report fail! REG_MCUFWDL:0x%08x\n", 7762306a36Sopenharmony_ci value32); 7862306a36Sopenharmony_ci goto exit; 7962306a36Sopenharmony_ci } 8062306a36Sopenharmony_ci value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); 8162306a36Sopenharmony_ci value32 |= MCUFWDL_RDY; 8262306a36Sopenharmony_ci value32 &= ~WINTINI_RDY; 8362306a36Sopenharmony_ci rtl_write_dword(rtlpriv, REG_MCUFWDL, value32); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci rtl92ee_firmware_selfreset(hw); 8662306a36Sopenharmony_ci counter = 0; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci do { 8962306a36Sopenharmony_ci value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); 9062306a36Sopenharmony_ci if (value32 & WINTINI_RDY) 9162306a36Sopenharmony_ci return 0; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci udelay(FW_8192C_POLLING_DELAY*10); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci } while (counter++ < FW_8192C_POLLING_TIMEOUT_COUNT); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci pr_err("Polling FW ready fail!! REG_MCUFWDL:0x%08x. count = %d\n", 9862306a36Sopenharmony_ci value32, counter); 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciexit: 10162306a36Sopenharmony_ci return err; 10262306a36Sopenharmony_ci} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciint rtl92ee_download_fw(struct ieee80211_hw *hw, bool buse_wake_on_wlan_fw) 10562306a36Sopenharmony_ci{ 10662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 10762306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 10862306a36Sopenharmony_ci struct rtlwifi_firmware_header *pfwheader; 10962306a36Sopenharmony_ci u8 *pfwdata; 11062306a36Sopenharmony_ci u32 fwsize; 11162306a36Sopenharmony_ci enum version_8192e version = rtlhal->version; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci if (!rtlhal->pfirmware) 11462306a36Sopenharmony_ci return 1; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci pfwheader = (struct rtlwifi_firmware_header *)rtlhal->pfirmware; 11762306a36Sopenharmony_ci rtlhal->fw_version = le16_to_cpu(pfwheader->version); 11862306a36Sopenharmony_ci rtlhal->fw_subversion = pfwheader->subversion; 11962306a36Sopenharmony_ci pfwdata = (u8 *)rtlhal->pfirmware; 12062306a36Sopenharmony_ci fwsize = rtlhal->fwsize; 12162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG, 12262306a36Sopenharmony_ci "normal Firmware SIZE %d\n", fwsize); 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci if (IS_FW_HEADER_EXIST(pfwheader)) { 12562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG, 12662306a36Sopenharmony_ci "Firmware Version(%d), Signature(%#x),Size(%d)\n", 12762306a36Sopenharmony_ci pfwheader->version, pfwheader->signature, 12862306a36Sopenharmony_ci (int)sizeof(struct rtlwifi_firmware_header)); 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci pfwdata = pfwdata + sizeof(struct rtlwifi_firmware_header); 13162306a36Sopenharmony_ci fwsize = fwsize - sizeof(struct rtlwifi_firmware_header); 13262306a36Sopenharmony_ci } else { 13362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG, 13462306a36Sopenharmony_ci "Firmware no Header, Signature(%#x)\n", 13562306a36Sopenharmony_ci pfwheader->signature); 13662306a36Sopenharmony_ci } 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci if (rtlhal->mac_func_enable) { 13962306a36Sopenharmony_ci if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) { 14062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MCUFWDL, 0); 14162306a36Sopenharmony_ci rtl92ee_firmware_selfreset(hw); 14262306a36Sopenharmony_ci } 14362306a36Sopenharmony_ci } 14462306a36Sopenharmony_ci _rtl92ee_enable_fw_download(hw, true); 14562306a36Sopenharmony_ci _rtl92ee_write_fw(hw, version, pfwdata, fwsize); 14662306a36Sopenharmony_ci _rtl92ee_enable_fw_download(hw, false); 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci return _rtl92ee_fw_free_to_go(hw); 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistatic bool _rtl92ee_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 15462306a36Sopenharmony_ci u8 val_hmetfr; 15562306a36Sopenharmony_ci bool result = false; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci val_hmetfr = rtl_read_byte(rtlpriv, REG_HMETFR); 15862306a36Sopenharmony_ci if (((val_hmetfr >> boxnum) & BIT(0)) == 0) 15962306a36Sopenharmony_ci result = true; 16062306a36Sopenharmony_ci return result; 16162306a36Sopenharmony_ci} 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic void _rtl92ee_fill_h2c_command(struct ieee80211_hw *hw, u8 element_id, 16462306a36Sopenharmony_ci u32 cmd_len, u8 *cmdbuffer) 16562306a36Sopenharmony_ci{ 16662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 16762306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 16862306a36Sopenharmony_ci struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 16962306a36Sopenharmony_ci u8 boxnum; 17062306a36Sopenharmony_ci u16 box_reg = 0, box_extreg = 0; 17162306a36Sopenharmony_ci u8 u1b_tmp; 17262306a36Sopenharmony_ci bool isfw_read = false; 17362306a36Sopenharmony_ci u8 buf_index = 0; 17462306a36Sopenharmony_ci bool bwrite_sucess = false; 17562306a36Sopenharmony_ci u8 wait_h2c_limmit = 100; 17662306a36Sopenharmony_ci u8 boxcontent[4], boxextcontent[4]; 17762306a36Sopenharmony_ci u32 h2c_waitcounter = 0; 17862306a36Sopenharmony_ci unsigned long flag; 17962306a36Sopenharmony_ci u8 idx; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci if (ppsc->dot11_psmode != EACTIVE || 18262306a36Sopenharmony_ci ppsc->inactive_pwrstate == ERFOFF) { 18362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 18462306a36Sopenharmony_ci "FillH2CCommand8192E(): Return because RF is off!!!\n"); 18562306a36Sopenharmony_ci return; 18662306a36Sopenharmony_ci } 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n"); 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci /* 1. Prevent race condition in setting H2C cmd. 19162306a36Sopenharmony_ci * (copy from MgntActSet_RF_State().) 19262306a36Sopenharmony_ci */ 19362306a36Sopenharmony_ci while (true) { 19462306a36Sopenharmony_ci spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag); 19562306a36Sopenharmony_ci if (rtlhal->h2c_setinprogress) { 19662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 19762306a36Sopenharmony_ci "H2C set in progress! Wait to set..element_id(%d).\n", 19862306a36Sopenharmony_ci element_id); 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci while (rtlhal->h2c_setinprogress) { 20162306a36Sopenharmony_ci spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, 20262306a36Sopenharmony_ci flag); 20362306a36Sopenharmony_ci h2c_waitcounter++; 20462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 20562306a36Sopenharmony_ci "Wait 100 us (%d times)...\n", 20662306a36Sopenharmony_ci h2c_waitcounter); 20762306a36Sopenharmony_ci udelay(100); 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci if (h2c_waitcounter > 1000) 21062306a36Sopenharmony_ci return; 21162306a36Sopenharmony_ci spin_lock_irqsave(&rtlpriv->locks.h2c_lock, 21262306a36Sopenharmony_ci flag); 21362306a36Sopenharmony_ci } 21462306a36Sopenharmony_ci spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); 21562306a36Sopenharmony_ci } else { 21662306a36Sopenharmony_ci rtlhal->h2c_setinprogress = true; 21762306a36Sopenharmony_ci spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); 21862306a36Sopenharmony_ci break; 21962306a36Sopenharmony_ci } 22062306a36Sopenharmony_ci } 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci while (!bwrite_sucess) { 22362306a36Sopenharmony_ci /* 2. Find the last BOX number which has been writen. */ 22462306a36Sopenharmony_ci boxnum = rtlhal->last_hmeboxnum; 22562306a36Sopenharmony_ci switch (boxnum) { 22662306a36Sopenharmony_ci case 0: 22762306a36Sopenharmony_ci box_reg = REG_HMEBOX_0; 22862306a36Sopenharmony_ci box_extreg = REG_HMEBOX_EXT_0; 22962306a36Sopenharmony_ci break; 23062306a36Sopenharmony_ci case 1: 23162306a36Sopenharmony_ci box_reg = REG_HMEBOX_1; 23262306a36Sopenharmony_ci box_extreg = REG_HMEBOX_EXT_1; 23362306a36Sopenharmony_ci break; 23462306a36Sopenharmony_ci case 2: 23562306a36Sopenharmony_ci box_reg = REG_HMEBOX_2; 23662306a36Sopenharmony_ci box_extreg = REG_HMEBOX_EXT_2; 23762306a36Sopenharmony_ci break; 23862306a36Sopenharmony_ci case 3: 23962306a36Sopenharmony_ci box_reg = REG_HMEBOX_3; 24062306a36Sopenharmony_ci box_extreg = REG_HMEBOX_EXT_3; 24162306a36Sopenharmony_ci break; 24262306a36Sopenharmony_ci default: 24362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 24462306a36Sopenharmony_ci "switch case %#x not processed\n", boxnum); 24562306a36Sopenharmony_ci break; 24662306a36Sopenharmony_ci } 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci /* 3. Check if the box content is empty. */ 24962306a36Sopenharmony_ci isfw_read = false; 25062306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, REG_CR); 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci if (u1b_tmp != 0xea) { 25362306a36Sopenharmony_ci isfw_read = true; 25462306a36Sopenharmony_ci } else { 25562306a36Sopenharmony_ci if (rtl_read_byte(rtlpriv, REG_TXDMA_STATUS) == 0xea || 25662306a36Sopenharmony_ci rtl_read_byte(rtlpriv, REG_TXPKT_EMPTY) == 0xea) 25762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_CFG1 + 3, 0xff); 25862306a36Sopenharmony_ci } 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci if (isfw_read) { 26162306a36Sopenharmony_ci wait_h2c_limmit = 100; 26262306a36Sopenharmony_ci isfw_read = _rtl92ee_check_fw_read_last_h2c(hw, boxnum); 26362306a36Sopenharmony_ci while (!isfw_read) { 26462306a36Sopenharmony_ci wait_h2c_limmit--; 26562306a36Sopenharmony_ci if (wait_h2c_limmit == 0) { 26662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 26762306a36Sopenharmony_ci "Waiting too long for FW read clear HMEBox(%d)!!!\n", 26862306a36Sopenharmony_ci boxnum); 26962306a36Sopenharmony_ci break; 27062306a36Sopenharmony_ci } 27162306a36Sopenharmony_ci udelay(10); 27262306a36Sopenharmony_ci isfw_read = 27362306a36Sopenharmony_ci _rtl92ee_check_fw_read_last_h2c(hw, boxnum); 27462306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, 0x130); 27562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 27662306a36Sopenharmony_ci "Waiting for FW read clear HMEBox(%d)!!! 0x130 = %2x\n", 27762306a36Sopenharmony_ci boxnum, u1b_tmp); 27862306a36Sopenharmony_ci } 27962306a36Sopenharmony_ci } 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci /* If Fw has not read the last 28262306a36Sopenharmony_ci * H2C cmd, break and give up this H2C. 28362306a36Sopenharmony_ci */ 28462306a36Sopenharmony_ci if (!isfw_read) { 28562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 28662306a36Sopenharmony_ci "Write H2C reg BOX[%d] fail,Fw don't read.\n", 28762306a36Sopenharmony_ci boxnum); 28862306a36Sopenharmony_ci break; 28962306a36Sopenharmony_ci } 29062306a36Sopenharmony_ci /* 4. Fill the H2C cmd into box */ 29162306a36Sopenharmony_ci memset(boxcontent, 0, sizeof(boxcontent)); 29262306a36Sopenharmony_ci memset(boxextcontent, 0, sizeof(boxextcontent)); 29362306a36Sopenharmony_ci boxcontent[0] = element_id; 29462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 29562306a36Sopenharmony_ci "Write element_id box_reg(%4x) = %2x\n", 29662306a36Sopenharmony_ci box_reg, element_id); 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci switch (cmd_len) { 29962306a36Sopenharmony_ci case 1: 30062306a36Sopenharmony_ci case 2: 30162306a36Sopenharmony_ci case 3: 30262306a36Sopenharmony_ci /*boxcontent[0] &= ~(BIT(7));*/ 30362306a36Sopenharmony_ci memcpy((u8 *)(boxcontent) + 1, 30462306a36Sopenharmony_ci cmdbuffer + buf_index, cmd_len); 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci for (idx = 0; idx < 4; idx++) { 30762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, box_reg + idx, 30862306a36Sopenharmony_ci boxcontent[idx]); 30962306a36Sopenharmony_ci } 31062306a36Sopenharmony_ci break; 31162306a36Sopenharmony_ci case 4: 31262306a36Sopenharmony_ci case 5: 31362306a36Sopenharmony_ci case 6: 31462306a36Sopenharmony_ci case 7: 31562306a36Sopenharmony_ci /*boxcontent[0] |= (BIT(7));*/ 31662306a36Sopenharmony_ci memcpy((u8 *)(boxextcontent), 31762306a36Sopenharmony_ci cmdbuffer + buf_index+3, cmd_len-3); 31862306a36Sopenharmony_ci memcpy((u8 *)(boxcontent) + 1, 31962306a36Sopenharmony_ci cmdbuffer + buf_index, 3); 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci for (idx = 0; idx < 4; idx++) { 32262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, box_extreg + idx, 32362306a36Sopenharmony_ci boxextcontent[idx]); 32462306a36Sopenharmony_ci } 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci for (idx = 0; idx < 4; idx++) { 32762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, box_reg + idx, 32862306a36Sopenharmony_ci boxcontent[idx]); 32962306a36Sopenharmony_ci } 33062306a36Sopenharmony_ci break; 33162306a36Sopenharmony_ci default: 33262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 33362306a36Sopenharmony_ci "switch case %#x not processed\n", cmd_len); 33462306a36Sopenharmony_ci break; 33562306a36Sopenharmony_ci } 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci bwrite_sucess = true; 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci rtlhal->last_hmeboxnum = boxnum + 1; 34062306a36Sopenharmony_ci if (rtlhal->last_hmeboxnum == 4) 34162306a36Sopenharmony_ci rtlhal->last_hmeboxnum = 0; 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, 34462306a36Sopenharmony_ci "pHalData->last_hmeboxnum = %d\n", 34562306a36Sopenharmony_ci rtlhal->last_hmeboxnum); 34662306a36Sopenharmony_ci } 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ci spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag); 34962306a36Sopenharmony_ci rtlhal->h2c_setinprogress = false; 35062306a36Sopenharmony_ci spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n"); 35362306a36Sopenharmony_ci} 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_civoid rtl92ee_fill_h2c_cmd(struct ieee80211_hw *hw, 35662306a36Sopenharmony_ci u8 element_id, u32 cmd_len, u8 *cmdbuffer) 35762306a36Sopenharmony_ci{ 35862306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 35962306a36Sopenharmony_ci u32 tmp_cmdbuf[2]; 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ci if (!rtlhal->fw_ready) { 36262306a36Sopenharmony_ci WARN_ONCE(true, 36362306a36Sopenharmony_ci "rtl8192ee: error H2C cmd because of Fw download fail!!!\n"); 36462306a36Sopenharmony_ci return; 36562306a36Sopenharmony_ci } 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci memset(tmp_cmdbuf, 0, 8); 36862306a36Sopenharmony_ci memcpy(tmp_cmdbuf, cmdbuffer, cmd_len); 36962306a36Sopenharmony_ci _rtl92ee_fill_h2c_command(hw, element_id, cmd_len, (u8 *)&tmp_cmdbuf); 37062306a36Sopenharmony_ci} 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_civoid rtl92ee_firmware_selfreset(struct ieee80211_hw *hw) 37362306a36Sopenharmony_ci{ 37462306a36Sopenharmony_ci u8 u1b_tmp; 37562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1); 37862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0)))); 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); 38162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2)))); 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci udelay(50); 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1); 38662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp | BIT(0))); 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); 38962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp | BIT(2))); 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 39262306a36Sopenharmony_ci " _8051Reset92E(): 8051 reset success .\n"); 39362306a36Sopenharmony_ci} 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_civoid rtl92ee_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode) 39662306a36Sopenharmony_ci{ 39762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 39862306a36Sopenharmony_ci u8 u1_h2c_set_pwrmode[H2C_92E_PWEMODE_LENGTH] = { 0 }; 39962306a36Sopenharmony_ci struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 40062306a36Sopenharmony_ci u8 rlbm, power_state = 0, byte5 = 0; 40162306a36Sopenharmony_ci u8 awake_intvl; /* DTIM = (awake_intvl - 1) */ 40262306a36Sopenharmony_ci struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; 40362306a36Sopenharmony_ci bool bt_ctrl_lps = (rtlpriv->cfg->ops->get_btc_status() ? 40462306a36Sopenharmony_ci btc_ops->btc_is_bt_ctrl_lps(rtlpriv) : false); 40562306a36Sopenharmony_ci bool bt_lps_on = (rtlpriv->cfg->ops->get_btc_status() ? 40662306a36Sopenharmony_ci btc_ops->btc_is_bt_lps_on(rtlpriv) : false); 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci if (bt_ctrl_lps) 40962306a36Sopenharmony_ci mode = (bt_lps_on ? FW_PS_MIN_MODE : FW_PS_ACTIVE_MODE); 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_DMESG, "FW LPS mode = %d (coex:%d)\n", 41262306a36Sopenharmony_ci mode, bt_ctrl_lps); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci switch (mode) { 41562306a36Sopenharmony_ci case FW_PS_MIN_MODE: 41662306a36Sopenharmony_ci rlbm = 0; 41762306a36Sopenharmony_ci awake_intvl = 2; 41862306a36Sopenharmony_ci break; 41962306a36Sopenharmony_ci case FW_PS_MAX_MODE: 42062306a36Sopenharmony_ci rlbm = 1; 42162306a36Sopenharmony_ci awake_intvl = 2; 42262306a36Sopenharmony_ci break; 42362306a36Sopenharmony_ci case FW_PS_DTIM_MODE: 42462306a36Sopenharmony_ci rlbm = 2; 42562306a36Sopenharmony_ci awake_intvl = ppsc->reg_max_lps_awakeintvl; 42662306a36Sopenharmony_ci /* hw->conf.ps_dtim_period or mac->vif->bss_conf.dtim_period 42762306a36Sopenharmony_ci * is only used in swlps. 42862306a36Sopenharmony_ci */ 42962306a36Sopenharmony_ci break; 43062306a36Sopenharmony_ci default: 43162306a36Sopenharmony_ci rlbm = 2; 43262306a36Sopenharmony_ci awake_intvl = 4; 43362306a36Sopenharmony_ci break; 43462306a36Sopenharmony_ci } 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_ci if (rtlpriv->mac80211.p2p) { 43762306a36Sopenharmony_ci awake_intvl = 2; 43862306a36Sopenharmony_ci rlbm = 1; 43962306a36Sopenharmony_ci } 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci if (mode == FW_PS_ACTIVE_MODE) { 44262306a36Sopenharmony_ci byte5 = 0x40; 44362306a36Sopenharmony_ci power_state = FW_PWR_STATE_ACTIVE; 44462306a36Sopenharmony_ci } else { 44562306a36Sopenharmony_ci if (bt_ctrl_lps) { 44662306a36Sopenharmony_ci byte5 = btc_ops->btc_get_lps_val(rtlpriv); 44762306a36Sopenharmony_ci power_state = btc_ops->btc_get_rpwm_val(rtlpriv); 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci if ((rlbm == 2) && (byte5 & BIT(4))) { 45062306a36Sopenharmony_ci /* Keep awake interval to 1 to prevent from 45162306a36Sopenharmony_ci * decreasing coex performance 45262306a36Sopenharmony_ci */ 45362306a36Sopenharmony_ci awake_intvl = 2; 45462306a36Sopenharmony_ci rlbm = 2; 45562306a36Sopenharmony_ci } 45662306a36Sopenharmony_ci } else { 45762306a36Sopenharmony_ci byte5 = 0x40; 45862306a36Sopenharmony_ci power_state = FW_PWR_STATE_RF_OFF; 45962306a36Sopenharmony_ci } 46062306a36Sopenharmony_ci } 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_MODE(u1_h2c_set_pwrmode, ((mode) ? 1 : 0)); 46362306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_RLBM(u1_h2c_set_pwrmode, rlbm); 46462306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_SMART_PS(u1_h2c_set_pwrmode, 46562306a36Sopenharmony_ci bt_ctrl_lps ? 0 : 46662306a36Sopenharmony_ci ((rtlpriv->mac80211.p2p) ? 46762306a36Sopenharmony_ci ppsc->smart_ps : 1)); 46862306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_AWAKE_INTERVAL(u1_h2c_set_pwrmode, 46962306a36Sopenharmony_ci awake_intvl); 47062306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1_h2c_set_pwrmode, 0); 47162306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_PWR_STATE(u1_h2c_set_pwrmode, power_state); 47262306a36Sopenharmony_ci SET_H2CCMD_PWRMODE_PARM_BYTE5(u1_h2c_set_pwrmode, byte5); 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG, 47562306a36Sopenharmony_ci "rtl92c_set_fw_pwrmode(): u1_h2c_set_pwrmode\n", 47662306a36Sopenharmony_ci u1_h2c_set_pwrmode, H2C_92E_PWEMODE_LENGTH); 47762306a36Sopenharmony_ci if (rtlpriv->cfg->ops->get_btc_status()) 47862306a36Sopenharmony_ci btc_ops->btc_record_pwr_mode(rtlpriv, u1_h2c_set_pwrmode, 47962306a36Sopenharmony_ci H2C_92E_PWEMODE_LENGTH); 48062306a36Sopenharmony_ci rtl92ee_fill_h2c_cmd(hw, H2C_92E_SETPWRMODE, H2C_92E_PWEMODE_LENGTH, 48162306a36Sopenharmony_ci u1_h2c_set_pwrmode); 48262306a36Sopenharmony_ci} 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_civoid rtl92ee_set_fw_media_status_rpt_cmd(struct ieee80211_hw *hw, u8 mstatus) 48562306a36Sopenharmony_ci{ 48662306a36Sopenharmony_ci u8 parm[3] = { 0 , 0 , 0 }; 48762306a36Sopenharmony_ci /* parm[0]: bit0=0-->Disconnect, bit0=1-->Connect 48862306a36Sopenharmony_ci * bit1=0-->update Media Status to MACID 48962306a36Sopenharmony_ci * bit1=1-->update Media Status from MACID to MACID_End 49062306a36Sopenharmony_ci * parm[1]: MACID, if this is INFRA_STA, MacID = 0 49162306a36Sopenharmony_ci * parm[2]: MACID_End 49262306a36Sopenharmony_ci */ 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci SET_H2CCMD_MSRRPT_PARM_OPMODE(parm, mstatus); 49562306a36Sopenharmony_ci SET_H2CCMD_MSRRPT_PARM_MACID_IND(parm, 0); 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci rtl92ee_fill_h2c_cmd(hw, H2C_92E_MSRRPT, 3, parm); 49862306a36Sopenharmony_ci} 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci#define BEACON_PG 0 /* ->1 */ 50162306a36Sopenharmony_ci#define PSPOLL_PG 2 50262306a36Sopenharmony_ci#define NULL_PG 3 50362306a36Sopenharmony_ci#define PROBERSP_PG 4 /* ->5 */ 50462306a36Sopenharmony_ci#define QOS_NULL_PG 6 50562306a36Sopenharmony_ci#define BT_QOS_NULL_PG 7 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci#define TOTAL_RESERVED_PKT_LEN 1024 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_cistatic u8 reserved_page_packet[TOTAL_RESERVED_PKT_LEN] = { 51062306a36Sopenharmony_ci /* page 0 beacon */ 51162306a36Sopenharmony_ci 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 51262306a36Sopenharmony_ci 0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78, 51362306a36Sopenharmony_ci 0xEC, 0x1A, 0x59, 0x0B, 0xAD, 0xD4, 0x20, 0x00, 51462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51562306a36Sopenharmony_ci 0x64, 0x00, 0x10, 0x04, 0x00, 0x05, 0x54, 0x65, 51662306a36Sopenharmony_ci 0x73, 0x74, 0x32, 0x01, 0x08, 0x82, 0x84, 0x0B, 51762306a36Sopenharmony_ci 0x16, 0x24, 0x30, 0x48, 0x6C, 0x03, 0x01, 0x06, 51862306a36Sopenharmony_ci 0x06, 0x02, 0x00, 0x00, 0x2A, 0x01, 0x02, 0x32, 51962306a36Sopenharmony_ci 0x04, 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 52062306a36Sopenharmony_ci 0x09, 0x03, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 52162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52362306a36Sopenharmony_ci 0x00, 0x3D, 0x00, 0xDD, 0x07, 0x00, 0xE0, 0x4C, 52462306a36Sopenharmony_ci 0x02, 0x02, 0x00, 0x00, 0xDD, 0x18, 0x00, 0x50, 52562306a36Sopenharmony_ci 0xF2, 0x01, 0x01, 0x00, 0x00, 0x50, 0xF2, 0x04, 52662306a36Sopenharmony_ci 0x01, 0x00, 0x00, 0x50, 0xF2, 0x04, 0x01, 0x00, 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci /* page 1 beacon */ 52962306a36Sopenharmony_ci 0x00, 0x50, 0xF2, 0x02, 0x00, 0x00, 0x00, 0x00, 53062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53662306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54062306a36Sopenharmony_ci 0x10, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00, 54162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 54262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci /* page 2 ps-poll */ 54762306a36Sopenharmony_ci 0xA4, 0x10, 0x01, 0xC0, 0xEC, 0x1A, 0x59, 0x0B, 54862306a36Sopenharmony_ci 0xAD, 0xD4, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78, 54962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55662306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55862306a36Sopenharmony_ci 0x18, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00, 55962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 56062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56262306a36Sopenharmony_ci 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_ci /* page 3 null */ 56562306a36Sopenharmony_ci 0x48, 0x01, 0x00, 0x00, 0xEC, 0x1A, 0x59, 0x0B, 56662306a36Sopenharmony_ci 0xAD, 0xD4, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78, 56762306a36Sopenharmony_ci 0xEC, 0x1A, 0x59, 0x0B, 0xAD, 0xD4, 0x00, 0x00, 56862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57662306a36Sopenharmony_ci 0x72, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00, 57762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 57862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58062306a36Sopenharmony_ci 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci /* page 4 probe_resp */ 58362306a36Sopenharmony_ci 0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10, 58462306a36Sopenharmony_ci 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42, 58562306a36Sopenharmony_ci 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 58662306a36Sopenharmony_ci 0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00, 58762306a36Sopenharmony_ci 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69, 58862306a36Sopenharmony_ci 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C, 58962306a36Sopenharmony_ci 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96, 59062306a36Sopenharmony_ci 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A, 59162306a36Sopenharmony_ci 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C, 59262306a36Sopenharmony_ci 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18, 59362306a36Sopenharmony_ci 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59662306a36Sopenharmony_ci 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02, 59762306a36Sopenharmony_ci 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci /* page 5 probe_resp */ 60162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60662306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60862306a36Sopenharmony_ci 0x1A, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00, 60962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 61062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61262306a36Sopenharmony_ci 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci /* page 6 qos null data */ 61562306a36Sopenharmony_ci 0xC8, 0x01, 0x00, 0x00, 0x84, 0xC9, 0xB2, 0xA7, 61662306a36Sopenharmony_ci 0xB3, 0x6E, 0x00, 0xE0, 0x4C, 0x02, 0x51, 0x02, 61762306a36Sopenharmony_ci 0x84, 0xC9, 0xB2, 0xA7, 0xB3, 0x6E, 0x00, 0x00, 61862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62662306a36Sopenharmony_ci 0x1A, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00, 62762306a36Sopenharmony_ci 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 62862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63062306a36Sopenharmony_ci 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci /* page 7 BT-qos null data */ 63362306a36Sopenharmony_ci 0xC8, 0x01, 0x00, 0x00, 0x84, 0xC9, 0xB2, 0xA7, 63462306a36Sopenharmony_ci 0xB3, 0x6E, 0x00, 0xE0, 0x4C, 0x02, 0x51, 0x02, 63562306a36Sopenharmony_ci 0x84, 0xC9, 0xB2, 0xA7, 0xB3, 0x6E, 0x00, 0x00, 63662306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64362306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64462306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64562306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64662306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64762306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64862306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64962306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65062306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65162306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65262306a36Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65362306a36Sopenharmony_ci}; 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_civoid rtl92ee_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished) 65662306a36Sopenharmony_ci{ 65762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 65862306a36Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 65962306a36Sopenharmony_ci struct sk_buff *skb = NULL; 66062306a36Sopenharmony_ci bool rtstatus; 66162306a36Sopenharmony_ci u32 totalpacketlen; 66262306a36Sopenharmony_ci u8 u1rsvdpageloc[5] = { 0 }; 66362306a36Sopenharmony_ci bool b_dlok = false; 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ci u8 *beacon; 66662306a36Sopenharmony_ci u8 *p_pspoll; 66762306a36Sopenharmony_ci u8 *nullfunc; 66862306a36Sopenharmony_ci u8 *p_probersp; 66962306a36Sopenharmony_ci u8 *qosnull; 67062306a36Sopenharmony_ci u8 *btqosnull; 67162306a36Sopenharmony_ci /*--------------------------------------------------------- 67262306a36Sopenharmony_ci * (1) beacon 67362306a36Sopenharmony_ci *--------------------------------------------------------- 67462306a36Sopenharmony_ci */ 67562306a36Sopenharmony_ci beacon = &reserved_page_packet[BEACON_PG * 128]; 67662306a36Sopenharmony_ci SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr); 67762306a36Sopenharmony_ci SET_80211_HDR_ADDRESS3(beacon, mac->bssid); 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ci /*------------------------------------------------------- 68062306a36Sopenharmony_ci * (2) ps-poll 68162306a36Sopenharmony_ci *-------------------------------------------------------- 68262306a36Sopenharmony_ci */ 68362306a36Sopenharmony_ci p_pspoll = &reserved_page_packet[PSPOLL_PG * 128]; 68462306a36Sopenharmony_ci SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000)); 68562306a36Sopenharmony_ci SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid); 68662306a36Sopenharmony_ci SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr); 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1rsvdpageloc, PSPOLL_PG); 68962306a36Sopenharmony_ci 69062306a36Sopenharmony_ci /*-------------------------------------------------------- 69162306a36Sopenharmony_ci * (3) null data 69262306a36Sopenharmony_ci *--------------------------------------------------------- 69362306a36Sopenharmony_ci */ 69462306a36Sopenharmony_ci nullfunc = &reserved_page_packet[NULL_PG * 128]; 69562306a36Sopenharmony_ci SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid); 69662306a36Sopenharmony_ci SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr); 69762306a36Sopenharmony_ci SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid); 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_ci SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1rsvdpageloc, NULL_PG); 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci /*--------------------------------------------------------- 70262306a36Sopenharmony_ci * (4) probe response 70362306a36Sopenharmony_ci *---------------------------------------------------------- 70462306a36Sopenharmony_ci */ 70562306a36Sopenharmony_ci p_probersp = &reserved_page_packet[PROBERSP_PG * 128]; 70662306a36Sopenharmony_ci SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid); 70762306a36Sopenharmony_ci SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr); 70862306a36Sopenharmony_ci SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid); 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ci SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1rsvdpageloc, PROBERSP_PG); 71162306a36Sopenharmony_ci 71262306a36Sopenharmony_ci /*--------------------------------------------------------- 71362306a36Sopenharmony_ci * (5) QoS null data 71462306a36Sopenharmony_ci *---------------------------------------------------------- 71562306a36Sopenharmony_ci */ 71662306a36Sopenharmony_ci qosnull = &reserved_page_packet[QOS_NULL_PG * 128]; 71762306a36Sopenharmony_ci SET_80211_HDR_ADDRESS1(qosnull, mac->bssid); 71862306a36Sopenharmony_ci SET_80211_HDR_ADDRESS2(qosnull, mac->mac_addr); 71962306a36Sopenharmony_ci SET_80211_HDR_ADDRESS3(qosnull, mac->bssid); 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ci SET_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(u1rsvdpageloc, QOS_NULL_PG); 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ci /*--------------------------------------------------------- 72462306a36Sopenharmony_ci * (6) BT QoS null data 72562306a36Sopenharmony_ci *---------------------------------------------------------- 72662306a36Sopenharmony_ci */ 72762306a36Sopenharmony_ci btqosnull = &reserved_page_packet[BT_QOS_NULL_PG * 128]; 72862306a36Sopenharmony_ci SET_80211_HDR_ADDRESS1(btqosnull, mac->bssid); 72962306a36Sopenharmony_ci SET_80211_HDR_ADDRESS2(btqosnull, mac->mac_addr); 73062306a36Sopenharmony_ci SET_80211_HDR_ADDRESS3(btqosnull, mac->bssid); 73162306a36Sopenharmony_ci 73262306a36Sopenharmony_ci SET_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(u1rsvdpageloc, BT_QOS_NULL_PG); 73362306a36Sopenharmony_ci 73462306a36Sopenharmony_ci totalpacketlen = TOTAL_RESERVED_PKT_LEN; 73562306a36Sopenharmony_ci 73662306a36Sopenharmony_ci RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD , 73762306a36Sopenharmony_ci "rtl92ee_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n", 73862306a36Sopenharmony_ci &reserved_page_packet[0], totalpacketlen); 73962306a36Sopenharmony_ci RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD , 74062306a36Sopenharmony_ci "rtl92ee_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n", 74162306a36Sopenharmony_ci u1rsvdpageloc, 3); 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_ci skb = dev_alloc_skb(totalpacketlen); 74462306a36Sopenharmony_ci if (!skb) 74562306a36Sopenharmony_ci return; 74662306a36Sopenharmony_ci skb_put_data(skb, &reserved_page_packet, totalpacketlen); 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ci rtstatus = rtl_cmd_send_packet(hw, skb); 74962306a36Sopenharmony_ci if (rtstatus) 75062306a36Sopenharmony_ci b_dlok = true; 75162306a36Sopenharmony_ci 75262306a36Sopenharmony_ci if (b_dlok) { 75362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 75462306a36Sopenharmony_ci "Set RSVD page location to Fw.\n"); 75562306a36Sopenharmony_ci RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD , 75662306a36Sopenharmony_ci "H2C_RSVDPAGE:\n", u1rsvdpageloc, 3); 75762306a36Sopenharmony_ci rtl92ee_fill_h2c_cmd(hw, H2C_92E_RSVDPAGE, 75862306a36Sopenharmony_ci sizeof(u1rsvdpageloc), u1rsvdpageloc); 75962306a36Sopenharmony_ci } else { 76062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 76162306a36Sopenharmony_ci "Set RSVD page location to Fw FAIL!!!!!!.\n"); 76262306a36Sopenharmony_ci } 76362306a36Sopenharmony_ci} 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci/*Shoud check FW support p2p or not.*/ 76662306a36Sopenharmony_cistatic void rtl92ee_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow) 76762306a36Sopenharmony_ci{ 76862306a36Sopenharmony_ci u8 u1_ctwindow_period[1] = {ctwindow}; 76962306a36Sopenharmony_ci 77062306a36Sopenharmony_ci rtl92ee_fill_h2c_cmd(hw, H2C_92E_P2P_PS_CTW_CMD, 1, u1_ctwindow_period); 77162306a36Sopenharmony_ci} 77262306a36Sopenharmony_ci 77362306a36Sopenharmony_civoid rtl92ee_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state) 77462306a36Sopenharmony_ci{ 77562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 77662306a36Sopenharmony_ci struct rtl_ps_ctl *rtlps = rtl_psc(rtl_priv(hw)); 77762306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 77862306a36Sopenharmony_ci struct rtl_p2p_ps_info *p2pinfo = &rtlps->p2p_ps_info; 77962306a36Sopenharmony_ci struct p2p_ps_offload_t *p2p_ps_offload = &rtlhal->p2p_ps_offload; 78062306a36Sopenharmony_ci u8 i; 78162306a36Sopenharmony_ci u16 ctwindow; 78262306a36Sopenharmony_ci u32 start_time, tsf_low; 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ci switch (p2p_ps_state) { 78562306a36Sopenharmony_ci case P2P_PS_DISABLE: 78662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_DISABLE\n"); 78762306a36Sopenharmony_ci memset(p2p_ps_offload, 0, sizeof(*p2p_ps_offload)); 78862306a36Sopenharmony_ci break; 78962306a36Sopenharmony_ci case P2P_PS_ENABLE: 79062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_ENABLE\n"); 79162306a36Sopenharmony_ci /* update CTWindow value. */ 79262306a36Sopenharmony_ci if (p2pinfo->ctwindow > 0) { 79362306a36Sopenharmony_ci p2p_ps_offload->ctwindow_en = 1; 79462306a36Sopenharmony_ci ctwindow = p2pinfo->ctwindow; 79562306a36Sopenharmony_ci rtl92ee_set_p2p_ctw_period_cmd(hw, ctwindow); 79662306a36Sopenharmony_ci } 79762306a36Sopenharmony_ci /* hw only support 2 set of NoA */ 79862306a36Sopenharmony_ci for (i = 0 ; i < p2pinfo->noa_num ; i++) { 79962306a36Sopenharmony_ci /* To control the register setting for which NOA*/ 80062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, 0x5cf, (i << 4)); 80162306a36Sopenharmony_ci if (i == 0) 80262306a36Sopenharmony_ci p2p_ps_offload->noa0_en = 1; 80362306a36Sopenharmony_ci else 80462306a36Sopenharmony_ci p2p_ps_offload->noa1_en = 1; 80562306a36Sopenharmony_ci /* config P2P NoA Descriptor Register */ 80662306a36Sopenharmony_ci rtl_write_dword(rtlpriv, 0x5E0, 80762306a36Sopenharmony_ci p2pinfo->noa_duration[i]); 80862306a36Sopenharmony_ci rtl_write_dword(rtlpriv, 0x5E4, 80962306a36Sopenharmony_ci p2pinfo->noa_interval[i]); 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_ci /*Get Current TSF value */ 81262306a36Sopenharmony_ci tsf_low = rtl_read_dword(rtlpriv, REG_TSFTR); 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ci start_time = p2pinfo->noa_start_time[i]; 81562306a36Sopenharmony_ci if (p2pinfo->noa_count_type[i] != 1) { 81662306a36Sopenharmony_ci while (start_time <= (tsf_low + (50 * 1024))) { 81762306a36Sopenharmony_ci start_time += p2pinfo->noa_interval[i]; 81862306a36Sopenharmony_ci if (p2pinfo->noa_count_type[i] != 255) 81962306a36Sopenharmony_ci p2pinfo->noa_count_type[i]--; 82062306a36Sopenharmony_ci } 82162306a36Sopenharmony_ci } 82262306a36Sopenharmony_ci rtl_write_dword(rtlpriv, 0x5E8, start_time); 82362306a36Sopenharmony_ci rtl_write_dword(rtlpriv, 0x5EC, 82462306a36Sopenharmony_ci p2pinfo->noa_count_type[i]); 82562306a36Sopenharmony_ci } 82662306a36Sopenharmony_ci if ((p2pinfo->opp_ps == 1) || (p2pinfo->noa_num > 0)) { 82762306a36Sopenharmony_ci /* rst p2p circuit */ 82862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, BIT(4)); 82962306a36Sopenharmony_ci p2p_ps_offload->offload_en = 1; 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci if (P2P_ROLE_GO == rtlpriv->mac80211.p2p) { 83262306a36Sopenharmony_ci p2p_ps_offload->role = 1; 83362306a36Sopenharmony_ci p2p_ps_offload->allstasleep = 0; 83462306a36Sopenharmony_ci } else { 83562306a36Sopenharmony_ci p2p_ps_offload->role = 0; 83662306a36Sopenharmony_ci } 83762306a36Sopenharmony_ci p2p_ps_offload->discovery = 0; 83862306a36Sopenharmony_ci } 83962306a36Sopenharmony_ci break; 84062306a36Sopenharmony_ci case P2P_PS_SCAN: 84162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN\n"); 84262306a36Sopenharmony_ci p2p_ps_offload->discovery = 1; 84362306a36Sopenharmony_ci break; 84462306a36Sopenharmony_ci case P2P_PS_SCAN_DONE: 84562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN_DONE\n"); 84662306a36Sopenharmony_ci p2p_ps_offload->discovery = 0; 84762306a36Sopenharmony_ci p2pinfo->p2p_ps_state = P2P_PS_ENABLE; 84862306a36Sopenharmony_ci break; 84962306a36Sopenharmony_ci default: 85062306a36Sopenharmony_ci break; 85162306a36Sopenharmony_ci } 85262306a36Sopenharmony_ci rtl92ee_fill_h2c_cmd(hw, H2C_92E_P2P_PS_OFFLOAD, 1, 85362306a36Sopenharmony_ci (u8 *)p2p_ps_offload); 85462306a36Sopenharmony_ci} 85562306a36Sopenharmony_ci 85662306a36Sopenharmony_civoid rtl92ee_c2h_ra_report_handler(struct ieee80211_hw *hw, 85762306a36Sopenharmony_ci u8 *cmd_buf, u8 cmd_len) 85862306a36Sopenharmony_ci{ 85962306a36Sopenharmony_ci u8 rate = cmd_buf[0] & 0x3F; 86062306a36Sopenharmony_ci bool collision_state = cmd_buf[3] & BIT(0); 86162306a36Sopenharmony_ci 86262306a36Sopenharmony_ci rtl92ee_dm_dynamic_arfb_select(hw, rate, collision_state); 86362306a36Sopenharmony_ci} 864