Skip to contentSkip to conversation

ath9k_htc: avoid scheduling while atomic on sta_rc_update

ath9k-devel Stanislaw Gruszka 2 participants 5 messages Jan 31, 2014 – Feb 3, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

mac80211 ->sta_rc_update() callback must be atomic. Since we have to take mutex and do other operations that can sleep when sending fimrware commands to device, the only option to satisfy atomicity requirement of ->sta_rc_update(), that I can see, is introduce work_struct and defer uploading new rates to that work.

I don't have h/w to test this patch. Since sta_rc_update() calls are very unlikely, those who would like to test that patch should remove my previous patch "ath9k_htc: make ->sta_rc_update atomic for most calls" and possibly even modify mac80211 to call sta_rc_update(), without actual reason, just to test changed ath9k_htc code.

Thanks
Stanislaw

---
 drivers/net/wireless/ath/ath9k/htc.h          |  2 +
 drivers/net/wireless/ath/ath9k/htc_drv_main.c | 60 +++++++++++++++++----------
 2 files changed, 40 insertions(+), 22 deletions(-)
drivers/net/wireless/ath/ath9k/htc.h +2 -0
index 58da346..99a2031 100644
@@ -262,6 +262,8 @@ enum tid_aggr_state {
 struct ath9k_htc_sta {
 	u8 index;
 	enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
+	struct work_struct rc_update_work;
+	struct ath9k_htc_priv *htc_priv;
 };
 
 #define ATH9K_HTC_RXBUF 256
drivers/net/wireless/ath/ath9k/htc_drv_main.c +38 -22

97 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#1 lore raw

I have different HW. How can trigger sta_rc_update?

Am 31.01.2014 14:37, schrieb Stanislaw Gruszka:

Quoted 137 lines

mac80211 ->sta_rc_update() callback must be atomic. Since we have to take mutex and do other operations that can sleep when sending fimrware commands to device, the only option to satisfy atomicity requirement of ->sta_rc_update(), that I can see, is introduce work_struct and defer uploading new rates to that work.

I don't have h/w to test this patch. Since sta_rc_update() calls are very unlikely, those who would like to test that patch should remove my previous patch "ath9k_htc: make ->sta_rc_update atomic for most calls" and possibly even modify mac80211 to call sta_rc_update(), without actual reason, just to test changed ath9k_htc code.

Thanks
Stanislaw

---
 drivers/net/wireless/ath/ath9k/htc.h          |  2 +
 drivers/net/wireless/ath/ath9k/htc_drv_main.c | 60 +++++++++++++++++----------
 2 files changed, 40 insertions(+), 22 deletions(-)
drivers/net/wireless/ath/ath9k/htc.h +2 -0
index 58da346..99a2031 100644
@@ -262,6 +262,8 @@ enum tid_aggr_state {
 struct ath9k_htc_sta {
 	u8 index;
 	enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
+	struct work_struct rc_update_work;
+	struct ath9k_htc_priv *htc_priv;
 };
 
 #define ATH9K_HTC_RXBUF 256
drivers/net/wireless/ath/ath9k/htc_drv_main.c +38 -22
index a57af9b..c9254a6 100644
@@ -1270,18 +1270,50 @@ static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
 	mutex_unlock(&priv->mutex);
 }
 
+static void ath9k_htc_sta_rc_update_work(struct work_struct *work)
+{
+	struct ath9k_htc_sta *ista =
+	    container_of(work, struct ath9k_htc_sta, rc_update_work);
+	struct ieee80211_sta *sta =
+	    container_of((void *)ista, struct ieee80211_sta, drv_priv);
+	struct ath9k_htc_priv *priv = ista->htc_priv;
+	struct ath_common *common = ath9k_hw_common(priv->ah);
+	struct ath9k_htc_target_rate trate;
+
+	mutex_lock(&priv->mutex);
+	ath9k_htc_ps_wakeup(priv);
+
+	memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
+	ath9k_htc_setup_rate(priv, sta, &trate);
+	if (!ath9k_htc_send_rate_cmd(priv, &trate))
+		ath_dbg(common, CONFIG,
+			"Supported rates for sta: %pM updated, rate caps: 0x%X\n",
+			sta->addr, be32_to_cpu(trate.capflags));
+	else
+		ath_dbg(common, CONFIG,
+			"Unable to update supported rates for sta: %pM\n",
+			sta->addr);
+
+	ath9k_htc_ps_restore(priv);
+	mutex_unlock(&priv->mutex);
+}
+
 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
 			     struct ieee80211_vif *vif,
 			     struct ieee80211_sta *sta)
 {
 	struct ath9k_htc_priv *priv = hw->priv;
+	struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
 	int ret;
 
 	mutex_lock(&priv->mutex);
 	ath9k_htc_ps_wakeup(priv);
 	ret = ath9k_htc_add_station(priv, vif, sta);
-	if (!ret)
+	if (!ret) {
+		INIT_WORK(&ista->rc_update_work, ath9k_htc_sta_rc_update_work);
+		ista->htc_priv = priv;
 		ath9k_htc_init_rate(priv, sta);
+	}
 	ath9k_htc_ps_restore(priv);
 	mutex_unlock(&priv->mutex);
 
@@ -1293,12 +1325,13 @@ static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
 				struct ieee80211_sta *sta)
 {
 	struct ath9k_htc_priv *priv = hw->priv;
-	struct ath9k_htc_sta *ista;
+	struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
 	int ret;
 
+	cancel_work_sync(&ista->rc_update_work);
+
 	mutex_lock(&priv->mutex);
 	ath9k_htc_ps_wakeup(priv);
-	ista = (struct ath9k_htc_sta *) sta->drv_priv;
 	htc_sta_drain(priv->htc, ista->index);
 	ret = ath9k_htc_remove_station(priv, vif, sta);
 	ath9k_htc_ps_restore(priv);
@@ -1311,29 +1344,12 @@ static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
 				    struct ieee80211_vif *vif,
 				    struct ieee80211_sta *sta, u32 changed)
 {
-	struct ath9k_htc_priv *priv = hw->priv;
-	struct ath_common *common = ath9k_hw_common(priv->ah);
-	struct ath9k_htc_target_rate trate;
+	struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
 
 	if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
 		return;
 
-	mutex_lock(&priv->mutex);
-	ath9k_htc_ps_wakeup(priv);
-
-	memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
-	ath9k_htc_setup_rate(priv, sta, &trate);
-	if (!ath9k_htc_send_rate_cmd(priv, &trate))
-		ath_dbg(common, CONFIG,
-			"Supported rates for sta: %pM updated, rate caps: 0x%X\n",
-			sta->addr, be32_to_cpu(trate.capflags));
-	else
-		ath_dbg(common, CONFIG,
-			"Unable to update supported rates for sta: %pM\n",
-			sta->addr);
-
-	ath9k_htc_ps_restore(priv);
-	mutex_unlock(&priv->mutex);
+	schedule_work(&ista->rc_update_work);
 }
 
 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
