mac80211: add an optimization for fast-rx support
[openwrt/staging/wigyori.git] / package / kernel / mac80211 / patches / 335-mac80211-support-A-MSDU-in-fast-rx.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Mon, 26 Feb 2018 22:09:29 +0100
3 Subject: [PATCH] mac80211: support A-MSDU in fast-rx
4
5 Only works if the IV was stripped from packets. Create a smaller
6 variant of ieee80211_rx_h_amsdu, which bypasses checks already done
7 within the fast-rx context.
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 @@ -2358,39 +2358,17 @@ ieee80211_deliver_skb(struct ieee80211_r
15 }
16
17 static ieee80211_rx_result debug_noinline
18 -ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
19 +__ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
20 {
21 struct net_device *dev = rx->sdata->dev;
22 struct sk_buff *skb = rx->skb;
23 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
24 __le16 fc = hdr->frame_control;
25 struct sk_buff_head frame_list;
26 - struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
27 struct ethhdr ethhdr;
28 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
29
30 - if (unlikely(!ieee80211_is_data(fc)))
31 - return RX_CONTINUE;
32 -
33 - if (unlikely(!ieee80211_is_data_present(fc)))
34 - return RX_DROP_MONITOR;
35 -
36 - if (!(status->rx_flags & IEEE80211_RX_AMSDU))
37 - return RX_CONTINUE;
38 -
39 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
40 - switch (rx->sdata->vif.type) {
41 - case NL80211_IFTYPE_AP_VLAN:
42 - if (!rx->sdata->u.vlan.sta)
43 - return RX_DROP_UNUSABLE;
44 - break;
45 - case NL80211_IFTYPE_STATION:
46 - if (!rx->sdata->u.mgd.use_4addr)
47 - return RX_DROP_UNUSABLE;
48 - break;
49 - default:
50 - return RX_DROP_UNUSABLE;
51 - }
52 check_da = NULL;
53 check_sa = NULL;
54 } else switch (rx->sdata->vif.type) {
55 @@ -2410,9 +2388,6 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx
56 break;
57 }
58
59 - if (is_multicast_ether_addr(hdr->addr1))
60 - return RX_DROP_UNUSABLE;
61 -
62 skb->dev = dev;
63 __skb_queue_head_init(&frame_list);
64
65 @@ -2440,6 +2415,44 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx
66 return RX_QUEUED;
67 }
68
69 +static ieee80211_rx_result debug_noinline
70 +ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
71 +{
72 + struct sk_buff *skb = rx->skb;
73 + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
74 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
75 + __le16 fc = hdr->frame_control;
76 +
77 + if (!(status->rx_flags & IEEE80211_RX_AMSDU))
78 + return RX_CONTINUE;
79 +
80 + if (unlikely(!ieee80211_is_data(fc)))
81 + return RX_CONTINUE;
82 +
83 + if (unlikely(!ieee80211_is_data_present(fc)))
84 + return RX_DROP_MONITOR;
85 +
86 + if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
87 + switch (rx->sdata->vif.type) {
88 + case NL80211_IFTYPE_AP_VLAN:
89 + if (!rx->sdata->u.vlan.sta)
90 + return RX_DROP_UNUSABLE;
91 + break;
92 + case NL80211_IFTYPE_STATION:
93 + if (!rx->sdata->u.mgd.use_4addr)
94 + return RX_DROP_UNUSABLE;
95 + break;
96 + default:
97 + return RX_DROP_UNUSABLE;
98 + }
99 + }
100 +
101 + if (is_multicast_ether_addr(hdr->addr1))
102 + return RX_DROP_UNUSABLE;
103 +
104 + return __ieee80211_rx_h_amsdu(rx);
105 +}
106 +
107 #ifdef CPTCFG_MAC80211_MESH
108 static ieee80211_rx_result
109 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
110 @@ -3899,6 +3912,7 @@ static bool ieee80211_invoke_fast_rx(str
111 u8 sa[ETH_ALEN];
112 } addrs __aligned(2);
113 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
114 + int res;
115
116 if (fast_rx->uses_rss)
117 stats = this_cpu_ptr(sta->pcpu_rx_stats);
118 @@ -3920,10 +3934,6 @@ static bool ieee80211_invoke_fast_rx(str
119 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
120 return false;
121
122 - /* we don't deal with A-MSDU deaggregation here */
123 - if (status->rx_flags & IEEE80211_RX_AMSDU)
124 - return false;
125 -
126 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
127 return false;
128
129 @@ -3951,25 +3961,31 @@ static bool ieee80211_invoke_fast_rx(str
130 * and strip the IV/MIC if necessary
131 */
132 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
133 + if (status->rx_flags & IEEE80211_RX_AMSDU)
134 + return false;
135 +
136 /* GCMP header length is the same */
137 snap_offs += IEEE80211_CCMP_HDR_LEN;
138 }
139
140 - if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
141 - goto drop;
142 - payload = (void *)(skb->data + snap_offs);
143 + if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
144 + if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
145 + goto drop;
146
147 - if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
148 - return false;
149 + payload = (void *)(skb->data + snap_offs);
150
151 - /* Don't handle these here since they require special code.
152 - * Accept AARP and IPX even though they should come with a
153 - * bridge-tunnel header - but if we get them this way then
154 - * there's little point in discarding them.
155 - */
156 - if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
157 - payload->proto == fast_rx->control_port_protocol))
158 - return false;
159 + if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
160 + return false;
161 +
162 + /* Don't handle these here since they require special code.
163 + * Accept AARP and IPX even though they should come with a
164 + * bridge-tunnel header - but if we get them this way then
165 + * there's little point in discarding them.
166 + */
167 + if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
168 + payload->proto == fast_rx->control_port_protocol))
169 + return false;
170 + }
171
172 /* after this point, don't punt to the slowpath! */
173
174 @@ -3983,12 +3999,6 @@ static bool ieee80211_invoke_fast_rx(str
175 }
176
177 /* statistics part of ieee80211_rx_h_sta_process() */
178 - stats->last_rx = jiffies;
179 - stats->last_rate = sta_stats_encode_rate(status);
180 -
181 - stats->fragments++;
182 - stats->packets++;
183 -
184 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
185 stats->last_signal = status->signal;
186 if (!fast_rx->uses_rss)
187 @@ -4017,6 +4027,20 @@ static bool ieee80211_invoke_fast_rx(str
188 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
189 goto drop;
190
191 + if (status->rx_flags & IEEE80211_RX_AMSDU) {
192 + res = __ieee80211_rx_h_amsdu(rx);
193 + if (res != RX_QUEUED)
194 + goto drop;
195 +
196 + return true;
197 + }
198 +
199 + stats->last_rx = jiffies;
200 + stats->last_rate = sta_stats_encode_rate(status);
201 +
202 + stats->fragments++;
203 + stats->packets++;
204 +
205 /* do the header conversion - first grab the addresses */
206 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
207 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);