Commit fa61cf70 authored by Juuso Oikarinen's avatar Juuso Oikarinen Committed by John W. Linville

cfg80211/mac80211: Update set_tx_power to use mBm instead of dBm units

In preparation for a TX power setting interface in the nl80211, change the
.set_tx_power function to use mBm units instead of dBm for greater accuracy and
smaller power levels.

Also, already in advance move the tx_power_setting enumeration to nl80211.

This change affects the .tx_set_power function prototype. As a result, the
corresponding changes are needed to modules using it. These are mac80211,
iwmc3200wifi and rndis_wlan.

Cc: Samuel Ortiz <samuel.ortiz@intel.com>
Cc: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: default avatarJuuso Oikarinen <juuso.oikarinen@nokia.com>
Acked-by: default avatarSamuel Ortiz <samuel.ortiz@intel.com>
Acked-by: default avatarJussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent a185045c
...@@ -670,20 +670,24 @@ static int iwm_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev, ...@@ -670,20 +670,24 @@ static int iwm_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
} }
static int iwm_cfg80211_set_txpower(struct wiphy *wiphy, static int iwm_cfg80211_set_txpower(struct wiphy *wiphy,
enum tx_power_setting type, int dbm) enum nl80211_tx_power_setting type, int mbm)
{ {
struct iwm_priv *iwm = wiphy_to_iwm(wiphy); struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
int ret; int ret;
switch (type) { switch (type) {
case TX_POWER_AUTOMATIC: case NL80211_TX_POWER_AUTOMATIC:
return 0; return 0;
case TX_POWER_FIXED: case NL80211_TX_POWER_FIXED:
if (mbm < 0 || (mbm % 100))
return -EOPNOTSUPP;
if (!test_bit(IWM_STATUS_READY, &iwm->status)) if (!test_bit(IWM_STATUS_READY, &iwm->status))
return 0; return 0;
ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
CFG_TX_PWR_LIMIT_USR, dbm * 2); CFG_TX_PWR_LIMIT_USR,
MBM_TO_DBM(mbm) * 2);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -520,8 +520,9 @@ static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, ...@@ -520,8 +520,9 @@ static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed); static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type, static int rndis_set_tx_power(struct wiphy *wiphy,
int dbm); enum nl80211_tx_power_setting type,
int mbm);
static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm); static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
static int rndis_connect(struct wiphy *wiphy, struct net_device *dev, static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
...@@ -1856,20 +1857,25 @@ static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed) ...@@ -1856,20 +1857,25 @@ static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
return 0; return 0;
} }
static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type, static int rndis_set_tx_power(struct wiphy *wiphy,
int dbm) enum nl80211_tx_power_setting type,
int mbm)
{ {
struct rndis_wlan_private *priv = wiphy_priv(wiphy); struct rndis_wlan_private *priv = wiphy_priv(wiphy);
struct usbnet *usbdev = priv->usbdev; struct usbnet *usbdev = priv->usbdev;
netdev_dbg(usbdev->net, "%s(): type:0x%x dbm:%i\n", netdev_dbg(usbdev->net, "%s(): type:0x%x mbm:%i\n",
__func__, type, dbm); __func__, type, mbm);
if (mbm < 0 || (mbm % 100))
return -ENOTSUPP;
/* Device doesn't support changing txpower after initialization, only /* Device doesn't support changing txpower after initialization, only
* turn off/on radio. Support 'auto' mode and setting same dBm that is * turn off/on radio. Support 'auto' mode and setting same dBm that is
* currently used. * currently used.
*/ */
if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) { if (type == NL80211_TX_POWER_AUTOMATIC ||
MBM_TO_DBM(mbm) == get_bcm4320_power_dbm(priv)) {
if (!priv->radio_on) if (!priv->radio_on)
disassociate(usbdev, true); /* turn on radio */ disassociate(usbdev, true); /* turn on radio */
......
...@@ -1659,4 +1659,17 @@ enum nl80211_cqm_rssi_threshold_event { ...@@ -1659,4 +1659,17 @@ enum nl80211_cqm_rssi_threshold_event {
NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
}; };
/**
* enum nl80211_tx_power_setting - TX power adjustment
* @NL80211_TX_POWER_AUTOMATIC: automatically determine transmit power
* @NL80211_TX_POWER_LIMITED: limit TX power by the mBm parameter
* @NL80211_TX_POWER_FIXED: fix TX power to the mBm parameter
*/
enum nl80211_tx_power_setting {
NL80211_TX_POWER_AUTOMATIC,
NL80211_TX_POWER_LIMITED,
NL80211_TX_POWER_FIXED,
};
#endif /* __LINUX_NL80211_H */ #endif /* __LINUX_NL80211_H */
...@@ -875,19 +875,6 @@ enum wiphy_params_flags { ...@@ -875,19 +875,6 @@ enum wiphy_params_flags {
WIPHY_PARAM_COVERAGE_CLASS = 1 << 4, WIPHY_PARAM_COVERAGE_CLASS = 1 << 4,
}; };
/**
* enum tx_power_setting - TX power adjustment
*
* @TX_POWER_AUTOMATIC: the dbm parameter is ignored
* @TX_POWER_LIMITED: limit TX power by the dbm parameter
* @TX_POWER_FIXED: fix TX power to the dbm parameter
*/
enum tx_power_setting {
TX_POWER_AUTOMATIC,
TX_POWER_LIMITED,
TX_POWER_FIXED,
};
/* /*
* cfg80211_bitrate_mask - masks for bitrate control * cfg80211_bitrate_mask - masks for bitrate control
*/ */
...@@ -1149,7 +1136,7 @@ struct cfg80211_ops { ...@@ -1149,7 +1136,7 @@ struct cfg80211_ops {
int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed); int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed);
int (*set_tx_power)(struct wiphy *wiphy, int (*set_tx_power)(struct wiphy *wiphy,
enum tx_power_setting type, int dbm); enum nl80211_tx_power_setting type, int mbm);
int (*get_tx_power)(struct wiphy *wiphy, int *dbm); int (*get_tx_power)(struct wiphy *wiphy, int *dbm);
int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev, int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,
......
...@@ -1329,28 +1329,28 @@ static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) ...@@ -1329,28 +1329,28 @@ static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
} }
static int ieee80211_set_tx_power(struct wiphy *wiphy, static int ieee80211_set_tx_power(struct wiphy *wiphy,
enum tx_power_setting type, int dbm) enum nl80211_tx_power_setting type, int mbm)
{ {
struct ieee80211_local *local = wiphy_priv(wiphy); struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_channel *chan = local->hw.conf.channel; struct ieee80211_channel *chan = local->hw.conf.channel;
u32 changes = 0; u32 changes = 0;
switch (type) { switch (type) {
case TX_POWER_AUTOMATIC: case NL80211_TX_POWER_AUTOMATIC:
local->user_power_level = -1; local->user_power_level = -1;
break; break;
case TX_POWER_LIMITED: case NL80211_TX_POWER_LIMITED:
if (dbm < 0) if (mbm < 0 || (mbm % 100))
return -EINVAL; return -EOPNOTSUPP;
local->user_power_level = dbm; local->user_power_level = MBM_TO_DBM(mbm);
break; break;
case TX_POWER_FIXED: case NL80211_TX_POWER_FIXED:
if (dbm < 0) if (mbm < 0 || (mbm % 100))
return -EINVAL; return -EOPNOTSUPP;
/* TODO: move to cfg80211 when it knows the channel */ /* TODO: move to cfg80211 when it knows the channel */
if (dbm > chan->max_power) if (MBM_TO_DBM(mbm) > chan->max_power)
return -EINVAL; return -EINVAL;
local->user_power_level = dbm; local->user_power_level = MBM_TO_DBM(mbm);
break; break;
} }
......
...@@ -829,7 +829,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev, ...@@ -829,7 +829,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
enum tx_power_setting type; enum nl80211_tx_power_setting type;
int dbm = 0; int dbm = 0;
if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
...@@ -852,7 +852,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev, ...@@ -852,7 +852,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
if (data->txpower.value < 0) if (data->txpower.value < 0)
return -EINVAL; return -EINVAL;
dbm = data->txpower.value; dbm = data->txpower.value;
type = TX_POWER_FIXED; type = NL80211_TX_POWER_FIXED;
/* TODO: do regulatory check! */ /* TODO: do regulatory check! */
} else { } else {
/* /*
...@@ -860,10 +860,10 @@ int cfg80211_wext_siwtxpower(struct net_device *dev, ...@@ -860,10 +860,10 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
* passed in from userland. * passed in from userland.
*/ */
if (data->txpower.value < 0) { if (data->txpower.value < 0) {
type = TX_POWER_AUTOMATIC; type = NL80211_TX_POWER_AUTOMATIC;
} else { } else {
dbm = data->txpower.value; dbm = data->txpower.value;
type = TX_POWER_LIMITED; type = NL80211_TX_POWER_LIMITED;
} }
} }
} else { } else {
...@@ -872,7 +872,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev, ...@@ -872,7 +872,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
return 0; return 0;
} }
return rdev->ops->set_tx_power(wdev->wiphy, type, dbm); return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
} }
EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
......
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