Signature · 10 lines
Regards,
Oleksij

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 278 bytes
Desc: OpenPGP digital signature
Url : http://lists.ath9k.org/pipermail/ath9k-devel/attachments/20140131/2bdc2372/attachment.pgp 
#2 lore raw
Quoted 1 line · Oleksij Rempel

I have different HW. How can trigger sta_rc_update?

Below patch should trigger it when any management frame is received from know sta and print information about it.

Thanks
Stanislaw

drivers/net/wireless/ath/ath9k/htc_drv_main.c +1 -3
index c9254a6..5cfc98c 100644
@@ -1346,9 +1346,7 @@ static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
 {
 	struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
 
-	if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
-		return;
-
+	printk("%s: schedule work\n", __func__);
 	schedule_work(&ista->rc_update_work);
 }
 
net/mac80211/rx.c +3 -1
index c24ca0d..642b326 100644
@@ -2847,8 +2847,10 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
 	rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
 	skb_queue_tail(&sdata->skb_queue, rx->skb);
 	ieee80211_queue_work(&rx->local->hw, &sdata->work);
-	if (rx->sta)
+	if (rx->sta) {
 		rx->sta->rx_packets++;
+		drv_sta_rc_update(rx->local, rx->sta->sdata, &rx->sta->sta, 0);
+	}
 
 	return RX_QUEUED;
 }
#3 lore raw

Am 31.01.2014 20:38, schrieb Stanislaw Gruszka:

Quoted 5 lines · Oleksij Rempel
Quoted 1 line

I have different HW. How can trigger sta_rc_update?

Below patch should trigger it when any management frame is received from know sta and print information about it.

It seems to work,
a least it didn't crashed. I was able to trigger it only in IBSS mode.

Signature · 10 lines
Regards,
Oleksij

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 278 bytes
Desc: OpenPGP digital signature
Url : http://lists.ath9k.org/pipermail/ath9k-devel/attachments/20140202/6865ec30/attachment.pgp 
#4 lore raw
Quoted 9 lines · Oleksij Rempel

Am 31.01.2014 20:38, schrieb Stanislaw Gruszka:

Quoted 5 lines · Oleksij Rempel
Quoted 1 line

I have different HW. How can trigger sta_rc_update?

Below patch should trigger it when any management frame is received from know sta and print information about it.

It seems to work,
a least it didn't crashed. I was able to trigger it only in IBSS mode.

Looks ieee80211_rx_h_mgmt with know STA is not used for Managed mode as frequent as I thought.

Thanks for testing! I'll post the patch shortly.
Stanislaw