Skip to contentSkip to conversation

mac80211: move mesh sync beacon handler into neighbour_update

PATCH Superseded Marco Porsch 4 participants 10 messages Feb 18, 2013 – Feb 26, 2013

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 mac80211: move mesh sync beacon handler into neighbour_update

Move the beacon handler into mesh_neighbour_update where the STA pointer is already available. This avoids additional overhead and simplifies the handler.
The repositioning will also benefit mesh PS which uses T_r and the updated T_offset value.

Rename the handler to better reflect its purpose.

---

v2:
calculate T_r outside mesh sync handler (Johannes) remove unused variables

 net/mac80211/ieee80211_i.h |    9 ++++-----
 net/mac80211/mesh.c        |    7 +------
 net/mac80211/mesh.h        |    4 +++-
 net/mac80211/mesh_plink.c  |   31 +++++++++++++++++++++++++-----
 net/mac80211/mesh_sync.c   |   45 ++++++++++----------------------------------
 5 files changed, 44 insertions(+), 52 deletions(-)
net/mac80211/ieee80211_i.h +4 -5
index 388580a..631760f 100644
@@ -529,11 +529,10 @@ struct ieee80211_if_ibss {
  */
 struct ieee802_11_elems;
 struct ieee80211_mesh_sync_ops {
-	void (*rx_bcn_presp)(struct ieee80211_sub_if_data *sdata,
-			     u16 stype,
-			     struct ieee80211_mgmt *mgmt,
-			     struct ieee802_11_elems *elems,
-			     struct ieee80211_rx_status *rx_status);
+	void (*rx_bcn)(struct sta_info *sta,
+		       struct ieee80211_mgmt *mgmt,
+		       struct ieee802_11_elems *elems,
+		       u64 t_r);
 	void (*adjust_tbtt)(struct ieee80211_sub_if_data *sdata);
 	/* add other framework functions here */
 };
net/mac80211/mesh.c +1 -6
index 29ce2aa..94682d2 100644
@@ -938,7 +938,6 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
 					struct ieee80211_rx_status *rx_status)
 {
 	struct ieee80211_local *local = sdata->local;
-	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
 	struct ieee802_11_elems elems;
 	struct ieee80211_channel *channel;
 	size_t baselen;
@@ -974,11 +973,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
 		return;
 
 	if (mesh_matches_local(sdata, &elems))
-		mesh_neighbour_update(sdata, mgmt->sa, &elems);
-
-	if (ifmsh->sync_ops)
-		ifmsh->sync_ops->rx_bcn_presp(sdata,
-			stype, mgmt, &elems, rx_status);
+		mesh_neighbour_update(sdata, mgmt, &elems, rx_status);
 }
 
 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
net/mac80211/mesh.h +3 -1
index 336c88a..ac02f38 100644
@@ -283,7 +283,9 @@ int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
 
 /* Mesh plinks */
 void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
-			   u8 *hw_addr, struct ieee802_11_elems *ie);
+			   struct ieee80211_mgmt *mgmt,
+			   struct ieee802_11_elems *ie,
+			   struct ieee80211_rx_status *rx_status);
 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie);
 u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
 void mesh_plink_broken(struct sta_info *sta);
net/mac80211/mesh_plink.c +26 -5
index 07d396d..d40fedd 100644
@@ -12,6 +12,7 @@
 #include "ieee80211_i.h"
 #include "rate.h"
 #include "mesh.h"
+#include "driver-ops.h"
 
 #define PLINK_GET_LLID(p) (p + 2)
 #define PLINK_GET_PLID(p) (p + 4)
@@ -497,23 +498,43 @@ mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
  * Initiates peering if appropriate.
  */
 void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
-			   u8 *hw_addr,
-			   struct ieee802_11_elems *elems)
+			   struct ieee80211_mgmt *mgmt,
+			   struct ieee802_11_elems *elems,
+			   struct ieee80211_rx_status *rx_status)
 {
+	struct ieee80211_local *local = sdata->local;
+	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
 	struct sta_info *sta;
 	u32 changed = 0;
+	u64 t_r;
+
+	/*
+	 * If available, calculate the time the beacon timestamp field was
+	 * received from the rx_status->mactime field. Otherwise get the
+	 * current TSF as approximation before entering rcu-read section.
+	 */
+	if (ieee80211_have_rx_timestamp(rx_status))
+		t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
+						       24 + 12 +
+						       elems->total_len +
+						       FCS_LEN,
+						       24);
+	else
+		t_r = drv_get_tsf(local, sdata);
 
-	sta = mesh_sta_info_get(sdata, hw_addr, elems);
+	sta = mesh_sta_info_get(sdata, mgmt->sa, elems);
 	if (!sta)
 		goto out;
 
 	if (mesh_peer_accepts_plinks(elems) &&
 	    sta->plink_state == NL80211_PLINK_LISTEN &&
-	    sdata->u.mesh.accepting_plinks &&
-	    sdata->u.mesh.mshcfg.auto_open_plinks &&
+	    ifmsh->accepting_plinks && ifmsh->mshcfg.auto_open_plinks &&
 	    rssi_threshold_check(sta, sdata))
 		changed = mesh_plink_open(sta);
 
