Skip to content

Commit fa61cf7

Browse files
Juuso Oikarinenlinvjw
authored andcommitted
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: Juuso Oikarinen <juuso.oikarinen@nokia.com> Acked-by: Samuel Ortiz <samuel.ortiz@intel.com> Acked-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent a185045 commit fa61cf7

6 files changed

Lines changed: 51 additions & 41 deletions

File tree

‎drivers/net/wireless/iwmc3200wifi/cfg80211.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,24 @@ static int iwm_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
670670
}
671671

672672
static int iwm_cfg80211_set_txpower(struct wiphy *wiphy,
673-
enum tx_power_setting type, int dbm)
673+
enum nl80211_tx_power_setting type, int mbm)
674674
{
675675
struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
676676
int ret;
677677

678678
switch (type) {
679-
case TX_POWER_AUTOMATIC:
679+
case NL80211_TX_POWER_AUTOMATIC:
680680
return 0;
681-
case TX_POWER_FIXED:
681+
case NL80211_TX_POWER_FIXED:
682+
if (mbm < 0 || (mbm % 100))
683+
return -EOPNOTSUPP;
684+
682685
if (!test_bit(IWM_STATUS_READY, &iwm->status))
683686
return 0;
684687

685688
ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
686-
CFG_TX_PWR_LIMIT_USR, dbm * 2);
689+
CFG_TX_PWR_LIMIT_USR,
690+
MBM_TO_DBM(mbm) * 2);
687691
if (ret < 0)
688692
return ret;
689693

‎drivers/net/wireless/rndis_wlan.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,9 @@ static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
520520

521521
static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
522522

523-
static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
524-
int dbm);
523+
static int rndis_set_tx_power(struct wiphy *wiphy,
524+
enum nl80211_tx_power_setting type,
525+
int mbm);
525526
static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
526527

527528
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)
18561857
return 0;
18571858
}
18581859

1859-
static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1860-
int dbm)
1860+
static int rndis_set_tx_power(struct wiphy *wiphy,
1861+
enum nl80211_tx_power_setting type,
1862+
int mbm)
18611863
{
18621864
struct rndis_wlan_private *priv = wiphy_priv(wiphy);
18631865
struct usbnet *usbdev = priv->usbdev;
18641866

1865-
netdev_dbg(usbdev->net, "%s(): type:0x%x dbm:%i\n",
1866-
__func__, type, dbm);
1867+
netdev_dbg(usbdev->net, "%s(): type:0x%x mbm:%i\n",
1868+
__func__, type, mbm);
1869+
1870+
if (mbm < 0 || (mbm % 100))
1871+
return -ENOTSUPP;
18671872

18681873
/* Device doesn't support changing txpower after initialization, only
18691874
* turn off/on radio. Support 'auto' mode and setting same dBm that is
18701875
* currently used.
18711876
*/
1872-
if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1877+
if (type == NL80211_TX_POWER_AUTOMATIC ||
1878+
MBM_TO_DBM(mbm) == get_bcm4320_power_dbm(priv)) {
18731879
if (!priv->radio_on)
18741880
disassociate(usbdev, true); /* turn on radio */
18751881

‎include/linux/nl80211.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,4 +1659,17 @@ enum nl80211_cqm_rssi_threshold_event {
16591659
NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
16601660
};
16611661

1662+
1663+
/**
1664+
* enum nl80211_tx_power_setting - TX power adjustment
1665+
* @NL80211_TX_POWER_AUTOMATIC: automatically determine transmit power
1666+
* @NL80211_TX_POWER_LIMITED: limit TX power by the mBm parameter
1667+
* @NL80211_TX_POWER_FIXED: fix TX power to the mBm parameter
1668+
*/
1669+
enum nl80211_tx_power_setting {
1670+
NL80211_TX_POWER_AUTOMATIC,
1671+
NL80211_TX_POWER_LIMITED,
1672+
NL80211_TX_POWER_FIXED,
1673+
};
1674+
16621675
#endif /* __LINUX_NL80211_H */

‎include/net/cfg80211.h‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,6 @@ enum wiphy_params_flags {
875875
WIPHY_PARAM_COVERAGE_CLASS = 1 << 4,
876876
};
877877

878-
/**
879-
* enum tx_power_setting - TX power adjustment
880-
*
881-
* @TX_POWER_AUTOMATIC: the dbm parameter is ignored
882-
* @TX_POWER_LIMITED: limit TX power by the dbm parameter
883-
* @TX_POWER_FIXED: fix TX power to the dbm parameter
884-
*/
885-
enum tx_power_setting {
886-
TX_POWER_AUTOMATIC,
887-
TX_POWER_LIMITED,
888-
TX_POWER_FIXED,
889-
};
890-
891878
/*
892879
* cfg80211_bitrate_mask - masks for bitrate control
893880
*/
@@ -1149,7 +1136,7 @@ struct cfg80211_ops {
11491136
int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed);
11501137

11511138
int (*set_tx_power)(struct wiphy *wiphy,
1152-
enum tx_power_setting type, int dbm);
1139+
enum nl80211_tx_power_setting type, int mbm);
11531140
int (*get_tx_power)(struct wiphy *wiphy, int *dbm);
11541141

11551142
int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,

‎net/mac80211/cfg.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,28 +1329,28 @@ static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
13291329
}
13301330

