5f858000c313049a90b738f24e71e2e26066597d
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 300-mac80211-add-stop-start-logic-for-software-TXQs.patch
1 From: Manikanta Pubbisetty <mpubbise@codeaurora.org>
2 Date: Wed, 11 Jul 2018 00:12:53 +0530
3 Subject: [PATCH] mac80211: add stop/start logic for software TXQs
4
5 Sometimes, it is required to stop the transmissions momentarily and
6 resume it later; stopping the txqs becomes very critical in scenarios where
7 the packet transmission has to be ceased completely. For example, during
8 the hardware restart, during off channel operations,
9 when initiating CSA(upon detecting a radar on the DFS channel), etc.
10
11 The TX queue stop/start logic in mac80211 works well in stopping the TX
12 when drivers make use of netdev queues, i.e, when Qdiscs in network layer
13 take care of traffic scheduling. Since the devices implementing
14 wake_tx_queue can run without Qdiscs, packets will be handed to mac80211
15 directly without queueing them in the netdev queues.
16
17 Also, mac80211 does not invoke any of the
18 netif_stop_*/netif_wake_* APIs if wake_tx_queue is implemented.
19 Since the queues are not stopped in this case, transmissions can continue
20 and this will impact negatively on the operation of the wireless device.
21
22 For example,
23 During hardware restart, we stop the netdev queues so that packets are
24 not sent to the driver. Since ath10k implements wake_tx_queue,
25 TX queues will not be stopped and packets might reach the hardware while
26 it is restarting; this can make hardware unresponsive and the only
27 possible option for recovery is to reboot the entire system.
28
29 There is another problem to this, it is observed that the packets
30 were sent on the DFS channel for a prolonged duration after radar
31 detection impacting the channel closing time.
32
33 We can still invoke netif stop/wake APIs when wake_tx_queue is implemented
34 but this could lead to packet drops in network layer; adding stop/start
35 logic for software TXQs in mac80211 instead makes more sense; the change
36 proposed adds the same in mac80211.
37
38 Signed-off-by: Manikanta Pubbisetty <mpubbise@codeaurora.org>
39 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
40 ---
41
42 --- a/include/net/mac80211.h
43 +++ b/include/net/mac80211.h
44 @@ -1504,6 +1504,8 @@ enum ieee80211_vif_flags {
45 * @drv_priv: data area for driver use, will always be aligned to
46 * sizeof(void \*).
47 * @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
48 + * @txqs_stopped: per AC flag to indicate that intermediate TXQs are stopped,
49 + * protected by fq->lock.
50 */
51 struct ieee80211_vif {
52 enum nl80211_iftype type;
53 @@ -1528,6 +1530,8 @@ struct ieee80211_vif {
54
55 unsigned int probe_req_reg;
56
57 + bool txqs_stopped[IEEE80211_NUM_ACS];
58 +
59 /* must be last */
60 u8 drv_priv[0] __aligned(sizeof(void *));
61 };
62 --- a/net/mac80211/ieee80211_i.h
63 +++ b/net/mac80211/ieee80211_i.h
64 @@ -818,6 +818,7 @@ enum txq_info_flags {
65 IEEE80211_TXQ_STOP,
66 IEEE80211_TXQ_AMPDU,
67 IEEE80211_TXQ_NO_AMSDU,
68 + IEEE80211_TXQ_STOP_NETIF_TX,
69 };
70
71 /**
72 @@ -1226,6 +1227,7 @@ struct ieee80211_local {
73
74 struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
75 struct tasklet_struct tx_pending_tasklet;
76 + struct tasklet_struct wake_txqs_tasklet;
77
78 atomic_t agg_queue_stop[IEEE80211_MAX_QUEUES];
79
80 @@ -2047,6 +2049,7 @@ void ieee80211_txq_remove_vlan(struct ie
81 struct ieee80211_sub_if_data *sdata);
82 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
83 struct txq_info *txqi);
84 +void ieee80211_wake_txqs(unsigned long data);
85 void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
86 u16 transaction, u16 auth_alg, u16 status,
87 const u8 *extra, size_t extra_len, const u8 *bssid,
88 --- a/net/mac80211/main.c
89 +++ b/net/mac80211/main.c
90 @@ -686,6 +686,10 @@ struct ieee80211_hw *ieee80211_alloc_hw_
91 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
92 (unsigned long)local);
93
94 + if (ops->wake_tx_queue)
95 + tasklet_init(&local->wake_txqs_tasklet, ieee80211_wake_txqs,
96 + (unsigned long)local);
97 +
98 tasklet_init(&local->tasklet,
99 ieee80211_tasklet_handler,
100 (unsigned long) local);
101 --- a/net/mac80211/tx.c
102 +++ b/net/mac80211/tx.c
103 @@ -3498,13 +3498,19 @@ struct sk_buff *ieee80211_tx_dequeue(str
104 struct ieee80211_tx_info *info;
105 struct ieee80211_tx_data tx;
106 ieee80211_tx_result r;
107 - struct ieee80211_vif *vif;
108 + struct ieee80211_vif *vif = txq->vif;
109
110 spin_lock_bh(&fq->lock);
111
112 - if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
113 + if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ||
114 + test_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags))
115 goto out;
116
117 + if (vif->txqs_stopped[ieee80211_ac_from_tid(txq->tid)]) {
118 + set_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags);
119 + goto out;
120 + }
121 +
122 /* Make sure fragments stay together. */
123 skb = __skb_dequeue(&txqi->frags);
124 if (skb)
125 @@ -3617,6 +3623,7 @@ begin:
126 }
127
128 IEEE80211_SKB_CB(skb)->control.vif = vif;
129 +
130 out:
131 spin_unlock_bh(&fq->lock);
132
133 --- a/net/mac80211/util.c
134 +++ b/net/mac80211/util.c
135 @@ -240,6 +240,99 @@ __le16 ieee80211_ctstoself_duration(stru
136 }
137 EXPORT_SYMBOL(ieee80211_ctstoself_duration);
138
139 +static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
140 +{
141 + struct ieee80211_local *local = sdata->local;
142 + struct ieee80211_vif *vif = &sdata->vif;
143 + struct fq *fq = &local->fq;
144 + struct ps_data *ps = NULL;
145 + struct txq_info *txqi;
146 + struct sta_info *sta;
147 + int i;
148 +
149 + spin_lock_bh(&fq->lock);
150 +
151 + if (sdata->vif.type == NL80211_IFTYPE_AP)
152 + ps = &sdata->bss->ps;
153 +
154 + sdata->vif.txqs_stopped[ac] = false;
155 +
156 + list_for_each_entry_rcu(sta, &local->sta_list, list) {
157 + if (sdata != sta->sdata)
158 + continue;
159 +
160 + for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
161 + struct ieee80211_txq *txq = sta->sta.txq[i];
162 +
163 + txqi = to_txq_info(txq);
164 +
165 + if (ac != txq->ac)
166 + continue;
167 +
168 + if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX,
169 + &txqi->flags))
170 + continue;
171 +
172 + spin_unlock_bh(&fq->lock);
173 + drv_wake_tx_queue(local, txqi);
174 + spin_lock_bh(&fq->lock);
175 + }
176 + }
177 +
178 + if (!vif->txq)
179 + goto out;
180 +
181 + txqi = to_txq_info(vif->txq);
182 +
183 + if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags) ||
184 + (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
185 + goto out;
186 +
187 + spin_unlock_bh(&fq->lock);
188 +
189 + drv_wake_tx_queue(local, txqi);
190 + return;
191 +out:
192 + spin_unlock_bh(&fq->lock);
193 +}
194 +
195 +void ieee80211_wake_txqs(unsigned long data)
196 +{
197 + struct ieee80211_local *local = (struct ieee80211_local *)data;
198 + struct ieee80211_sub_if_data *sdata;
199 + int n_acs = IEEE80211_NUM_ACS;
200 + unsigned long flags;
201 + int i;
202 +
203 + rcu_read_lock();
204 + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
205 +
206 + if (local->hw.queues < IEEE80211_NUM_ACS)
207 + n_acs = 1;
208 +
209 + for (i = 0; i < local->hw.queues; i++) {
210 + if (local->queue_stop_reasons[i])
211 + continue;
212 +
213 + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
214 + list_for_each_entry_rcu(sdata, &local->interfaces, list) {
215 + int ac;
216 +
217 + for (ac = 0; ac < n_acs; ac++) {
218 + int ac_queue = sdata->vif.hw_queue[ac];
219 +
220 + if (ac_queue == i ||
221 + sdata->vif.cab_queue == i)
222 + __ieee80211_wake_txqs(sdata, ac);
223 + }
224 + }
225 + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
226 + }
227 +
228 + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
229 + rcu_read_unlock();
230 +}
231 +
232 void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
233 {
234 struct ieee80211_sub_if_data *sdata;
235 @@ -308,6 +401,9 @@ static void __ieee80211_wake_queue(struc
236 rcu_read_unlock();
237 } else
238 tasklet_schedule(&local->tx_pending_tasklet);
239 +
240 + if (local->ops->wake_tx_queue)
241 + tasklet_schedule(&local->wake_txqs_tasklet);
242 }
243
244 void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
245 @@ -351,9 +447,6 @@ static void __ieee80211_stop_queue(struc
246 if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue]))
247 return;
248
249 - if (local->ops->wake_tx_queue)
250 - return;
251 -
252 if (local->hw.queues < IEEE80211_NUM_ACS)
253 n_acs = 1;
254
255 @@ -366,8 +459,15 @@ static void __ieee80211_stop_queue(struc
256
257 for (ac = 0; ac < n_acs; ac++) {
258 if (sdata->vif.hw_queue[ac] == queue ||
259 - sdata->vif.cab_queue == queue)
260 - netif_stop_subqueue(sdata->dev, ac);
261 + sdata->vif.cab_queue == queue) {
262 + if (!local->ops->wake_tx_queue) {
263 + netif_stop_subqueue(sdata->dev, ac);
264 + continue;
265 + }
266 + spin_lock(&local->fq.lock);
267 + sdata->vif.txqs_stopped[ac] = true;
268 + spin_unlock(&local->fq.lock);
269 + }
270 }
271 }
272 rcu_read_unlock();