1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Thu, 16 Feb 2023 11:07:30 +0100
3 Subject: [PATCH] wifi: mac80211: use mesh header cache to speed up mesh
6 Significantly reduces mesh forwarding path CPU usage and enables the
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 --- a/net/mac80211/rx.c
13 +++ b/net/mac80211/rx.c
14 @@ -2720,6 +2720,65 @@ ieee80211_deliver_skb(struct ieee80211_r
18 +#ifdef CPTCFG_MAC80211_MESH
20 +ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,
21 + struct sk_buff *skb, int hdrlen)
23 + struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
24 + struct ieee80211_mesh_fast_tx *entry = NULL;
25 + struct ieee80211s_hdr *mesh_hdr;
26 + struct tid_ampdu_tx *tid_tx;
27 + struct sta_info *sta;
31 + mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(eth));
32 + if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
33 + entry = mesh_fast_tx_get(sdata, mesh_hdr->eaddr1);
34 + else if (!(mesh_hdr->flags & MESH_FLAGS_AE))
35 + entry = mesh_fast_tx_get(sdata, skb->data);
39 + sta = rcu_dereference(entry->mpath->next_hop);
43 + if (skb_linearize(skb))
46 + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
47 + tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
49 + if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
52 + if (tid_tx->timeout)
53 + tid_tx->last_tx = jiffies;
56 + ieee80211_aggr_check(sdata, sta, skb);
58 + if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
62 + skb->protocol = htons(skb->len - hdrlen);
63 + skb_set_network_header(skb, hdrlen + 2);
65 + skb->dev = sdata->dev;
66 + memcpy(ð, skb->data, ETH_HLEN - 2);
68 + __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
69 + eth.h_dest, eth.h_source);
70 + IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
71 + IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
77 static ieee80211_rx_result
78 ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
80 @@ -2824,6 +2883,10 @@ ieee80211_rx_mesh_data(struct ieee80211_
82 skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
85 + ieee80211_rx_mesh_fast_forward(sdata, skb, mesh_hdrlen))
88 ieee80211_fill_mesh_addresses(&hdr, &hdr.frame_control,
89 eth->h_dest, eth->h_source);
90 hdrlen = ieee80211_hdrlen(hdr.frame_control);
91 @@ -2862,6 +2925,7 @@ ieee80211_rx_mesh_data(struct ieee80211_
92 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
93 info->control.vif = &sdata->vif;
94 info->control.jiffies = jiffies;
95 + fwd_skb->dev = sdata->dev;
97 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
98 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
99 @@ -2883,7 +2947,6 @@ ieee80211_rx_mesh_data(struct ieee80211_
102 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
103 - fwd_skb->dev = sdata->dev;
104 ieee80211_add_pending_skb(local, fwd_skb);
107 --- a/net/mac80211/ieee80211_i.h
108 +++ b/net/mac80211/ieee80211_i.h
109 @@ -2022,6 +2022,8 @@ void __ieee80211_xmit_fast(struct ieee80
110 struct ieee80211_fast_tx *fast_tx,
111 struct sk_buff *skb, bool ampdu,
112 const u8 *da, const u8 *sa);
113 +void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
114 + struct sta_info *sta, struct sk_buff *skb);
117 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
118 --- a/net/mac80211/tx.c
119 +++ b/net/mac80211/tx.c
120 @@ -1191,10 +1191,8 @@ static bool ieee80211_tx_prep_agg(struct
125 -ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
126 - struct sta_info *sta,
127 - struct sk_buff *skb)
128 +void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
129 + struct sta_info *sta, struct sk_buff *skb)
131 struct rate_control_ref *ref = sdata->local->rate_ctrl;