Commit d75589a0 authored by Bitterblue Smith's avatar Bitterblue Smith Committed by Ping-Ke Shih

wifi: rtlwifi: Clean up rtl8192d-common a bit

Improve readability:
 * add empty lines
 * use abs_diff in rtl92d_dm_txpower_tracking_callback_thermalmeter
 * roll up repeated statements into a for loop in
   rtl92d_dm_txpower_tracking_callback_thermalmeter
 * shorten lines by replacing many instances of "rtlpriv->dm" with "dm"
   pointer in rtl92d_dm_txpower_tracking_callback_thermalmeter
 * sort some declarations by length
 * refactor _rtl92d_get_txpower_writeval_by_regulatory a little
 * refactor _rtl92de_readpowervalue_fromprom a little

Delete unused structs tag_dynamic_init_gain_operation_type_definition
and swat.

Simplify rtl92d_fill_h2c_cmd a little and delete a pointless wrapper
function.

Tested with a single MAC single PHY USB dongle from Aliexpress labelled
"CC&C WL-6210-V3".
Signed-off-by: default avatarBitterblue Smith <rtl8821cerfe2@gmail.com>
Acked-by: default avatarPing-Ke Shih <pkshih@realtek.com>
Signed-off-by: default avatarPing-Ke Shih <pkshih@realtek.com>
Link: https://msgid.link/f6acfa78-2f4e-47f1-95d4-65aa77510113@gmail.com
parent db5ae2e1
...@@ -48,27 +48,6 @@ ...@@ -48,27 +48,6 @@
#define TX_POWER_NEAR_FIELD_THRESH_LVL1 67 #define TX_POWER_NEAR_FIELD_THRESH_LVL1 67
#define INDEX_MAPPING_NUM 13 #define INDEX_MAPPING_NUM 13
struct swat {
u8 failure_cnt;
u8 try_flag;
u8 stop_trying;
long pre_rssi;
long trying_threshold;
u8 cur_antenna;
u8 pre_antenna;
};
enum tag_dynamic_init_gain_operation_type_definition {
DIG_TYPE_THRESH_HIGH = 0,
DIG_TYPE_THRESH_LOW = 1,
DIG_TYPE_BACKOFF = 2,
DIG_TYPE_RX_GAIN_MIN = 3,
DIG_TYPE_RX_GAIN_MAX = 4,
DIG_TYPE_ENABLE = 5,
DIG_TYPE_DISABLE = 6,
DIG_OP_TYPE_MAX
};
enum dm_1r_cca { enum dm_1r_cca {
CCA_1R = 0, CCA_1R = 0,
CCA_2R = 1, CCA_2R = 1,
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
bool rtl92d_is_fw_downloaded(struct rtl_priv *rtlpriv) bool rtl92d_is_fw_downloaded(struct rtl_priv *rtlpriv)
{ {
return (rtl_read_dword(rtlpriv, REG_MCUFWDL) & MCUFWDL_RDY) ? return !!(rtl_read_dword(rtlpriv, REG_MCUFWDL) & MCUFWDL_RDY);
true : false;
} }
EXPORT_SYMBOL_GPL(rtl92d_is_fw_downloaded); EXPORT_SYMBOL_GPL(rtl92d_is_fw_downloaded);
...@@ -50,17 +49,22 @@ void rtl92d_write_fw(struct ieee80211_hw *hw, ...@@ -50,17 +49,22 @@ void rtl92d_write_fw(struct ieee80211_hw *hw,
u32 page, offset; u32 page, offset;
rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, "FW size is %d bytes,\n", size); rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, "FW size is %d bytes,\n", size);
if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE)
rtl_fill_dummy(bufferptr, &size); rtl_fill_dummy(bufferptr, &size);
pagenums = size / FW_8192D_PAGE_SIZE; pagenums = size / FW_8192D_PAGE_SIZE;
remainsize = size % FW_8192D_PAGE_SIZE; remainsize = size % FW_8192D_PAGE_SIZE;
if (pagenums > 8) if (pagenums > 8)
pr_err("Page numbers should not greater then 8\n"); pr_err("Page numbers should not greater then 8\n");
for (page = 0; page < pagenums; page++) { for (page = 0; page < pagenums; page++) {
offset = page * FW_8192D_PAGE_SIZE; offset = page * FW_8192D_PAGE_SIZE;
rtl_fw_page_write(hw, page, (bufferptr + offset), rtl_fw_page_write(hw, page, (bufferptr + offset),
FW_8192D_PAGE_SIZE); FW_8192D_PAGE_SIZE);
} }
if (remainsize) { if (remainsize) {
offset = pagenums * FW_8192D_PAGE_SIZE; offset = pagenums * FW_8192D_PAGE_SIZE;
page = pagenums; page = pagenums;
...@@ -79,14 +83,17 @@ int rtl92d_fw_free_to_go(struct ieee80211_hw *hw) ...@@ -79,14 +83,17 @@ int rtl92d_fw_free_to_go(struct ieee80211_hw *hw)
value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
} while ((counter++ < FW_8192D_POLLING_TIMEOUT_COUNT) && } while ((counter++ < FW_8192D_POLLING_TIMEOUT_COUNT) &&
(!(value32 & FWDL_CHKSUM_RPT))); (!(value32 & FWDL_CHKSUM_RPT)));
if (counter >= FW_8192D_POLLING_TIMEOUT_COUNT) { if (counter >= FW_8192D_POLLING_TIMEOUT_COUNT) {
pr_err("chksum report fail! REG_MCUFWDL:0x%08x\n", pr_err("chksum report fail! REG_MCUFWDL:0x%08x\n",
value32); value32);
return -EIO; return -EIO;
} }
value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
value32 |= MCUFWDL_RDY; value32 |= MCUFWDL_RDY;
rtl_write_dword(rtlpriv, REG_MCUFWDL, value32); rtl_write_dword(rtlpriv, REG_MCUFWDL, value32);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(rtl92d_fw_free_to_go); EXPORT_SYMBOL_GPL(rtl92d_fw_free_to_go);
...@@ -99,7 +106,9 @@ void rtl92d_firmware_selfreset(struct ieee80211_hw *hw) ...@@ -99,7 +106,9 @@ void rtl92d_firmware_selfreset(struct ieee80211_hw *hw)
/* Set (REG_HMETFR + 3) to 0x20 is reset 8051 */ /* Set (REG_HMETFR + 3) to 0x20 is reset 8051 */
rtl_write_byte(rtlpriv, REG_HMETFR + 3, 0x20); rtl_write_byte(rtlpriv, REG_HMETFR + 3, 0x20);
u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
while (u1b_tmp & BIT(2)) { while (u1b_tmp & BIT(2)) {
delay--; delay--;
if (delay == 0) if (delay == 0)
...@@ -174,23 +183,22 @@ static bool _rtl92d_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum) ...@@ -174,23 +183,22 @@ static bool _rtl92d_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum)
return result; return result;
} }
static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw, void rtl92d_fill_h2c_cmd(struct ieee80211_hw *hw,
u8 element_id, u32 cmd_len, u8 *cmdbuffer) u8 element_id, u32 cmd_len, u8 *cmdbuffer)
{ {
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
u8 boxnum; struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
struct rtl_priv *rtlpriv = rtl_priv(hw);
u8 boxcontent[4], boxextcontent[2];
u16 box_reg = 0, box_extreg = 0; u16 box_reg = 0, box_extreg = 0;
u8 u1b_tmp; u8 wait_writeh2c_limmit = 100;
bool isfw_read = false;
u8 buf_index = 0;
bool bwrite_success = false; bool bwrite_success = false;
u8 wait_h2c_limmit = 100; u8 wait_h2c_limmit = 100;
u8 wait_writeh2c_limmit = 100;
u8 boxcontent[4], boxextcontent[2];
u32 h2c_waitcounter = 0; u32 h2c_waitcounter = 0;
bool isfw_read = false;
unsigned long flag; unsigned long flag;
u8 u1b_tmp;
u8 boxnum;
u8 idx; u8 idx;
if (ppsc->rfpwr_state == ERFOFF || ppsc->inactive_pwrstate == ERFOFF) { if (ppsc->rfpwr_state == ERFOFF || ppsc->inactive_pwrstate == ERFOFF) {
...@@ -198,7 +206,9 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw, ...@@ -198,7 +206,9 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
"Return as RF is off!!!\n"); "Return as RF is off!!!\n");
return; return;
} }
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n"); rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n");
while (true) { while (true) {
spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag); spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
if (rtlhal->h2c_setinprogress) { if (rtlhal->h2c_setinprogress) {
...@@ -228,35 +238,23 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw, ...@@ -228,35 +238,23 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
break; break;
} }
} }
while (!bwrite_success) { while (!bwrite_success) {
wait_writeh2c_limmit--; wait_writeh2c_limmit--;
if (wait_writeh2c_limmit == 0) { if (wait_writeh2c_limmit == 0) {
pr_err("Write H2C fail because no trigger for FW INT!\n"); pr_err("Write H2C fail because no trigger for FW INT!\n");
break; break;
} }
boxnum = rtlhal->last_hmeboxnum; boxnum = rtlhal->last_hmeboxnum;
switch (boxnum) { if (boxnum > 3) {
case 0: pr_err("boxnum %#x too big\n", boxnum);
box_reg = REG_HMEBOX_0;
box_extreg = REG_HMEBOX_EXT_0;
break;
case 1:
box_reg = REG_HMEBOX_1;
box_extreg = REG_HMEBOX_EXT_1;
break;
case 2:
box_reg = REG_HMEBOX_2;
box_extreg = REG_HMEBOX_EXT_2;
break;
case 3:
box_reg = REG_HMEBOX_3;
box_extreg = REG_HMEBOX_EXT_3;
break;
default:
pr_err("switch case %#x not processed\n",
boxnum);
break; break;
} }
box_reg = REG_HMEBOX_0 + boxnum * SIZE_OF_REG_HMEBOX;
box_extreg = REG_HMEBOX_EXT_0 + boxnum * SIZE_OF_REG_HMEBOX_EXT;
isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum); isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
while (!isfw_read) { while (!isfw_read) {
wait_h2c_limmit--; wait_h2c_limmit--;
...@@ -266,78 +264,70 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw, ...@@ -266,78 +264,70 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
boxnum); boxnum);
break; break;
} }
udelay(10); udelay(10);
isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum); isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF); u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF);
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
"Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n", "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n",
boxnum, u1b_tmp); boxnum, u1b_tmp);
} }
if (!isfw_read) { if (!isfw_read) {
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
"Write H2C register BOX[%d] fail!!!!! Fw do not read.\n", "Write H2C register BOX[%d] fail!!!!! Fw do not read.\n",
boxnum); boxnum);
break; break;
} }
memset(boxcontent, 0, sizeof(boxcontent)); memset(boxcontent, 0, sizeof(boxcontent));
memset(boxextcontent, 0, sizeof(boxextcontent)); memset(boxextcontent, 0, sizeof(boxextcontent));
boxcontent[0] = element_id; boxcontent[0] = element_id;
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
"Write element_id box_reg(%4x) = %2x\n", "Write element_id box_reg(%4x) = %2x\n",
box_reg, element_id); box_reg, element_id);
switch (cmd_len) { switch (cmd_len) {
case 1: case 1 ... 3:
boxcontent[0] &= ~(BIT(7)); /* BOX: | ID | A0 | A1 | A2 |
memcpy(boxcontent + 1, cmdbuffer + buf_index, 1); * BOX_EXT: --- N/A ------
for (idx = 0; idx < 4; idx++) */
rtl_write_byte(rtlpriv, box_reg + idx, boxcontent[0] &= ~BIT(7);
boxcontent[idx]); memcpy(boxcontent + 1, cmdbuffer, cmd_len);
break;
case 2:
boxcontent[0] &= ~(BIT(7));
memcpy(boxcontent + 1, cmdbuffer + buf_index, 2);
for (idx = 0; idx < 4; idx++)
rtl_write_byte(rtlpriv, box_reg + idx,
boxcontent[idx]);
break;
case 3:
boxcontent[0] &= ~(BIT(7));
memcpy(boxcontent + 1, cmdbuffer + buf_index, 3);
for (idx = 0; idx < 4; idx++)
rtl_write_byte(rtlpriv, box_reg + idx,
boxcontent[idx]);
break;
case 4:
boxcontent[0] |= (BIT(7));
memcpy(boxextcontent, cmdbuffer + buf_index, 2);
memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 2);
for (idx = 0; idx < 2; idx++)
rtl_write_byte(rtlpriv, box_extreg + idx,
boxextcontent[idx]);
for (idx = 0; idx < 4; idx++) for (idx = 0; idx < 4; idx++)
rtl_write_byte(rtlpriv, box_reg + idx, rtl_write_byte(rtlpriv, box_reg + idx,
boxcontent[idx]); boxcontent[idx]);
break; break;
case 5: case 4 ... 5:
boxcontent[0] |= (BIT(7)); /* * ID ext = ID | BIT(7)
memcpy(boxextcontent, cmdbuffer + buf_index, 2); * BOX: | ID ext | A2 | A3 | A4 |
memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 3); * BOX_EXT: | A0 | A1 |
*/
boxcontent[0] |= BIT(7);
memcpy(boxextcontent, cmdbuffer, 2);
memcpy(boxcontent + 1, cmdbuffer + 2, cmd_len - 2);
for (idx = 0; idx < 2; idx++) for (idx = 0; idx < 2; idx++)
rtl_write_byte(rtlpriv, box_extreg + idx, rtl_write_byte(rtlpriv, box_extreg + idx,
boxextcontent[idx]); boxextcontent[idx]);
for (idx = 0; idx < 4; idx++) for (idx = 0; idx < 4; idx++)
rtl_write_byte(rtlpriv, box_reg + idx, rtl_write_byte(rtlpriv, box_reg + idx,
boxcontent[idx]); boxcontent[idx]);
break; break;
default: default:
pr_err("switch case %#x not processed\n", pr_err("switch case %#x not processed\n", cmd_len);
cmd_len);
break; break;
} }
bwrite_success = true; bwrite_success = true;
rtlhal->last_hmeboxnum = boxnum + 1; rtlhal->last_hmeboxnum = boxnum + 1;
if (rtlhal->last_hmeboxnum == 4) if (rtlhal->last_hmeboxnum == 4)
rtlhal->last_hmeboxnum = 0; rtlhal->last_hmeboxnum = 0;
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
"pHalData->last_hmeboxnum = %d\n", "pHalData->last_hmeboxnum = %d\n",
rtlhal->last_hmeboxnum); rtlhal->last_hmeboxnum);
...@@ -347,16 +337,6 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw, ...@@ -347,16 +337,6 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n"); rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n");
} }
void rtl92d_fill_h2c_cmd(struct ieee80211_hw *hw,
u8 element_id, u32 cmd_len, u8 *cmdbuffer)
{
u32 tmp_cmdbuf[2];
memset(tmp_cmdbuf, 0, 8);
memcpy(tmp_cmdbuf, cmdbuffer, cmd_len);
_rtl92d_fill_h2c_command(hw, element_id, cmd_len, (u8 *)&tmp_cmdbuf);
}
EXPORT_SYMBOL_GPL(rtl92d_fill_h2c_cmd); EXPORT_SYMBOL_GPL(rtl92d_fill_h2c_cmd);
void rtl92d_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus) void rtl92d_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus)
......
...@@ -41,8 +41,7 @@ static u32 _rtl92d_phy_rf_serial_read(struct ieee80211_hw *hw, ...@@ -41,8 +41,7 @@ static u32 _rtl92d_phy_rf_serial_read(struct ieee80211_hw *hw,
tmplong & (~BLSSIREADEDGE)); tmplong & (~BLSSIREADEDGE));
udelay(10); udelay(10);
rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2); rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2);
udelay(50); udelay(100);
udelay(50);
rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD, rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
tmplong | BLSSIREADEDGE); tmplong | BLSSIREADEDGE);
udelay(10); udelay(10);
...@@ -319,23 +318,21 @@ void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw) ...@@ -319,23 +318,21 @@ void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw)
struct rtl_phy *rtlphy = &rtlpriv->phy; struct rtl_phy *rtlphy = &rtlpriv->phy;
rtlphy->default_initialgain[0] = rtlphy->default_initialgain[0] =
(u8)rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0); rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0);
rtlphy->default_initialgain[1] = rtlphy->default_initialgain[1] =
(u8)rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0); rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0);
rtlphy->default_initialgain[2] = rtlphy->default_initialgain[2] =
(u8)rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0); rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0);
rtlphy->default_initialgain[3] = rtlphy->default_initialgain[3] =
(u8)rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0); rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0);
rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
"Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n", "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
rtlphy->default_initialgain[0], rtlphy->default_initialgain[0],
rtlphy->default_initialgain[1], rtlphy->default_initialgain[1],
rtlphy->default_initialgain[2], rtlphy->default_initialgain[2],
rtlphy->default_initialgain[3]); rtlphy->default_initialgain[3]);
rtlphy->framesync = (u8)rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3, rtlphy->framesync = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3, MASKBYTE0);
MASKBYTE0); rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2, MASKDWORD);
rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2,
MASKDWORD);
rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
"Default framesync (0x%x) = 0x%x\n", "Default framesync (0x%x) = 0x%x\n",
ROFDM0_RXDETECTOR3, rtlphy->framesync); ROFDM0_RXDETECTOR3, rtlphy->framesync);
...@@ -349,7 +346,7 @@ static void _rtl92d_get_txpower_index(struct ieee80211_hw *hw, u8 channel, ...@@ -349,7 +346,7 @@ static void _rtl92d_get_txpower_index(struct ieee80211_hw *hw, u8 channel,
struct rtl_phy *rtlphy = &rtlpriv->phy; struct rtl_phy *rtlphy = &rtlpriv->phy;
struct rtl_hal *rtlhal = &rtlpriv->rtlhal; struct rtl_hal *rtlhal = &rtlpriv->rtlhal;
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
u8 index = (channel - 1); u8 index = channel - 1;
/* 1. CCK */ /* 1. CCK */
if (rtlhal->current_bandtype == BAND_ON_2_4G) { if (rtlhal->current_bandtype == BAND_ON_2_4G) {
...@@ -643,6 +640,7 @@ static void rtl92d_phy_set_io(struct ieee80211_hw *hw) ...@@ -643,6 +640,7 @@ static void rtl92d_phy_set_io(struct ieee80211_hw *hw)
rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
"--->Cmd(%#x), set_io_inprogress(%d)\n", "--->Cmd(%#x), set_io_inprogress(%d)\n",
rtlphy->current_io_type, rtlphy->set_io_inprogress); rtlphy->current_io_type, rtlphy->set_io_inprogress);
switch (rtlphy->current_io_type) { switch (rtlphy->current_io_type) {
case IO_CMD_RESUME_DM_BY_SCAN: case IO_CMD_RESUME_DM_BY_SCAN:
de_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1; de_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1;
...@@ -659,6 +657,7 @@ static void rtl92d_phy_set_io(struct ieee80211_hw *hw) ...@@ -659,6 +657,7 @@ static void rtl92d_phy_set_io(struct ieee80211_hw *hw)
rtlphy->current_io_type); rtlphy->current_io_type);
break; break;
} }
rtlphy->set_io_inprogress = false; rtlphy->set_io_inprogress = false;
rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<---(%#x)\n", rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<---(%#x)\n",
rtlphy->current_io_type); rtlphy->current_io_type);
...@@ -673,6 +672,7 @@ bool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype) ...@@ -673,6 +672,7 @@ bool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
"-->IO Cmd(%#x), set_io_inprogress(%d)\n", "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
iotype, rtlphy->set_io_inprogress); iotype, rtlphy->set_io_inprogress);
do { do {
switch (iotype) { switch (iotype) {
case IO_CMD_RESUME_DM_BY_SCAN: case IO_CMD_RESUME_DM_BY_SCAN:
...@@ -691,12 +691,14 @@ bool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype) ...@@ -691,12 +691,14 @@ bool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
break; break;
} }
} while (false); } while (false);
if (postprocessing && !rtlphy->set_io_inprogress) { if (postprocessing && !rtlphy->set_io_inprogress) {
rtlphy->set_io_inprogress = true; rtlphy->set_io_inprogress = true;
rtlphy->current_io_type = iotype; rtlphy->current_io_type = iotype;
} else { } else {
return false; return false;
} }
rtl92d_phy_set_io(hw); rtl92d_phy_set_io(hw);
rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<--IO Type(%#x)\n", iotype); rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<--IO Type(%#x)\n", iotype);
return true; return true;
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#define REG_HMEBOX_EXT_1 0x008A #define REG_HMEBOX_EXT_1 0x008A
#define REG_HMEBOX_EXT_2 0x008C #define REG_HMEBOX_EXT_2 0x008C
#define REG_HMEBOX_EXT_3 0x008E #define REG_HMEBOX_EXT_3 0x008E
#define SIZE_OF_REG_HMEBOX_EXT 2
#define REG_BIST_SCAN 0x00D0 #define REG_BIST_SCAN 0x00D0
#define REG_BIST_RPT 0x00D4 #define REG_BIST_RPT 0x00D4
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
#define REG_HMEBOX_1 0x01D4 #define REG_HMEBOX_1 0x01D4
#define REG_HMEBOX_2 0x01D8 #define REG_HMEBOX_2 0x01D8
#define REG_HMEBOX_3 0x01DC #define REG_HMEBOX_3 0x01DC
#define SIZE_OF_REG_HMEBOX 4
#define REG_LLT_INIT 0x01E0 #define REG_LLT_INIT 0x01E0
#define REG_BB_ACCEESS_CTRL 0x01E8 #define REG_BB_ACCEESS_CTRL 0x01E8
......
...@@ -16,10 +16,11 @@ void rtl92d_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) ...@@ -16,10 +16,11 @@ void rtl92d_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
switch (bandwidth) { switch (bandwidth) {
case HT_CHANNEL_WIDTH_20: case HT_CHANNEL_WIDTH_20:
for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
rtlphy->rfreg_chnlval[rfpath] = ((rtlphy->rfreg_chnlval rtlphy->rfreg_chnlval[rfpath] &= 0xfffff3ff;
[rfpath] & 0xfffff3ff) | 0x0400); rtlphy->rfreg_chnlval[rfpath] |= 0x0400;
rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(10) |
BIT(11), 0x01); rtl_set_rfreg(hw, rfpath, RF_CHNLBW,
BIT(10) | BIT(11), 0x01);
rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD,
"20M RF 0x18 = 0x%x\n", "20M RF 0x18 = 0x%x\n",
...@@ -29,10 +30,11 @@ void rtl92d_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) ...@@ -29,10 +30,11 @@ void rtl92d_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
break; break;
case HT_CHANNEL_WIDTH_20_40: case HT_CHANNEL_WIDTH_20_40:
for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
rtlphy->rfreg_chnlval[rfpath] = rtlphy->rfreg_chnlval[rfpath] &= 0xfffff3ff;
((rtlphy->rfreg_chnlval[rfpath] & 0xfffff3ff));
rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(10) | BIT(11), rtl_set_rfreg(hw, rfpath, RF_CHNLBW,
0x00); BIT(10) | BIT(11), 0x00);
rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD,
"40M RF 0x18 = 0x%x\n", "40M RF 0x18 = 0x%x\n",
rtlphy->rfreg_chnlval[rfpath]); rtlphy->rfreg_chnlval[rfpath]);
...@@ -157,6 +159,31 @@ static void _rtl92d_phy_get_power_base(struct ieee80211_hw *hw, ...@@ -157,6 +159,31 @@ static void _rtl92d_phy_get_power_base(struct ieee80211_hw *hw,
} }
} }
static void _rtl92d_get_pwr_diff_limit(struct ieee80211_hw *hw, u8 channel,
u8 index, u8 rf, u8 pwr_diff_limit[4])
{
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_phy *rtlphy = &rtlpriv->phy;
u32 mcs_offset;
u8 limit;
int i;
mcs_offset = rtlphy->mcs_offset[0][index + (rf ? 8 : 0)];
for (i = 0; i < 4; i++) {
pwr_diff_limit[i] = (mcs_offset >> (i * 8)) & 0x7f;
if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40)
limit = rtlefuse->pwrgroup_ht40[rf][channel - 1];
else
limit = rtlefuse->pwrgroup_ht20[rf][channel - 1];
if (pwr_diff_limit[i] > limit)
pwr_diff_limit[i] = limit;
}
}
static void _rtl92d_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw, static void _rtl92d_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw,
u8 channel, u8 index, u8 channel, u8 index,
u32 *powerbase0, u32 *powerbase0,
...@@ -166,107 +193,86 @@ static void _rtl92d_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw, ...@@ -166,107 +193,86 @@ static void _rtl92d_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw,
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_phy *rtlphy = &rtlpriv->phy; struct rtl_phy *rtlphy = &rtlpriv->phy;
u8 i, chnlgroup = 0, pwr_diff_limit[4];
u32 writeval = 0, customer_limit, rf; u32 writeval = 0, customer_limit, rf;
u8 chnlgroup = 0, pwr_diff_limit[4];
for (rf = 0; rf < 2; rf++) { for (rf = 0; rf < 2; rf++) {
switch (rtlefuse->eeprom_regulatory) { switch (rtlefuse->eeprom_regulatory) {
case 0: case 0:
chnlgroup = 0; writeval = rtlphy->mcs_offset[0][index + (rf ? 8 : 0)];
writeval = rtlphy->mcs_offset
[chnlgroup][index +
(rf ? 8 : 0)] + ((index < 2) ?
powerbase0[rf] :
powerbase1[rf]);
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"RTK better performance, writeval(%c) = 0x%x\n", "RTK better performance\n");
rf == 0 ? 'A' : 'B', writeval);
break; break;
case 1: case 1:
if (rtlphy->pwrgroup_cnt == 1) if (rtlphy->pwrgroup_cnt == 1)
chnlgroup = 0; chnlgroup = 0;
if (rtlphy->pwrgroup_cnt >= MAX_PG_GROUP) {
if (rtlphy->pwrgroup_cnt < MAX_PG_GROUP)
break;
chnlgroup = rtl92d_phy_get_chnlgroup_bypg(channel - 1); chnlgroup = rtl92d_phy_get_chnlgroup_bypg(channel - 1);
if (rtlphy->current_chan_bw == if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20)
HT_CHANNEL_WIDTH_20)
chnlgroup++; chnlgroup++;
else else
chnlgroup += 4; chnlgroup += 4;
writeval = rtlphy->mcs_offset writeval = rtlphy->mcs_offset
[chnlgroup][index + [chnlgroup][index + (rf ? 8 : 0)];
(rf ? 8 : 0)] + ((index < 2) ?
powerbase0[rf] :
powerbase1[rf]);
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n", "Realtek regulatory, 20MHz\n");
rf == 0 ? 'A' : 'B', writeval);
}
break; break;
case 2: case 2:
writeval = ((index < 2) ? powerbase0[rf] : writeval = 0;
powerbase1[rf]);
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR, "Better regulatory\n");
"Better regulatory, writeval(%c) = 0x%x\n",
rf == 0 ? 'A' : 'B', writeval);
break; break;
case 3: case 3:
chnlgroup = 0;
if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"customer's limit, 40MHz rf(%c) = 0x%x\n", "customer's limit, 40MHz rf(%c) = 0x%x\n",
rf == 0 ? 'A' : 'B', rf == 0 ? 'A' : 'B',
rtlefuse->pwrgroup_ht40[rf] rtlefuse->pwrgroup_ht40[rf][channel - 1]);
[channel - 1]);
} else { } else {
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"customer's limit, 20MHz rf(%c) = 0x%x\n", "customer's limit, 20MHz rf(%c) = 0x%x\n",
rf == 0 ? 'A' : 'B', rf == 0 ? 'A' : 'B',
rtlefuse->pwrgroup_ht20[rf] rtlefuse->pwrgroup_ht20[rf][channel - 1]);
[channel - 1]);
}
for (i = 0; i < 4; i++) {
pwr_diff_limit[i] = (u8)((rtlphy->mcs_offset
[chnlgroup][index + (rf ? 8 : 0)] &
(0x7f << (i * 8))) >> (i * 8));
if (rtlphy->current_chan_bw ==
HT_CHANNEL_WIDTH_20_40) {
if (pwr_diff_limit[i] >
rtlefuse->pwrgroup_ht40[rf]
[channel - 1])
pwr_diff_limit[i] =
rtlefuse->pwrgroup_ht40
[rf][channel - 1];
} else {
if (pwr_diff_limit[i] >
rtlefuse->pwrgroup_ht20[rf][channel - 1])
pwr_diff_limit[i] =
rtlefuse->pwrgroup_ht20[rf]
[channel - 1];
}
} }
_rtl92d_get_pwr_diff_limit(hw, channel, index, rf,
pwr_diff_limit);
customer_limit = (pwr_diff_limit[3] << 24) | customer_limit = (pwr_diff_limit[3] << 24) |
(pwr_diff_limit[2] << 16) | (pwr_diff_limit[2] << 16) |
(pwr_diff_limit[1] << 8) | (pwr_diff_limit[1] << 8) |
(pwr_diff_limit[0]); (pwr_diff_limit[0]);
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"Customer's limit rf(%c) = 0x%x\n", "Customer's limit rf(%c) = 0x%x\n",
rf == 0 ? 'A' : 'B', customer_limit); rf == 0 ? 'A' : 'B', customer_limit);
writeval = customer_limit + ((index < 2) ?
powerbase0[rf] : powerbase1[rf]); writeval = customer_limit;
RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"Customer, writeval rf(%c)= 0x%x\n", RTPRINT(rtlpriv, FPHY, PHY_TXPWR, "Customer\n");
rf == 0 ? 'A' : 'B', writeval);
break; break;
default: default:
chnlgroup = 0; writeval = rtlphy->mcs_offset[0][index + (rf ? 8 : 0)];
writeval = rtlphy->mcs_offset[chnlgroup][index +
(rf ? 8 : 0)] + ((index < 2) ?
powerbase0[rf] : powerbase1[rf]);
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
"RTK better performance, writeval rf(%c) = 0x%x\n", "RTK better performance\n");
rf == 0 ? 'A' : 'B', writeval);
break; break;
} }
if (index < 2)
writeval += powerbase0[rf];
else
writeval += powerbase1[rf];
RTPRINT(rtlpriv, FPHY, PHY_TXPWR, "writeval rf(%c)= 0x%x\n",
rf == 0 ? 'A' : 'B', writeval);
*(p_outwriteval + rf) = writeval; *(p_outwriteval + rf) = writeval;
} }
} }
......
...@@ -349,14 +349,16 @@ static void _rtl92de_translate_rx_signal_stuff(struct ieee80211_hw *hw, ...@@ -349,14 +349,16 @@ static void _rtl92de_translate_rx_signal_stuff(struct ieee80211_hw *hw,
__le32 *pdesc, __le32 *pdesc,
struct rx_fwinfo_92d *p_drvinfo) struct rx_fwinfo_92d *p_drvinfo)
{ {
struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
struct ieee80211_hdr *hdr; struct ieee80211_hdr *hdr;
bool packet_matchbssid;
bool packet_beacon;
bool packet_toself;
u16 type, cfc;
u8 *tmp_buf; u8 *tmp_buf;
u8 *praddr; u8 *praddr;
u16 type, cfc;
__le16 fc; __le16 fc;
bool packet_matchbssid, packet_toself, packet_beacon = false;
tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift; tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
hdr = (struct ieee80211_hdr *)tmp_buf; hdr = (struct ieee80211_hdr *)tmp_buf;
...@@ -372,8 +374,7 @@ static void _rtl92de_translate_rx_signal_stuff(struct ieee80211_hw *hw, ...@@ -372,8 +374,7 @@ static void _rtl92de_translate_rx_signal_stuff(struct ieee80211_hw *hw,
(!pstats->hwerror) && (!pstats->crc) && (!pstats->icv)); (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
packet_toself = packet_matchbssid && packet_toself = packet_matchbssid &&
ether_addr_equal(praddr, rtlefuse->dev_addr); ether_addr_equal(praddr, rtlefuse->dev_addr);
if (ieee80211_is_beacon(fc)) packet_beacon = ieee80211_is_beacon(fc);
packet_beacon = true;
_rtl92de_query_rxphystatus(hw, pstats, pdesc, p_drvinfo, _rtl92de_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
packet_matchbssid, packet_toself, packet_matchbssid, packet_toself,
packet_beacon); packet_beacon);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment