Skip to content

Commit

Permalink
rtl8xxxu: add code to handle BSS_CHANGED_TXPOWER/IEEE80211_CONF_CHANG…
Browse files Browse the repository at this point in the history
…E_POWER

The 'iw set txpower' is not handled by the driver. Use the existing
set_tx_power fuction to apply the tx power change

Signed-off-by: Chris Chiu <chiu@endlessos.org>
  • Loading branch information
Chris Chiu authored and mschiu77 committed Mar 27, 2021
1 parent 5e305ce commit 48f8fbc
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ struct rtl8xxxu_fileops {
void (*enable_rf) (struct rtl8xxxu_priv *priv);
void (*disable_rf) (struct rtl8xxxu_priv *priv);
void (*usb_quirks) (struct rtl8xxxu_priv *priv);
u8 (*dbm_to_txpwridx) (struct rtl8xxxu_priv *priv, u16 mode, int dbm);
void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
bool ht40);
void (*update_rate_mask) (struct rtl8xxxu_priv *priv,
Expand Down Expand Up @@ -1508,6 +1509,8 @@ void rtl8xxxu_disabled_to_emu(struct rtl8xxxu_priv *priv);
int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv);
void rtl8xxxu_gen1_phy_iq_calibrate(struct rtl8xxxu_priv *priv);
void rtl8xxxu_gen1_init_phy_bb(struct rtl8xxxu_priv *priv);
u8 rtl8xxxu_gen1_dbm_to_txpwridx(struct rtl8xxxu_priv *priv,
u16 mode, int dbm);
void rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv *priv,
int channel, bool ht40);
void rtl8xxxu_gen1_config_channel(struct ieee80211_hw *hw);
Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ struct rtl8xxxu_fileops rtl8192cu_fops = {
.enable_rf = rtl8xxxu_gen1_enable_rf,
.disable_rf = rtl8xxxu_gen1_disable_rf,
.usb_quirks = rtl8xxxu_gen1_usb_quirks,
.dbm_to_txpwridx = rtl8xxxu_gen1_dbm_to_txpwridx,
.set_tx_power = rtl8xxxu_gen1_set_tx_power,
.update_rate_mask = rtl8xxxu_update_rate_mask,
.report_connect = rtl8xxxu_gen1_report_connect,
Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ struct rtl8xxxu_fileops rtl8723au_fops = {
.enable_rf = rtl8xxxu_gen1_enable_rf,
.disable_rf = rtl8xxxu_gen1_disable_rf,
.usb_quirks = rtl8xxxu_gen1_usb_quirks,
.dbm_to_txpwridx = rtl8xxxu_gen1_dbm_to_txpwridx,
.set_tx_power = rtl8xxxu_gen1_set_tx_power,
.update_rate_mask = rtl8xxxu_update_rate_mask,
.report_connect = rtl8xxxu_gen1_report_connect,
Expand Down
91 changes: 91 additions & 0 deletions drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,38 @@ void rtl8xxxu_gen2_config_channel(struct ieee80211_hw *hw)
}
}

#define MAX_TXPWR_IDX_NMODE_92S 63

u8
rtl8xxxu_gen1_dbm_to_txpwridx(struct rtl8xxxu_priv *priv, u16 mode, int dbm)
{
u8 txpwridx;
long offset;

switch (mode) {
case WIRELESS_MODE_B:
offset = -7;
break;
case WIRELESS_MODE_G:
case WIRELESS_MODE_N_24G:
offset = -8;
break;
default:
offset = -8;
break;
}

if ((dbm - offset) > 0)
txpwridx = (u8)((dbm - offset) * 2);
else
txpwridx = 0;

if (txpwridx > MAX_TXPWR_IDX_NMODE_92S)
txpwridx = MAX_TXPWR_IDX_NMODE_92S;

return txpwridx;
}

void
rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
{
Expand Down Expand Up @@ -4508,6 +4540,55 @@ rtl8xxxu_wireless_mode(struct ieee80211_hw *hw, struct ieee80211_sta *sta)
return network_type;
}

static void rtl8xxxu_update_txpower(struct rtl8xxxu_priv *priv, int power)
{
bool ht40 = false;
struct ieee80211_hw *hw = priv->hw;
int channel = hw->conf.chandef.chan->hw_value;
u8 cck_txpwridx, ofdm_txpwridx;
int i, group;

if (!priv->fops->dbm_to_txpwridx)
return;

switch (hw->conf.chandef.width) {
case NL80211_CHAN_WIDTH_20_NOHT:
case NL80211_CHAN_WIDTH_20:
ht40 = false;
break;
case NL80211_CHAN_WIDTH_40:
ht40 = true;
break;
default:
return;
}

// change the power level to power index
cck_txpwridx = priv->fops->dbm_to_txpwridx(priv, WIRELESS_MODE_B,
power);
ofdm_txpwridx = priv->fops->dbm_to_txpwridx(priv, WIRELESS_MODE_N_24G,
power);

if (ofdm_txpwridx - priv->ofdm_tx_power_index_diff[1].a > 0)
ofdm_txpwridx -= priv->ofdm_tx_power_index_diff[1].a;
else
ofdm_txpwridx = 0;

group = rtl8xxxu_gen1_channel_to_group(channel);

if (cck_txpwridx <= priv->cck_tx_power_index_A[group]) {
priv->cck_tx_power_index_A[group] = cck_txpwridx;
priv->cck_tx_power_index_B[group] = cck_txpwridx;
}

if (ofdm_txpwridx <= priv->ht40_1s_tx_power_index_A[group]) {
priv->ht40_1s_tx_power_index_A[i] = ofdm_txpwridx;
priv->ht40_1s_tx_power_index_B[i] = ofdm_txpwridx;
}

priv->fops->set_tx_power(priv, channel, ht40);
}

static void
rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_bss_conf *bss_conf, u32 changed)
Expand All @@ -4518,6 +4599,7 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
u32 val32;
u8 val8;


if (changed & BSS_CHANGED_ASSOC) {
dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc);

Expand Down Expand Up @@ -4604,6 +4686,12 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
dev_dbg(dev, "Changed BASIC_RATES!\n");
rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates);
}

if (changed & BSS_CHANGED_TXPOWER) {
dev_dbg(dev, "Changed TX power!\n");
//rtl8xxxu_update_txpower(priv, bss_conf->txpower); // iterate
rtl8xxxu_update_txpower(priv, hw->conf.power_level);
}
error:
return;
}
Expand Down Expand Up @@ -5891,6 +5979,9 @@ static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
priv->fops->config_channel(hw);
}

if (changed & IEEE80211_CONF_CHANGE_POWER)
rtl8xxxu_update_txpower(priv, hw->conf.power_level);

exit:
return ret;
}
Expand Down

0 comments on commit 48f8fbc

Please sign in to comment.