+	if (ifmsh->sync_ops)
+		ifmsh->sync_ops->rx_bcn(sta, mgmt, elems, t_r);
+
 	ieee80211_mps_frame_release(sta, elems);
 out:
 	rcu_read_unlock();
net/mac80211/mesh_sync.c +10 -35

85 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 2/3 mac80211: mesh power save doze scheduling

Configure the HW for PS mode if the local mesh PS parameters allow so.

Expose a callback ieee80211_mps_init for drivers to register mesh powersave ops:
- hw_doze - put the radio to sleep now, wake up at given TBTT
- hw_wakeup - wake the radio up for frame RX
These ops may be extended in the future to allow drivers/HW to implement mesh PS themselves. (The current design goal was to concentrate most mesh PS routines in mac80211 to keep driver modifications minimal.

Track the beacon timing information of peers we are in PS mode towards. Calculate the next TBTT per STA. Stay awake to receive multicast traffic after DTIM beacons.

When going to doze state, get the most imminent STA TBTT and configure the driver to trigger a wakeup on time to catch that beacon. After successful receipt put the HW to doze again. Set a timeout for the case that the beacon is not received on time. In this case calculate the following TBTT and go to doze again.

For mesh Awake Windows wakeup on SWBA (beacon_get_tim) and start a timer which triggers a doze call on expiry.

---
 include/net/mac80211.h     |   29 ++++
 net/mac80211/ieee80211_i.h |    7 +-
 net/mac80211/mesh.c        |   11 ++
 net/mac80211/mesh.h        |   13 ++
 net/mac80211/mesh_plink.c  |    3 +
 net/mac80211/mesh_ps.c     |  313 ++++++++++++++++++++++++++++++++++++++++++++
 net/mac80211/sta_info.h    |   10 ++
 net/mac80211/tx.c          |    2 +
 8 files changed, 387 insertions(+), 1 deletion(-)
include/net/mac80211.h +29 -0
index f7eba13..a27383f 100644
@@ -2801,6 +2801,18 @@ enum ieee80211_tpt_led_trigger_flags {
 	IEEE80211_TPT_LEDTRIG_FL_CONNECTED	= BIT(2),
 };
 
+/**
+ * struct ieee80211_mps_ops - callbacks from mac80211 to the driver for mesh PS
+ *
+ * @hw_doze: put the radio to doze state to conserve power, schedule wakeup
+ *	at given TSF value to receive peer beacon
+ * @hw_wakeup: wake up the radio to receive frames again
+ */
+struct ieee80211_mps_ops {
+	void (*hw_doze)(struct ieee80211_hw *hw, u64 nexttbtt);
+	void (*hw_wakeup)(struct ieee80211_hw *hw);
+};
+
 #ifdef CONFIG_MAC80211_LEDS
 extern char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw);
 extern char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw);
@@ -4058,6 +4070,23 @@ void ieee80211_stop_rx_ba_session(struct ieee80211_vif *vif, u16 ba_rx_bitmap,
  */
 void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn);
 
+/**
+ * ieee80211_mps_init - register callbacks for mesh powersave mode
+ *
+ * @hw: the hardware
+ * @ops: callbacks for this device
+ *
+ * called by driver on mesh interface add/remove
+ */
+#ifdef CONFIG_MAC80211_MESH
+void ieee80211_mps_init(struct ieee80211_hw *hw,
+			const struct ieee80211_mps_ops *ops);
+#else
+static inline void ieee80211_mps_init(struct ieee80211_hw *hw,
+				      const struct ieee80211_mps_ops *ops)
+{ return; }
+#endif
+
 /* Rate control API */
 
 /**
net/mac80211/ieee80211_i.h +6 -1
index 631760f..c42a506 100644
@@ -599,6 +599,7 @@ struct ieee80211_if_mesh {
 	int ps_peers_light_sleep;
 	int ps_peers_deep_sleep;
 	struct ps_data ps;
+	struct timer_list awake_window_end_timer;
 };
 
 #ifdef CONFIG_MAC80211_MESH
@@ -1092,7 +1093,7 @@ struct ieee80211_local {
 	bool pspolling;
 	bool offchannel_ps_enabled;
 	/*
-	 * PS can only be enabled when we have exactly one managed
+	 * managed mode PS can only be enabled when we have exactly one managed
 	 * interface (and monitors) in PS, this then points there.
 	 */
 	struct ieee80211_sub_if_data *ps_sdata;
