forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/wireless/mediatek/mt76/agg-rx.c
....@@ -1,21 +1,16 @@
1
+// SPDX-License-Identifier: ISC
12 /*
23 * Copyright (C) 2018 Felix Fietkau <nbd@nbd.name>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
154 */
165 #include "mt76.h"
176
18
-#define REORDER_TIMEOUT (HZ / 10)
7
+static unsigned long mt76_aggr_tid_to_timeo(u8 tidno)
8
+{
9
+ /* Currently voice traffic (AC_VO) always runs without aggregation,
10
+ * no special handling is needed. AC_BE/AC_BK use tids 0-3. Just check
11
+ * for non AC_BK/AC_BE and set smaller timeout for it. */
12
+ return HZ / (tidno >= 4 ? 25 : 10);
13
+}
1914
2015 static void
2116 mt76_aggr_release(struct mt76_rx_tid *tid, struct sk_buff_head *frames, int idx)
....@@ -34,8 +29,9 @@
3429 }
3530
3631 static void
37
-mt76_rx_aggr_release_frames(struct mt76_rx_tid *tid, struct sk_buff_head *frames,
38
- u16 head)
32
+mt76_rx_aggr_release_frames(struct mt76_rx_tid *tid,
33
+ struct sk_buff_head *frames,
34
+ u16 head)
3935 {
4036 int idx;
4137
....@@ -74,15 +70,15 @@
7470 for (idx = (tid->head + 1) % tid->size;
7571 idx != start && nframes;
7672 idx = (idx + 1) % tid->size) {
77
-
7873 skb = tid->reorder_buf[idx];
7974 if (!skb)
8075 continue;
8176
8277 nframes--;
83
- status = (struct mt76_rx_status *) skb->cb;
84
- if (!time_after(jiffies, status->reorder_time +
85
- REORDER_TIMEOUT))
78
+ status = (struct mt76_rx_status *)skb->cb;
79
+ if (!time_after(jiffies,
80
+ status->reorder_time +
81
+ mt76_aggr_tid_to_timeo(tid->num)))
8682 continue;
8783
8884 mt76_rx_aggr_release_frames(tid, frames, status->seqno);
....@@ -112,7 +108,7 @@
112108
113109 if (nframes)
114110 ieee80211_queue_delayed_work(tid->dev->hw, &tid->reorder_work,
115
- REORDER_TIMEOUT);
111
+ mt76_aggr_tid_to_timeo(tid->num));
116112 mt76_rx_complete(dev, &frames, NULL);
117113
118114 rcu_read_unlock();
....@@ -122,8 +118,8 @@
122118 static void
123119 mt76_rx_aggr_check_ctl(struct sk_buff *skb, struct sk_buff_head *frames)
124120 {
125
- struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
126
- struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data;
121
+ struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
122
+ struct ieee80211_bar *bar = mt76_skb_get_hdr(skb);
127123 struct mt76_wcid *wcid = status->wcid;
128124 struct mt76_rx_tid *tid;
129125 u16 seqno;
....@@ -135,21 +131,23 @@
135131 return;
136132
137133 status->tid = le16_to_cpu(bar->control) >> 12;
138
- seqno = le16_to_cpu(bar->start_seq_num) >> 4;
134
+ seqno = IEEE80211_SEQ_TO_SN(le16_to_cpu(bar->start_seq_num));
139135 tid = rcu_dereference(wcid->aggr[status->tid]);
140136 if (!tid)
141137 return;
142138
143139 spin_lock_bh(&tid->lock);
144
- mt76_rx_aggr_release_frames(tid, frames, seqno);
145
- mt76_rx_aggr_release_head(tid, frames);
140
+ if (!tid->stopped) {
141
+ mt76_rx_aggr_release_frames(tid, frames, seqno);
142
+ mt76_rx_aggr_release_head(tid, frames);
143
+ }
146144 spin_unlock_bh(&tid->lock);
147145 }
148146
149147 void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
150148 {
151
- struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
152
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
149
+ struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
150
+ struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
153151 struct mt76_wcid *wcid = status->wcid;
154152 struct ieee80211_sta *sta;
155153 struct mt76_rx_tid *tid;
....@@ -233,7 +231,8 @@
233231 tid->nframes++;
234232 mt76_rx_aggr_release_head(tid, frames);
235233
236
- ieee80211_queue_delayed_work(tid->dev->hw, &tid->reorder_work, REORDER_TIMEOUT);
234
+ ieee80211_queue_delayed_work(tid->dev->hw, &tid->reorder_work,
235
+ mt76_aggr_tid_to_timeo(tid->num));
237236
238237 out:
239238 spin_unlock_bh(&tid->lock);
....@@ -253,6 +252,7 @@
253252 tid->dev = dev;
254253 tid->head = ssn;
255254 tid->size = size;
255
+ tid->num = tidno;
256256 INIT_DELAYED_WORK(&tid->reorder_work, mt76_rx_aggr_reorder_work);
257257 spin_lock_init(&tid->lock);
258258
....@@ -266,8 +266,6 @@
266266 {
267267 u16 size = tid->size;
268268 int i;
269
-
270
- cancel_delayed_work(&tid->reorder_work);
271269
272270 spin_lock_bh(&tid->lock);
273271
....@@ -284,21 +282,19 @@
284282 }
285283
286284 spin_unlock_bh(&tid->lock);
285
+
286
+ cancel_delayed_work_sync(&tid->reorder_work);
287287 }
288288
289289 void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tidno)
290290 {
291
- struct mt76_rx_tid *tid;
291
+ struct mt76_rx_tid *tid = NULL;
292292
293
- rcu_read_lock();
294
-
295
- tid = rcu_dereference(wcid->aggr[tidno]);
293
+ tid = rcu_replace_pointer(wcid->aggr[tidno], tid,
294
+ lockdep_is_held(&dev->mutex));
296295 if (tid) {
297
- rcu_assign_pointer(wcid->aggr[tidno], NULL);
298296 mt76_rx_aggr_shutdown(dev, tid);
299297 kfree_rcu(tid, rcu_head);
300298 }
301
-
302
- rcu_read_unlock();
303299 }
304300 EXPORT_SYMBOL_GPL(mt76_rx_aggr_stop);