Commit cfcdbde3 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville

mac80211: change TX aggregation locking

To prepare for allowing drivers to sleep in
ampdu_action, change the locking in the TX
aggregation code to use the mutex the RX part
already uses. The spinlock is still necessary
around some code to avoid races with TX, but
now we can also synchronize_net() to avoid
getting an inconsistent sequence number.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 83a5cbf7
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright 2005-2006, Devicescape Software, Inc. * Copyright 2005-2006, Devicescape Software, Inc.
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
* Copyright 2007, Michael Wu <flamingice@sourmilk.net> * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
* Copyright 2007-2009, Intel Corporation * Copyright 2007-2010, Intel Corporation
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -140,18 +140,23 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, ...@@ -140,18 +140,23 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
struct tid_ampdu_tx *tid_tx = sta->ampdu_mlme.tid_tx[tid]; struct tid_ampdu_tx *tid_tx = sta->ampdu_mlme.tid_tx[tid];
int ret; int ret;
lockdep_assert_held(&sta->lock); lockdep_assert_held(&sta->ampdu_mlme.mtx);
if (WARN_ON(!tid_tx)) if (!tid_tx)
return -ENOENT; return -ENOENT;
spin_lock_bh(&sta->lock);
if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
/* not even started yet! */ /* not even started yet! */
rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL); rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
spin_unlock_bh(&sta->lock);
call_rcu(&tid_tx->rcu_head, kfree_tid_tx); call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
return 0; return 0;
} }
spin_unlock_bh(&sta->lock);
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n", printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
sta->sta.addr, tid); sta->sta.addr, tid);
...@@ -269,6 +274,8 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid) ...@@ -269,6 +274,8 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
u16 start_seq_num; u16 start_seq_num;
int ret; int ret;
lockdep_assert_held(&sta->ampdu_mlme.mtx);
/* /*
* While we're asking the driver about the aggregation, * While we're asking the driver about the aggregation,
* stop the AC queue so that we don't have to worry * stop the AC queue so that we don't have to worry
...@@ -281,10 +288,11 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid) ...@@ -281,10 +288,11 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state); clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
/* /*
* This might be off by one due to a race that we can't * make sure no packets are being processed to get
* really prevent here without synchronize_net() which * valid starting sequence number
* can't be called now.
*/ */
synchronize_net();
start_seq_num = sta->tid_seq[tid] >> 4; start_seq_num = sta->tid_seq[tid] >> 4;
ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START, ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
...@@ -294,7 +302,10 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid) ...@@ -294,7 +302,10 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
printk(KERN_DEBUG "BA request denied - HW unavailable for" printk(KERN_DEBUG "BA request denied - HW unavailable for"
" tid %d\n", tid); " tid %d\n", tid);
#endif #endif
spin_lock_bh(&sta->lock);
rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL); rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
spin_unlock_bh(&sta->lock);
ieee80211_wake_queue_agg(local, tid); ieee80211_wake_queue_agg(local, tid);
call_rcu(&tid_tx->rcu_head, kfree_tid_tx); call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
return; return;
...@@ -309,7 +320,9 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid) ...@@ -309,7 +320,9 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
#endif #endif
spin_lock_bh(&sta->lock);
sta->ampdu_mlme.addba_req_num[tid]++; sta->ampdu_mlme.addba_req_num[tid]++;
spin_unlock_bh(&sta->lock);
/* send AddBA request */ /* send AddBA request */
ieee80211_send_addba_request(sdata, sta->sta.addr, tid, ieee80211_send_addba_request(sdata, sta->sta.addr, tid,
...@@ -445,16 +458,25 @@ ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid) ...@@ -445,16 +458,25 @@ ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
ieee80211_wake_queue_agg(local, tid); ieee80211_wake_queue_agg(local, tid);
} }
/* caller must hold sta->lock */
static void ieee80211_agg_tx_operational(struct ieee80211_local *local, static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
struct sta_info *sta, u16 tid) struct sta_info *sta, u16 tid)
{ {
lockdep_assert_held(&sta->lock); lockdep_assert_held(&sta->ampdu_mlme.mtx);
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid); printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
#endif #endif
drv_ampdu_action(local, sta->sdata,
IEEE80211_AMPDU_TX_OPERATIONAL,
&sta->sta, tid, NULL);
/*
* synchronize with TX path, while splicing the TX path
* should block so it won't put more packets onto pending.
*/
spin_lock_bh(&sta->lock);
ieee80211_agg_splice_packets(local, sta->ampdu_mlme.tid_tx[tid], tid); ieee80211_agg_splice_packets(local, sta->ampdu_mlme.tid_tx[tid], tid);
/* /*
* Now mark as operational. This will be visible * Now mark as operational. This will be visible
...@@ -464,9 +486,7 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local, ...@@ -464,9 +486,7 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
set_bit(HT_AGG_STATE_OPERATIONAL, &sta->ampdu_mlme.tid_tx[tid]->state); set_bit(HT_AGG_STATE_OPERATIONAL, &sta->ampdu_mlme.tid_tx[tid]->state);
ieee80211_agg_splice_finish(local, tid); ieee80211_agg_splice_finish(local, tid);
drv_ampdu_action(local, sta->sdata, spin_unlock_bh(&sta->lock);
IEEE80211_AMPDU_TX_OPERATIONAL,
&sta->sta, tid, NULL);
} }
void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid) void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
...@@ -486,37 +506,35 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid) ...@@ -486,37 +506,35 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
return; return;
} }
rcu_read_lock(); mutex_lock(&local->sta_mtx);
sta = sta_info_get(sdata, ra); sta = sta_info_get(sdata, ra);
if (!sta) { if (!sta) {
rcu_read_unlock(); mutex_unlock(&local->sta_mtx);
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "Could not find station: %pM\n", ra); printk(KERN_DEBUG "Could not find station: %pM\n", ra);
#endif #endif
return; return;
} }
spin_lock_bh(&sta->lock); mutex_lock(&sta->ampdu_mlme.mtx);
tid_tx = sta->ampdu_mlme.tid_tx[tid]; tid_tx = sta->ampdu_mlme.tid_tx[tid];
if (WARN_ON(!tid_tx)) { if (WARN_ON(!tid_tx)) {
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "addBA was not requested!\n"); printk(KERN_DEBUG "addBA was not requested!\n");
#endif #endif
spin_unlock_bh(&sta->lock); goto unlock;
rcu_read_unlock();
return;
} }
if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))) if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
goto out; goto unlock;
if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
ieee80211_agg_tx_operational(local, sta, tid); ieee80211_agg_tx_operational(local, sta, tid);
out: unlock:
spin_unlock_bh(&sta->lock); mutex_unlock(&sta->ampdu_mlme.mtx);
rcu_read_unlock(); mutex_unlock(&local->sta_mtx);
} }
void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif, void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
...@@ -548,21 +566,14 @@ EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); ...@@ -548,21 +566,14 @@ EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
enum ieee80211_back_parties initiator) enum ieee80211_back_parties initiator)
{ {
struct tid_ampdu_tx *tid_tx;
int ret; int ret;
spin_lock_bh(&sta->lock); mutex_lock(&sta->ampdu_mlme.mtx);
tid_tx = sta->ampdu_mlme.tid_tx[tid];
if (!tid_tx) {
ret = -ENOENT;
goto unlock;
}
ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator); ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
unlock: mutex_unlock(&sta->ampdu_mlme.mtx);
spin_unlock_bh(&sta->lock);
return ret; return ret;
} }
...@@ -627,16 +638,17 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid) ...@@ -627,16 +638,17 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
ra, tid); ra, tid);
#endif /* CONFIG_MAC80211_HT_DEBUG */ #endif /* CONFIG_MAC80211_HT_DEBUG */
rcu_read_lock(); mutex_lock(&local->sta_mtx);
sta = sta_info_get(sdata, ra); sta = sta_info_get(sdata, ra);
if (!sta) { if (!sta) {
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "Could not find station: %pM\n", ra); printk(KERN_DEBUG "Could not find station: %pM\n", ra);
#endif #endif
rcu_read_unlock(); goto unlock;
return;
} }
mutex_lock(&sta->ampdu_mlme.mtx);
spin_lock_bh(&sta->lock); spin_lock_bh(&sta->lock);
tid_tx = sta->ampdu_mlme.tid_tx[tid]; tid_tx = sta->ampdu_mlme.tid_tx[tid];
...@@ -644,9 +656,7 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid) ...@@ -644,9 +656,7 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
#endif #endif
spin_unlock_bh(&sta->lock); goto unlock_sta;
rcu_read_unlock();
return;
} }
if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR) if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR)
...@@ -672,8 +682,11 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid) ...@@ -672,8 +682,11 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
call_rcu(&tid_tx->rcu_head, kfree_tid_tx); call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
unlock_sta:
spin_unlock_bh(&sta->lock); spin_unlock_bh(&sta->lock);
rcu_read_unlock(); mutex_unlock(&sta->ampdu_mlme.mtx);
unlock:
mutex_unlock(&local->sta_mtx);
} }
void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif, void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
...@@ -714,10 +727,9 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local, ...@@ -714,10 +727,9 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
spin_lock_bh(&sta->lock); mutex_lock(&sta->ampdu_mlme.mtx);
tid_tx = sta->ampdu_mlme.tid_tx[tid]; tid_tx = sta->ampdu_mlme.tid_tx[tid];
if (!tid_tx) if (!tid_tx)
goto out; goto out;
...@@ -751,5 +763,5 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local, ...@@ -751,5 +763,5 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
} }
out: out:
spin_unlock_bh(&sta->lock); mutex_unlock(&sta->ampdu_mlme.mtx);
} }
...@@ -349,6 +349,9 @@ static inline int drv_ampdu_action(struct ieee80211_local *local, ...@@ -349,6 +349,9 @@ static inline int drv_ampdu_action(struct ieee80211_local *local,
u16 *ssn) u16 *ssn)
{ {
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
might_sleep();
local_bh_disable(); local_bh_disable();
if (local->ops->ampdu_action) if (local->ops->ampdu_action)
ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action, ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright 2005-2006, Devicescape Software, Inc. * Copyright 2005-2006, Devicescape Software, Inc.
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
* Copyright 2007, Michael Wu <flamingice@sourmilk.net> * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
* Copyright 2007-2008, Intel Corporation * Copyright 2007-2010, Intel Corporation
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -136,11 +136,7 @@ void ieee80211_ba_session_work(struct work_struct *work) ...@@ -136,11 +136,7 @@ void ieee80211_ba_session_work(struct work_struct *work)
___ieee80211_stop_rx_ba_session( ___ieee80211_stop_rx_ba_session(
sta, tid, WLAN_BACK_RECIPIENT, sta, tid, WLAN_BACK_RECIPIENT,
WLAN_REASON_QSTA_TIMEOUT); WLAN_REASON_QSTA_TIMEOUT);
}
mutex_unlock(&sta->ampdu_mlme.mtx);
spin_lock_bh(&sta->lock);
for (tid = 0; tid < STA_TID_NUM; tid++) {
tid_tx = sta->ampdu_mlme.tid_tx[tid]; tid_tx = sta->ampdu_mlme.tid_tx[tid];
if (!tid_tx) if (!tid_tx)
continue; continue;
...@@ -152,7 +148,7 @@ void ieee80211_ba_session_work(struct work_struct *work) ...@@ -152,7 +148,7 @@ void ieee80211_ba_session_work(struct work_struct *work)
___ieee80211_stop_tx_ba_session(sta, tid, ___ieee80211_stop_tx_ba_session(sta, tid,
WLAN_BACK_INITIATOR); WLAN_BACK_INITIATOR);
} }
spin_unlock_bh(&sta->lock); mutex_unlock(&sta->ampdu_mlme.mtx);
} }
void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment