Skip to contentSkip to conversation

mac80211: add command to get current rssi

PATCH Superseded Victor Goldenshtein 2 participants 5 messages Jun 20, 2012 mac80211

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 mac80211: add command to get current rssi

Get current rssi (in dBm) from the driver/FW.

Instead of reporting the signal received in the last rx packet, which might be inaccurate if rx traffic is low and beacon filtering is enabled, get the singal from the driver/FW.

---

v4:
Trace also station mac address.

 include/net/mac80211.h      |    5 +++++
 net/mac80211/cfg.c          |   21 +++++++++++++--------
 net/mac80211/driver-ops.h   |   16 ++++++++++++++++
 net/mac80211/driver-trace.h |    6 ++++++
 4 files changed, 40 insertions(+), 8 deletions(-)
include/net/mac80211.h +5 -0
index 95e39b6..c65564e 100644
@@ -2246,6 +2246,9 @@ enum ieee80211_rate_control_changed {
  * @get_et_strings:  Ethtool API to get a set of strings to describe stats
  *	and perhaps other supported types of ethtool data-sets.
  *
+ * @get_rssi: Get current signal strength in dBm, the function is optional
+ *	and can sleep.
+ *
  */
 struct ieee80211_ops {
 	void (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb);
@@ -2385,6 +2388,8 @@ struct ieee80211_ops {
 	void	(*get_et_strings)(struct ieee80211_hw *hw,
 				  struct ieee80211_vif *vif,
 				  u32 sset, u8 *data);
+	int	(*get_rssi)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+			    struct ieee80211_sta *sta, s8 *rssi_dbm);
 };
 
 /**
net/mac80211/cfg.c +13 -8
index 7d5108a..bcbfb23 100644
@@ -353,6 +353,7 @@ void sta_set_rate_info_tx(struct sta_info *sta,
 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
 {
 	struct ieee80211_sub_if_data *sdata = sta->sdata;
+	struct ieee80211_local *local = sdata->local;
 	struct timespec uptime;
 
 	sinfo->generation = sdata->local->sta_generation;
@@ -388,7 +389,9 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
 	if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
 	    (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
 		sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
-		sinfo->signal = (s8)sta->last_signal;
+		if (!local->ops->get_rssi ||
+		    drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
+			sinfo->signal = (s8)sta->last_signal;
 		sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
 	}
 
@@ -517,7 +520,7 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
 	 * network device.
 	 */
 
-	rcu_read_lock();
+	mutex_lock(&local->sta_mtx);
 
 	if (sdata->vif.type == NL80211_IFTYPE_STATION) {
 		sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
@@ -546,7 +549,7 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
 			data[i] = (u8)sinfo.signal_avg;
 		i++;
 	} else {
-		list_for_each_entry_rcu(sta, &local->sta_list, list) {
+		list_for_each_entry(sta, &local->sta_list, list) {
 			/* Make sure this station belongs to the proper dev */
 			if (sta->sdata->dev != dev)
 				continue;
@@ -603,7 +606,7 @@ do_survey:
 	else
 		data[i++] = -1LL;
 
-	rcu_read_unlock();
+	mutex_unlock(&local->sta_mtx);
 
 	if (WARN_ON(i != STA_STATS_LEN))
 		return;
@@ -629,10 +632,11 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
 				 int idx, u8 *mac, struct station_info *sinfo)
 {
 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
 	struct sta_info *sta;
 	int ret = -ENOENT;
 
-	rcu_read_lock();
+	mutex_lock(&local->sta_mtx);
 
 	sta = sta_info_get_by_idx(sdata, idx);
 	if (sta) {
@@ -641,7 +645,7 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
 		sta_set_sinfo(sta, sinfo);
 	}
 
-	rcu_read_unlock();
+	mutex_unlock(&local->sta_mtx);
 
 	return ret;
 }
@@ -658,10 +662,11 @@ static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
 				 u8 *mac, struct station_info *sinfo)
 {
 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
 	struct sta_info *sta;
 	int ret = -ENOENT;
 
-	rcu_read_lock();
+	mutex_lock(&local->sta_mtx);
 
 	sta = sta_info_get_bss(sdata, mac);
 	if (sta) {
@@ -669,7 +674,7 @@ static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
 		sta_set_sinfo(sta, sinfo);
 	}
 
-	rcu_read_unlock();
+	mutex_unlock(&local->sta_mtx);
 
 	return ret;
 }
net/mac80211/driver-ops.h +16 -0
index 6d33a0c..370c721 100644
@@ -845,4 +845,20 @@ drv_allow_buffered_frames(struct ieee80211_local *local,
 						  more_data);
 	trace_drv_return_void(local);
 }
+
+static inline int drv_get_rssi(struct ieee80211_local *local,
+				struct ieee80211_sub_if_data *sdata,
+				struct ieee80211_sta *sta,
+				s8 *rssi_dbm)
+{
+	int ret;
+
+	might_sleep();
+
+	trace_drv_get_rssi(local, sdata);
+	ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
+	trace_drv_return_int(local, ret);
+
+	return ret;
+}
 #endif /* __MAC80211_DRIVER_OPS */
net/mac80211/driver-trace.h +6 -0
index 6de00b2..23928c5 100644
@@ -1218,6 +1218,12 @@ DEFINE_EVENT(release_evt, drv_allow_buffered_frames,
 	TP_ARGS(local, sta, tids, num_frames, reason, more_data)
 );
 
+DEFINE_EVENT(local_sdata_addr_evt, drv_get_rssi,
+	TP_PROTO(struct ieee80211_local *local,
+		 struct ieee80211_sub_if_data *sdata),
+	TP_ARGS(local, sdata)
+);
+
 /*
  * Tracing for API calls that drivers call.
  */
Signature · 1 line
1.7.5.4
maintainer
#1 lore raw

net/mac80211/driver-ops.h drv_allow_buffered_frames(struct ieee80211_local *local, · line 860

Quoted 3 lines · Victor Goldenshtein
net/mac80211/driver-ops.h +3 -0
+	trace_drv_get_rssi(local, sdata);
+	ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
+	trace_drv_return_int(local, ret);

Where are you tracing the sta?

And why not trace the value returned in *rssi_dbm?

johannes

#2 lore raw
Quoted 8 lines · Johannes Berg
Quoted 3 lines · Victor Goldenshtein

+     trace_drv_get_rssi(local, sdata);
+     ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
+     trace_drv_return_int(local, ret);

Where are you tracing the sta?

We talked about print sta address with "local_sdata_addr_evt" event macro, the output looks like this:

# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |

              iw-1394  [000]        ...1  1083.713867: drv_get_rssi:
phy0 vif:wlan0(2) addr:08:00:28:cc:65:43
              iw-1394  [000]        ...1  1083.729736: drv_return_int: phy0 - 0
Quoted 2 lines

And why not trace the value returned in *rssi_dbm?

Is it really required ? there are various driver-ops which are "get stuff" without printing them in the tracer.

Signature · 2 lines
Thanks,
Victor.
maintainer
#3 lore raw
Quoted 11 lines · Victor
Quoted 8 lines · Johannes Berg

net/mac80211/driver-ops.h drv_allow_buffered_frames(struct ieee80211_local *local, · line 860

Quoted 3 lines · Victor Goldenshtein
net/mac80211/driver-ops.h +3 -0
+     trace_drv_get_rssi(local, sdata);
+     ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
+     trace_drv_return_int(local, ret);

Where are you tracing the sta?

Quoted 8 lines

We talked about print sta address with "local_sdata_addr_evt" event macro, the output looks like this:

# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |

              iw-1394  [000]        ...1  1083.713867: drv_get_rssi:
phy0 vif:wlan0(2) addr:08:00:28:cc:65:43
              iw-1394  [000]        ...1  1083.729736: drv_return_int: phy0 - 0

That's not the STA address, that's the VIF address.

Quoted 5 lines
Quoted 2 lines

And why not trace the value returned in *rssi_dbm?

Is it really required ? there are various driver-ops which are "get stuff" without printing them in the tracer.

It'd be nice to fix all the ones, but I can't make you do that :-)

johannes

#4 lore raw
Quoted 15 lines · Johannes Berg
Quoted 14 lines · Victor
Quoted 8 lines · Johannes Berg
Quoted 3 lines · Victor Goldenshtein

+     trace_drv_get_rssi(local, sdata);
+     ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
+     trace_drv_return_int(local, ret);

Where are you tracing the sta?

We talked about print sta address with "local_sdata_addr_evt" event macro, the output looks like this:

Quoted 8 lines
Quoted 5 lines

#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
#              | |       |                     ||||       |         | iw-1394  [000]        ...1  1083.713867: drv_get_rssi:
phy0 vif:wlan0(2) addr:08:00:28:cc:65:43
              iw-1394  [000]        ...1  1083.729736: drv_return_int: phy0 - 0

That's not the STA address, that's the VIF address.

ops... you're right.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

And why not trace the value returned in *rssi_dbm?

Is it really required ? there are various driver-ops which are "get stuff" without printing them in the tracer.

It'd be nice to fix all the ones, but I can't make you do that :-)

will respin this one two ;)

Signature · 2 lines
Thanks,
Victor.