@@ -1111,6 +1112,10 @@ struct ieee80211_local {
 
 	int user_power_level; /* in dBm, for all interfaces */
 
+	/* mesh power save can be enabled for multiple (but only mesh) vif */
+	bool mps_enabled;
+	const struct ieee80211_mps_ops *mps_ops;
+
 	enum ieee80211_smps_mode smps_mode;
 
 	struct work_struct restart_work;
net/mac80211/mesh.c +11 -0
index 94682d2..61cfbe0 100644
@@ -168,6 +168,7 @@ void mesh_sta_cleanup(struct sta_info *sta)
 	if (sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
 		changed |= mesh_plink_deactivate(sta);
 		del_timer_sync(&sta->plink_timer);
+		del_timer_sync(&sta->nexttbtt_timer);
 	}
 
 	if (changed)
@@ -1026,6 +1027,7 @@ void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
 
 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
 {
+	struct ieee80211_local *local = sdata->local;
 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
 
 	if (ifmsh->preq_queue_len &&
@@ -1047,6 +1049,12 @@ void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
 
 	if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
 		mesh_sync_adjust_tbtt(sdata);
+
+	if (test_and_clear_bit(MESH_WORK_PS_HW_CONF, &ifmsh->wrkq_flags))
+		ieee80211_mps_hw_conf(local);
+
+	if (test_and_clear_bit(MESH_WORK_PS_DOZE, &ifmsh->wrkq_flags))
+		ieee80211_mps_doze(local);
 }
 
 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
@@ -1086,6 +1094,9 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
 	setup_timer(&ifmsh->mesh_path_root_timer,
 		    ieee80211_mesh_path_root_timer,
 		    (unsigned long) sdata);
+	setup_timer(&ifmsh->awake_window_end_timer,
+		    ieee80211_mps_awake_window_end,
+		    (unsigned long) sdata);
 	INIT_LIST_HEAD(&ifmsh->preq_queue.list);
 	skb_queue_head_init(&ifmsh->ps.bc_buf);
 	spin_lock_init(&ifmsh->mesh_preq_queue_lock);
net/mac80211/mesh.h +13 -0
index ac02f38..8dd8637 100644
@@ -58,6 +58,8 @@ enum mesh_path_flags {
  * @MESH_WORK_ROOT: the mesh root station needs to send a frame
  * @MESH_WORK_DRIFT_ADJUST: time to compensate for clock drift relative to other
  * mesh nodes
+ * @MESH_WORK_PS_HW_CONF: perform checks for PS mode and configure hardware
+ * @MESH_WORK_PS_DOZE: perform checks for doze state and put hardware to doze
  */
 enum mesh_deferred_task_flags {
 	MESH_WORK_HOUSEKEEPING,
@@ -65,6 +67,8 @@ enum mesh_deferred_task_flags {
 	MESH_WORK_GROW_MPP_TABLE,
 	MESH_WORK_ROOT,
 	MESH_WORK_DRIFT_ADJUST,
+	MESH_WORK_PS_HW_CONF,
+	MESH_WORK_PS_DOZE,
 };
 
 /**
@@ -256,6 +260,15 @@ void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
 				    bool tx, bool acked);
 void ieee80211_mps_frame_release(struct sta_info *sta,
 				 struct ieee802_11_elems *elems);
+void ieee80211_mps_hw_conf(struct ieee80211_local *local);
+void ieee80211_mps_sta_tbtt_update(struct sta_info *sta,
+				   struct ieee80211_mgmt *mgmt,
+				   const struct ieee80211_tim_ie *tim,
+				   u64 tsf);
+void ieee80211_mps_sta_tbtt_timeout(unsigned long data);
+void ieee80211_mps_awake_window_start(struct ieee80211_sub_if_data *sdata);
+void ieee80211_mps_awake_window_end(unsigned long data);
+void ieee80211_mps_doze(struct ieee80211_local *local);
 
 /* Mesh paths */
 int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
net/mac80211/mesh_plink.c +3 -0
index d40fedd..ab4b836 100644
@@ -422,6 +422,8 @@ __mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
 
 	sta->plink_state = NL80211_PLINK_LISTEN;
 	init_timer(&sta->plink_timer);
+	setup_timer(&sta->nexttbtt_timer, ieee80211_mps_sta_tbtt_timeout,
+		    (unsigned long) sta);
 
 	sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
 	sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
@@ -536,6 +538,7 @@ void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
 		ifmsh->sync_ops->rx_bcn(sta, mgmt, elems, t_r);
 
 	ieee80211_mps_frame_release(sta, elems);
+	ieee80211_mps_sta_tbtt_update(sta, mgmt, elems->tim, t_r);
 out:
 	rcu_read_unlock();
 	ieee80211_mbss_info_change_notify(sdata, changed);
net/mac80211/mesh_ps.c +313 -0

352 lines not on this page · raw message

net/mac80211/sta_info.h +10 -0
index 4947341..3d25b6b 100644
@@ -58,6 +58,7 @@
  * @WLAN_STA_TOFFSET_KNOWN: toffset calculated for this station is valid.
  * @WLAN_STA_MPSP_OWNER: local STA is owner of a mesh Peer Service Period.
  * @WLAN_STA_MPSP_RECIPIENT: local STA is recipient of a MPSP.
+ * @WLAN_STA_MPS_WAIT_FOR_CAB: multicast frames from this STA are imminent.
  */
 enum ieee80211_sta_info_flags {
 	WLAN_STA_AUTH,
@@ -82,6 +83,7 @@ enum ieee80211_sta_info_flags {
 	WLAN_STA_TOFFSET_KNOWN,
 	WLAN_STA_MPSP_OWNER,
 	WLAN_STA_MPSP_RECIPIENT,
+	WLAN_STA_MPS_WAIT_FOR_CAB,
 };
 
 #define ADDBA_RESP_INTERVAL HZ
@@ -288,6 +290,10 @@ struct sta_ampdu_mlme {
  * @local_pm: local link-specific power save mode
  * @peer_pm: peer-specific power save mode towards local STA
  * @nonpeer_pm: STA power save mode towards non-peer neighbors
+ * @beacon_interval: beacon interval of neighbor STA (in us)
+ * @nexttbtt_tsf: next TBTT in local TSF units
+ * @nexttbtt_jiffies: next TBTT in jiffies units
+ * @nexttbtt_timer: timeout for missed beacons
  * @debugfs: debug filesystem info
  * @dead: set to true when sta is unlinked
  * @uploaded: set to true when sta is uploaded to the driver
@@ -389,6 +395,10 @@ struct sta_info {
 	enum nl80211_mesh_power_mode local_pm;
 	enum nl80211_mesh_power_mode peer_pm;
 	enum nl80211_mesh_power_mode nonpeer_pm;
+	u32 beacon_interval;
+	u64 nexttbtt_tsf;
+	unsigned long nexttbtt_jiffies;
+	struct timer_list nexttbtt_timer;
 #endif
 
 #ifdef CONFIG_MAC80211_DEBUGFS
net/mac80211/tx.c +2 -0
index 5b9602b..a44c712 100644
@@ -2460,6 +2460,8 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
 		memcpy(skb_put(skb, bcn->head_len), bcn->head, bcn->head_len);
 		ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb);
 		memcpy(skb_put(skb, bcn->tail_len), bcn->tail, bcn->tail_len);
+
+		ieee80211_mps_awake_window_start(sdata);
 	} else {
 		WARN_ON(1);
 		goto out;
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/3 mac80211: mesh power save doze scheduling

Quoted 11 lines · Marco Porsch

---

net/mac80211/mesh_ps.c +10 -0
+/**
+ * ieee80211_mps_sta_tbtt_update - update peer beacon wakeup schedule
+ *
+ * @sta: mesh STA
+ * @mgmt: beacon frame
+ * @tim: TIM IE of beacon frame
+ * @tsf_local: current HW TSF
+ */
+void ieee80211_mps_sta_tbtt_update(struct sta_info *sta,
+				   struct ieee80211_mgmt *mgmt,

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 752

Quoted 10 lines
net/mac80211/mesh_ps.c +10 -0
+				   const struct ieee80211_tim_ie *tim,
+				   u64 tsf_local)
+{
+	struct ieee80211_sub_if_data *sdata = sta->sdata;
+
+	if (!sdata->local->mps_enabled ||
+	    sta->plink_state != NL80211_PLINK_ESTAB)
+		return;
+
+	sta->beacon_interval = le16_to_cpu(mgmt->u.beacon.beacon_int) * 1024;

If you want, you could use ieee80211_tu_to_usec instead of "* 1024":
sta->beacon_interval = ieee80211_tu_to_usec(le16_to_cpu(mgmt->u.beacon.beacon_int));

Regards,
Chr

maintainer
#3 lore raw

PATCH v2 2/3 mac80211: mesh power save doze scheduling

In reply to Marco Porsch
Quoted 6 lines · Marco Porsch
include/net/mac80211.h +6 -0
+/**
+ * ieee80211_mps_init - register callbacks for mesh powersave mode
+ *
+ * @hw: the hardware
+ * @ops: callbacks for this device
+ *

include/net/mac80211.h void ieee80211_stop_rx_ba_session(struct ieee80211_vif *vif, u16 ba_rx_bitmap, · line 4088

Quoted 10 lines
include/net/mac80211.h +10 -0
+ * called by driver on mesh interface add/remove
+ */
+#ifdef CONFIG_MAC80211_MESH
+void ieee80211_mps_init(struct ieee80211_hw *hw,
+			const struct ieee80211_mps_ops *ops);
+#else
+static inline void ieee80211_mps_init(struct ieee80211_hw *hw,
+				      const struct ieee80211_mps_ops *ops)
+{ return; }
+#endif

The "return" there is spurious. Is it really worth providing a static inline? It seems drivers might want to #ifdef it anyway so they don't have carry around the ops struct and the called functions if mesh isn't compiled in.

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 861

Quoted 12 lines
net/mac80211/mesh_ps.c +12 -0
+static bool mps_doze_check_sta(struct ieee80211_local *local, u64 *nexttbtt)
+{
+       struct sta_info *sta;
+       bool allow = true;
+       u64 nexttbtt_min = ULLONG_MAX;
+
+       mutex_lock(&local->sta_mtx);
+       list_for_each_entry(sta, &local->sta_list, list) {
+               if (!ieee80211_vif_is_mesh(&sta->sdata->vif) ||
+                   !ieee80211_sdata_running(sta->sdata) ||
+                   sta->plink_state != NL80211_PLINK_ESTAB) {
+                       continue;

This is strange, why bother with the else if there's a continue?

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 866

Quoted 5 lines
net/mac80211/mesh_ps.c +5 -0
+               } else if (test_sta_flag(sta, WLAN_STA_MPS_WAIT_FOR_CAB) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_OWNER) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT) ||
+                          !timer_pending(&sta->nexttbtt_timer) ||
+                          time_after(jiffies, sta->nexttbtt_jiffies)) {

Are you sure jiffies are good enough? Some systems have HZ=33 or so I think, which makes a jiffy like 30ms.

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 871

Quoted 5 lines
net/mac80211/mesh_ps.c +5 -0
+                       allow = false;
+                       break;
+               } else if (sta->nexttbtt_tsf < nexttbtt_min) {
+                       nexttbtt_min = sta->nexttbtt_tsf;
+               }

ditto, why bother with else after break?

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 876

Quoted 2 lines
net/mac80211/mesh_ps.c +2 -0
+       if (nexttbtt_min != ULLONG_MAX)
+               *nexttbtt = nexttbtt_min;

The API of this function is very strange. Sometimes it might set it, sometimes it might leave it, but that's not even consistent with the "allow" return value ... It seems it'd be better to always set it.

Quoted 4 lines

+/**
+ * ieee80211_mps_doze - trigger radio doze state after checking conditions
+ *
+ * @local: local interface data

"interface"? hardly.

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 888

Quoted 3 lines
net/mac80211/mesh_ps.c +3 -0
+void ieee80211_mps_doze(struct ieee80211_local *local)
+{
+	u64 nexttbtt = 0;

and get rid of the assignment here.

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 905

Quoted 8 lines
net/mac80211/mesh_ps.c +8 -0
+
+void ieee80211_mps_init(struct ieee80211_hw *hw,
+			const struct ieee80211_mps_ops *ops)
+{
+	struct ieee80211_local *local = hw_to_local(hw);
+
+	if (!ops)
+		local->mps_enabled = false;

Allowing that seems pointless ... in fact, why is there this assignment function anyway? It seems these are pretty normal, if #ifdef MESH, driver callbacks?

johannes

#4 lore raw

PATCH v2 2/3 mac80211: mesh power save doze scheduling

Hi Johannes,

Quoted 15 lines · Johannes Berg
Quoted 13 lines · Marco Porsch
include/net/mac80211.h +13 -0
+/**
+ * ieee80211_mps_init - register callbacks for mesh powersave mode
+ *
+ * @hw: the hardware
+ * @ops: callbacks for this device
+ *
+ * called by driver on mesh interface add/remove
+ */
+#ifdef CONFIG_MAC80211_MESH
+void ieee80211_mps_init(struct ieee80211_hw *hw,
+			const struct ieee80211_mps_ops *ops);
+#else
+static inline void ieee80211_mps_init(struct ieee80211_hw *hw,
Quoted 8 lines

include/net/mac80211.h void ieee80211_stop_rx_ba_session(struct ieee80211_vif *vif, u16 ba_rx_bitmap, · line 4088

Quoted 3 lines
include/net/mac80211.h +3 -0
+				      const struct ieee80211_mps_ops *ops)
+{ return; }
+#endif

The "return" there is spurious. Is it really worth providing a static inline? It seems drivers might want to #ifdef it anyway so they don't have carry around the ops struct and the called functions if mesh isn't compiled in.

Ok, that seems reasonable. And that one function would be gone if I just use additional ieee80211_ops (see below).

Quoted 6 lines
Quoted 6 lines
net/mac80211/mesh_ps.c +6 -0
+static bool mps_doze_check_sta(struct ieee80211_local *local, u64 *nexttbtt)
+{
+       struct sta_info *sta;
+       bool allow = true;
+       u64 nexttbtt_min = ULLONG_MAX;
+
Quoted 8 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 861

Quoted 6 lines
net/mac80211/mesh_ps.c +6 -0
+       mutex_lock(&local->sta_mtx);
+       list_for_each_entry(sta, &local->sta_list, list) {
+               if (!ieee80211_vif_is_mesh(&sta->sdata->vif) ||
+                   !ieee80211_sdata_running(sta->sdata) ||
+                   sta->plink_state != NL80211_PLINK_ESTAB) {
+                       continue;

This is strange, why bother with the else if there's a continue?

I don't quite get this comment. The current logic is like this:

if (unrelated cases) {
	continue;
} else if (related and blocking) {
	allow = false;
	break;
} else if (related, non-blocking and new minimum) {
	min = sta->nexttbtt;
}
Quoted 8 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 866

Quoted 5 lines
net/mac80211/mesh_ps.c +5 -0
+               } else if (test_sta_flag(sta, WLAN_STA_MPS_WAIT_FOR_CAB) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_OWNER) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT) ||
+                          !timer_pending(&sta->nexttbtt_timer) ||
+                          time_after(jiffies, sta->nexttbtt_jiffies)) {

Are you sure jiffies are good enough? Some systems have HZ=33 or so I think, which makes a jiffy like 30ms.

Hm, jiffies is what I have available easily. Using the TSF would be obvious but may suffer from delay when obtaining it. Umm... hrtimers again?

Quoted 6 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 871

Quoted 5 lines
net/mac80211/mesh_ps.c +5 -0
+                       allow = false;
+                       break;
+               } else if (sta->nexttbtt_tsf < nexttbtt_min) {
+                       nexttbtt_min = sta->nexttbtt_tsf;
+               }
Quoted 8 lines

ditto, why bother with else after break?

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 876

Quoted 2 lines
net/mac80211/mesh_ps.c +2 -0
+       if (nexttbtt_min != ULLONG_MAX)
+               *nexttbtt = nexttbtt_min;

The API of this function is very strange. Sometimes it might set it, sometimes it might leave it, but that's not even consistent with the "allow" return value ... It seems it'd be better to always set it.

Alright. Will just have to make sure to hand out zero as invalid value, not ULLONG_MAX.

Quoted 6 lines
Quoted 4 lines

+/**
+ * ieee80211_mps_doze - trigger radio doze state after checking conditions
+ *
+ * @local: local interface data

"interface"? hardly.

* @local: mac80211 hw info struct

Quoted 6 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 888

Quoted 3 lines
net/mac80211/mesh_ps.c +3 -0
+void ieee80211_mps_doze(struct ieee80211_local *local)
+{
+	u64 nexttbtt = 0;

and get rid of the assignment here.

Quoted 12 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 905

Quoted 8 lines
net/mac80211/mesh_ps.c +8 -0
+
+void ieee80211_mps_init(struct ieee80211_hw *hw,
+			const struct ieee80211_mps_ops *ops)
+{
+	struct ieee80211_local *local = hw_to_local(hw);
+
+	if (!ops)
+		local->mps_enabled = false;

Allowing that seems pointless ... in fact, why is there this assignment function anyway? It seems these are pretty normal, if #ifdef MESH, driver callbacks?

So may I just add them to the ieee80211_ops under #ifdef? That would certainly make things easier. I would add a HW capability flag for MPS doze as well.

--Marco

maintainer
#5 lore raw

PATCH v2 2/3 mac80211: mesh power save doze scheduling

Quoted 4 lines · Marco Porsch
Quoted 1 line

This is strange, why bother with the else if there's a continue?

I don't quite get this comment. The current logic is like this:

Quoted 8 lines
if (unrelated cases) {
	continue;
} else if (related and blocking) {
	allow = false;
	break;
} else if (related, non-blocking and new minimum) {
	min = sta->nexttbtt;
}

Yeah I guess I don't see why it's not just

        if (unrelated cases)
        	continue;
        
        if (related & blocking) {
        	allow = false;
        	break;
        }
        
        if (...)
        	min = ...

but it really doesn't matter much.

Quoted 11 lines
Quoted 8 lines

net/mac80211/mesh_ps.c void ieee80211_mps_frame_release(struct sta_info *sta, · line 866

Quoted 5 lines
net/mac80211/mesh_ps.c +5 -0
+               } else if (test_sta_flag(sta, WLAN_STA_MPS_WAIT_FOR_CAB) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_OWNER) ||
+                          test_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT) ||
+                          !timer_pending(&sta->nexttbtt_timer) ||
+                          time_after(jiffies, sta->nexttbtt_jiffies)) {

Are you sure jiffies are good enough? Some systems have HZ=33 or so I think, which makes a jiffy like 30ms.

Hm, jiffies is what I have available easily. Using the TSF would be obvious but may suffer from delay when obtaining it. Umm... hrtimers again?

I really don't care about your messed up timing stuff here, just saying :)

johannes

#6 lore raw

PATCH v2 3/3 ath9k: mesh powersave support

In reply to Marco Porsch

Register mesh PS ops on interface add and de-register on removal.

React to doze/wakeup calls issued by mac80211. Add a PS status flag PS_MAC80211_CTL to store last mesh PS command from mac80211.

Initialize HW beacon wakeup registers.
On doze call configure the HW to wakeup on the given TSF value.

---
 drivers/net/wireless/ath/ath9k/ath9k.h  |    1 +
 drivers/net/wireless/ath/ath9k/beacon.c |   21 ++++++++++-
 drivers/net/wireless/ath/ath9k/hw.c     |   17 +++++++--
 drivers/net/wireless/ath/ath9k/main.c   |   63 ++++++++++++++++++++++++++++++-
 4 files changed, 95 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath9k/ath9k.h +1 -0
index 97c90b2..b82727b 100644
@@ -652,6 +652,7 @@ enum sc_op_flags {
 #define PS_WAIT_FOR_TX_ACK        BIT(3)
 #define PS_BEACON_SYNC            BIT(4)
 #define PS_WAIT_FOR_ANI           BIT(5)
+#define PS_MAC80211_CTL           BIT(6)
 
 struct ath_rate_table;
 
drivers/net/wireless/ath/ath9k/beacon.c +20 -1
index dd37719..7ef698b 100644
@@ -599,6 +599,23 @@ static void ath9k_beacon_config_adhoc(struct ath_softc *sc,
 	ath9k_beacon_init(sc, nexttbtt, intval);
 }
 
+static void ath9k_beacon_config_mesh(struct ath_softc *sc,
+				     struct ath_beacon_config *conf)
+{
+	struct ath9k_beacon_state bs;
+
+	/*
+	 * when PS is enabled, ath9k_hw_setrxabort is set.
+	 * to wake up again to receive peers' beacons, we set an
+	 * arbitrary initial value for sleepduration here
+	 */
+	memset(&bs, 0, sizeof(bs));
+	bs.bs_sleepduration = IEEE80211_MS_TO_TU(100);
+	ath9k_hw_set_sta_beacon_timers(sc->sc_ah, &bs);
+
+	ath9k_beacon_config_adhoc(sc, conf);
+}
+
 bool ath9k_allow_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
 {
 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
@@ -707,9 +724,11 @@ void ath9k_set_beacon(struct ath_softc *sc)
 		ath9k_beacon_config_ap(sc, cur_conf);
 		break;
 	case NL80211_IFTYPE_ADHOC:
-	case NL80211_IFTYPE_MESH_POINT:
 		ath9k_beacon_config_adhoc(sc, cur_conf);
 		break;
+	case NL80211_IFTYPE_MESH_POINT:
+		ath9k_beacon_config_mesh(sc, cur_conf);
+		break;
 	case NL80211_IFTYPE_STATION:
 		ath9k_beacon_config_sta(sc, cur_conf);
 		break;
drivers/net/wireless/ath/ath9k/hw.c +13 -4
index 42cf3c7..0e0fe03 100644
@@ -2254,16 +2254,24 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
 }
 EXPORT_SYMBOL(ath9k_hw_beaconinit);
 
+/**
+ * ath9k_hw_set_sta_beacon_timers
+ *
+ * in mesh mode overwriting AR_NEXT_TBTT_TIMER and setting AR_TBTT_TIMER_EN
+ * would shift the own TBTT
+ */
 void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
 				    const struct ath9k_beacon_state *bs)
 {
 	u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
+	u32 ar_timer_mode = AR_DTIM_TIMER_EN | AR_TIM_TIMER_EN;
 	struct ath9k_hw_capabilities *pCap = &ah->caps;
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	ENABLE_REGWRITE_BUFFER(ah);
 
-	REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
+	if (ah->opmode != NL80211_IFTYPE_MESH_POINT)
+		REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
 
 	REG_WRITE(ah, AR_BEACON_PERIOD,
 		  TU_TO_USEC(bs->bs_intval));
@@ -2317,9 +2325,10 @@ void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
 
 	REGWRITE_BUFFER_FLUSH(ah);
 
-	REG_SET_BIT(ah, AR_TIMER_MODE,
-		    AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
-		    AR_DTIM_TIMER_EN);
+	if (ah->opmode != NL80211_IFTYPE_MESH_POINT)
+		ar_timer_mode |= AR_TBTT_TIMER_EN;
+
+	REG_SET_BIT(ah, AR_TIMER_MODE, ar_timer_mode);
 
 	/* TSF Out of Range Threshold */
 	REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
drivers/net/wireless/ath/ath9k/main.c +61 -2

87 lines not on this page · raw message

Signature · 1 line
1.7.9.5
maintainer
#7 lore raw

PATCH v2 1/3 mac80211: move mesh sync beacon handler into neighbour_update

In reply to Marco Porsch

net/mac80211/mesh_plink.c mesh_sta_info_get(struct ieee80211_sub_if_data *sdata, · line 521

Quoted 11 lines · Marco Porsch
net/mac80211/mesh_plink.c +11 -0
+	/*
+	 * If available, calculate the time the beacon timestamp field was
+	 * received from the rx_status->mactime field. Otherwise get the
+	 * current TSF as approximation before entering rcu-read section.
+	 */
+	if (ieee80211_have_rx_timestamp(rx_status))
+		t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
+						       24 + 12 +
+						       elems->total_len +
+						       FCS_LEN,
+						       24);

That doesn't seem right -- it's calculating the timestamp at the end of the frame, but you said you wanted the timestamp at the "timestamp field" time, which is just 24 bytes into the frame.

Quoted 8 lines
net/mac80211/mesh_sync.c +5 -1
+static void mesh_sync_offset_rx_bcn(struct sta_info *sta,
+				    struct ieee80211_mgmt *mgmt,
+				    struct ieee802_11_elems *elems,
+				    u64 t_r)
 {
+	struct ieee80211_sub_if_data *sdata = sta->sdata;
 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
-	struct ieee80211_local *local = sdata->local;

net/mac80211/mesh_sync.c void mesh_sync_adjust_tbtt(struct ieee80211_sub_if_data *sdata) · line 91

Quoted 10 lines
net/mac80211/mesh_sync.c +2 -3
-	struct sta_info *sta;
-	u64 t_t, t_r;
+	u64 t_t;
 
 	WARN_ON(ifmsh->mesh_sp_id != IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET);
 
 	/* standard mentions only beacons */
-	if (stype != IEEE80211_STYPE_BEACON)
+	if (!ieee80211_is_beacon(mgmt->frame_control))
 		return;

This is a bit odd -- why should a function that's called _rx_bcn() have to check it? Seems the check should be outside the API boundary.

net/mac80211/mesh_sync.c static void mesh_sync_offset_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, · line 126

Quoted 7 lines
net/mac80211/mesh_sync.c +0 -7
-	if (ieee80211_have_rx_timestamp(rx_status))
-		/* time when timestamp field was received */
-		t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
-						       24 + 12 +
-						       elems->total_len +
-						       FCS_LEN,
-						       24);

I see this was already wrong ...

johannes

#8 lore raw

PATCH v2 1/3 mac80211: move mesh sync beacon handler into neighbour_update

Quoted 17 lines · Johannes Berg

net/mac80211/mesh_plink.c mesh_sta_info_get(struct ieee80211_sub_if_data *sdata, · line 521

Quoted 11 lines · Marco Porsch
net/mac80211/mesh_plink.c +11 -0
+     /*
+      * If available, calculate the time the beacon timestamp field was
+      * received from the rx_status->mactime field. Otherwise get the
+      * current TSF as approximation before entering rcu-read section.
+      */
+     if (ieee80211_have_rx_timestamp(rx_status))
+             t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
+                                                    24 + 12 +
+                                                    elems->total_len +
+                                                    FCS_LEN,
+                                                    24);

That doesn't seem right -- it's calculating the timestamp at the end of the frame, but you said you wanted the timestamp at the "timestamp field" time, which is just 24 bytes into the frame.

[...]

Quoted 9 lines

net/mac80211/mesh_sync.c static void mesh_sync_offset_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, · line 126

Quoted 7 lines
net/mac80211/mesh_sync.c +0 -7
-     if (ieee80211_have_rx_timestamp(rx_status))
-             /* time when timestamp field was received */
-             t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
-                                                    24 + 12 +
-                                                    elems->total_len +
-                                                    FCS_LEN,
-                                                    24);

I see this was already wrong ...

No it's OK. The API is actually ieee80211_calculate_rx_timestamp(local, status, len, offset).

Signature · 1 line
Thomas
maintainer
#9 lore raw

PATCH v2 1/3 mac80211: move mesh sync beacon handler into neighbour_update

Quoted 30 lines · Thomas Pedersen
Quoted 17 lines · Johannes Berg

net/mac80211/mesh_plink.c mesh_sta_info_get(struct ieee80211_sub_if_data *sdata, · line 521

Quoted 11 lines · Marco Porsch
net/mac80211/mesh_plink.c +11 -0
+     /*
+      * If available, calculate the time the beacon timestamp field was
+      * received from the rx_status->mactime field. Otherwise get the
+      * current TSF as approximation before entering rcu-read section.
+      */
+     if (ieee80211_have_rx_timestamp(rx_status))
+             t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
+                                                    24 + 12 +
+                                                    elems->total_len +
+                                                    FCS_LEN,
+                                                    24);

That doesn't seem right -- it's calculating the timestamp at the end of the frame, but you said you wanted the timestamp at the "timestamp field" time, which is just 24 bytes into the frame.

[...]

Quoted 8 lines
Quoted 7 lines
net/mac80211/mesh_sync.c +0 -7
-     if (ieee80211_have_rx_timestamp(rx_status))
-             /* time when timestamp field was received */
-             t_r = ieee80211_calculate_rx_timestamp(local, rx_status,
-                                                    24 + 12 +
-                                                    elems->total_len +
-                                                    FCS_LEN,
-                                                    24);
Quoted 4 lines
Quoted 1 line

I see this was already wrong ...

No it's OK. The API is actually ieee80211_calculate_rx_timestamp(local, status, len, offset).

Oops, indeed, my mistake.

johannes