3b0bae67a5f176307ec0dd2851115d102ab5d097
[openwrt/staging/rmilecki.git] /
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
4 forwarding
5
6 Significantly reduces mesh forwarding path CPU usage and enables the
7 direct use of iTXQ.
8
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
10 ---
11
12 --- a/net/mac80211/rx.c
13 +++ b/net/mac80211/rx.c
14 @@ -2720,6 +2720,65 @@ ieee80211_deliver_skb(struct ieee80211_r
15 }
16 }
17
18 +#ifdef CPTCFG_MAC80211_MESH
19 +static bool
20 +ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,
21 + struct sk_buff *skb, int hdrlen)
22 +{
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;
28 + struct ethhdr eth;
29 + u8 tid;
30 +
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);
36 + if (!entry)
37 + return false;
38 +
39 + sta = rcu_dereference(entry->mpath->next_hop);
40 + if (!sta)
41 + return false;
42 +
43 + if (skb_linearize(skb))
44 + return false;
45 +
46 + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
47 + tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
48 + if (tid_tx) {
49 + if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
50 + return false;
51 +
52 + if (tid_tx->timeout)
53 + tid_tx->last_tx = jiffies;
54 + }
55 +
56 + ieee80211_aggr_check(sdata, sta, skb);
57 +
58 + if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
59 + &skb->protocol))
60 + hdrlen += ETH_ALEN;
61 + else
62 + skb->protocol = htons(skb->len - hdrlen);
63 + skb_set_network_header(skb, hdrlen + 2);
64 +
65 + skb->dev = sdata->dev;
66 + memcpy(&eth, skb->data, ETH_HLEN - 2);
67 + skb_pull(skb, sizeof(eth));
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);
72 +
73 + return true;
74 +}
75 +#endif
76 +
77 static ieee80211_rx_result
78 ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
79 struct sk_buff *skb)
80 @@ -2824,6 +2883,10 @@ ieee80211_rx_mesh_data(struct ieee80211_
81
82 skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
83
84 + if (!multicast &&
85 + ieee80211_rx_mesh_fast_forward(sdata, skb, mesh_hdrlen))
86 + return RX_QUEUED;
87 +
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;
96 if (multicast) {
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_
100 }
101
102 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
103 - fwd_skb->dev = sdata->dev;
104 ieee80211_add_pending_skb(local, fwd_skb);
105
106 rx_accept:
107 --- a/net/mac80211/ieee80211_i.h
108 +++ b/net/mac80211/ieee80211_i.h
109 @@ -2018,6 +2018,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);
115
116 /* HT */
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
121 return queued;
122 }
123
124 -static void
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)
130 {
131 struct rate_control_ref *ref = sdata->local->rate_ctrl;
132 u16 tid;