From 9de31c0bdb537b03db2fd326d6be43bfcbdd2541 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 10 Oct 2018 11:18:43 -0700 Subject: [PATCH] qcacld-3.0: Fix power units in wlan_hdd_cfg80211_set_txpower() wlan_hdd_cfg80211_set_txpower() currently expects the input power to be in units of dBm. However cfg80211 specifies the set_tx_power() method will pass the power in mBm, and that to get dBm the driver should use MBM_TO_DBM(). The userspace tool "iw" also expects the power to be in mBm. In order to comply with the definition of cfg80211, change the implementation of wlan_hdd_cfg80211_set_txpower() to expect the power in mBm and use MBM_TO_DBM() to convert the power to dBm. But for backward compatibility with userspace entities which are expecting the current implementation, if the converted power is 0 then assume the input power is already in dBm and use it without conversion. Change-Id: I7c64f7ac14249a307357c91f8bea4dad8d59ff28 CRs-Fixed: 2331003 --- core/hdd/src/wlan_hdd_power.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/hdd/src/wlan_hdd_power.c b/core/hdd/src/wlan_hdd_power.c index 80302a4bec05..7d6adbf2b5b6 100644 --- a/core/hdd/src/wlan_hdd_power.c +++ b/core/hdd/src/wlan_hdd_power.c @@ -1954,14 +1954,14 @@ int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy, * @wiphy: Pointer to wiphy * @wdev: Pointer to network device * @type: TX power setting type - * @dbm: TX power in dbm + * @mbm: TX power in mBm * * Return: 0 for success, non-zero for failure */ static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, struct wireless_dev *wdev, enum nl80211_tx_power_setting type, - int dbm) + int mbm) { struct hdd_context *hdd_ctx = (struct hdd_context *) wiphy_priv(wiphy); mac_handle_t mac_handle; @@ -1969,6 +1969,7 @@ static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, struct qdf_mac_addr selfMac = QDF_MAC_ADDR_BCAST_INIT; QDF_STATUS status; int errno; + int dbm; hdd_enter(); @@ -1987,6 +1988,16 @@ static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, mac_handle = hdd_ctx->mac_handle; + dbm = MBM_TO_DBM(mbm); + + /* + * the original implementation of this function expected power + * values in dBm instead of mBm. If the conversion from mBm to + * dBm is zero, then assume dBm was passed. + */ + if (!dbm) + dbm = mbm; + status = sme_cfg_set_int(mac_handle, WNI_CFG_CURRENT_TX_POWER_LEVEL, dbm); if (QDF_IS_STATUS_ERROR(status)) { @@ -2026,14 +2037,14 @@ static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, struct wireless_dev *wdev, enum nl80211_tx_power_setting type, - int dbm) + int mbm) { int ret; cds_ssr_protect(__func__); ret = __wlan_hdd_cfg80211_set_txpower(wiphy, wdev, - type, dbm); + type, mbm); cds_ssr_unprotect(__func__); return ret;