Commit a25a66ac authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by John W. Linville

iwlwifi: fix set_tx_power vs scan

According to comment in iwl_bg_scan_completed, setting tx power should
be deferred during pending scan, but we are not doing this.

This patch change code to really defer setting tx power after scan
complete. Additionally refactor iwl_set_tx_power code and call
lib->send_tx_power() directly from iwlagn_commit_rxon.
Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Acked-by: default avatarWey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 4cbf1b12
...@@ -245,13 +245,10 @@ int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) ...@@ -245,13 +245,10 @@ int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
/* If we issue a new RXON command which required a tune then we must /* If we issue a new RXON command which required a tune then we must
* send a new TXPOWER command or we won't be able to Tx any frames */ * send a new TXPOWER command or we won't be able to Tx any frames */
ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); ret = priv->cfg->ops->lib->send_tx_power(priv);
if (ret) { if (ret)
IWL_ERR(priv, "Error sending TX power (%d)\n", ret); IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
return ret; return ret;
}
return 0;
} }
void iwl_update_chain_flags(struct iwl_priv *priv) void iwl_update_chain_flags(struct iwl_priv *priv)
...@@ -4179,6 +4176,7 @@ static int iwl_init_drv(struct iwl_priv *priv) ...@@ -4179,6 +4176,7 @@ static int iwl_init_drv(struct iwl_priv *priv)
* this value will get overwritten by channel max power avg * this value will get overwritten by channel max power avg
* from eeprom */ * from eeprom */
priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN; priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
priv->tx_power_next = IWLAGN_TX_POWER_TARGET_POWER_MIN;
ret = iwl_init_channel_map(priv); ret = iwl_init_channel_map(priv);
if (ret) { if (ret) {
......
...@@ -1206,8 +1206,16 @@ EXPORT_SYMBOL(iwl_apm_init); ...@@ -1206,8 +1206,16 @@ EXPORT_SYMBOL(iwl_apm_init);
int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
{ {
int ret = 0; int ret;
s8 prev_tx_power = priv->tx_power_user_lmt; s8 prev_tx_power;
lockdep_assert_held(&priv->mutex);
if (priv->tx_power_user_lmt == tx_power && !force)
return 0;
if (!priv->cfg->ops->lib->send_tx_power)
return -EOPNOTSUPP;
if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
IWL_WARN(priv, IWL_WARN(priv,
...@@ -1224,30 +1232,26 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) ...@@ -1224,30 +1232,26 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
return -EINVAL; return -EINVAL;
} }
if (priv->tx_power_user_lmt != tx_power) if (!iwl_is_ready_rf(priv))
force = true; return -EIO;
/* if nic is not up don't send command */ /* scan complete use tx_power_next, need to be updated */
if (iwl_is_ready_rf(priv)) { priv->tx_power_next = tx_power;
priv->tx_power_user_lmt = tx_power; if (test_bit(STATUS_SCANNING, &priv->status) && !force) {
if (force && priv->cfg->ops->lib->send_tx_power) IWL_DEBUG_INFO(priv, "Deferring tx power set while scanning\n");
ret = priv->cfg->ops->lib->send_tx_power(priv); return 0;
else if (!priv->cfg->ops->lib->send_tx_power)
ret = -EOPNOTSUPP;
/*
* if fail to set tx_power, restore the orig. tx power
*/
if (ret)
priv->tx_power_user_lmt = prev_tx_power;
} }
/* prev_tx_power = priv->tx_power_user_lmt;
* Even this is an async host command, the command priv->tx_power_user_lmt = tx_power;
* will always report success from uCode
* So once driver can placing the command into the queue ret = priv->cfg->ops->lib->send_tx_power(priv);
* successfully, driver can use priv->tx_power_user_lmt
* to reflect the current tx power /* if fail to set tx_power, restore the orig. tx power */
*/ if (ret) {
priv->tx_power_user_lmt = prev_tx_power;
priv->tx_power_next = prev_tx_power;
}
return ret; return ret;
} }
EXPORT_SYMBOL(iwl_set_tx_power); EXPORT_SYMBOL(iwl_set_tx_power);
...@@ -2016,7 +2020,9 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed) ...@@ -2016,7 +2020,9 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
priv->tx_power_user_lmt, conf->power_level); priv->tx_power_user_lmt, conf->power_level);
iwl_set_tx_power(priv, conf->power_level, false); ret = iwl_set_tx_power(priv, conf->power_level, false);
if (ret)
IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
} }
if (!iwl_is_ready(priv)) { if (!iwl_is_ready(priv)) {
......
...@@ -1517,6 +1517,7 @@ struct iwl_priv { ...@@ -1517,6 +1517,7 @@ struct iwl_priv {
s8 tx_power_user_lmt; s8 tx_power_user_lmt;
s8 tx_power_device_lmt; s8 tx_power_device_lmt;
s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */ s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
s8 tx_power_next;
#ifdef CONFIG_IWLWIFI_DEBUG #ifdef CONFIG_IWLWIFI_DEBUG
......
...@@ -603,13 +603,15 @@ static void iwl_bg_scan_completed(struct work_struct *work) ...@@ -603,13 +603,15 @@ static void iwl_bg_scan_completed(struct work_struct *work)
if (!iwl_is_ready_rf(priv)) if (!iwl_is_ready_rf(priv))
goto out; goto out;
/* Since setting the TXPOWER may have been deferred while /*
* performing the scan, fire one off */ * We do not commit power settings while scan is pending,
iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); * do it now if the settings changed.
*/
iwl_set_tx_power(priv, priv->tx_power_next, false);
priv->cfg->ops->utils->post_scan(priv); priv->cfg->ops->utils->post_scan(priv);
out: out:
mutex_unlock(&priv->mutex); mutex_unlock(&priv->mutex);
} }
......
...@@ -3866,6 +3866,7 @@ static int iwl3945_init_drv(struct iwl_priv *priv) ...@@ -3866,6 +3866,7 @@ static int iwl3945_init_drv(struct iwl_priv *priv)
priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER; priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
priv->tx_power_next = IWL_DEFAULT_TX_POWER;
if (eeprom->version < EEPROM_3945_EEPROM_VERSION) { if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
......
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