13311331
static int ieee80211_set_tx_power(struct wiphy *wiphy,
1332-
enum tx_power_setting type, int dbm)
1332+
enum nl80211_tx_power_setting type, int mbm)
13331333
{
13341334
struct ieee80211_local *local = wiphy_priv(wiphy);
13351335
struct ieee80211_channel *chan = local->hw.conf.channel;
13361336
u32 changes = 0;
13371337

13381338
switch (type) {
1339-
case TX_POWER_AUTOMATIC:
1339+
case NL80211_TX_POWER_AUTOMATIC:
13401340
local->user_power_level = -1;
13411341
break;
1342-
case TX_POWER_LIMITED:
1343-
if (dbm < 0)
1344-
return -EINVAL;
1345-
local->user_power_level = dbm;
1342+
case NL80211_TX_POWER_LIMITED:
1343+
if (mbm < 0 || (mbm % 100))
1344+
return -EOPNOTSUPP;
1345+
local->user_power_level = MBM_TO_DBM(mbm);
13461346
break;
1347-
case TX_POWER_FIXED:
1348-
if (dbm < 0)
1349-
return -EINVAL;
1347+
case NL80211_TX_POWER_FIXED:
1348+
if (mbm < 0 || (mbm % 100))
1349+
return -EOPNOTSUPP;
13501350
/* TODO: move to cfg80211 when it knows the channel */
1351-
if (dbm > chan->max_power)
1351+
if (MBM_TO_DBM(mbm) > chan->max_power)
13521352
return -EINVAL;
1353-
local->user_power_level = dbm;
1353+
local->user_power_level = MBM_TO_DBM(mbm);
13541354
break;
13551355
}
13561356

‎net/wireless/wext-compat.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
829829
{
830830
struct wireless_dev *wdev = dev->ieee80211_ptr;
831831
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
832-
enum tx_power_setting type;
832+
enum nl80211_tx_power_setting type;
833833
int dbm = 0;
834834

835835
if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
@@ -852,18 +852,18 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
852852
if (data->txpower.value < 0)
853853
return -EINVAL;
854854
dbm = data->txpower.value;
855-
type = TX_POWER_FIXED;
855+
type = NL80211_TX_POWER_FIXED;
856856
/* TODO: do regulatory check! */
857857
} else {
858858
/*
859859
* Automatic power level setting, max being the value
860860
* passed in from userland.
861861
*/
862862
if (data->txpower.value < 0) {
863-
type = TX_POWER_AUTOMATIC;
863+
type = NL80211_TX_POWER_AUTOMATIC;
864864
} else {
865865
dbm = data->txpower.value;
866-
type = TX_POWER_LIMITED;
866+
type = NL80211_TX_POWER_LIMITED;
867867
}
868868
}
869869
} else {
@@ -872,7 +872,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
872872
return 0;
873873
}
874874

875-
return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);
875+
return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
876876
}
877877
EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
878878

0 commit comments

Comments
 (0)