a9352ce3abf60d0c838c862d39d189a03ddfa5de
[openwrt/staging/mkresin.git] / package / kernel / mac80211 / patches / subsys / 316-mac80211-enable-QoS-support-for-nl80211-ctrl-port.patch
1 From: Markus Theil <markus.theil@tu-ilmenau.de>
2 Date: Sat, 6 Feb 2021 12:51:12 +0100
3 Subject: [PATCH] mac80211: enable QoS support for nl80211 ctrl port
4
5 This patch unifies sending control port frames
6 over nl80211 and AF_PACKET sockets a little more.
7
8 Before this patch, EAPOL frames got QoS prioritization
9 only when using AF_PACKET sockets.
10
11 __ieee80211_select_queue only selects a QoS-enabled queue
12 for control port frames, when the control port protocol
13 is set correctly on the skb. For the AF_PACKET path this
14 works, but the nl80211 path used ETH_P_802_3.
15
16 Another check for injected frames in wme.c then prevented
17 the QoS TID to be copied in the frame.
18
19 In order to fix this, get rid of the frame injection marking
20 for nl80211 ctrl port and set the correct ethernet protocol.
21
22 Please note:
23 An erlier version of this path tried to prevent
24 frame aggregation for control port frames in order to speed up
25 the initial connection setup a little. This seemed to cause
26 issues on my older Intel dvm-based hardware, and was therefore
27 removed again. Future commits which try to reintroduce this
28 have to check carefully how hw behaves with aggregated and
29 non-aggregated traffic for the same TID.
30 My NIC: Intel(R) Centrino(R) Ultimate-N 6300 AGN, REV=0x74
31
32 Reported-by: kernel test robot <lkp@intel.com>
33 Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de>
34 Link: https://lore.kernel.org/r/20210206115112.567881-1-markus.theil@tu-ilmenau.de
35 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
36 ---
37
38 --- a/net/mac80211/status.c
39 +++ b/net/mac80211/status.c
40 @@ -628,16 +628,12 @@ static void ieee80211_report_ack_skb(str
41 u64 cookie = IEEE80211_SKB_CB(skb)->ack.cookie;
42 struct ieee80211_sub_if_data *sdata;
43 struct ieee80211_hdr *hdr = (void *)skb->data;
44 - __be16 ethertype = 0;
45 -
46 - if (skb->len >= ETH_HLEN && skb->protocol == cpu_to_be16(ETH_P_802_3))
47 - skb_copy_bits(skb, 2 * ETH_ALEN, &ethertype, ETH_TLEN);
48
49 rcu_read_lock();
50 sdata = ieee80211_sdata_from_skb(local, skb);
51 if (sdata) {
52 - if (ethertype == sdata->control_port_protocol ||
53 - ethertype == cpu_to_be16(ETH_P_PREAUTH))
54 + if (skb->protocol == sdata->control_port_protocol ||
55 + skb->protocol == cpu_to_be16(ETH_P_PREAUTH))
56 cfg80211_control_port_tx_status(&sdata->wdev,
57 cookie,
58 skb->data,
59 --- a/net/mac80211/tx.c
60 +++ b/net/mac80211/tx.c
61 @@ -1182,9 +1182,7 @@ ieee80211_tx_prepare(struct ieee80211_su
62 tx->sta = rcu_dereference(sdata->u.vlan.sta);
63 if (!tx->sta && sdata->wdev.use_4addr)
64 return TX_DROP;
65 - } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX |
66 - IEEE80211_TX_CTL_INJECTED) ||
67 - tx->sdata->control_port_protocol == tx->skb->protocol) {
68 + } else if (tx->sdata->control_port_protocol == tx->skb->protocol) {
69 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
70 }
71 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
72 @@ -5393,6 +5391,7 @@ int ieee80211_tx_control_port(struct wip
73 {
74 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
75 struct ieee80211_local *local = sdata->local;
76 + struct sta_info *sta;
77 struct sk_buff *skb;
78 struct ethhdr *ehdr;
79 u32 ctrl_flags = 0;
80 @@ -5415,8 +5414,7 @@ int ieee80211_tx_control_port(struct wip
81 if (cookie)
82 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
83
84 - flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX |
85 - IEEE80211_TX_CTL_INJECTED;
86 + flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX;
87
88 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
89 sizeof(struct ethhdr) + len);
90 @@ -5433,10 +5431,25 @@ int ieee80211_tx_control_port(struct wip
91 ehdr->h_proto = proto;
92
93 skb->dev = dev;
94 - skb->protocol = htons(ETH_P_802_3);
95 + skb->protocol = proto;
96 skb_reset_network_header(skb);
97 skb_reset_mac_header(skb);
98
99 + /* update QoS header to prioritize control port frames if possible,
100 + * priorization also happens for control port frames send over
101 + * AF_PACKET
102 + */
103 + rcu_read_lock();
104 +
105 + if (ieee80211_lookup_ra_sta(sdata, skb, &sta) == 0 && !IS_ERR(sta)) {
106 + u16 queue = __ieee80211_select_queue(sdata, sta, skb);
107 +
108 + skb_set_queue_mapping(skb, queue);
109 + skb_get_hash(skb);
110 + }
111 +
112 + rcu_read_unlock();
113 +
114 /* mutex lock is only needed for incrementing the cookie counter */
115 mutex_lock(&local->mtx);
116