18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2014  Realtek Corporation.*/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "../wifi.h"
58c2ecf20Sopenharmony_ci#include "../pci.h"
68c2ecf20Sopenharmony_ci#include "../base.h"
78c2ecf20Sopenharmony_ci#include "../core.h"
88c2ecf20Sopenharmony_ci#include "../efuse.h"
98c2ecf20Sopenharmony_ci#include "reg.h"
108c2ecf20Sopenharmony_ci#include "def.h"
118c2ecf20Sopenharmony_ci#include "fw.h"
128c2ecf20Sopenharmony_ci#include "dm.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic void _rtl92ee_enable_fw_download(struct ieee80211_hw *hw, bool enable)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
178c2ecf20Sopenharmony_ci	u8 tmp;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	if (enable) {
208c2ecf20Sopenharmony_ci		rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x05);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci		tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL + 2);
238c2ecf20Sopenharmony_ci		rtl_write_byte(rtlpriv, REG_MCUFWDL + 2, tmp & 0xf7);
248c2ecf20Sopenharmony_ci	} else {
258c2ecf20Sopenharmony_ci		tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
268c2ecf20Sopenharmony_ci		rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp & 0xfe);
278c2ecf20Sopenharmony_ci	}
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic void _rtl92ee_write_fw(struct ieee80211_hw *hw,
318c2ecf20Sopenharmony_ci			      enum version_8192e version,
328c2ecf20Sopenharmony_ci			      u8 *buffer, u32 size)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
358c2ecf20Sopenharmony_ci	u8 *bufferptr = (u8 *)buffer;
368c2ecf20Sopenharmony_ci	u32 pagenums, remainsize;
378c2ecf20Sopenharmony_ci	u32 page, offset;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "FW size is %d bytes,\n", size);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	rtl_fill_dummy(bufferptr, &size);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	pagenums = size / FW_8192C_PAGE_SIZE;
448c2ecf20Sopenharmony_ci	remainsize = size % FW_8192C_PAGE_SIZE;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (pagenums > 8)
478c2ecf20Sopenharmony_ci		pr_err("Page numbers should not greater then 8\n");
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	for (page = 0; page < pagenums; page++) {
508c2ecf20Sopenharmony_ci		offset = page * FW_8192C_PAGE_SIZE;
518c2ecf20Sopenharmony_ci		rtl_fw_page_write(hw, page, (bufferptr + offset),
528c2ecf20Sopenharmony_ci				  FW_8192C_PAGE_SIZE);
538c2ecf20Sopenharmony_ci		udelay(2);
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	if (remainsize) {
578c2ecf20Sopenharmony_ci		offset = pagenums * FW_8192C_PAGE_SIZE;
588c2ecf20Sopenharmony_ci		page = pagenums;
598c2ecf20Sopenharmony_ci		rtl_fw_page_write(hw, page, (bufferptr + offset), remainsize);
608c2ecf20Sopenharmony_ci	}
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic int _rtl92ee_fw_free_to_go(struct ieee80211_hw *hw)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
668c2ecf20Sopenharmony_ci	int err = -EIO;
678c2ecf20Sopenharmony_ci	u32 counter = 0;
688c2ecf20Sopenharmony_ci	u32 value32;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	do {
718c2ecf20Sopenharmony_ci		value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
728c2ecf20Sopenharmony_ci	} while ((counter++ < FW_8192C_POLLING_TIMEOUT_COUNT) &&
738c2ecf20Sopenharmony_ci		 (!(value32 & FWDL_CHKSUM_RPT)));
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	if (counter >= FW_8192C_POLLING_TIMEOUT_COUNT) {
768c2ecf20Sopenharmony_ci		pr_err("chksum report fail! REG_MCUFWDL:0x%08x\n",
778c2ecf20Sopenharmony_ci		       value32);
788c2ecf20Sopenharmony_ci		goto exit;
798c2ecf20Sopenharmony_ci	}
808c2ecf20Sopenharmony_ci	value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
818c2ecf20Sopenharmony_ci	value32 |= MCUFWDL_RDY;
828c2ecf20Sopenharmony_ci	value32 &= ~WINTINI_RDY;
838c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_MCUFWDL, value32);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	rtl92ee_firmware_selfreset(hw);
868c2ecf20Sopenharmony_ci	counter = 0;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	do {
898c2ecf20Sopenharmony_ci		value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
908c2ecf20Sopenharmony_ci		if (value32 & WINTINI_RDY)
918c2ecf20Sopenharmony_ci			return 0;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci		udelay(FW_8192C_POLLING_DELAY*10);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	} while (counter++ < FW_8192C_POLLING_TIMEOUT_COUNT);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	pr_err("Polling FW ready fail!! REG_MCUFWDL:0x%08x. count = %d\n",
988c2ecf20Sopenharmony_ci	       value32, counter);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ciexit:
1018c2ecf20Sopenharmony_ci	return err;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciint rtl92ee_download_fw(struct ieee80211_hw *hw, bool buse_wake_on_wlan_fw)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1078c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1088c2ecf20Sopenharmony_ci	struct rtlwifi_firmware_header *pfwheader;
1098c2ecf20Sopenharmony_ci	u8 *pfwdata;
1108c2ecf20Sopenharmony_ci	u32 fwsize;
1118c2ecf20Sopenharmony_ci	enum version_8192e version = rtlhal->version;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	if (!rtlhal->pfirmware)
1148c2ecf20Sopenharmony_ci		return 1;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	pfwheader = (struct rtlwifi_firmware_header *)rtlhal->pfirmware;
1178c2ecf20Sopenharmony_ci	rtlhal->fw_version = le16_to_cpu(pfwheader->version);
1188c2ecf20Sopenharmony_ci	rtlhal->fw_subversion = pfwheader->subversion;
1198c2ecf20Sopenharmony_ci	pfwdata = (u8 *)rtlhal->pfirmware;
1208c2ecf20Sopenharmony_ci	fwsize = rtlhal->fwsize;
1218c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG,
1228c2ecf20Sopenharmony_ci		"normal Firmware SIZE %d\n", fwsize);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	if (IS_FW_HEADER_EXIST(pfwheader)) {
1258c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG,
1268c2ecf20Sopenharmony_ci			"Firmware Version(%d), Signature(%#x),Size(%d)\n",
1278c2ecf20Sopenharmony_ci			pfwheader->version, pfwheader->signature,
1288c2ecf20Sopenharmony_ci			(int)sizeof(struct rtlwifi_firmware_header));
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci		pfwdata = pfwdata + sizeof(struct rtlwifi_firmware_header);
1318c2ecf20Sopenharmony_ci		fwsize = fwsize - sizeof(struct rtlwifi_firmware_header);
1328c2ecf20Sopenharmony_ci	} else {
1338c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG,
1348c2ecf20Sopenharmony_ci			"Firmware no Header, Signature(%#x)\n",
1358c2ecf20Sopenharmony_ci			pfwheader->signature);
1368c2ecf20Sopenharmony_ci	}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	if (rtlhal->mac_func_enable) {
1398c2ecf20Sopenharmony_ci		if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) {
1408c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, REG_MCUFWDL, 0);
1418c2ecf20Sopenharmony_ci			rtl92ee_firmware_selfreset(hw);
1428c2ecf20Sopenharmony_ci		}
1438c2ecf20Sopenharmony_ci	}
1448c2ecf20Sopenharmony_ci	_rtl92ee_enable_fw_download(hw, true);
1458c2ecf20Sopenharmony_ci	_rtl92ee_write_fw(hw, version, pfwdata, fwsize);
1468c2ecf20Sopenharmony_ci	_rtl92ee_enable_fw_download(hw, false);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	return _rtl92ee_fw_free_to_go(hw);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistatic bool _rtl92ee_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1548c2ecf20Sopenharmony_ci	u8 val_hmetfr;
1558c2ecf20Sopenharmony_ci	bool result = false;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	val_hmetfr = rtl_read_byte(rtlpriv, REG_HMETFR);
1588c2ecf20Sopenharmony_ci	if (((val_hmetfr >> boxnum) & BIT(0)) == 0)
1598c2ecf20Sopenharmony_ci		result = true;
1608c2ecf20Sopenharmony_ci	return result;
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic void _rtl92ee_fill_h2c_command(struct ieee80211_hw *hw, u8 element_id,
1648c2ecf20Sopenharmony_ci				      u32 cmd_len, u8 *cmdbuffer)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1678c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1688c2ecf20Sopenharmony_ci	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1698c2ecf20Sopenharmony_ci	u8 boxnum;
1708c2ecf20Sopenharmony_ci	u16 box_reg = 0, box_extreg = 0;
1718c2ecf20Sopenharmony_ci	u8 u1b_tmp;
1728c2ecf20Sopenharmony_ci	bool isfw_read = false;
1738c2ecf20Sopenharmony_ci	u8 buf_index = 0;
1748c2ecf20Sopenharmony_ci	bool bwrite_sucess = false;
1758c2ecf20Sopenharmony_ci	u8 wait_h2c_limmit = 100;
1768c2ecf20Sopenharmony_ci	u8 boxcontent[4], boxextcontent[4];
1778c2ecf20Sopenharmony_ci	u32 h2c_waitcounter = 0;
1788c2ecf20Sopenharmony_ci	unsigned long flag;
1798c2ecf20Sopenharmony_ci	u8 idx;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	if (ppsc->dot11_psmode != EACTIVE ||
1828c2ecf20Sopenharmony_ci	    ppsc->inactive_pwrstate == ERFOFF) {
1838c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
1848c2ecf20Sopenharmony_ci			"FillH2CCommand8192E(): Return because RF is off!!!\n");
1858c2ecf20Sopenharmony_ci		return;
1868c2ecf20Sopenharmony_ci	}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n");
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	/* 1. Prevent race condition in setting H2C cmd.
1918c2ecf20Sopenharmony_ci	 * (copy from MgntActSet_RF_State().)
1928c2ecf20Sopenharmony_ci	 */
1938c2ecf20Sopenharmony_ci	while (true) {
1948c2ecf20Sopenharmony_ci		spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
1958c2ecf20Sopenharmony_ci		if (rtlhal->h2c_setinprogress) {
1968c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
1978c2ecf20Sopenharmony_ci				"H2C set in progress! Wait to set..element_id(%d).\n",
1988c2ecf20Sopenharmony_ci				element_id);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci			while (rtlhal->h2c_setinprogress) {
2018c2ecf20Sopenharmony_ci				spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock,
2028c2ecf20Sopenharmony_ci						       flag);
2038c2ecf20Sopenharmony_ci				h2c_waitcounter++;
2048c2ecf20Sopenharmony_ci				rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
2058c2ecf20Sopenharmony_ci					"Wait 100 us (%d times)...\n",
2068c2ecf20Sopenharmony_ci					h2c_waitcounter);
2078c2ecf20Sopenharmony_ci				udelay(100);
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci				if (h2c_waitcounter > 1000)
2108c2ecf20Sopenharmony_ci					return;
2118c2ecf20Sopenharmony_ci				spin_lock_irqsave(&rtlpriv->locks.h2c_lock,
2128c2ecf20Sopenharmony_ci						  flag);
2138c2ecf20Sopenharmony_ci			}
2148c2ecf20Sopenharmony_ci			spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
2158c2ecf20Sopenharmony_ci		} else {
2168c2ecf20Sopenharmony_ci			rtlhal->h2c_setinprogress = true;
2178c2ecf20Sopenharmony_ci			spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
2188c2ecf20Sopenharmony_ci			break;
2198c2ecf20Sopenharmony_ci		}
2208c2ecf20Sopenharmony_ci	}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	while (!bwrite_sucess) {
2238c2ecf20Sopenharmony_ci		/* 2. Find the last BOX number which has been writen. */
2248c2ecf20Sopenharmony_ci		boxnum = rtlhal->last_hmeboxnum;
2258c2ecf20Sopenharmony_ci		switch (boxnum) {
2268c2ecf20Sopenharmony_ci		case 0:
2278c2ecf20Sopenharmony_ci			box_reg = REG_HMEBOX_0;
2288c2ecf20Sopenharmony_ci			box_extreg = REG_HMEBOX_EXT_0;
2298c2ecf20Sopenharmony_ci			break;
2308c2ecf20Sopenharmony_ci		case 1:
2318c2ecf20Sopenharmony_ci			box_reg = REG_HMEBOX_1;
2328c2ecf20Sopenharmony_ci			box_extreg = REG_HMEBOX_EXT_1;
2338c2ecf20Sopenharmony_ci			break;
2348c2ecf20Sopenharmony_ci		case 2:
2358c2ecf20Sopenharmony_ci			box_reg = REG_HMEBOX_2;
2368c2ecf20Sopenharmony_ci			box_extreg = REG_HMEBOX_EXT_2;
2378c2ecf20Sopenharmony_ci			break;
2388c2ecf20Sopenharmony_ci		case 3:
2398c2ecf20Sopenharmony_ci			box_reg = REG_HMEBOX_3;
2408c2ecf20Sopenharmony_ci			box_extreg = REG_HMEBOX_EXT_3;
2418c2ecf20Sopenharmony_ci			break;
2428c2ecf20Sopenharmony_ci		default:
2438c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
2448c2ecf20Sopenharmony_ci				"switch case %#x not processed\n", boxnum);
2458c2ecf20Sopenharmony_ci			break;
2468c2ecf20Sopenharmony_ci		}
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci		/* 3. Check if the box content is empty. */
2498c2ecf20Sopenharmony_ci		isfw_read = false;
2508c2ecf20Sopenharmony_ci		u1b_tmp = rtl_read_byte(rtlpriv, REG_CR);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci		if (u1b_tmp != 0xea) {
2538c2ecf20Sopenharmony_ci			isfw_read = true;
2548c2ecf20Sopenharmony_ci		} else {
2558c2ecf20Sopenharmony_ci			if (rtl_read_byte(rtlpriv, REG_TXDMA_STATUS) == 0xea ||
2568c2ecf20Sopenharmony_ci			    rtl_read_byte(rtlpriv, REG_TXPKT_EMPTY) == 0xea)
2578c2ecf20Sopenharmony_ci				rtl_write_byte(rtlpriv, REG_SYS_CFG1 + 3, 0xff);
2588c2ecf20Sopenharmony_ci		}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci		if (isfw_read) {
2618c2ecf20Sopenharmony_ci			wait_h2c_limmit = 100;
2628c2ecf20Sopenharmony_ci			isfw_read = _rtl92ee_check_fw_read_last_h2c(hw, boxnum);
2638c2ecf20Sopenharmony_ci			while (!isfw_read) {
2648c2ecf20Sopenharmony_ci				wait_h2c_limmit--;
2658c2ecf20Sopenharmony_ci				if (wait_h2c_limmit == 0) {
2668c2ecf20Sopenharmony_ci					rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
2678c2ecf20Sopenharmony_ci						"Waiting too long for FW read clear HMEBox(%d)!!!\n",
2688c2ecf20Sopenharmony_ci						boxnum);
2698c2ecf20Sopenharmony_ci					break;
2708c2ecf20Sopenharmony_ci				}
2718c2ecf20Sopenharmony_ci				udelay(10);
2728c2ecf20Sopenharmony_ci				isfw_read =
2738c2ecf20Sopenharmony_ci				  _rtl92ee_check_fw_read_last_h2c(hw, boxnum);
2748c2ecf20Sopenharmony_ci				u1b_tmp = rtl_read_byte(rtlpriv, 0x130);
2758c2ecf20Sopenharmony_ci				rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
2768c2ecf20Sopenharmony_ci					"Waiting for FW read clear HMEBox(%d)!!! 0x130 = %2x\n",
2778c2ecf20Sopenharmony_ci					boxnum, u1b_tmp);
2788c2ecf20Sopenharmony_ci			}
2798c2ecf20Sopenharmony_ci		}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci		/* If Fw has not read the last
2828c2ecf20Sopenharmony_ci		 * H2C cmd, break and give up this H2C.
2838c2ecf20Sopenharmony_ci		 */
2848c2ecf20Sopenharmony_ci		if (!isfw_read) {
2858c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
2868c2ecf20Sopenharmony_ci				"Write H2C reg BOX[%d] fail,Fw don't read.\n",
2878c2ecf20Sopenharmony_ci				boxnum);
2888c2ecf20Sopenharmony_ci			break;
2898c2ecf20Sopenharmony_ci		}
2908c2ecf20Sopenharmony_ci		/* 4. Fill the H2C cmd into box */
2918c2ecf20Sopenharmony_ci		memset(boxcontent, 0, sizeof(boxcontent));
2928c2ecf20Sopenharmony_ci		memset(boxextcontent, 0, sizeof(boxextcontent));
2938c2ecf20Sopenharmony_ci		boxcontent[0] = element_id;
2948c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
2958c2ecf20Sopenharmony_ci			"Write element_id box_reg(%4x) = %2x\n",
2968c2ecf20Sopenharmony_ci			box_reg, element_id);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci		switch (cmd_len) {
2998c2ecf20Sopenharmony_ci		case 1:
3008c2ecf20Sopenharmony_ci		case 2:
3018c2ecf20Sopenharmony_ci		case 3:
3028c2ecf20Sopenharmony_ci			/*boxcontent[0] &= ~(BIT(7));*/
3038c2ecf20Sopenharmony_ci			memcpy((u8 *)(boxcontent) + 1,
3048c2ecf20Sopenharmony_ci			       cmdbuffer + buf_index, cmd_len);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci			for (idx = 0; idx < 4; idx++) {
3078c2ecf20Sopenharmony_ci				rtl_write_byte(rtlpriv, box_reg + idx,
3088c2ecf20Sopenharmony_ci					       boxcontent[idx]);
3098c2ecf20Sopenharmony_ci			}
3108c2ecf20Sopenharmony_ci			break;
3118c2ecf20Sopenharmony_ci		case 4:
3128c2ecf20Sopenharmony_ci		case 5:
3138c2ecf20Sopenharmony_ci		case 6:
3148c2ecf20Sopenharmony_ci		case 7:
3158c2ecf20Sopenharmony_ci			/*boxcontent[0] |= (BIT(7));*/
3168c2ecf20Sopenharmony_ci			memcpy((u8 *)(boxextcontent),
3178c2ecf20Sopenharmony_ci			       cmdbuffer + buf_index+3, cmd_len-3);
3188c2ecf20Sopenharmony_ci			memcpy((u8 *)(boxcontent) + 1,
3198c2ecf20Sopenharmony_ci			       cmdbuffer + buf_index, 3);
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci			for (idx = 0; idx < 4; idx++) {
3228c2ecf20Sopenharmony_ci				rtl_write_byte(rtlpriv, box_extreg + idx,
3238c2ecf20Sopenharmony_ci					       boxextcontent[idx]);
3248c2ecf20Sopenharmony_ci			}
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci			for (idx = 0; idx < 4; idx++) {
3278c2ecf20Sopenharmony_ci				rtl_write_byte(rtlpriv, box_reg + idx,
3288c2ecf20Sopenharmony_ci					       boxcontent[idx]);
3298c2ecf20Sopenharmony_ci			}
3308c2ecf20Sopenharmony_ci			break;
3318c2ecf20Sopenharmony_ci		default:
3328c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
3338c2ecf20Sopenharmony_ci				"switch case %#x not processed\n", cmd_len);
3348c2ecf20Sopenharmony_ci			break;
3358c2ecf20Sopenharmony_ci		}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci		bwrite_sucess = true;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci		rtlhal->last_hmeboxnum = boxnum + 1;
3408c2ecf20Sopenharmony_ci		if (rtlhal->last_hmeboxnum == 4)
3418c2ecf20Sopenharmony_ci			rtlhal->last_hmeboxnum = 0;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
3448c2ecf20Sopenharmony_ci			"pHalData->last_hmeboxnum  = %d\n",
3458c2ecf20Sopenharmony_ci			rtlhal->last_hmeboxnum);
3468c2ecf20Sopenharmony_ci	}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
3498c2ecf20Sopenharmony_ci	rtlhal->h2c_setinprogress = false;
3508c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n");
3538c2ecf20Sopenharmony_ci}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_civoid rtl92ee_fill_h2c_cmd(struct ieee80211_hw *hw,
3568c2ecf20Sopenharmony_ci			  u8 element_id, u32 cmd_len, u8 *cmdbuffer)
3578c2ecf20Sopenharmony_ci{
3588c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3598c2ecf20Sopenharmony_ci	u32 tmp_cmdbuf[2];
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	if (!rtlhal->fw_ready) {
3628c2ecf20Sopenharmony_ci		WARN_ONCE(true,
3638c2ecf20Sopenharmony_ci			  "rtl8192ee: error H2C cmd because of Fw download fail!!!\n");
3648c2ecf20Sopenharmony_ci		return;
3658c2ecf20Sopenharmony_ci	}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	memset(tmp_cmdbuf, 0, 8);
3688c2ecf20Sopenharmony_ci	memcpy(tmp_cmdbuf, cmdbuffer, cmd_len);
3698c2ecf20Sopenharmony_ci	_rtl92ee_fill_h2c_command(hw, element_id, cmd_len, (u8 *)&tmp_cmdbuf);
3708c2ecf20Sopenharmony_ci}
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_civoid rtl92ee_firmware_selfreset(struct ieee80211_hw *hw)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	u8 u1b_tmp;
3758c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
3788c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0))));
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
3818c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2))));
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	udelay(50);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
3868c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp | BIT(0)));
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
3898c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp | BIT(2)));
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
3928c2ecf20Sopenharmony_ci		"  _8051Reset92E(): 8051 reset success .\n");
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_civoid rtl92ee_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3988c2ecf20Sopenharmony_ci	u8 u1_h2c_set_pwrmode[H2C_92E_PWEMODE_LENGTH] = { 0 };
3998c2ecf20Sopenharmony_ci	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
4008c2ecf20Sopenharmony_ci	u8 rlbm, power_state = 0, byte5 = 0;
4018c2ecf20Sopenharmony_ci	u8 awake_intvl;	/* DTIM = (awake_intvl - 1) */
4028c2ecf20Sopenharmony_ci	struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
4038c2ecf20Sopenharmony_ci	bool bt_ctrl_lps = (rtlpriv->cfg->ops->get_btc_status() ?
4048c2ecf20Sopenharmony_ci			    btc_ops->btc_is_bt_ctrl_lps(rtlpriv) : false);
4058c2ecf20Sopenharmony_ci	bool bt_lps_on = (rtlpriv->cfg->ops->get_btc_status() ?
4068c2ecf20Sopenharmony_ci			  btc_ops->btc_is_bt_lps_on(rtlpriv) : false);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	if (bt_ctrl_lps)
4098c2ecf20Sopenharmony_ci		mode = (bt_lps_on ? FW_PS_MIN_MODE : FW_PS_ACTIVE_MODE);
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_POWER, DBG_DMESG, "FW LPS mode = %d (coex:%d)\n",
4128c2ecf20Sopenharmony_ci		mode, bt_ctrl_lps);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	switch (mode) {
4158c2ecf20Sopenharmony_ci	case FW_PS_MIN_MODE:
4168c2ecf20Sopenharmony_ci		rlbm = 0;
4178c2ecf20Sopenharmony_ci		awake_intvl = 2;
4188c2ecf20Sopenharmony_ci		break;
4198c2ecf20Sopenharmony_ci	case FW_PS_MAX_MODE:
4208c2ecf20Sopenharmony_ci		rlbm = 1;
4218c2ecf20Sopenharmony_ci		awake_intvl = 2;
4228c2ecf20Sopenharmony_ci		break;
4238c2ecf20Sopenharmony_ci	case FW_PS_DTIM_MODE:
4248c2ecf20Sopenharmony_ci		rlbm = 2;
4258c2ecf20Sopenharmony_ci		awake_intvl = ppsc->reg_max_lps_awakeintvl;
4268c2ecf20Sopenharmony_ci		/* hw->conf.ps_dtim_period or mac->vif->bss_conf.dtim_period
4278c2ecf20Sopenharmony_ci		 * is only used in swlps.
4288c2ecf20Sopenharmony_ci		 */
4298c2ecf20Sopenharmony_ci		break;
4308c2ecf20Sopenharmony_ci	default:
4318c2ecf20Sopenharmony_ci		rlbm = 2;
4328c2ecf20Sopenharmony_ci		awake_intvl = 4;
4338c2ecf20Sopenharmony_ci		break;
4348c2ecf20Sopenharmony_ci	}
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	if (rtlpriv->mac80211.p2p) {
4378c2ecf20Sopenharmony_ci		awake_intvl = 2;
4388c2ecf20Sopenharmony_ci		rlbm = 1;
4398c2ecf20Sopenharmony_ci	}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	if (mode == FW_PS_ACTIVE_MODE) {
4428c2ecf20Sopenharmony_ci		byte5 = 0x40;
4438c2ecf20Sopenharmony_ci		power_state = FW_PWR_STATE_ACTIVE;
4448c2ecf20Sopenharmony_ci	} else {
4458c2ecf20Sopenharmony_ci		if (bt_ctrl_lps) {
4468c2ecf20Sopenharmony_ci			byte5 = btc_ops->btc_get_lps_val(rtlpriv);
4478c2ecf20Sopenharmony_ci			power_state = btc_ops->btc_get_rpwm_val(rtlpriv);
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci			if ((rlbm == 2) && (byte5 & BIT(4))) {
4508c2ecf20Sopenharmony_ci				/* Keep awake interval to 1 to prevent from
4518c2ecf20Sopenharmony_ci				 * decreasing coex performance
4528c2ecf20Sopenharmony_ci				 */
4538c2ecf20Sopenharmony_ci				awake_intvl = 2;
4548c2ecf20Sopenharmony_ci				rlbm = 2;
4558c2ecf20Sopenharmony_ci			}
4568c2ecf20Sopenharmony_ci		} else {
4578c2ecf20Sopenharmony_ci			byte5 = 0x40;
4588c2ecf20Sopenharmony_ci			power_state = FW_PWR_STATE_RF_OFF;
4598c2ecf20Sopenharmony_ci		}
4608c2ecf20Sopenharmony_ci	}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_MODE(u1_h2c_set_pwrmode, ((mode) ? 1 : 0));
4638c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_RLBM(u1_h2c_set_pwrmode, rlbm);
4648c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_SMART_PS(u1_h2c_set_pwrmode,
4658c2ecf20Sopenharmony_ci					 bt_ctrl_lps ? 0 :
4668c2ecf20Sopenharmony_ci					 ((rtlpriv->mac80211.p2p) ?
4678c2ecf20Sopenharmony_ci					  ppsc->smart_ps : 1));
4688c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_AWAKE_INTERVAL(u1_h2c_set_pwrmode,
4698c2ecf20Sopenharmony_ci					       awake_intvl);
4708c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1_h2c_set_pwrmode, 0);
4718c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_PWR_STATE(u1_h2c_set_pwrmode, power_state);
4728c2ecf20Sopenharmony_ci	SET_H2CCMD_PWRMODE_PARM_BYTE5(u1_h2c_set_pwrmode, byte5);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
4758c2ecf20Sopenharmony_ci		      "rtl92c_set_fw_pwrmode(): u1_h2c_set_pwrmode\n",
4768c2ecf20Sopenharmony_ci		      u1_h2c_set_pwrmode, H2C_92E_PWEMODE_LENGTH);
4778c2ecf20Sopenharmony_ci	if (rtlpriv->cfg->ops->get_btc_status())
4788c2ecf20Sopenharmony_ci		btc_ops->btc_record_pwr_mode(rtlpriv, u1_h2c_set_pwrmode,
4798c2ecf20Sopenharmony_ci					     H2C_92E_PWEMODE_LENGTH);
4808c2ecf20Sopenharmony_ci	rtl92ee_fill_h2c_cmd(hw, H2C_92E_SETPWRMODE, H2C_92E_PWEMODE_LENGTH,
4818c2ecf20Sopenharmony_ci			     u1_h2c_set_pwrmode);
4828c2ecf20Sopenharmony_ci}
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_civoid rtl92ee_set_fw_media_status_rpt_cmd(struct ieee80211_hw *hw, u8 mstatus)
4858c2ecf20Sopenharmony_ci{
4868c2ecf20Sopenharmony_ci	u8 parm[3] = { 0 , 0 , 0 };
4878c2ecf20Sopenharmony_ci	/* parm[0]: bit0=0-->Disconnect, bit0=1-->Connect
4888c2ecf20Sopenharmony_ci	 *          bit1=0-->update Media Status to MACID
4898c2ecf20Sopenharmony_ci	 *          bit1=1-->update Media Status from MACID to MACID_End
4908c2ecf20Sopenharmony_ci	 * parm[1]: MACID, if this is INFRA_STA, MacID = 0
4918c2ecf20Sopenharmony_ci	 * parm[2]: MACID_End
4928c2ecf20Sopenharmony_ci	 */
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	SET_H2CCMD_MSRRPT_PARM_OPMODE(parm, mstatus);
4958c2ecf20Sopenharmony_ci	SET_H2CCMD_MSRRPT_PARM_MACID_IND(parm, 0);
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci	rtl92ee_fill_h2c_cmd(hw, H2C_92E_MSRRPT, 3, parm);
4988c2ecf20Sopenharmony_ci}
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci#define BEACON_PG		0 /* ->1 */
5018c2ecf20Sopenharmony_ci#define PSPOLL_PG		2
5028c2ecf20Sopenharmony_ci#define NULL_PG			3
5038c2ecf20Sopenharmony_ci#define PROBERSP_PG		4 /* ->5 */
5048c2ecf20Sopenharmony_ci#define QOS_NULL_PG		6
5058c2ecf20Sopenharmony_ci#define BT_QOS_NULL_PG	7
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci#define TOTAL_RESERVED_PKT_LEN	1024
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_cistatic u8 reserved_page_packet[TOTAL_RESERVED_PKT_LEN] = {
5108c2ecf20Sopenharmony_ci	/* page 0 beacon */
5118c2ecf20Sopenharmony_ci	0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
5128c2ecf20Sopenharmony_ci	0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78,
5138c2ecf20Sopenharmony_ci	0xEC, 0x1A, 0x59, 0x0B, 0xAD, 0xD4, 0x20, 0x00,
5148c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5158c2ecf20Sopenharmony_ci	0x64, 0x00, 0x10, 0x04, 0x00, 0x05, 0x54, 0x65,
5168c2ecf20Sopenharmony_ci	0x73, 0x74, 0x32, 0x01, 0x08, 0x82, 0x84, 0x0B,
5178c2ecf20Sopenharmony_ci	0x16, 0x24, 0x30, 0x48, 0x6C, 0x03, 0x01, 0x06,
5188c2ecf20Sopenharmony_ci	0x06, 0x02, 0x00, 0x00, 0x2A, 0x01, 0x02, 0x32,
5198c2ecf20Sopenharmony_ci	0x04, 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C,
5208c2ecf20Sopenharmony_ci	0x09, 0x03, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
5218c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5228c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5238c2ecf20Sopenharmony_ci	0x00, 0x3D, 0x00, 0xDD, 0x07, 0x00, 0xE0, 0x4C,
5248c2ecf20Sopenharmony_ci	0x02, 0x02, 0x00, 0x00, 0xDD, 0x18, 0x00, 0x50,
5258c2ecf20Sopenharmony_ci	0xF2, 0x01, 0x01, 0x00, 0x00, 0x50, 0xF2, 0x04,
5268c2ecf20Sopenharmony_ci	0x01, 0x00, 0x00, 0x50, 0xF2, 0x04, 0x01, 0x00,
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	/* page 1 beacon */
5298c2ecf20Sopenharmony_ci	0x00, 0x50, 0xF2, 0x02, 0x00, 0x00, 0x00, 0x00,
5308c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5318c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5328c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5338c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5348c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5358c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5368c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5378c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5388c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5398c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5408c2ecf20Sopenharmony_ci	0x10, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00,
5418c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00,
5428c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5438c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5448c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	/* page 2  ps-poll */
5478c2ecf20Sopenharmony_ci	0xA4, 0x10, 0x01, 0xC0, 0xEC, 0x1A, 0x59, 0x0B,
5488c2ecf20Sopenharmony_ci	0xAD, 0xD4, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78,
5498c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5508c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5518c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5528c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5538c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5548c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5558c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5568c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5578c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5588c2ecf20Sopenharmony_ci	0x18, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00,
5598c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
5608c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5618c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5628c2ecf20Sopenharmony_ci	0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci	/* page 3  null */
5658c2ecf20Sopenharmony_ci	0x48, 0x01, 0x00, 0x00, 0xEC, 0x1A, 0x59, 0x0B,
5668c2ecf20Sopenharmony_ci	0xAD, 0xD4, 0x00, 0xE0, 0x4C, 0x02, 0xB1, 0x78,
5678c2ecf20Sopenharmony_ci	0xEC, 0x1A, 0x59, 0x0B, 0xAD, 0xD4, 0x00, 0x00,
5688c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5698c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5708c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5718c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5728c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5738c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5748c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5758c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5768c2ecf20Sopenharmony_ci	0x72, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00,
5778c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
5788c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5798c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5808c2ecf20Sopenharmony_ci	0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci	/* page 4  probe_resp */
5838c2ecf20Sopenharmony_ci	0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
5848c2ecf20Sopenharmony_ci	0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
5858c2ecf20Sopenharmony_ci	0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
5868c2ecf20Sopenharmony_ci	0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00,
5878c2ecf20Sopenharmony_ci	0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
5888c2ecf20Sopenharmony_ci	0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
5898c2ecf20Sopenharmony_ci	0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
5908c2ecf20Sopenharmony_ci	0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
5918c2ecf20Sopenharmony_ci	0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
5928c2ecf20Sopenharmony_ci	0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
5938c2ecf20Sopenharmony_ci	0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5948c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5958c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5968c2ecf20Sopenharmony_ci	0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
5978c2ecf20Sopenharmony_ci	0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5988c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	/* page 5  probe_resp */
6018c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6028c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6038c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6048c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6058c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6068c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6078c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6088c2ecf20Sopenharmony_ci	0x1A, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00,
6098c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
6108c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6118c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6128c2ecf20Sopenharmony_ci	0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	/* page 6 qos null data */
6158c2ecf20Sopenharmony_ci	0xC8, 0x01, 0x00, 0x00, 0x84, 0xC9, 0xB2, 0xA7,
6168c2ecf20Sopenharmony_ci	0xB3, 0x6E, 0x00, 0xE0, 0x4C, 0x02, 0x51, 0x02,
6178c2ecf20Sopenharmony_ci	0x84, 0xC9, 0xB2, 0xA7, 0xB3, 0x6E, 0x00, 0x00,
6188c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6198c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6208c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6218c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6228c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6238c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6248c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6258c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6268c2ecf20Sopenharmony_ci	0x1A, 0x00, 0x28, 0x8C, 0x00, 0x12, 0x00, 0x00,
6278c2ecf20Sopenharmony_ci	0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00,
6288c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6298c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6308c2ecf20Sopenharmony_ci	0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci	/* page 7 BT-qos null data */
6338c2ecf20Sopenharmony_ci	0xC8, 0x01, 0x00, 0x00, 0x84, 0xC9, 0xB2, 0xA7,
6348c2ecf20Sopenharmony_ci	0xB3, 0x6E, 0x00, 0xE0, 0x4C, 0x02, 0x51, 0x02,
6358c2ecf20Sopenharmony_ci	0x84, 0xC9, 0xB2, 0xA7, 0xB3, 0x6E, 0x00, 0x00,
6368c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6378c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6388c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6398c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6408c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6418c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6428c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6438c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6448c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6458c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6468c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6478c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6488c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6498c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6508c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6518c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6528c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6538c2ecf20Sopenharmony_ci};
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_civoid rtl92ee_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
6568c2ecf20Sopenharmony_ci{
6578c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
6588c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
6598c2ecf20Sopenharmony_ci	struct sk_buff *skb = NULL;
6608c2ecf20Sopenharmony_ci	bool rtstatus;
6618c2ecf20Sopenharmony_ci	u32 totalpacketlen;
6628c2ecf20Sopenharmony_ci	u8 u1rsvdpageloc[5] = { 0 };
6638c2ecf20Sopenharmony_ci	bool b_dlok = false;
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_ci	u8 *beacon;
6668c2ecf20Sopenharmony_ci	u8 *p_pspoll;
6678c2ecf20Sopenharmony_ci	u8 *nullfunc;
6688c2ecf20Sopenharmony_ci	u8 *p_probersp;
6698c2ecf20Sopenharmony_ci	u8 *qosnull;
6708c2ecf20Sopenharmony_ci	u8 *btqosnull;
6718c2ecf20Sopenharmony_ci	/*---------------------------------------------------------
6728c2ecf20Sopenharmony_ci	 *			(1) beacon
6738c2ecf20Sopenharmony_ci	 *---------------------------------------------------------
6748c2ecf20Sopenharmony_ci	 */
6758c2ecf20Sopenharmony_ci	beacon = &reserved_page_packet[BEACON_PG * 128];
6768c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr);
6778c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS3(beacon, mac->bssid);
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	/*-------------------------------------------------------
6808c2ecf20Sopenharmony_ci	 *			(2) ps-poll
6818c2ecf20Sopenharmony_ci	 *--------------------------------------------------------
6828c2ecf20Sopenharmony_ci	 */
6838c2ecf20Sopenharmony_ci	p_pspoll = &reserved_page_packet[PSPOLL_PG * 128];
6848c2ecf20Sopenharmony_ci	SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000));
6858c2ecf20Sopenharmony_ci	SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid);
6868c2ecf20Sopenharmony_ci	SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr);
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1rsvdpageloc, PSPOLL_PG);
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	/*--------------------------------------------------------
6918c2ecf20Sopenharmony_ci	 *			(3) null data
6928c2ecf20Sopenharmony_ci	 *---------------------------------------------------------
6938c2ecf20Sopenharmony_ci	 */
6948c2ecf20Sopenharmony_ci	nullfunc = &reserved_page_packet[NULL_PG * 128];
6958c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid);
6968c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr);
6978c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid);
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1rsvdpageloc, NULL_PG);
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	/*---------------------------------------------------------
7028c2ecf20Sopenharmony_ci	 *			(4) probe response
7038c2ecf20Sopenharmony_ci	 *----------------------------------------------------------
7048c2ecf20Sopenharmony_ci	 */
7058c2ecf20Sopenharmony_ci	p_probersp = &reserved_page_packet[PROBERSP_PG * 128];
7068c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid);
7078c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr);
7088c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid);
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1rsvdpageloc, PROBERSP_PG);
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	/*---------------------------------------------------------
7138c2ecf20Sopenharmony_ci	 *			(5) QoS null data
7148c2ecf20Sopenharmony_ci	 *----------------------------------------------------------
7158c2ecf20Sopenharmony_ci	 */
7168c2ecf20Sopenharmony_ci	qosnull = &reserved_page_packet[QOS_NULL_PG * 128];
7178c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS1(qosnull, mac->bssid);
7188c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS2(qosnull, mac->mac_addr);
7198c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS3(qosnull, mac->bssid);
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	SET_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(u1rsvdpageloc, QOS_NULL_PG);
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	/*---------------------------------------------------------
7248c2ecf20Sopenharmony_ci	 *			(6) BT QoS null data
7258c2ecf20Sopenharmony_ci	 *----------------------------------------------------------
7268c2ecf20Sopenharmony_ci	 */
7278c2ecf20Sopenharmony_ci	btqosnull = &reserved_page_packet[BT_QOS_NULL_PG * 128];
7288c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS1(btqosnull, mac->bssid);
7298c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS2(btqosnull, mac->mac_addr);
7308c2ecf20Sopenharmony_ci	SET_80211_HDR_ADDRESS3(btqosnull, mac->bssid);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	SET_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(u1rsvdpageloc, BT_QOS_NULL_PG);
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	totalpacketlen = TOTAL_RESERVED_PKT_LEN;
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD ,
7378c2ecf20Sopenharmony_ci		      "rtl92ee_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n",
7388c2ecf20Sopenharmony_ci		      &reserved_page_packet[0], totalpacketlen);
7398c2ecf20Sopenharmony_ci	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD ,
7408c2ecf20Sopenharmony_ci		      "rtl92ee_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n",
7418c2ecf20Sopenharmony_ci		      u1rsvdpageloc, 3);
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	skb = dev_alloc_skb(totalpacketlen);
7448c2ecf20Sopenharmony_ci	if (!skb)
7458c2ecf20Sopenharmony_ci		return;
7468c2ecf20Sopenharmony_ci	skb_put_data(skb, &reserved_page_packet, totalpacketlen);
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	rtstatus = rtl_cmd_send_packet(hw, skb);
7498c2ecf20Sopenharmony_ci	if (rtstatus)
7508c2ecf20Sopenharmony_ci		b_dlok = true;
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	if (b_dlok) {
7538c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
7548c2ecf20Sopenharmony_ci			"Set RSVD page location to Fw.\n");
7558c2ecf20Sopenharmony_ci		RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD ,
7568c2ecf20Sopenharmony_ci			      "H2C_RSVDPAGE:\n", u1rsvdpageloc, 3);
7578c2ecf20Sopenharmony_ci		rtl92ee_fill_h2c_cmd(hw, H2C_92E_RSVDPAGE,
7588c2ecf20Sopenharmony_ci				     sizeof(u1rsvdpageloc), u1rsvdpageloc);
7598c2ecf20Sopenharmony_ci	} else {
7608c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING,
7618c2ecf20Sopenharmony_ci			"Set RSVD page location to Fw FAIL!!!!!!.\n");
7628c2ecf20Sopenharmony_ci	}
7638c2ecf20Sopenharmony_ci}
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci/*Shoud check FW support p2p or not.*/
7668c2ecf20Sopenharmony_cistatic void rtl92ee_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow)
7678c2ecf20Sopenharmony_ci{
7688c2ecf20Sopenharmony_ci	u8 u1_ctwindow_period[1] = {ctwindow};
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	rtl92ee_fill_h2c_cmd(hw, H2C_92E_P2P_PS_CTW_CMD, 1, u1_ctwindow_period);
7718c2ecf20Sopenharmony_ci}
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_civoid rtl92ee_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state)
7748c2ecf20Sopenharmony_ci{
7758c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
7768c2ecf20Sopenharmony_ci	struct rtl_ps_ctl *rtlps = rtl_psc(rtl_priv(hw));
7778c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
7788c2ecf20Sopenharmony_ci	struct rtl_p2p_ps_info *p2pinfo = &rtlps->p2p_ps_info;
7798c2ecf20Sopenharmony_ci	struct p2p_ps_offload_t *p2p_ps_offload = &rtlhal->p2p_ps_offload;
7808c2ecf20Sopenharmony_ci	u8 i;
7818c2ecf20Sopenharmony_ci	u16 ctwindow;
7828c2ecf20Sopenharmony_ci	u32 start_time, tsf_low;
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci	switch (p2p_ps_state) {
7858c2ecf20Sopenharmony_ci	case P2P_PS_DISABLE:
7868c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_DISABLE\n");
7878c2ecf20Sopenharmony_ci		memset(p2p_ps_offload, 0, sizeof(*p2p_ps_offload));
7888c2ecf20Sopenharmony_ci		break;
7898c2ecf20Sopenharmony_ci	case P2P_PS_ENABLE:
7908c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_ENABLE\n");
7918c2ecf20Sopenharmony_ci		/* update CTWindow value. */
7928c2ecf20Sopenharmony_ci		if (p2pinfo->ctwindow > 0) {
7938c2ecf20Sopenharmony_ci			p2p_ps_offload->ctwindow_en = 1;
7948c2ecf20Sopenharmony_ci			ctwindow = p2pinfo->ctwindow;
7958c2ecf20Sopenharmony_ci			rtl92ee_set_p2p_ctw_period_cmd(hw, ctwindow);
7968c2ecf20Sopenharmony_ci		}
7978c2ecf20Sopenharmony_ci		/* hw only support 2 set of NoA */
7988c2ecf20Sopenharmony_ci		for (i = 0 ; i < p2pinfo->noa_num ; i++) {
7998c2ecf20Sopenharmony_ci			/* To control the register setting for which NOA*/
8008c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, 0x5cf, (i << 4));
8018c2ecf20Sopenharmony_ci			if (i == 0)
8028c2ecf20Sopenharmony_ci				p2p_ps_offload->noa0_en = 1;
8038c2ecf20Sopenharmony_ci			else
8048c2ecf20Sopenharmony_ci				p2p_ps_offload->noa1_en = 1;
8058c2ecf20Sopenharmony_ci			/* config P2P NoA Descriptor Register */
8068c2ecf20Sopenharmony_ci			rtl_write_dword(rtlpriv, 0x5E0,
8078c2ecf20Sopenharmony_ci					p2pinfo->noa_duration[i]);
8088c2ecf20Sopenharmony_ci			rtl_write_dword(rtlpriv, 0x5E4,
8098c2ecf20Sopenharmony_ci					p2pinfo->noa_interval[i]);
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_ci			/*Get Current TSF value */
8128c2ecf20Sopenharmony_ci			tsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci			start_time = p2pinfo->noa_start_time[i];
8158c2ecf20Sopenharmony_ci			if (p2pinfo->noa_count_type[i] != 1) {
8168c2ecf20Sopenharmony_ci				while (start_time <= (tsf_low + (50 * 1024))) {
8178c2ecf20Sopenharmony_ci					start_time += p2pinfo->noa_interval[i];
8188c2ecf20Sopenharmony_ci					if (p2pinfo->noa_count_type[i] != 255)
8198c2ecf20Sopenharmony_ci						p2pinfo->noa_count_type[i]--;
8208c2ecf20Sopenharmony_ci				}
8218c2ecf20Sopenharmony_ci			}
8228c2ecf20Sopenharmony_ci			rtl_write_dword(rtlpriv, 0x5E8, start_time);
8238c2ecf20Sopenharmony_ci			rtl_write_dword(rtlpriv, 0x5EC,
8248c2ecf20Sopenharmony_ci					p2pinfo->noa_count_type[i]);
8258c2ecf20Sopenharmony_ci		}
8268c2ecf20Sopenharmony_ci		if ((p2pinfo->opp_ps == 1) || (p2pinfo->noa_num > 0)) {
8278c2ecf20Sopenharmony_ci			/* rst p2p circuit */
8288c2ecf20Sopenharmony_ci			rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, BIT(4));
8298c2ecf20Sopenharmony_ci			p2p_ps_offload->offload_en = 1;
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci			if (P2P_ROLE_GO == rtlpriv->mac80211.p2p) {
8328c2ecf20Sopenharmony_ci				p2p_ps_offload->role = 1;
8338c2ecf20Sopenharmony_ci				p2p_ps_offload->allstasleep = 0;
8348c2ecf20Sopenharmony_ci			} else {
8358c2ecf20Sopenharmony_ci				p2p_ps_offload->role = 0;
8368c2ecf20Sopenharmony_ci			}
8378c2ecf20Sopenharmony_ci			p2p_ps_offload->discovery = 0;
8388c2ecf20Sopenharmony_ci		}
8398c2ecf20Sopenharmony_ci		break;
8408c2ecf20Sopenharmony_ci	case P2P_PS_SCAN:
8418c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN\n");
8428c2ecf20Sopenharmony_ci		p2p_ps_offload->discovery = 1;
8438c2ecf20Sopenharmony_ci		break;
8448c2ecf20Sopenharmony_ci	case P2P_PS_SCAN_DONE:
8458c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN_DONE\n");
8468c2ecf20Sopenharmony_ci		p2p_ps_offload->discovery = 0;
8478c2ecf20Sopenharmony_ci		p2pinfo->p2p_ps_state = P2P_PS_ENABLE;
8488c2ecf20Sopenharmony_ci		break;
8498c2ecf20Sopenharmony_ci	default:
8508c2ecf20Sopenharmony_ci		break;
8518c2ecf20Sopenharmony_ci	}
8528c2ecf20Sopenharmony_ci	rtl92ee_fill_h2c_cmd(hw, H2C_92E_P2P_PS_OFFLOAD, 1,
8538c2ecf20Sopenharmony_ci			     (u8 *)p2p_ps_offload);
8548c2ecf20Sopenharmony_ci}
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_civoid rtl92ee_c2h_ra_report_handler(struct ieee80211_hw *hw,
8578c2ecf20Sopenharmony_ci				   u8 *cmd_buf, u8 cmd_len)
8588c2ecf20Sopenharmony_ci{
8598c2ecf20Sopenharmony_ci	u8 rate = cmd_buf[0] & 0x3F;
8608c2ecf20Sopenharmony_ci	bool collision_state = cmd_buf[3] & BIT(0);
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci	rtl92ee_dm_dynamic_arfb_select(hw, rate, collision_state);
8638c2ecf20Sopenharmony_ci}
864