mac80211: fix mesh issues and improve performance
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 319-wifi-mac80211-mesh-fast-xmit-support.patch
1 From: Sriram R <quic_srirrama@quicinc.com>
2 Date: Thu, 18 Aug 2022 12:35:42 +0530
3 Subject: [PATCH] wifi: mac80211: mesh fast xmit support
4
5 Currently fast xmit is supported in AP, STA and other device types where
6 the destination doesn't change for the lifetime of its association by
7 caching the static parts of the header that can be reused directly for
8 every Tx such as addresses and updates only mutable header fields such as
9 PN.
10 This technique is not directly applicable for a Mesh device type due
11 to the dynamic nature of the topology and protocol. The header is built
12 based on the destination mesh device which is proxying a certain external
13 device and based on the Mesh destination the next hop changes.
14 And the RA/A1 which is the next hop for reaching the destination can
15 vary during runtime as per the best route based on airtime. To accommodate
16 these changes and to come up with a solution to avoid overhead during header
17 generation, the headers comprising the MAC, Mesh and LLC part are cached
18 whenever data for a certain external destination is sent.
19 This cached header is reused every time a data is sent to that external
20 destination.
21
22 To ensure the changes in network are reflected in these cached headers,
23 flush affected cached entries on path changes, as well as other conditions
24 that currently trigger a fast xmit check in other modes (key changes etc.)
25
26 In order to keep the cache small, use a short timeout for expiring cache
27 entries.
28
29 Co-developed-by: Felix Fietkau <nbd@nbd.name>
30 Signed-off-by: Sriram R <quic_srirrama@quicinc.com>
31 Signed-off-by: Felix Fietkau <nbd@nbd.name>
32 ---
33
34 --- a/net/mac80211/ieee80211_i.h
35 +++ b/net/mac80211/ieee80211_i.h
36 @@ -37,6 +37,7 @@
37 extern const struct cfg80211_ops mac80211_config_ops;
38
39 struct ieee80211_local;
40 +struct mhdr_cache_entry;
41
42 /* Maximum number of broadcast/multicast frames to buffer when some of the
43 * associated stations are using power saving. */
44 @@ -655,6 +656,20 @@ struct mesh_table {
45 atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
46 };
47
48 +/**
49 + * struct mesh_hdr_cache - mesh fast xmit header cache
50 + *
51 + * @rhead: hash table containing struct mhdr_cache_entry, using skb DA as key
52 + * @walk_head: linked list containing all mhdr_cache_entry objects
53 + * @walk_lock: lock protecting walk_head and rhead
54 + * @enabled: indicates if header cache is initialized
55 + */
56 +struct mesh_hdr_cache {
57 + struct rhashtable rhead;
58 + struct hlist_head walk_head;
59 + spinlock_t walk_lock;
60 +};
61 +
62 struct ieee80211_if_mesh {
63 struct timer_list housekeeping_timer;
64 struct timer_list mesh_path_timer;
65 @@ -733,6 +748,7 @@ struct ieee80211_if_mesh {
66 struct mesh_table mpp_paths; /* Store paths for MPP&MAP */
67 int mesh_paths_generation;
68 int mpp_paths_generation;
69 + struct mesh_hdr_cache hdr_cache;
70 };
71
72 #ifdef CPTCFG_MAC80211_MESH
73 @@ -1998,6 +2014,9 @@ int ieee80211_tx_control_port(struct wip
74 int link_id, u64 *cookie);
75 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
76 const u8 *buf, size_t len);
77 +void __ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
78 + struct mhdr_cache_entry *entry,
79 + struct sk_buff *skb);
80
81 /* HT */
82 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
83 --- a/net/mac80211/mesh.c
84 +++ b/net/mac80211/mesh.c
85 @@ -780,6 +780,8 @@ static void ieee80211_mesh_housekeeping(
86 changed = mesh_accept_plinks_update(sdata);
87 ieee80211_mbss_info_change_notify(sdata, changed);
88
89 + mesh_hdr_cache_gc(sdata);
90 +
91 mod_timer(&ifmsh->housekeeping_timer,
92 round_jiffies(jiffies +
93 IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
94 --- a/net/mac80211/mesh.h
95 +++ b/net/mac80211/mesh.h
96 @@ -122,11 +122,49 @@ struct mesh_path {
97 u8 rann_snd_addr[ETH_ALEN];
98 u32 rann_metric;
99 unsigned long last_preq_to_root;
100 + unsigned long fast_xmit_check;
101 bool is_root;
102 bool is_gate;
103 u32 path_change_count;
104 };
105
106 +#define MESH_HEADER_CACHE_MAX_SIZE 512
107 +#define MESH_HEADER_CACHE_THRESHOLD_SIZE 384
108 +#define MESH_HEADER_CACHE_TIMEOUT 8000 /* msecs */
109 +#define MESH_HEADER_MAX_LEN 68 /* mac+mesh+rfc1042 hdr */
110 +
111 +/**
112 + * struct mhdr_cache_entry - Cached Mesh header entry
113 + * @addr_key: The Ethernet DA which is the key for this entry
114 + * @hdr: The cached header
115 + * @machdr_len: Total length of the mac header
116 + * @hdrlen: Length of this header entry
117 + * @key: Key corresponding to the nexthop stored in the header
118 + * @pn_offs: Offset to PN which is updated for every xmit
119 + * @band: band used for tx
120 + * @walk_list: list containing all the cached header entries
121 + * @rhash: rhashtable pointer
122 + * @mpath: The Mesh path corresponding to the Mesh DA
123 + * @mppath: The MPP entry corresponding to this DA
124 + * @timestamp: Last used time of this entry
125 + * @rcu: rcu to free this entry
126 + * @path_change_count: Stored path change value corresponding to the mpath
127 + */
128 +struct mhdr_cache_entry {
129 + u8 addr_key[ETH_ALEN] __aligned(2);
130 + u8 hdr[MESH_HEADER_MAX_LEN];
131 + u16 machdr_len;
132 + u16 hdrlen;
133 + u8 pn_offs;
134 + u8 band;
135 + struct ieee80211_key __rcu *key;
136 + struct hlist_node walk_list;
137 + struct rhash_head rhash;
138 + struct mesh_path *mpath, *mppath;
139 + unsigned long timestamp;
140 + struct rcu_head rcu;
141 +};
142 +
143 /* Recent multicast cache */
144 /* RMC_BUCKETS must be a power of 2, maximum 256 */
145 #define RMC_BUCKETS 256
146 @@ -298,6 +336,15 @@ void mesh_path_discard_frame(struct ieee
147 void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
148
149 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
150 +struct mhdr_cache_entry *
151 +mesh_get_cached_hdr(struct ieee80211_sub_if_data *sdata, const u8 *addr);
152 +void mesh_cache_hdr(struct ieee80211_sub_if_data *sdata,
153 + struct sk_buff *skb, struct mesh_path *mpath);
154 +void mesh_hdr_cache_gc(struct ieee80211_sub_if_data *sdata);
155 +void mesh_hdr_cache_flush(struct ieee80211_sub_if_data *sdata, const u8 *addr,
156 + bool is_mpp);
157 +void mesh_refresh_path(struct ieee80211_sub_if_data *sdata,
158 + struct mesh_path *mpath, const u8 *addr);
159
160 #ifdef CPTCFG_MAC80211_MESH
161 static inline
162 --- a/net/mac80211/mesh_hwmp.c
163 +++ b/net/mac80211/mesh_hwmp.c
164 @@ -491,8 +491,11 @@ static u32 hwmp_route_info_get(struct ie
165 }
166
167 if (fresh_info) {
168 - if (rcu_access_pointer(mpath->next_hop) != sta)
169 + if (rcu_access_pointer(mpath->next_hop) != sta) {
170 mpath->path_change_count++;
171 + mesh_hdr_cache_flush(mpath->sdata, mpath->dst,
172 + false);
173 + }
174 mesh_path_assign_nexthop(mpath, sta);
175 mpath->flags |= MESH_PATH_SN_VALID;
176 mpath->metric = new_metric;
177 @@ -539,8 +542,11 @@ static u32 hwmp_route_info_get(struct ie
178 }
179
180 if (fresh_info) {
181 - if (rcu_access_pointer(mpath->next_hop) != sta)
182 + if (rcu_access_pointer(mpath->next_hop) != sta) {
183 mpath->path_change_count++;
184 + mesh_hdr_cache_flush(mpath->sdata, mpath->dst,
185 + false);
186 + }
187 mesh_path_assign_nexthop(mpath, sta);
188 mpath->metric = last_hop_metric;
189 mpath->exp_time = time_after(mpath->exp_time, exp_time)
190 @@ -977,7 +983,7 @@ free:
191 * Locking: the function must be called from within a rcu read lock block.
192 *
193 */
194 -static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
195 +void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
196 {
197 struct ieee80211_sub_if_data *sdata = mpath->sdata;
198 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
199 @@ -1215,6 +1221,20 @@ static int mesh_nexthop_lookup_nolearn(s
200 return 0;
201 }
202
203 +void mesh_refresh_path(struct ieee80211_sub_if_data *sdata,
204 + struct mesh_path *mpath, const u8 *addr)
205 +{
206 + if (mpath->flags & (MESH_PATH_REQ_QUEUED | MESH_PATH_FIXED |
207 + MESH_PATH_RESOLVING))
208 + return;
209 +
210 + if (time_after(jiffies,
211 + mpath->exp_time -
212 + msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
213 + (!addr || ether_addr_equal(sdata->vif.addr, addr)))
214 + mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
215 +}
216 +
217 /**
218 * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling
219 * this function is considered "using" the associated mpath, so preempt a path
220 @@ -1242,19 +1262,18 @@ int mesh_nexthop_lookup(struct ieee80211
221 if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
222 return -ENOENT;
223
224 - if (time_after(jiffies,
225 - mpath->exp_time -
226 - msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
227 - ether_addr_equal(sdata->vif.addr, hdr->addr4) &&
228 - !(mpath->flags & MESH_PATH_RESOLVING) &&
229 - !(mpath->flags & MESH_PATH_FIXED))
230 - mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
231 + mesh_refresh_path(sdata, mpath, hdr->addr4);
232
233 next_hop = rcu_dereference(mpath->next_hop);
234 if (next_hop) {
235 memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
236 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
237 ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
238 + /* Cache the whole header so as to use next time rather than resolving
239 + * and building it every time
240 + */
241 + if (ieee80211_hw_check(&sdata->local->hw, SUPPORT_FAST_XMIT))
242 + mesh_cache_hdr(sdata, skb, mpath);
243 return 0;
244 }
245
246 --- a/net/mac80211/mesh_pathtbl.c
247 +++ b/net/mac80211/mesh_pathtbl.c
248 @@ -14,6 +14,7 @@
249 #include "wme.h"
250 #include "ieee80211_i.h"
251 #include "mesh.h"
252 +#include <linux/rhashtable.h>
253
254 static void mesh_path_free_rcu(struct mesh_table *tbl, struct mesh_path *mpath);
255
256 @@ -32,6 +33,41 @@ static const struct rhashtable_params me
257 .hashfn = mesh_table_hash,
258 };
259
260 +static const struct rhashtable_params mesh_hdr_rht_params = {
261 + .nelem_hint = 10,
262 + .automatic_shrinking = true,
263 + .key_len = ETH_ALEN,
264 + .key_offset = offsetof(struct mhdr_cache_entry, addr_key),
265 + .head_offset = offsetof(struct mhdr_cache_entry, rhash),
266 + .hashfn = mesh_table_hash,
267 +};
268 +
269 +static void __mesh_hdr_cache_entry_free(void *ptr, void *tblptr)
270 +{
271 + struct mhdr_cache_entry *mhdr = ptr;
272 +
273 + kfree_rcu(mhdr, rcu);
274 +}
275 +
276 +static void mesh_hdr_cache_deinit(struct ieee80211_sub_if_data *sdata)
277 +{
278 + struct mesh_hdr_cache *cache;
279 +
280 + cache = &sdata->u.mesh.hdr_cache;
281 + rhashtable_free_and_destroy(&cache->rhead,
282 + __mesh_hdr_cache_entry_free, NULL);
283 +}
284 +
285 +static void mesh_hdr_cache_init(struct ieee80211_sub_if_data *sdata)
286 +{
287 + struct mesh_hdr_cache *cache;
288 +
289 + cache = &sdata->u.mesh.hdr_cache;
290 + rhashtable_init(&cache->rhead, &mesh_hdr_rht_params);
291 + INIT_HLIST_HEAD(&cache->walk_head);
292 + spin_lock_init(&cache->walk_lock);
293 +}
294 +
295 static inline bool mpath_expired(struct mesh_path *mpath)
296 {
297 return (mpath->flags & MESH_PATH_ACTIVE) &&
298 @@ -381,6 +417,211 @@ struct mesh_path *mesh_path_new(struct i
299 return new_mpath;
300 }
301
302 +struct mhdr_cache_entry *
303 +mesh_get_cached_hdr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
304 +{
305 + struct mesh_path *mpath, *mppath;
306 + struct mhdr_cache_entry *entry;
307 + struct mesh_hdr_cache *cache;
308 +
309 + cache = &sdata->u.mesh.hdr_cache;
310 + entry = rhashtable_lookup(&cache->rhead, addr, mesh_hdr_rht_params);
311 + if (!entry)
312 + return NULL;
313 +
314 + mpath = rcu_dereference(entry->mpath);
315 + mppath = rcu_dereference(entry->mppath);
316 + if (!(mpath->flags & MESH_PATH_ACTIVE) || mpath_expired(mpath))
317 + return NULL;
318 +
319 + mesh_refresh_path(sdata, mpath, NULL);
320 + if (mppath)
321 + mppath->exp_time = jiffies;
322 + entry->timestamp = jiffies;
323 +
324 + return entry;
325 +}
326 +
327 +void mesh_cache_hdr(struct ieee80211_sub_if_data *sdata,
328 + struct sk_buff *skb, struct mesh_path *mpath)
329 +{
330 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
331 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
332 + struct mesh_hdr_cache *cache;
333 + struct mhdr_cache_entry *mhdr, *old_mhdr;
334 + struct ieee80211s_hdr *meshhdr;
335 + struct sta_info *next_hop;
336 + struct ieee80211_key *key;
337 + struct mesh_path *mppath;
338 + u16 meshhdr_len;
339 + u8 pn_offs = 0;
340 + int hdrlen;
341 +
342 + if (sdata->noack_map)
343 + return;
344 +
345 + if (!ieee80211_is_data_qos(hdr->frame_control))
346 + return;
347 +
348 + hdrlen = ieee80211_hdrlen(hdr->frame_control);
349 + meshhdr = (struct ieee80211s_hdr *)(skb->data + hdrlen);
350 + meshhdr_len = ieee80211_get_mesh_hdrlen(meshhdr);
351 +
352 + cache = &sdata->u.mesh.hdr_cache;
353 + if (atomic_read(&cache->rhead.nelems) >= MESH_HEADER_CACHE_MAX_SIZE)
354 + return;
355 +
356 + next_hop = rcu_dereference(mpath->next_hop);
357 + if (!next_hop)
358 + return;
359 +
360 + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
361 + /* This is required to keep the mppath alive */
362 + mppath = mpp_path_lookup(sdata, meshhdr->eaddr1);
363 + if (!mppath)
364 + return;
365 + } else if (ieee80211_has_a4(hdr->frame_control)) {
366 + mppath = mpath;
367 + } else {
368 + return;
369 + }
370 +
371 + /* rate limit, in case fast xmit can't be enabled */
372 + if (mppath->fast_xmit_check == jiffies)
373 + return;
374 +
375 + mppath->fast_xmit_check = jiffies;
376 +
377 + key = rcu_access_pointer(next_hop->ptk[next_hop->ptk_idx]);
378 + if (!key)
379 + key = rcu_access_pointer(sdata->default_unicast_key);
380 +
381 + if (key) {
382 + bool gen_iv, iv_spc;
383 +
384 + gen_iv = key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
385 + iv_spc = key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
386 +
387 + if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
388 + (key->flags & KEY_FLAG_TAINTED))
389 + return;
390 +
391 + switch (key->conf.cipher) {
392 + case WLAN_CIPHER_SUITE_CCMP:
393 + case WLAN_CIPHER_SUITE_CCMP_256:
394 + if (gen_iv)
395 + pn_offs = hdrlen;
396 + if (gen_iv || iv_spc)
397 + hdrlen += IEEE80211_CCMP_HDR_LEN;
398 + break;
399 + case WLAN_CIPHER_SUITE_GCMP:
400 + case WLAN_CIPHER_SUITE_GCMP_256:
401 + if (gen_iv)
402 + pn_offs = hdrlen;
403 + if (gen_iv || iv_spc)
404 + hdrlen += IEEE80211_GCMP_HDR_LEN;
405 + break;
406 + default:
407 + return;
408 + }
409 + }
410 +
411 + if (WARN_ON_ONCE(hdrlen + meshhdr_len + sizeof(rfc1042_header) >
412 + MESH_HEADER_MAX_LEN))
413 + return;
414 +
415 + mhdr = kzalloc(sizeof(*mhdr), GFP_ATOMIC);
416 + if (!mhdr)
417 + return;
418 +
419 + memcpy(mhdr->addr_key, mppath->dst, ETH_ALEN);
420 + mhdr->machdr_len = hdrlen;
421 + mhdr->hdrlen = mhdr->machdr_len + meshhdr_len + sizeof(rfc1042_header);
422 + rcu_assign_pointer(mhdr->mpath, mpath);
423 + if (meshhdr->flags & MESH_FLAGS_AE)
424 + rcu_assign_pointer(mhdr->mppath, mppath);
425 + rcu_assign_pointer(mhdr->key, key);
426 + mhdr->timestamp = jiffies;
427 + mhdr->band = info->band;
428 + mhdr->pn_offs = pn_offs;
429 +
430 + if (pn_offs) {
431 + memcpy(mhdr->hdr, skb->data, pn_offs);
432 + memcpy(mhdr->hdr + mhdr->machdr_len, skb->data + pn_offs,
433 + mhdr->hdrlen - mhdr->machdr_len);
434 + } else {
435 + memcpy(mhdr->hdr, skb->data, mhdr->hdrlen);
436 + }
437 +
438 + if (key) {
439 + hdr = (struct ieee80211_hdr *)mhdr->hdr;
440 + hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
441 + }
442 +
443 + spin_lock_bh(&cache->walk_lock);
444 + old_mhdr = rhashtable_lookup_get_insert_fast(&cache->rhead,
445 + &mhdr->rhash,
446 + mesh_hdr_rht_params);
447 + if (likely(!old_mhdr))
448 + hlist_add_head(&mhdr->walk_list, &cache->walk_head);
449 + else
450 + kfree(mhdr);
451 + spin_unlock_bh(&cache->walk_lock);
452 +}
453 +
454 +static void mesh_hdr_cache_entry_free(struct mesh_hdr_cache *cache,
455 + struct mhdr_cache_entry *entry)
456 +{
457 + hlist_del_rcu(&entry->walk_list);
458 + rhashtable_remove_fast(&cache->rhead, &entry->rhash, mesh_hdr_rht_params);
459 + kfree_rcu(entry, rcu);
460 +}
461 +
462 +void mesh_hdr_cache_gc(struct ieee80211_sub_if_data *sdata)
463 +{
464 + unsigned long timeout = msecs_to_jiffies(MESH_HEADER_CACHE_TIMEOUT);
465 + struct mesh_hdr_cache *cache;
466 + struct mhdr_cache_entry *entry;
467 + struct hlist_node *n;
468 +
469 + cache = &sdata->u.mesh.hdr_cache;
470 + if (atomic_read(&cache->rhead.nelems) < MESH_HEADER_CACHE_THRESHOLD_SIZE)
471 + return;
472 +
473 + spin_lock_bh(&cache->walk_lock);
474 + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
475 + if (!time_is_after_jiffies(entry->timestamp + timeout))
476 + mesh_hdr_cache_entry_free(cache, entry);
477 + spin_unlock_bh(&cache->walk_lock);
478 +}
479 +
480 +void mesh_hdr_cache_flush(struct ieee80211_sub_if_data *sdata, const u8 *addr,
481 + bool is_mpp)
482 +{
483 + struct mesh_hdr_cache *cache = &sdata->u.mesh.hdr_cache;
484 + struct mhdr_cache_entry *entry;
485 + struct hlist_node *n;
486 +
487 + cache = &sdata->u.mesh.hdr_cache;
488 + spin_lock_bh(&cache->walk_lock);
489 +
490 + /* Only one header per mpp address is expected in the header cache */
491 + if (is_mpp) {
492 + entry = rhashtable_lookup(&cache->rhead, addr,
493 + mesh_hdr_rht_params);
494 + if (entry)
495 + mesh_hdr_cache_entry_free(cache, entry);
496 + goto out;
497 + }
498 +
499 + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
500 + if (ether_addr_equal(entry->mpath->dst, addr))
501 + mesh_hdr_cache_entry_free(cache, entry);
502 +
503 +out:
504 + spin_unlock_bh(&cache->walk_lock);
505 +}
506 +
507 /**
508 * mesh_path_add - allocate and add a new path to the mesh path table
509 * @dst: destination address of the path (ETH_ALEN length)
510 @@ -521,6 +762,8 @@ static void mesh_path_free_rcu(struct me
511
512 static void __mesh_path_del(struct mesh_table *tbl, struct mesh_path *mpath)
513 {
514 + mesh_hdr_cache_flush(mpath->sdata, mpath->dst,
515 + tbl == &mpath->sdata->u.mesh.mpp_paths);
516 hlist_del_rcu(&mpath->walk_list);
517 rhashtable_remove_fast(&tbl->rhead, &mpath->rhash, mesh_rht_params);
518 mesh_path_free_rcu(tbl, mpath);
519 @@ -747,6 +990,7 @@ void mesh_path_fix_nexthop(struct mesh_p
520 mpath->exp_time = 0;
521 mpath->flags = MESH_PATH_FIXED | MESH_PATH_SN_VALID;
522 mesh_path_activate(mpath);
523 + mesh_hdr_cache_flush(mpath->sdata, mpath->dst, false);
524 spin_unlock_bh(&mpath->state_lock);
525 ewma_mesh_fail_avg_init(&next_hop->mesh->fail_avg);
526 /* init it at a low value - 0 start is tricky */
527 @@ -758,6 +1002,7 @@ void mesh_pathtbl_init(struct ieee80211_
528 {
529 mesh_table_init(&sdata->u.mesh.mesh_paths);
530 mesh_table_init(&sdata->u.mesh.mpp_paths);
531 + mesh_hdr_cache_init(sdata);
532 }
533
534 static
535 @@ -785,6 +1030,7 @@ void mesh_path_expire(struct ieee80211_s
536
537 void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata)
538 {
539 + mesh_hdr_cache_deinit(sdata);
540 mesh_table_free(&sdata->u.mesh.mesh_paths);
541 mesh_table_free(&sdata->u.mesh.mpp_paths);
542 }
543 --- a/net/mac80211/rx.c
544 +++ b/net/mac80211/rx.c
545 @@ -2791,6 +2791,7 @@ ieee80211_rx_mesh_data(struct ieee80211_
546 if (mesh_hdr->flags & MESH_FLAGS_AE) {
547 struct mesh_path *mppath;
548 char *proxied_addr;
549 + bool update = false;
550
551 if (multicast)
552 proxied_addr = mesh_hdr->eaddr1;
553 @@ -2806,11 +2807,18 @@ ieee80211_rx_mesh_data(struct ieee80211_
554 mpp_path_add(sdata, proxied_addr, eth->h_source);
555 } else {
556 spin_lock_bh(&mppath->state_lock);
557 - if (!ether_addr_equal(mppath->mpp, eth->h_source))
558 + if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
559 memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
560 + update = true;
561 + }
562 mppath->exp_time = jiffies;
563 spin_unlock_bh(&mppath->state_lock);
564 }
565 +
566 + /* flush fast xmit cache if the address path changed */
567 + if (update)
568 + mesh_hdr_cache_flush(sdata, proxied_addr, true);
569 +
570 rcu_read_unlock();
571 }
572
573 --- a/net/mac80211/tx.c
574 +++ b/net/mac80211/tx.c
575 @@ -3021,6 +3021,9 @@ void ieee80211_check_fast_xmit(struct st
576 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
577 return;
578
579 + if (ieee80211_vif_is_mesh(&sdata->vif))
580 + mesh_hdr_cache_flush(sdata, sta->addr, false);
581 +
582 /* Locking here protects both the pointer itself, and against concurrent
583 * invocations winning data access races to, e.g., the key pointer that
584 * is used.
585 @@ -3723,6 +3726,155 @@ free:
586 kfree_skb(skb);
587 }
588
589 +void __ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
590 + struct mhdr_cache_entry *entry,
591 + struct sk_buff *skb)
592 +{
593 + struct ieee80211_local *local = sdata->local;
594 + struct ieee80211_tx_data tx = {};
595 + struct ieee80211_tx_info *info;
596 + struct ieee80211_key *key;
597 + struct ieee80211_hdr *hdr;
598 + struct mesh_path *mpath;
599 + ieee80211_tx_result r;
600 + struct sta_info *sta;
601 + u8 tid;
602 +
603 + if (!IS_ENABLED(CPTCFG_MAC80211_MESH))
604 + return;
605 +
606 + info = IEEE80211_SKB_CB(skb);
607 + memset(info, 0, sizeof(*info));
608 + info->band = entry->band;
609 + info->control.vif = &sdata->vif;
610 + info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
611 + IEEE80211_TX_CTL_DONTFRAG;
612 +
613 + info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT;
614 +
615 +#ifdef CONFIG_MAC80211_DEBUGFS
616 + if (local->force_tx_status)
617 + info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
618 +#endif
619 +
620 + mpath = entry->mpath;
621 + key = entry->key;
622 + sta = rcu_dereference(mpath->next_hop);
623 +
624 + __skb_queue_head_init(&tx.skbs);
625 +
626 + tx.flags = IEEE80211_TX_UNICAST;
627 + tx.local = local;
628 + tx.sdata = sdata;
629 + tx.sta = sta;
630 + tx.key = key;
631 + tx.skb = skb;
632 +
633 + hdr = (struct ieee80211_hdr *)skb->data;
634 + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
635 + *ieee80211_get_qos_ctl(hdr) = tid;
636 +
637 + ieee80211_aggr_check(sdata, sta, skb);
638 +
639 + if (ieee80211_queue_skb(local, sdata, sta, skb))
640 + return;
641 +
642 + r = ieee80211_xmit_fast_finish(sdata, sta, entry->pn_offs, key, &tx);
643 + if (r == TX_DROP) {
644 + kfree_skb(skb);
645 + return;
646 + }
647 +
648 + __skb_queue_tail(&tx.skbs, skb);
649 + ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
650 +}
651 +
652 +
653 +static bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
654 + struct sk_buff *skb, u32 ctrl_flags)
655 +{
656 + struct ieee80211_local *local = sdata->local;
657 + struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
658 + struct mhdr_cache_entry *entry;
659 + struct ieee80211s_hdr *meshhdr;
660 + u8 sa[ETH_ALEN] __aligned(2);
661 + struct sta_info *sta;
662 + bool copy_sa = false;
663 + u16 ethertype;
664 +
665 + if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
666 + return false;
667 +
668 + if (ifmsh->mshcfg.dot11MeshNolearn)
669 + return false;
670 +
671 + if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
672 + return false;
673 +
674 + /* Add support for these cases later */
675 + if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep)
676 + return false;
677 +
678 + if (is_multicast_ether_addr(skb->data))
679 + return false;
680 +
681 + ethertype = (skb->data[12] << 8) | skb->data[13];
682 + if (ethertype < ETH_P_802_3_MIN)
683 + return false;
684 +
685 + if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
686 + return false;
687 +
688 + if (skb->ip_summed == CHECKSUM_PARTIAL) {
689 + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
690 + if (skb_checksum_help(skb))
691 + return false;
692 + }
693 +
694 + entry = mesh_get_cached_hdr(sdata, skb->data);
695 + if (!entry)
696 + return false;
697 +
698 + /* Avoid extra work in this path */
699 + if (skb_headroom(skb) < (entry->hdrlen - ETH_HLEN + 2))
700 + return false;
701 +
702 + /* If the skb is shared we need to obtain our own copy */
703 + if (skb_shared(skb)) {
704 + struct sk_buff *oskb = skb;
705 +
706 + skb = skb_clone(skb, GFP_ATOMIC);
707 + if (!skb)
708 + return false;
709 +
710 + kfree_skb(oskb);
711 + }
712 +
713 + sta = rcu_dereference(entry->mpath->next_hop);
714 + skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
715 +
716 + meshhdr = (struct ieee80211s_hdr *)(entry->hdr + entry->machdr_len);
717 + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
718 + /* preserve SA from eth header for 6-addr frames */
719 + ether_addr_copy(sa, skb->data + ETH_ALEN);
720 + copy_sa = true;
721 + }
722 +
723 + memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr,
724 + entry->hdrlen);
725 +
726 + meshhdr = (struct ieee80211s_hdr *)(skb->data + entry->machdr_len);
727 + put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
728 + &meshhdr->seqnum);
729 + meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
730 + if (copy_sa)
731 + ether_addr_copy(meshhdr->eaddr2, sa);
732 +
733 + __ieee80211_mesh_xmit_fast(sdata, entry, skb);
734 +
735 + return true;
736 +}
737 +
738 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
739 struct sta_info *sta,
740 struct ieee80211_fast_tx *fast_tx,
741 @@ -4244,8 +4396,14 @@ void __ieee80211_subif_start_xmit(struct
742 return;
743 }
744
745 + sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
746 +
747 rcu_read_lock();
748
749 + if (ieee80211_vif_is_mesh(&sdata->vif) &&
750 + ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
751 + goto out;
752 +
753 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
754 goto out_free;
755
756 @@ -4255,8 +4413,6 @@ void __ieee80211_subif_start_xmit(struct
757 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
758 ieee80211_aggr_check(sdata, sta, skb);
759
760 - sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
761 -
762 if (sta) {
763 struct ieee80211_fast_tx *fast_tx;
764