18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2012  Realtek Corporation.*/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "../wifi.h"
58c2ecf20Sopenharmony_ci#include "../pci.h"
68c2ecf20Sopenharmony_ci#include "../usb.h"
78c2ecf20Sopenharmony_ci#include "../ps.h"
88c2ecf20Sopenharmony_ci#include "../cam.h"
98c2ecf20Sopenharmony_ci#include "../stats.h"
108c2ecf20Sopenharmony_ci#include "reg.h"
118c2ecf20Sopenharmony_ci#include "def.h"
128c2ecf20Sopenharmony_ci#include "phy.h"
138c2ecf20Sopenharmony_ci#include "rf.h"
148c2ecf20Sopenharmony_ci#include "dm.h"
158c2ecf20Sopenharmony_ci#include "mac.h"
168c2ecf20Sopenharmony_ci#include "trx.h"
178c2ecf20Sopenharmony_ci#include "../rtl8192c/fw_common.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/module.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* macro to shorten lines */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define LINK_Q	ui_link_quality
248c2ecf20Sopenharmony_ci#define RX_EVM	rx_evm_percentage
258c2ecf20Sopenharmony_ci#define RX_SIGQ	rx_mimo_sig_qual
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_civoid rtl92c_read_chip_version(struct ieee80211_hw *hw)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
308c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
318c2ecf20Sopenharmony_ci	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
328c2ecf20Sopenharmony_ci	enum version_8192c chip_version = VERSION_UNKNOWN;
338c2ecf20Sopenharmony_ci	const char *versionid;
348c2ecf20Sopenharmony_ci	u32 value32;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
378c2ecf20Sopenharmony_ci	if (value32 & TRP_VAUX_EN) {
388c2ecf20Sopenharmony_ci		chip_version = (value32 & TYPE_ID) ? VERSION_TEST_CHIP_92C :
398c2ecf20Sopenharmony_ci			       VERSION_TEST_CHIP_88C;
408c2ecf20Sopenharmony_ci	} else {
418c2ecf20Sopenharmony_ci		/* Normal mass production chip. */
428c2ecf20Sopenharmony_ci		chip_version = NORMAL_CHIP;
438c2ecf20Sopenharmony_ci		chip_version |= ((value32 & TYPE_ID) ? CHIP_92C : 0);
448c2ecf20Sopenharmony_ci		chip_version |= ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0);
458c2ecf20Sopenharmony_ci		if (IS_VENDOR_UMC(chip_version))
468c2ecf20Sopenharmony_ci			chip_version |= ((value32 & CHIP_VER_RTL_MASK) ?
478c2ecf20Sopenharmony_ci					 CHIP_VENDOR_UMC_B_CUT : 0);
488c2ecf20Sopenharmony_ci		if (IS_92C_SERIAL(chip_version)) {
498c2ecf20Sopenharmony_ci			value32 = rtl_read_dword(rtlpriv, REG_HPON_FSM);
508c2ecf20Sopenharmony_ci			chip_version |= ((CHIP_BONDING_IDENTIFIER(value32) ==
518c2ecf20Sopenharmony_ci				 CHIP_BONDING_92C_1T2R) ? CHIP_92C_1T2R : 0);
528c2ecf20Sopenharmony_ci		}
538c2ecf20Sopenharmony_ci	}
548c2ecf20Sopenharmony_ci	rtlhal->version  = (enum version_8192c)chip_version;
558c2ecf20Sopenharmony_ci	pr_info("Chip version 0x%x\n", chip_version);
568c2ecf20Sopenharmony_ci	switch (rtlhal->version) {
578c2ecf20Sopenharmony_ci	case VERSION_NORMAL_TSMC_CHIP_92C_1T2R:
588c2ecf20Sopenharmony_ci		versionid = "NORMAL_B_CHIP_92C";
598c2ecf20Sopenharmony_ci		break;
608c2ecf20Sopenharmony_ci	case VERSION_NORMAL_TSMC_CHIP_92C:
618c2ecf20Sopenharmony_ci		versionid = "NORMAL_TSMC_CHIP_92C";
628c2ecf20Sopenharmony_ci		break;
638c2ecf20Sopenharmony_ci	case VERSION_NORMAL_TSMC_CHIP_88C:
648c2ecf20Sopenharmony_ci		versionid = "NORMAL_TSMC_CHIP_88C";
658c2ecf20Sopenharmony_ci		break;
668c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_92C_1T2R_A_CUT:
678c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_i92C_1T2R_A_CUT";
688c2ecf20Sopenharmony_ci		break;
698c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_92C_A_CUT:
708c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_92C_A_CUT";
718c2ecf20Sopenharmony_ci		break;
728c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_88C_A_CUT:
738c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_88C_A_CUT";
748c2ecf20Sopenharmony_ci		break;
758c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_92C_1T2R_B_CUT:
768c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_92C_1T2R_B_CUT";
778c2ecf20Sopenharmony_ci		break;
788c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_92C_B_CUT:
798c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_92C_B_CUT";
808c2ecf20Sopenharmony_ci		break;
818c2ecf20Sopenharmony_ci	case VERSION_NORMAL_UMC_CHIP_88C_B_CUT:
828c2ecf20Sopenharmony_ci		versionid = "NORMAL_UMC_CHIP_88C_B_CUT";
838c2ecf20Sopenharmony_ci		break;
848c2ecf20Sopenharmony_ci	case VERSION_TEST_CHIP_92C:
858c2ecf20Sopenharmony_ci		versionid = "TEST_CHIP_92C";
868c2ecf20Sopenharmony_ci		break;
878c2ecf20Sopenharmony_ci	case VERSION_TEST_CHIP_88C:
888c2ecf20Sopenharmony_ci		versionid = "TEST_CHIP_88C";
898c2ecf20Sopenharmony_ci		break;
908c2ecf20Sopenharmony_ci	default:
918c2ecf20Sopenharmony_ci		versionid = "UNKNOWN";
928c2ecf20Sopenharmony_ci		break;
938c2ecf20Sopenharmony_ci	}
948c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
958c2ecf20Sopenharmony_ci		"Chip Version ID: %s\n", versionid);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	if (IS_92C_SERIAL(rtlhal->version))
988c2ecf20Sopenharmony_ci		rtlphy->rf_type =
998c2ecf20Sopenharmony_ci			 (IS_92C_1T2R(rtlhal->version)) ? RF_1T2R : RF_2T2R;
1008c2ecf20Sopenharmony_ci	else
1018c2ecf20Sopenharmony_ci		rtlphy->rf_type = RF_1T1R;
1028c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
1038c2ecf20Sopenharmony_ci		"Chip RF Type: %s\n",
1048c2ecf20Sopenharmony_ci		rtlphy->rf_type == RF_2T2R ? "RF_2T2R" : "RF_1T1R");
1058c2ecf20Sopenharmony_ci	if (get_rf_type(rtlphy) == RF_1T1R)
1068c2ecf20Sopenharmony_ci		rtlpriv->dm.rfpath_rxenable[0] = true;
1078c2ecf20Sopenharmony_ci	else
1088c2ecf20Sopenharmony_ci		rtlpriv->dm.rfpath_rxenable[0] =
1098c2ecf20Sopenharmony_ci		    rtlpriv->dm.rfpath_rxenable[1] = true;
1108c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
1118c2ecf20Sopenharmony_ci		rtlhal->version);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci/**
1158c2ecf20Sopenharmony_ci * writeLLT - LLT table write access
1168c2ecf20Sopenharmony_ci * @io: io callback
1178c2ecf20Sopenharmony_ci * @address: LLT logical address.
1188c2ecf20Sopenharmony_ci * @data: LLT data content
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * Realtek hardware access function.
1218c2ecf20Sopenharmony_ci *
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_cibool rtl92c_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1268c2ecf20Sopenharmony_ci	bool status = true;
1278c2ecf20Sopenharmony_ci	long count = 0;
1288c2ecf20Sopenharmony_ci	u32 value = _LLT_INIT_ADDR(address) |
1298c2ecf20Sopenharmony_ci	    _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
1328c2ecf20Sopenharmony_ci	do {
1338c2ecf20Sopenharmony_ci		value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
1348c2ecf20Sopenharmony_ci		if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
1358c2ecf20Sopenharmony_ci			break;
1368c2ecf20Sopenharmony_ci		if (count > POLLING_LLT_THRESHOLD) {
1378c2ecf20Sopenharmony_ci			pr_err("Failed to polling write LLT done at address %d! _LLT_OP_VALUE(%x)\n",
1388c2ecf20Sopenharmony_ci			       address, _LLT_OP_VALUE(value));
1398c2ecf20Sopenharmony_ci			status = false;
1408c2ecf20Sopenharmony_ci			break;
1418c2ecf20Sopenharmony_ci		}
1428c2ecf20Sopenharmony_ci	} while (++count);
1438c2ecf20Sopenharmony_ci	return status;
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/**
1478c2ecf20Sopenharmony_ci * rtl92c_init_LLT_table - Init LLT table
1488c2ecf20Sopenharmony_ci * @io: io callback
1498c2ecf20Sopenharmony_ci * @boundary:
1508c2ecf20Sopenharmony_ci *
1518c2ecf20Sopenharmony_ci * Realtek hardware access function.
1528c2ecf20Sopenharmony_ci *
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_cibool rtl92c_init_llt_table(struct ieee80211_hw *hw, u32 boundary)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	bool rst = true;
1578c2ecf20Sopenharmony_ci	u32	i;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	for (i = 0; i < (boundary - 1); i++) {
1608c2ecf20Sopenharmony_ci		rst = rtl92c_llt_write(hw, i , i + 1);
1618c2ecf20Sopenharmony_ci		if (!rst) {
1628c2ecf20Sopenharmony_ci			pr_err("===> %s #1 fail\n", __func__);
1638c2ecf20Sopenharmony_ci			return rst;
1648c2ecf20Sopenharmony_ci		}
1658c2ecf20Sopenharmony_ci	}
1668c2ecf20Sopenharmony_ci	/* end of list */
1678c2ecf20Sopenharmony_ci	rst = rtl92c_llt_write(hw, (boundary - 1), 0xFF);
1688c2ecf20Sopenharmony_ci	if (!rst) {
1698c2ecf20Sopenharmony_ci		pr_err("===> %s #2 fail\n", __func__);
1708c2ecf20Sopenharmony_ci		return rst;
1718c2ecf20Sopenharmony_ci	}
1728c2ecf20Sopenharmony_ci	/* Make the other pages as ring buffer
1738c2ecf20Sopenharmony_ci	 * This ring buffer is used as beacon buffer if we config this MAC
1748c2ecf20Sopenharmony_ci	 *  as two MAC transfer.
1758c2ecf20Sopenharmony_ci	 * Otherwise used as local loopback buffer.
1768c2ecf20Sopenharmony_ci	 */
1778c2ecf20Sopenharmony_ci	for (i = boundary; i < LLT_LAST_ENTRY_OF_TX_PKT_BUFFER; i++) {
1788c2ecf20Sopenharmony_ci		rst = rtl92c_llt_write(hw, i, (i + 1));
1798c2ecf20Sopenharmony_ci		if (!rst) {
1808c2ecf20Sopenharmony_ci			pr_err("===> %s #3 fail\n", __func__);
1818c2ecf20Sopenharmony_ci			return rst;
1828c2ecf20Sopenharmony_ci		}
1838c2ecf20Sopenharmony_ci	}
1848c2ecf20Sopenharmony_ci	/* Let last entry point to the start entry of ring buffer */
1858c2ecf20Sopenharmony_ci	rst = rtl92c_llt_write(hw, LLT_LAST_ENTRY_OF_TX_PKT_BUFFER, boundary);
1868c2ecf20Sopenharmony_ci	if (!rst) {
1878c2ecf20Sopenharmony_ci		pr_err("===> %s #4 fail\n", __func__);
1888c2ecf20Sopenharmony_ci		return rst;
1898c2ecf20Sopenharmony_ci	}
1908c2ecf20Sopenharmony_ci	return rst;
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_civoid rtl92c_set_key(struct ieee80211_hw *hw, u32 key_index,
1948c2ecf20Sopenharmony_ci		     u8 *p_macaddr, bool is_group, u8 enc_algo,
1958c2ecf20Sopenharmony_ci		     bool is_wepkey, bool clear_all)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1988c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1998c2ecf20Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2008c2ecf20Sopenharmony_ci	u8 *macaddr = p_macaddr;
2018c2ecf20Sopenharmony_ci	u32 entry_id = 0;
2028c2ecf20Sopenharmony_ci	bool is_pairwise = false;
2038c2ecf20Sopenharmony_ci	static u8 cam_const_addr[4][6] = {
2048c2ecf20Sopenharmony_ci		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2058c2ecf20Sopenharmony_ci		{0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2068c2ecf20Sopenharmony_ci		{0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2078c2ecf20Sopenharmony_ci		{0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2088c2ecf20Sopenharmony_ci	};
2098c2ecf20Sopenharmony_ci	static u8 cam_const_broad[] = {
2108c2ecf20Sopenharmony_ci		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2118c2ecf20Sopenharmony_ci	};
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	if (clear_all) {
2148c2ecf20Sopenharmony_ci		u8 idx = 0;
2158c2ecf20Sopenharmony_ci		u8 cam_offset = 0;
2168c2ecf20Sopenharmony_ci		u8 clear_number = 5;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
2198c2ecf20Sopenharmony_ci		for (idx = 0; idx < clear_number; idx++) {
2208c2ecf20Sopenharmony_ci			rtl_cam_mark_invalid(hw, cam_offset + idx);
2218c2ecf20Sopenharmony_ci			rtl_cam_empty_entry(hw, cam_offset + idx);
2228c2ecf20Sopenharmony_ci			if (idx < 5) {
2238c2ecf20Sopenharmony_ci				memset(rtlpriv->sec.key_buf[idx], 0,
2248c2ecf20Sopenharmony_ci				       MAX_KEY_LEN);
2258c2ecf20Sopenharmony_ci				rtlpriv->sec.key_len[idx] = 0;
2268c2ecf20Sopenharmony_ci			}
2278c2ecf20Sopenharmony_ci		}
2288c2ecf20Sopenharmony_ci	} else {
2298c2ecf20Sopenharmony_ci		switch (enc_algo) {
2308c2ecf20Sopenharmony_ci		case WEP40_ENCRYPTION:
2318c2ecf20Sopenharmony_ci			enc_algo = CAM_WEP40;
2328c2ecf20Sopenharmony_ci			break;
2338c2ecf20Sopenharmony_ci		case WEP104_ENCRYPTION:
2348c2ecf20Sopenharmony_ci			enc_algo = CAM_WEP104;
2358c2ecf20Sopenharmony_ci			break;
2368c2ecf20Sopenharmony_ci		case TKIP_ENCRYPTION:
2378c2ecf20Sopenharmony_ci			enc_algo = CAM_TKIP;
2388c2ecf20Sopenharmony_ci			break;
2398c2ecf20Sopenharmony_ci		case AESCCMP_ENCRYPTION:
2408c2ecf20Sopenharmony_ci			enc_algo = CAM_AES;
2418c2ecf20Sopenharmony_ci			break;
2428c2ecf20Sopenharmony_ci		default:
2438c2ecf20Sopenharmony_ci			pr_err("illegal switch case\n");
2448c2ecf20Sopenharmony_ci			enc_algo = CAM_TKIP;
2458c2ecf20Sopenharmony_ci			break;
2468c2ecf20Sopenharmony_ci		}
2478c2ecf20Sopenharmony_ci		if (is_wepkey || rtlpriv->sec.use_defaultkey) {
2488c2ecf20Sopenharmony_ci			macaddr = cam_const_addr[key_index];
2498c2ecf20Sopenharmony_ci			entry_id = key_index;
2508c2ecf20Sopenharmony_ci		} else {
2518c2ecf20Sopenharmony_ci			if (is_group) {
2528c2ecf20Sopenharmony_ci				macaddr = cam_const_broad;
2538c2ecf20Sopenharmony_ci				entry_id = key_index;
2548c2ecf20Sopenharmony_ci			} else {
2558c2ecf20Sopenharmony_ci				if (mac->opmode == NL80211_IFTYPE_AP ||
2568c2ecf20Sopenharmony_ci				    mac->opmode == NL80211_IFTYPE_MESH_POINT) {
2578c2ecf20Sopenharmony_ci					entry_id = rtl_cam_get_free_entry(hw,
2588c2ecf20Sopenharmony_ci								 p_macaddr);
2598c2ecf20Sopenharmony_ci					if (entry_id >=  TOTAL_CAM_ENTRY) {
2608c2ecf20Sopenharmony_ci						pr_err("Can not find free hw security cam entry\n");
2618c2ecf20Sopenharmony_ci						return;
2628c2ecf20Sopenharmony_ci					}
2638c2ecf20Sopenharmony_ci				} else {
2648c2ecf20Sopenharmony_ci					entry_id = CAM_PAIRWISE_KEY_POSITION;
2658c2ecf20Sopenharmony_ci				}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci				key_index = PAIRWISE_KEYIDX;
2688c2ecf20Sopenharmony_ci				is_pairwise = true;
2698c2ecf20Sopenharmony_ci			}
2708c2ecf20Sopenharmony_ci		}
2718c2ecf20Sopenharmony_ci		if (rtlpriv->sec.key_len[key_index] == 0) {
2728c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG,
2738c2ecf20Sopenharmony_ci				"delete one entry\n");
2748c2ecf20Sopenharmony_ci			if (mac->opmode == NL80211_IFTYPE_AP ||
2758c2ecf20Sopenharmony_ci			    mac->opmode == NL80211_IFTYPE_MESH_POINT)
2768c2ecf20Sopenharmony_ci				rtl_cam_del_entry(hw, p_macaddr);
2778c2ecf20Sopenharmony_ci			rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2788c2ecf20Sopenharmony_ci		} else {
2798c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_SEC, DBG_LOUD,
2808c2ecf20Sopenharmony_ci				"The insert KEY length is %d\n",
2818c2ecf20Sopenharmony_ci				 rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
2828c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_SEC, DBG_LOUD,
2838c2ecf20Sopenharmony_ci				"The insert KEY is %x %x\n",
2848c2ecf20Sopenharmony_ci				rtlpriv->sec.key_buf[0][0],
2858c2ecf20Sopenharmony_ci				rtlpriv->sec.key_buf[0][1]);
2868c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG,
2878c2ecf20Sopenharmony_ci				"add one entry\n");
2888c2ecf20Sopenharmony_ci			if (is_pairwise) {
2898c2ecf20Sopenharmony_ci				RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
2908c2ecf20Sopenharmony_ci					      "Pairwise Key content",
2918c2ecf20Sopenharmony_ci					      rtlpriv->sec.pairwise_key,
2928c2ecf20Sopenharmony_ci					      rtlpriv->sec.
2938c2ecf20Sopenharmony_ci					      key_len[PAIRWISE_KEYIDX]);
2948c2ecf20Sopenharmony_ci				rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG,
2958c2ecf20Sopenharmony_ci					"set Pairwise key\n");
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci				rtl_cam_add_one_entry(hw, macaddr, key_index,
2988c2ecf20Sopenharmony_ci						entry_id, enc_algo,
2998c2ecf20Sopenharmony_ci						CAM_CONFIG_NO_USEDK,
3008c2ecf20Sopenharmony_ci						rtlpriv->sec.
3018c2ecf20Sopenharmony_ci						key_buf[key_index]);
3028c2ecf20Sopenharmony_ci			} else {
3038c2ecf20Sopenharmony_ci				rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG,
3048c2ecf20Sopenharmony_ci					"set group key\n");
3058c2ecf20Sopenharmony_ci				if (mac->opmode == NL80211_IFTYPE_ADHOC) {
3068c2ecf20Sopenharmony_ci					rtl_cam_add_one_entry(hw,
3078c2ecf20Sopenharmony_ci						rtlefuse->dev_addr,
3088c2ecf20Sopenharmony_ci						PAIRWISE_KEYIDX,
3098c2ecf20Sopenharmony_ci						CAM_PAIRWISE_KEY_POSITION,
3108c2ecf20Sopenharmony_ci						enc_algo,
3118c2ecf20Sopenharmony_ci						CAM_CONFIG_NO_USEDK,
3128c2ecf20Sopenharmony_ci						rtlpriv->sec.key_buf
3138c2ecf20Sopenharmony_ci						[entry_id]);
3148c2ecf20Sopenharmony_ci				}
3158c2ecf20Sopenharmony_ci				rtl_cam_add_one_entry(hw, macaddr, key_index,
3168c2ecf20Sopenharmony_ci						entry_id, enc_algo,
3178c2ecf20Sopenharmony_ci						CAM_CONFIG_NO_USEDK,
3188c2ecf20Sopenharmony_ci						rtlpriv->sec.key_buf[entry_id]);
3198c2ecf20Sopenharmony_ci			}
3208c2ecf20Sopenharmony_ci		}
3218c2ecf20Sopenharmony_ci	}
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ciu32 rtl92c_get_txdma_status(struct ieee80211_hw *hw)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	return rtl_read_dword(rtlpriv, REG_TXDMA_STATUS);
3298c2ecf20Sopenharmony_ci}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_civoid rtl92c_enable_interrupt(struct ieee80211_hw *hw)
3328c2ecf20Sopenharmony_ci{
3338c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3348c2ecf20Sopenharmony_ci	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
3358c2ecf20Sopenharmony_ci	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	if (IS_HARDWARE_TYPE_8192CE(rtlpriv)) {
3388c2ecf20Sopenharmony_ci		rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] &
3398c2ecf20Sopenharmony_ci				0xFFFFFFFF);
3408c2ecf20Sopenharmony_ci		rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] &
3418c2ecf20Sopenharmony_ci				0xFFFFFFFF);
3428c2ecf20Sopenharmony_ci	} else {
3438c2ecf20Sopenharmony_ci		rtl_write_dword(rtlpriv, REG_HIMR, rtlusb->irq_mask[0] &
3448c2ecf20Sopenharmony_ci				0xFFFFFFFF);
3458c2ecf20Sopenharmony_ci		rtl_write_dword(rtlpriv, REG_HIMRE, rtlusb->irq_mask[1] &
3468c2ecf20Sopenharmony_ci				0xFFFFFFFF);
3478c2ecf20Sopenharmony_ci	}
3488c2ecf20Sopenharmony_ci}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_civoid rtl92c_init_interrupt(struct ieee80211_hw *hw)
3518c2ecf20Sopenharmony_ci{
3528c2ecf20Sopenharmony_ci	 rtl92c_enable_interrupt(hw);
3538c2ecf20Sopenharmony_ci}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_civoid rtl92c_disable_interrupt(struct ieee80211_hw *hw)
3568c2ecf20Sopenharmony_ci{
3578c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
3608c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_civoid rtl92c_set_qos(struct ieee80211_hw *hw, int aci)
3648c2ecf20Sopenharmony_ci{
3658c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	rtl92c_dm_init_edca_turbo(hw);
3688c2ecf20Sopenharmony_ci	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, (u8 *)&aci);
3698c2ecf20Sopenharmony_ci}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_civoid rtl92c_init_driver_info_size(struct ieee80211_hw *hw, u8 size)
3728c2ecf20Sopenharmony_ci{
3738c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, size);
3768c2ecf20Sopenharmony_ci}
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ciint rtl92c_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
3798c2ecf20Sopenharmony_ci{
3808c2ecf20Sopenharmony_ci	u8 value;
3818c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	switch (type) {
3848c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_UNSPECIFIED:
3858c2ecf20Sopenharmony_ci		value = NT_NO_LINK;
3868c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
3878c2ecf20Sopenharmony_ci			"Set Network type to NO LINK!\n");
3888c2ecf20Sopenharmony_ci		break;
3898c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
3908c2ecf20Sopenharmony_ci		value = NT_LINK_AD_HOC;
3918c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
3928c2ecf20Sopenharmony_ci			"Set Network type to Ad Hoc!\n");
3938c2ecf20Sopenharmony_ci		break;
3948c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
3958c2ecf20Sopenharmony_ci		value = NT_LINK_AP;
3968c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
3978c2ecf20Sopenharmony_ci			"Set Network type to STA!\n");
3988c2ecf20Sopenharmony_ci		break;
3998c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
4008c2ecf20Sopenharmony_ci		value = NT_AS_AP;
4018c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
4028c2ecf20Sopenharmony_ci			"Set Network type to AP!\n");
4038c2ecf20Sopenharmony_ci		break;
4048c2ecf20Sopenharmony_ci	default:
4058c2ecf20Sopenharmony_ci		rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
4068c2ecf20Sopenharmony_ci			"Network type %d not supported!\n", type);
4078c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
4088c2ecf20Sopenharmony_ci	}
4098c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, MSR, value);
4108c2ecf20Sopenharmony_ci	return 0;
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_civoid rtl92c_init_network_type(struct ieee80211_hw *hw)
4148c2ecf20Sopenharmony_ci{
4158c2ecf20Sopenharmony_ci	rtl92c_set_network_type(hw, NL80211_IFTYPE_UNSPECIFIED);
4168c2ecf20Sopenharmony_ci}
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_civoid rtl92c_init_adaptive_ctrl(struct ieee80211_hw *hw)
4198c2ecf20Sopenharmony_ci{
4208c2ecf20Sopenharmony_ci	u16	value16;
4218c2ecf20Sopenharmony_ci	u32	value32;
4228c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	/* Response Rate Set */
4258c2ecf20Sopenharmony_ci	value32 = rtl_read_dword(rtlpriv, REG_RRSR);
4268c2ecf20Sopenharmony_ci	value32 &= ~RATE_BITMAP_ALL;
4278c2ecf20Sopenharmony_ci	value32 |= RATE_RRSR_CCK_ONLY_1M;
4288c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_RRSR, value32);
4298c2ecf20Sopenharmony_ci	/* SIFS (used in NAV) */
4308c2ecf20Sopenharmony_ci	value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
4318c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv,  REG_SPEC_SIFS, value16);
4328c2ecf20Sopenharmony_ci	/* Retry Limit */
4338c2ecf20Sopenharmony_ci	value16 = _LRL(0x30) | _SRL(0x30);
4348c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv,  REG_RL, value16);
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_civoid rtl92c_init_rate_fallback(struct ieee80211_hw *hw)
4388c2ecf20Sopenharmony_ci{
4398c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	/* Set Data Auto Rate Fallback Retry Count register. */
4428c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv,  REG_DARFRC, 0x00000000);
4438c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv,  REG_DARFRC+4, 0x10080404);
4448c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv,  REG_RARFRC, 0x04030201);
4458c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv,  REG_RARFRC+4, 0x08070605);
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cistatic void rtl92c_set_cck_sifs(struct ieee80211_hw *hw, u8 trx_sifs,
4498c2ecf20Sopenharmony_ci				u8 ctx_sifs)
4508c2ecf20Sopenharmony_ci{
4518c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_SIFS_CCK, trx_sifs);
4548c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, (REG_SIFS_CCK + 1), ctx_sifs);
4558c2ecf20Sopenharmony_ci}
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistatic void rtl92c_set_ofdm_sifs(struct ieee80211_hw *hw, u8 trx_sifs,
4588c2ecf20Sopenharmony_ci				 u8 ctx_sifs)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_SIFS_OFDM, trx_sifs);
4638c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, (REG_SIFS_OFDM + 1), ctx_sifs);
4648c2ecf20Sopenharmony_ci}
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_civoid rtl92c_init_edca_param(struct ieee80211_hw *hw,
4678c2ecf20Sopenharmony_ci			    u16 queue, u16 txop, u8 cw_min, u8 cw_max, u8 aifs)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	/* sequence: VO, VI, BE, BK ==> the same as 92C hardware design.
4708c2ecf20Sopenharmony_ci	 * referenc : enum nl80211_txq_q or ieee80211_set_wmm_default function.
4718c2ecf20Sopenharmony_ci	 */
4728c2ecf20Sopenharmony_ci	u32 value;
4738c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	value = (u32)aifs;
4768c2ecf20Sopenharmony_ci	value |= ((u32)cw_min & 0xF) << 8;
4778c2ecf20Sopenharmony_ci	value |= ((u32)cw_max & 0xF) << 12;
4788c2ecf20Sopenharmony_ci	value |= (u32)txop << 16;
4798c2ecf20Sopenharmony_ci	/* 92C hardware register sequence is the same as queue number. */
4808c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, (REG_EDCA_VO_PARAM + (queue * 4)), value);
4818c2ecf20Sopenharmony_ci}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_civoid rtl92c_init_edca(struct ieee80211_hw *hw)
4848c2ecf20Sopenharmony_ci{
4858c2ecf20Sopenharmony_ci	u16 value16;
4868c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	/* disable EDCCA count down, to reduce collison and retry */
4898c2ecf20Sopenharmony_ci	value16 = rtl_read_word(rtlpriv, REG_RD_CTRL);
4908c2ecf20Sopenharmony_ci	value16 |= DIS_EDCA_CNT_DWN;
4918c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_RD_CTRL, value16);
4928c2ecf20Sopenharmony_ci	/* Update SIFS timing.  ??????????
4938c2ecf20Sopenharmony_ci	 * pHalData->SifsTime = 0x0e0e0a0a; */
4948c2ecf20Sopenharmony_ci	rtl92c_set_cck_sifs(hw, 0xa, 0xa);
4958c2ecf20Sopenharmony_ci	rtl92c_set_ofdm_sifs(hw, 0xe, 0xe);
4968c2ecf20Sopenharmony_ci	/* Set CCK/OFDM SIFS to be 10us. */
4978c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_SIFS_CCK, 0x0a0a);
4988c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_SIFS_OFDM, 0x1010);
4998c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0204);
5008c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x014004);
5018c2ecf20Sopenharmony_ci	/* TXOP */
5028c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, 0x005EA42B);
5038c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0x0000A44F);
5048c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x005EA324);
5058c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x002FA226);
5068c2ecf20Sopenharmony_ci	/* PIFS */
5078c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
5088c2ecf20Sopenharmony_ci	/* AGGR BREAK TIME Register */
5098c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
5108c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0040);
5118c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_BCNDMATIM, 0x02);
5128c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_ATIMWND, 0x02);
5138c2ecf20Sopenharmony_ci}
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_civoid rtl92c_init_ampdu_aggregation(struct ieee80211_hw *hw)
5168c2ecf20Sopenharmony_ci{
5178c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x99997631);
5208c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
5218c2ecf20Sopenharmony_ci	/* init AMPDU aggregation number, tuning for Tx's TP, */
5228c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, 0x4CA, 0x0708);
5238c2ecf20Sopenharmony_ci}
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_civoid rtl92c_init_beacon_max_error(struct ieee80211_hw *hw)
5268c2ecf20Sopenharmony_ci{
5278c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xFF);
5308c2ecf20Sopenharmony_ci}
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_civoid rtl92c_init_rdg_setting(struct ieee80211_hw *hw)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_RD_CTRL, 0xFF);
5378c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_RD_NAV_NXT, 0x200);
5388c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_RD_RESP_PKT_TH, 0x05);
5398c2ecf20Sopenharmony_ci}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_civoid rtl92c_init_retry_function(struct ieee80211_hw *hw)
5428c2ecf20Sopenharmony_ci{
5438c2ecf20Sopenharmony_ci	u8	value8;
5448c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	value8 = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL);
5478c2ecf20Sopenharmony_ci	value8 |= EN_AMPDU_RTY_NEW;
5488c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL, value8);
5498c2ecf20Sopenharmony_ci	/* Set ACK timeout */
5508c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
5518c2ecf20Sopenharmony_ci}
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_civoid rtl92c_disable_fast_edca(struct ieee80211_hw *hw)
5548c2ecf20Sopenharmony_ci{
5558c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	rtl_write_word(rtlpriv, REG_FAST_EDCA_CTRL, 0);
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_civoid rtl92c_set_min_space(struct ieee80211_hw *hw, bool is2T)
5618c2ecf20Sopenharmony_ci{
5628c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5638c2ecf20Sopenharmony_ci	u8 value = is2T ? MAX_MSS_DENSITY_2T : MAX_MSS_DENSITY_1T;
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, value);
5668c2ecf20Sopenharmony_ci}
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci/*==============================================================*/
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_cistatic void _rtl92c_query_rxphystatus(struct ieee80211_hw *hw,
5718c2ecf20Sopenharmony_ci				      struct rtl_stats *pstats,
5728c2ecf20Sopenharmony_ci				      struct rx_desc_92c *p_desc,
5738c2ecf20Sopenharmony_ci				      struct rx_fwinfo_92c *p_drvinfo,
5748c2ecf20Sopenharmony_ci				      bool packet_match_bssid,
5758c2ecf20Sopenharmony_ci				      bool packet_toself,
5768c2ecf20Sopenharmony_ci				      bool packet_beacon)
5778c2ecf20Sopenharmony_ci{
5788c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5798c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
5808c2ecf20Sopenharmony_ci	struct phy_sts_cck_8192s_t *cck_buf;
5818c2ecf20Sopenharmony_ci	s8 rx_pwr_all = 0, rx_pwr[4];
5828c2ecf20Sopenharmony_ci	u8 rf_rx_num = 0, evm, pwdb_all;
5838c2ecf20Sopenharmony_ci	u8 i, max_spatial_stream;
5848c2ecf20Sopenharmony_ci	u32 rssi, total_rssi = 0;
5858c2ecf20Sopenharmony_ci	bool in_powersavemode = false;
5868c2ecf20Sopenharmony_ci	bool is_cck_rate;
5878c2ecf20Sopenharmony_ci	__le32 *pdesc = (__le32 *)p_desc;
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	is_cck_rate = RX_HAL_IS_CCK_RATE(p_desc->rxmcs);
5908c2ecf20Sopenharmony_ci	pstats->packet_matchbssid = packet_match_bssid;
5918c2ecf20Sopenharmony_ci	pstats->packet_toself = packet_toself;
5928c2ecf20Sopenharmony_ci	pstats->packet_beacon = packet_beacon;
5938c2ecf20Sopenharmony_ci	pstats->is_cck = is_cck_rate;
5948c2ecf20Sopenharmony_ci	pstats->RX_SIGQ[0] = -1;
5958c2ecf20Sopenharmony_ci	pstats->RX_SIGQ[1] = -1;
5968c2ecf20Sopenharmony_ci	if (is_cck_rate) {
5978c2ecf20Sopenharmony_ci		u8 report, cck_highpwr;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci		cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
6008c2ecf20Sopenharmony_ci		if (!in_powersavemode)
6018c2ecf20Sopenharmony_ci			cck_highpwr = rtlphy->cck_high_power;
6028c2ecf20Sopenharmony_ci		else
6038c2ecf20Sopenharmony_ci			cck_highpwr = false;
6048c2ecf20Sopenharmony_ci		if (!cck_highpwr) {
6058c2ecf20Sopenharmony_ci			u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci			report = cck_buf->cck_agc_rpt & 0xc0;
6088c2ecf20Sopenharmony_ci			report = report >> 6;
6098c2ecf20Sopenharmony_ci			switch (report) {
6108c2ecf20Sopenharmony_ci			case 0x3:
6118c2ecf20Sopenharmony_ci				rx_pwr_all = -46 - (cck_agc_rpt & 0x3e);
6128c2ecf20Sopenharmony_ci				break;
6138c2ecf20Sopenharmony_ci			case 0x2:
6148c2ecf20Sopenharmony_ci				rx_pwr_all = -26 - (cck_agc_rpt & 0x3e);
6158c2ecf20Sopenharmony_ci				break;
6168c2ecf20Sopenharmony_ci			case 0x1:
6178c2ecf20Sopenharmony_ci				rx_pwr_all = -12 - (cck_agc_rpt & 0x3e);
6188c2ecf20Sopenharmony_ci				break;
6198c2ecf20Sopenharmony_ci			case 0x0:
6208c2ecf20Sopenharmony_ci				rx_pwr_all = 16 - (cck_agc_rpt & 0x3e);
6218c2ecf20Sopenharmony_ci				break;
6228c2ecf20Sopenharmony_ci			}
6238c2ecf20Sopenharmony_ci		} else {
6248c2ecf20Sopenharmony_ci			u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci			report = p_drvinfo->cfosho[0] & 0x60;
6278c2ecf20Sopenharmony_ci			report = report >> 5;
6288c2ecf20Sopenharmony_ci			switch (report) {
6298c2ecf20Sopenharmony_ci			case 0x3:
6308c2ecf20Sopenharmony_ci				rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1);
6318c2ecf20Sopenharmony_ci				break;
6328c2ecf20Sopenharmony_ci			case 0x2:
6338c2ecf20Sopenharmony_ci				rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1);
6348c2ecf20Sopenharmony_ci				break;
6358c2ecf20Sopenharmony_ci			case 0x1:
6368c2ecf20Sopenharmony_ci				rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1);
6378c2ecf20Sopenharmony_ci				break;
6388c2ecf20Sopenharmony_ci			case 0x0:
6398c2ecf20Sopenharmony_ci				rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1);
6408c2ecf20Sopenharmony_ci				break;
6418c2ecf20Sopenharmony_ci			}
6428c2ecf20Sopenharmony_ci		}
6438c2ecf20Sopenharmony_ci		pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
6448c2ecf20Sopenharmony_ci		pstats->rx_pwdb_all = pwdb_all;
6458c2ecf20Sopenharmony_ci		pstats->recvsignalpower = rx_pwr_all;
6468c2ecf20Sopenharmony_ci		if (packet_match_bssid) {
6478c2ecf20Sopenharmony_ci			u8 sq;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci			if (pstats->rx_pwdb_all > 40)
6508c2ecf20Sopenharmony_ci				sq = 100;
6518c2ecf20Sopenharmony_ci			else {
6528c2ecf20Sopenharmony_ci				sq = cck_buf->sq_rpt;
6538c2ecf20Sopenharmony_ci				if (sq > 64)
6548c2ecf20Sopenharmony_ci					sq = 0;
6558c2ecf20Sopenharmony_ci				else if (sq < 20)
6568c2ecf20Sopenharmony_ci					sq = 100;
6578c2ecf20Sopenharmony_ci				else
6588c2ecf20Sopenharmony_ci					sq = ((64 - sq) * 100) / 44;
6598c2ecf20Sopenharmony_ci			}
6608c2ecf20Sopenharmony_ci			pstats->signalquality = sq;
6618c2ecf20Sopenharmony_ci			pstats->RX_SIGQ[0] = sq;
6628c2ecf20Sopenharmony_ci			pstats->RX_SIGQ[1] = -1;
6638c2ecf20Sopenharmony_ci		}
6648c2ecf20Sopenharmony_ci	} else {
6658c2ecf20Sopenharmony_ci		rtlpriv->dm.rfpath_rxenable[0] =
6668c2ecf20Sopenharmony_ci		    rtlpriv->dm.rfpath_rxenable[1] = true;
6678c2ecf20Sopenharmony_ci		for (i = RF90_PATH_A; i < RF90_PATH_MAX; i++) {
6688c2ecf20Sopenharmony_ci			if (rtlpriv->dm.rfpath_rxenable[i])
6698c2ecf20Sopenharmony_ci				rf_rx_num++;
6708c2ecf20Sopenharmony_ci			rx_pwr[i] =
6718c2ecf20Sopenharmony_ci			    ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110;
6728c2ecf20Sopenharmony_ci			rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
6738c2ecf20Sopenharmony_ci			total_rssi += rssi;
6748c2ecf20Sopenharmony_ci			rtlpriv->stats.rx_snr_db[i] =
6758c2ecf20Sopenharmony_ci			    (long)(p_drvinfo->rxsnr[i] / 2);
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci			if (packet_match_bssid)
6788c2ecf20Sopenharmony_ci				pstats->rx_mimo_signalstrength[i] = (u8) rssi;
6798c2ecf20Sopenharmony_ci		}
6808c2ecf20Sopenharmony_ci		rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
6818c2ecf20Sopenharmony_ci		pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
6828c2ecf20Sopenharmony_ci		pstats->rx_pwdb_all = pwdb_all;
6838c2ecf20Sopenharmony_ci		pstats->rxpower = rx_pwr_all;
6848c2ecf20Sopenharmony_ci		pstats->recvsignalpower = rx_pwr_all;
6858c2ecf20Sopenharmony_ci		if (get_rx_desc_rx_mcs(pdesc) &&
6868c2ecf20Sopenharmony_ci		    get_rx_desc_rx_mcs(pdesc) >= DESC_RATEMCS8 &&
6878c2ecf20Sopenharmony_ci		    get_rx_desc_rx_mcs(pdesc) <= DESC_RATEMCS15)
6888c2ecf20Sopenharmony_ci			max_spatial_stream = 2;
6898c2ecf20Sopenharmony_ci		else
6908c2ecf20Sopenharmony_ci			max_spatial_stream = 1;
6918c2ecf20Sopenharmony_ci		for (i = 0; i < max_spatial_stream; i++) {
6928c2ecf20Sopenharmony_ci			evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
6938c2ecf20Sopenharmony_ci			if (packet_match_bssid) {
6948c2ecf20Sopenharmony_ci				if (i == 0)
6958c2ecf20Sopenharmony_ci					pstats->signalquality =
6968c2ecf20Sopenharmony_ci					    (u8) (evm & 0xff);
6978c2ecf20Sopenharmony_ci				pstats->RX_SIGQ[i] =
6988c2ecf20Sopenharmony_ci				    (u8) (evm & 0xff);
6998c2ecf20Sopenharmony_ci			}
7008c2ecf20Sopenharmony_ci		}
7018c2ecf20Sopenharmony_ci	}
7028c2ecf20Sopenharmony_ci	if (is_cck_rate)
7038c2ecf20Sopenharmony_ci		pstats->signalstrength =
7048c2ecf20Sopenharmony_ci		    (u8)(rtl_signal_scale_mapping(hw, pwdb_all));
7058c2ecf20Sopenharmony_ci	else if (rf_rx_num != 0)
7068c2ecf20Sopenharmony_ci		pstats->signalstrength =
7078c2ecf20Sopenharmony_ci		    (u8)(rtl_signal_scale_mapping(hw, total_rssi /= rf_rx_num));
7088c2ecf20Sopenharmony_ci}
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_civoid rtl92c_translate_rx_signal_stuff(struct ieee80211_hw *hw,
7118c2ecf20Sopenharmony_ci					       struct sk_buff *skb,
7128c2ecf20Sopenharmony_ci					       struct rtl_stats *pstats,
7138c2ecf20Sopenharmony_ci					       struct rx_desc_92c *pdesc,
7148c2ecf20Sopenharmony_ci					       struct rx_fwinfo_92c *p_drvinfo)
7158c2ecf20Sopenharmony_ci{
7168c2ecf20Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
7178c2ecf20Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
7188c2ecf20Sopenharmony_ci	struct ieee80211_hdr *hdr;
7198c2ecf20Sopenharmony_ci	u8 *tmp_buf;
7208c2ecf20Sopenharmony_ci	u8 *praddr;
7218c2ecf20Sopenharmony_ci	__le16 fc;
7228c2ecf20Sopenharmony_ci	u16 type, cpu_fc;
7238c2ecf20Sopenharmony_ci	bool packet_matchbssid, packet_toself, packet_beacon = false;
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
7268c2ecf20Sopenharmony_ci	hdr = (struct ieee80211_hdr *)tmp_buf;
7278c2ecf20Sopenharmony_ci	fc = hdr->frame_control;
7288c2ecf20Sopenharmony_ci	cpu_fc = le16_to_cpu(fc);
7298c2ecf20Sopenharmony_ci	type = WLAN_FC_GET_TYPE(fc);
7308c2ecf20Sopenharmony_ci	praddr = hdr->addr1;
7318c2ecf20Sopenharmony_ci	packet_matchbssid =
7328c2ecf20Sopenharmony_ci	    ((IEEE80211_FTYPE_CTL != type) &&
7338c2ecf20Sopenharmony_ci	     ether_addr_equal(mac->bssid,
7348c2ecf20Sopenharmony_ci			      (cpu_fc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
7358c2ecf20Sopenharmony_ci			      (cpu_fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
7368c2ecf20Sopenharmony_ci			      hdr->addr3) &&
7378c2ecf20Sopenharmony_ci	     (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	packet_toself = packet_matchbssid &&
7408c2ecf20Sopenharmony_ci	    ether_addr_equal(praddr, rtlefuse->dev_addr);
7418c2ecf20Sopenharmony_ci	if (ieee80211_is_beacon(fc))
7428c2ecf20Sopenharmony_ci		packet_beacon = true;
7438c2ecf20Sopenharmony_ci	_rtl92c_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
7448c2ecf20Sopenharmony_ci				   packet_matchbssid, packet_toself,
7458c2ecf20Sopenharmony_ci				   packet_beacon);
7468c2ecf20Sopenharmony_ci	rtl_process_phyinfo(hw, tmp_buf, pstats);
7478c2ecf20Sopenharmony_ci}
748