1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sun, 26 Feb 2023 13:53:08 +0100
3 Subject: [PATCH] wifi: mac80211: mesh fast xmit support
5 Previously, fast xmit only worked on interface types where initially a
6 sta lookup is performed, and a cached header can be attached to the sta,
7 requiring only some fields to be updated at runtime.
9 This technique is not directly applicable for a mesh device type due
10 to the dynamic nature of the topology and protocol. There are more
11 addresses that need to be filled, and there is an extra header with a
12 dynamic length based on the addressing mode.
14 Change the code to cache entries contain a copy of the mesh subframe header +
15 bridge tunnel header, as well as an embedded struct ieee80211_fast_tx, which
16 contains the information for building the 802.11 header.
18 Add a mesh specific early fast xmit call, which looks up a cached entry and
19 adds only the mesh subframe header, before passing it over to the generic
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.)
26 This code is loosely based on a previous implementation by:
27 Sriram R <quic_srirrama@quicinc.com>
29 Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
30 Signed-off-by: Felix Fietkau <nbd@nbd.name>
33 --- a/net/mac80211/ieee80211_i.h
34 +++ b/net/mac80211/ieee80211_i.h
36 extern const struct cfg80211_ops mac80211_config_ops;
38 struct ieee80211_local;
39 +struct ieee80211_mesh_fast_tx;
41 /* Maximum number of broadcast/multicast frames to buffer when some of the
42 * associated stations are using power saving. */
43 @@ -655,6 +656,19 @@ struct mesh_table {
44 atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
48 + * struct mesh_tx_cache - mesh fast xmit header cache
50 + * @rht: hash table containing struct ieee80211_mesh_fast_tx, using skb DA as key
51 + * @walk_head: linked list containing all ieee80211_mesh_fast_tx objects
52 + * @walk_lock: lock protecting walk_head and rht
54 +struct mesh_tx_cache {
55 + struct rhashtable rht;
56 + struct hlist_head walk_head;
57 + spinlock_t walk_lock;
60 struct ieee80211_if_mesh {
61 struct timer_list housekeeping_timer;
62 struct timer_list mesh_path_timer;
63 @@ -733,6 +747,7 @@ struct ieee80211_if_mesh {
64 struct mesh_table mpp_paths; /* Store paths for MPP&MAP */
65 int mesh_paths_generation;
66 int mpp_paths_generation;
67 + struct mesh_tx_cache tx_cache;
70 #ifdef CPTCFG_MAC80211_MESH
71 @@ -1998,6 +2013,11 @@ int ieee80211_tx_control_port(struct wip
72 int link_id, u64 *cookie);
73 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
74 const u8 *buf, size_t len);
75 +void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
76 + struct sta_info *sta,
77 + struct ieee80211_fast_tx *fast_tx,
78 + struct sk_buff *skb, bool ampdu,
79 + const u8 *da, const u8 *sa);
82 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
83 --- a/net/mac80211/mesh.c
84 +++ b/net/mac80211/mesh.c
86 #include <asm/unaligned.h>
87 #include "ieee80211_i.h"
90 #include "driver-ops.h"
92 static int mesh_allocated;
93 @@ -698,6 +699,95 @@ ieee80211_mesh_update_bss_params(struct
94 __le32_to_cpu(he_oper->he_oper_params);
97 +bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
98 + struct sk_buff *skb, u32 ctrl_flags)
100 + struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
101 + struct ieee80211_mesh_fast_tx *entry;
102 + struct ieee80211s_hdr *meshhdr;
103 + u8 sa[ETH_ALEN] __aligned(2);
104 + struct tid_ampdu_tx *tid_tx;
105 + struct sta_info *sta;
106 + bool copy_sa = false;
110 + if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
113 + if (ifmsh->mshcfg.dot11MeshNolearn)
116 + /* Add support for these cases later */
117 + if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep)
120 + if (is_multicast_ether_addr(skb->data))
123 + ethertype = (skb->data[12] << 8) | skb->data[13];
124 + if (ethertype < ETH_P_802_3_MIN)
127 + if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
130 + if (skb->ip_summed == CHECKSUM_PARTIAL) {
131 + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
132 + if (skb_checksum_help(skb))
136 + entry = mesh_fast_tx_get(sdata, skb->data);
140 + if (skb_headroom(skb) + 2 * ETH_ALEN < entry->hdrlen +
141 + entry->fast_tx.hdr_len)
144 + sta = rcu_dereference(entry->mpath->next_hop);
148 + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
149 + tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
151 + if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
153 + if (tid_tx->timeout)
154 + tid_tx->last_tx = jiffies;
157 + skb = skb_share_check(skb, GFP_ATOMIC);
161 + skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
163 + meshhdr = (struct ieee80211s_hdr *)entry->hdr;
164 + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
165 + /* preserve SA from eth header for 6-addr frames */
166 + ether_addr_copy(sa, skb->data + ETH_ALEN);
170 + memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr,
173 + meshhdr = (struct ieee80211s_hdr *)skb->data;
174 + put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
176 + meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
178 + ether_addr_copy(meshhdr->eaddr2, sa);
180 + __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
181 + entry->mpath->dst, sdata->vif.addr);
187 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
188 * @hdr: 802.11 frame header
189 @@ -780,6 +870,8 @@ static void ieee80211_mesh_housekeeping(
190 changed = mesh_accept_plinks_update(sdata);
191 ieee80211_mbss_info_change_notify(sdata, changed);
193 + mesh_fast_tx_gc(sdata);
195 mod_timer(&ifmsh->housekeeping_timer,
196 round_jiffies(jiffies +
197 IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
198 --- a/net/mac80211/mesh.h
199 +++ b/net/mac80211/mesh.h
200 @@ -122,11 +122,41 @@ struct mesh_path {
201 u8 rann_snd_addr[ETH_ALEN];
203 unsigned long last_preq_to_root;
204 + unsigned long fast_tx_check;
207 u32 path_change_count;
210 +#define MESH_FAST_TX_CACHE_MAX_SIZE 512
211 +#define MESH_FAST_TX_CACHE_THRESHOLD_SIZE 384
212 +#define MESH_FAST_TX_CACHE_TIMEOUT 8000 /* msecs */
215 + * struct ieee80211_mesh_fast_tx - cached mesh fast tx entry
216 + * @rhash: rhashtable pointer
217 + * @addr_key: The Ethernet DA which is the key for this entry
218 + * @fast_tx: base fast_tx data
219 + * @hdr: cached mesh and rfc1042 headers
220 + * @hdrlen: length of mesh + rfc1042
221 + * @walk_list: list containing all the fast tx entries
222 + * @mpath: mesh path corresponding to the Mesh DA
223 + * @mppath: MPP entry corresponding to this DA
224 + * @timestamp: Last used time of this entry
226 +struct ieee80211_mesh_fast_tx {
227 + struct rhash_head rhash;
228 + u8 addr_key[ETH_ALEN] __aligned(2);
230 + struct ieee80211_fast_tx fast_tx;
231 + u8 hdr[sizeof(struct ieee80211s_hdr) + sizeof(rfc1042_header)];
234 + struct mesh_path *mpath, *mppath;
235 + struct hlist_node walk_list;
236 + unsigned long timestamp;
239 /* Recent multicast cache */
240 /* RMC_BUCKETS must be a power of 2, maximum 256 */
241 #define RMC_BUCKETS 256
242 @@ -298,6 +328,20 @@ void mesh_path_discard_frame(struct ieee
243 void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
245 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
246 +struct ieee80211_mesh_fast_tx *
247 +mesh_fast_tx_get(struct ieee80211_sub_if_data *sdata, const u8 *addr);
248 +bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
249 + struct sk_buff *skb, u32 ctrl_flags);
250 +void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
251 + struct sk_buff *skb, struct mesh_path *mpath);
252 +void mesh_fast_tx_gc(struct ieee80211_sub_if_data *sdata);
253 +void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata,
255 +void mesh_fast_tx_flush_mpath(struct mesh_path *mpath);
256 +void mesh_fast_tx_flush_sta(struct ieee80211_sub_if_data *sdata,
257 + struct sta_info *sta);
258 +void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
259 + struct mesh_path *mpath, const u8 *addr);
261 #ifdef CPTCFG_MAC80211_MESH
263 --- a/net/mac80211/mesh_hwmp.c
264 +++ b/net/mac80211/mesh_hwmp.c
265 @@ -394,6 +394,7 @@ static u32 hwmp_route_info_get(struct ie
266 u32 orig_sn, orig_metric;
267 unsigned long orig_lifetime, exp_time;
268 u32 last_hop_metric, new_metric;
269 + bool flush_mpath = false;
273 @@ -491,8 +492,10 @@ static u32 hwmp_route_info_get(struct ie
277 - if (rcu_access_pointer(mpath->next_hop) != sta)
278 + if (rcu_access_pointer(mpath->next_hop) != sta) {
279 mpath->path_change_count++;
280 + flush_mpath = true;
282 mesh_path_assign_nexthop(mpath, sta);
283 mpath->flags |= MESH_PATH_SN_VALID;
284 mpath->metric = new_metric;
285 @@ -502,6 +505,8 @@ static u32 hwmp_route_info_get(struct ie
286 mpath->hop_count = hopcount;
287 mesh_path_activate(mpath);
288 spin_unlock_bh(&mpath->state_lock);
290 + mesh_fast_tx_flush_mpath(mpath);
291 ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
292 /* init it at a low value - 0 start is tricky */
293 ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
294 @@ -539,8 +544,10 @@ static u32 hwmp_route_info_get(struct ie
298 - if (rcu_access_pointer(mpath->next_hop) != sta)
299 + if (rcu_access_pointer(mpath->next_hop) != sta) {
300 mpath->path_change_count++;
301 + flush_mpath = true;
303 mesh_path_assign_nexthop(mpath, sta);
304 mpath->metric = last_hop_metric;
305 mpath->exp_time = time_after(mpath->exp_time, exp_time)
306 @@ -548,6 +555,8 @@ static u32 hwmp_route_info_get(struct ie
307 mpath->hop_count = 1;
308 mesh_path_activate(mpath);
309 spin_unlock_bh(&mpath->state_lock);
311 + mesh_fast_tx_flush_mpath(mpath);
312 ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
313 /* init it at a low value - 0 start is tricky */
314 ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
315 @@ -1215,6 +1224,20 @@ static int mesh_nexthop_lookup_nolearn(s
319 +void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
320 + struct mesh_path *mpath, const u8 *addr)
322 + if (mpath->flags & (MESH_PATH_REQ_QUEUED | MESH_PATH_FIXED |
323 + MESH_PATH_RESOLVING))
326 + if (time_after(jiffies,
328 + msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
329 + (!addr || ether_addr_equal(sdata->vif.addr, addr)))
330 + mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
334 * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling
335 * this function is considered "using" the associated mpath, so preempt a path
336 @@ -1242,19 +1265,15 @@ int mesh_nexthop_lookup(struct ieee80211
337 if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
340 - if (time_after(jiffies,
342 - msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
343 - ether_addr_equal(sdata->vif.addr, hdr->addr4) &&
344 - !(mpath->flags & MESH_PATH_RESOLVING) &&
345 - !(mpath->flags & MESH_PATH_FIXED))
346 - mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
347 + mesh_path_refresh(sdata, mpath, hdr->addr4);
349 next_hop = rcu_dereference(mpath->next_hop);
351 memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
352 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
353 ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
354 + if (ieee80211_hw_check(&sdata->local->hw, SUPPORT_FAST_XMIT))
355 + mesh_fast_tx_cache(sdata, skb, mpath);
359 --- a/net/mac80211/mesh_pathtbl.c
360 +++ b/net/mac80211/mesh_pathtbl.c
363 #include "ieee80211_i.h"
365 +#include <linux/rhashtable.h>
367 static void mesh_path_free_rcu(struct mesh_table *tbl, struct mesh_path *mpath);
369 @@ -32,6 +33,41 @@ static const struct rhashtable_params me
370 .hashfn = mesh_table_hash,
373 +static const struct rhashtable_params fast_tx_rht_params = {
375 + .automatic_shrinking = true,
376 + .key_len = ETH_ALEN,
377 + .key_offset = offsetof(struct ieee80211_mesh_fast_tx, addr_key),
378 + .head_offset = offsetof(struct ieee80211_mesh_fast_tx, rhash),
379 + .hashfn = mesh_table_hash,
382 +static void __mesh_fast_tx_entry_free(void *ptr, void *tblptr)
384 + struct ieee80211_mesh_fast_tx *entry = ptr;
386 + kfree_rcu(entry, fast_tx.rcu_head);
389 +static void mesh_fast_tx_deinit(struct ieee80211_sub_if_data *sdata)
391 + struct mesh_tx_cache *cache;
393 + cache = &sdata->u.mesh.tx_cache;
394 + rhashtable_free_and_destroy(&cache->rht,
395 + __mesh_fast_tx_entry_free, NULL);
398 +static void mesh_fast_tx_init(struct ieee80211_sub_if_data *sdata)
400 + struct mesh_tx_cache *cache;
402 + cache = &sdata->u.mesh.tx_cache;
403 + rhashtable_init(&cache->rht, &fast_tx_rht_params);
404 + INIT_HLIST_HEAD(&cache->walk_head);
405 + spin_lock_init(&cache->walk_lock);
408 static inline bool mpath_expired(struct mesh_path *mpath)
410 return (mpath->flags & MESH_PATH_ACTIVE) &&
411 @@ -381,6 +417,243 @@ struct mesh_path *mesh_path_new(struct i
415 +static void mesh_fast_tx_entry_free(struct mesh_tx_cache *cache,
416 + struct ieee80211_mesh_fast_tx *entry)
418 + hlist_del_rcu(&entry->walk_list);
419 + rhashtable_remove_fast(&cache->rht, &entry->rhash, fast_tx_rht_params);
420 + kfree_rcu(entry, fast_tx.rcu_head);
423 +struct ieee80211_mesh_fast_tx *
424 +mesh_fast_tx_get(struct ieee80211_sub_if_data *sdata, const u8 *addr)
426 + struct ieee80211_mesh_fast_tx *entry;
427 + struct mesh_tx_cache *cache;
429 + cache = &sdata->u.mesh.tx_cache;
430 + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
434 + if (!(entry->mpath->flags & MESH_PATH_ACTIVE) ||
435 + mpath_expired(entry->mpath)) {
436 + spin_lock_bh(&cache->walk_lock);
437 + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
439 + mesh_fast_tx_entry_free(cache, entry);
440 + spin_unlock_bh(&cache->walk_lock);
444 + mesh_path_refresh(sdata, entry->mpath, NULL);
446 + entry->mppath->exp_time = jiffies;
447 + entry->timestamp = jiffies;
452 +void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
453 + struct sk_buff *skb, struct mesh_path *mpath)
455 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
456 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
457 + struct ieee80211_mesh_fast_tx *entry, *prev;
458 + struct ieee80211_mesh_fast_tx build = {};
459 + struct ieee80211s_hdr *meshhdr;
460 + struct mesh_tx_cache *cache;
461 + struct ieee80211_key *key;
462 + struct mesh_path *mppath;
463 + struct sta_info *sta;
466 + if (sdata->noack_map ||
467 + !ieee80211_is_data_qos(hdr->frame_control))
470 + build.fast_tx.hdr_len = ieee80211_hdrlen(hdr->frame_control);
471 + meshhdr = (struct ieee80211s_hdr *)(skb->data + build.fast_tx.hdr_len);
472 + build.hdrlen = ieee80211_get_mesh_hdrlen(meshhdr);
474 + cache = &sdata->u.mesh.tx_cache;
475 + if (atomic_read(&cache->rht.nelems) >= MESH_FAST_TX_CACHE_MAX_SIZE)
478 + sta = rcu_dereference(mpath->next_hop);
482 + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
483 + /* This is required to keep the mppath alive */
484 + mppath = mpp_path_lookup(sdata, meshhdr->eaddr1);
487 + build.mppath = mppath;
488 + } else if (ieee80211_has_a4(hdr->frame_control)) {
494 + /* rate limit, in case fast xmit can't be enabled */
495 + if (mppath->fast_tx_check == jiffies)
498 + mppath->fast_tx_check = jiffies;
501 + * Same use of the sta lock as in ieee80211_check_fast_xmit, in order
502 + * to protect against concurrent sta key updates.
504 + spin_lock_bh(&sta->lock);
505 + key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
507 + key = rcu_access_pointer(sdata->default_unicast_key);
508 + build.fast_tx.key = key;
511 + bool gen_iv, iv_spc;
513 + gen_iv = key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
514 + iv_spc = key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
516 + if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
517 + (key->flags & KEY_FLAG_TAINTED))
520 + switch (key->conf.cipher) {
521 + case WLAN_CIPHER_SUITE_CCMP:
522 + case WLAN_CIPHER_SUITE_CCMP_256:
524 + build.fast_tx.pn_offs = build.fast_tx.hdr_len;
525 + if (gen_iv || iv_spc)
526 + build.fast_tx.hdr_len += IEEE80211_CCMP_HDR_LEN;
528 + case WLAN_CIPHER_SUITE_GCMP:
529 + case WLAN_CIPHER_SUITE_GCMP_256:
531 + build.fast_tx.pn_offs = build.fast_tx.hdr_len;
532 + if (gen_iv || iv_spc)
533 + build.fast_tx.hdr_len += IEEE80211_GCMP_HDR_LEN;
540 + memcpy(build.addr_key, mppath->dst, ETH_ALEN);
541 + build.timestamp = jiffies;
542 + build.fast_tx.band = info->band;
543 + build.fast_tx.da_offs = offsetof(struct ieee80211_hdr, addr3);
544 + build.fast_tx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
545 + build.mpath = mpath;
546 + memcpy(build.hdr, meshhdr, build.hdrlen);
547 + memcpy(build.hdr + build.hdrlen, rfc1042_header, sizeof(rfc1042_header));
548 + build.hdrlen += sizeof(rfc1042_header);
549 + memcpy(build.fast_tx.hdr, hdr, build.fast_tx.hdr_len);
551 + hdr = (struct ieee80211_hdr *)build.fast_tx.hdr;
552 + if (build.fast_tx.key)
553 + hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
555 + qc = ieee80211_get_qos_ctl(hdr);
556 + qc[1] |= IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8;
558 + entry = kmemdup(&build, sizeof(build), GFP_ATOMIC);
562 + spin_lock(&cache->walk_lock);
563 + prev = rhashtable_lookup_get_insert_fast(&cache->rht,
565 + fast_tx_rht_params);
566 + if (unlikely(IS_ERR(prev))) {
572 + * replace any previous entry in the hash table, in case we're
573 + * replacing it with a different type (e.g. mpath -> mpp)
575 + if (unlikely(prev)) {
576 + rhashtable_replace_fast(&cache->rht, &prev->rhash,
577 + &entry->rhash, fast_tx_rht_params);
578 + hlist_del_rcu(&prev->walk_list);
579 + kfree_rcu(prev, fast_tx.rcu_head);
582 + hlist_add_head(&entry->walk_list, &cache->walk_head);
585 + spin_unlock(&cache->walk_lock);
587 + spin_unlock_bh(&sta->lock);
590 +void mesh_fast_tx_gc(struct ieee80211_sub_if_data *sdata)
592 + unsigned long timeout = msecs_to_jiffies(MESH_FAST_TX_CACHE_TIMEOUT);
593 + struct mesh_tx_cache *cache;
594 + struct ieee80211_mesh_fast_tx *entry;
595 + struct hlist_node *n;
597 + cache = &sdata->u.mesh.tx_cache;
598 + if (atomic_read(&cache->rht.nelems) < MESH_FAST_TX_CACHE_THRESHOLD_SIZE)
601 + spin_lock_bh(&cache->walk_lock);
602 + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
603 + if (!time_is_after_jiffies(entry->timestamp + timeout))
604 + mesh_fast_tx_entry_free(cache, entry);
605 + spin_unlock_bh(&cache->walk_lock);
608 +void mesh_fast_tx_flush_mpath(struct mesh_path *mpath)
610 + struct ieee80211_sub_if_data *sdata = mpath->sdata;
611 + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
612 + struct ieee80211_mesh_fast_tx *entry;
613 + struct hlist_node *n;
615 + cache = &sdata->u.mesh.tx_cache;
616 + spin_lock_bh(&cache->walk_lock);
617 + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
618 + if (entry->mpath == mpath)
619 + mesh_fast_tx_entry_free(cache, entry);
620 + spin_unlock_bh(&cache->walk_lock);
623 +void mesh_fast_tx_flush_sta(struct ieee80211_sub_if_data *sdata,
624 + struct sta_info *sta)
626 + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
627 + struct ieee80211_mesh_fast_tx *entry;
628 + struct hlist_node *n;
630 + cache = &sdata->u.mesh.tx_cache;
631 + spin_lock_bh(&cache->walk_lock);
632 + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
633 + if (rcu_access_pointer(entry->mpath->next_hop) == sta)
634 + mesh_fast_tx_entry_free(cache, entry);
635 + spin_unlock_bh(&cache->walk_lock);
638 +void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata,
641 + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
642 + struct ieee80211_mesh_fast_tx *entry;
644 + cache = &sdata->u.mesh.tx_cache;
645 + spin_lock_bh(&cache->walk_lock);
646 + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
648 + mesh_fast_tx_entry_free(cache, entry);
649 + spin_unlock_bh(&cache->walk_lock);
653 * mesh_path_add - allocate and add a new path to the mesh path table
654 * @dst: destination address of the path (ETH_ALEN length)
655 @@ -464,6 +737,8 @@ int mpp_path_add(struct ieee80211_sub_if
660 + mesh_fast_tx_flush_addr(sdata, dst);
662 sdata->u.mesh.mpp_paths_generation++;
664 @@ -523,6 +798,10 @@ static void __mesh_path_del(struct mesh_
666 hlist_del_rcu(&mpath->walk_list);
667 rhashtable_remove_fast(&tbl->rhead, &mpath->rhash, mesh_rht_params);
668 + if (tbl == &mpath->sdata->u.mesh.mpp_paths)
669 + mesh_fast_tx_flush_addr(mpath->sdata, mpath->dst);
671 + mesh_fast_tx_flush_mpath(mpath);
672 mesh_path_free_rcu(tbl, mpath);
675 @@ -747,6 +1026,7 @@ void mesh_path_fix_nexthop(struct mesh_p
677 mpath->flags = MESH_PATH_FIXED | MESH_PATH_SN_VALID;
678 mesh_path_activate(mpath);
679 + mesh_fast_tx_flush_mpath(mpath);
680 spin_unlock_bh(&mpath->state_lock);
681 ewma_mesh_fail_avg_init(&next_hop->mesh->fail_avg);
682 /* init it at a low value - 0 start is tricky */
683 @@ -758,6 +1038,7 @@ void mesh_pathtbl_init(struct ieee80211_
685 mesh_table_init(&sdata->u.mesh.mesh_paths);
686 mesh_table_init(&sdata->u.mesh.mpp_paths);
687 + mesh_fast_tx_init(sdata);
691 @@ -785,6 +1066,7 @@ void mesh_path_expire(struct ieee80211_s
693 void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata)
695 + mesh_fast_tx_deinit(sdata);
696 mesh_table_free(&sdata->u.mesh.mesh_paths);
697 mesh_table_free(&sdata->u.mesh.mpp_paths);
699 --- a/net/mac80211/rx.c
700 +++ b/net/mac80211/rx.c
701 @@ -2791,6 +2791,7 @@ ieee80211_rx_mesh_data(struct ieee80211_
702 if (mesh_hdr->flags & MESH_FLAGS_AE) {
703 struct mesh_path *mppath;
705 + bool update = false;
708 proxied_addr = mesh_hdr->eaddr1;
709 @@ -2806,11 +2807,18 @@ ieee80211_rx_mesh_data(struct ieee80211_
710 mpp_path_add(sdata, proxied_addr, eth->h_source);
712 spin_lock_bh(&mppath->state_lock);
713 - if (!ether_addr_equal(mppath->mpp, eth->h_source))
714 + if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
715 memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
718 mppath->exp_time = jiffies;
719 spin_unlock_bh(&mppath->state_lock);
722 + /* flush fast xmit cache if the address path changed */
724 + mesh_fast_tx_flush_addr(sdata, proxied_addr);
729 --- a/net/mac80211/tx.c
730 +++ b/net/mac80211/tx.c
731 @@ -3021,6 +3021,9 @@ void ieee80211_check_fast_xmit(struct st
732 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
735 + if (ieee80211_vif_is_mesh(&sdata->vif))
736 + mesh_fast_tx_flush_sta(sdata, sta);
738 /* Locking here protects both the pointer itself, and against concurrent
739 * invocations winning data access races to, e.g., the key pointer that
741 @@ -3402,6 +3405,9 @@ static bool ieee80211_amsdu_aggregate(st
742 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
745 + if (ieee80211_vif_is_mesh(&sdata->vif))
751 @@ -3634,10 +3640,11 @@ free:
755 -static void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
756 - struct sta_info *sta,
757 - struct ieee80211_fast_tx *fast_tx,
758 - struct sk_buff *skb, u8 tid, bool ampdu)
759 +void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
760 + struct sta_info *sta,
761 + struct ieee80211_fast_tx *fast_tx,
762 + struct sk_buff *skb, bool ampdu,
763 + const u8 *da, const u8 *sa)
765 struct ieee80211_local *local = sdata->local;
766 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
767 @@ -3645,8 +3652,6 @@ static void __ieee80211_xmit_fast(struct
768 struct ieee80211_tx_data tx;
769 ieee80211_tx_result r;
770 int hw_headroom = sdata->local->hw.extra_tx_headroom;
771 - int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
774 skb = skb_share_check(skb, GFP_ATOMIC);
776 @@ -3661,16 +3666,15 @@ static void __ieee80211_xmit_fast(struct
777 * more room than we already have in 'extra_head'
779 if (unlikely(ieee80211_skb_resize(sdata, skb,
780 - max_t(int, extra_head + hw_headroom -
781 + max_t(int, fast_tx->hdr_len + hw_headroom -
782 skb_headroom(skb), 0),
786 - memcpy(ð, skb->data, ETH_HLEN - 2);
787 - hdr = skb_push(skb, extra_head);
788 + hdr = skb_push(skb, fast_tx->hdr_len);
789 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
790 - memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
791 - memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
792 + memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN);
793 + memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN);
795 info = IEEE80211_SKB_CB(skb);
796 memset(info, 0, sizeof(*info));
797 @@ -3689,7 +3693,8 @@ static void __ieee80211_xmit_fast(struct
800 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
801 - tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
802 + u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
804 *ieee80211_get_qos_ctl(hdr) = tid;
807 @@ -3732,6 +3737,7 @@ static bool ieee80211_xmit_fast(struct i
808 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
809 struct tid_ampdu_tx *tid_tx = NULL;
810 struct sk_buff *next;
812 u8 tid = IEEE80211_NUM_TIDS;
814 /* control port protocol needs a lot of special handling */
815 @@ -3757,14 +3763,18 @@ static bool ieee80211_xmit_fast(struct i
819 + memcpy(ð, skb->data, ETH_HLEN - 2);
821 /* after this point (skb is modified) we cannot return false */
822 + skb_pull(skb, ETH_HLEN - 2);
823 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
827 skb_list_walk_safe(skb, skb, next) {
828 skb_mark_not_on_list(skb);
829 - __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid, tid_tx);
830 + __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx,
831 + eth.h_dest, eth.h_source);
835 @@ -4244,8 +4254,15 @@ void __ieee80211_subif_start_xmit(struct
839 + sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
843 + if (ieee80211_vif_is_mesh(&sdata->vif) &&
844 + ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) &&
845 + ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
848 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
851 @@ -4255,8 +4272,6 @@ void __ieee80211_subif_start_xmit(struct
852 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
853 ieee80211_aggr_check(sdata, sta, skb);
855 - sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
858 struct ieee80211_fast_tx *fast_tx;