abca7aac9e92060952bc9d9f7fc5d883f45f6982
[openwrt/staging/neocturne.git] /
1 From af6d8265c47e46881b80c6b073f53c8c4af52d28 Mon Sep 17 00:00:00 2001
2 From: Sergey Ryazanov <ryazanov.s.a@gmail.com>
3 Date: Mon, 16 May 2022 13:26:00 +0300
4 Subject: ath10k: add encapsulation offloading support
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Frame encapsulation from Ethernet into the IEEE 802.11 frame format
10 takes a considerable host CPU time on the xmit path. The firmware is
11 able to do this operation for us, so enable encapsulation offloading for
12 AP and Sta interface types to improve overall system performance.
13
14 The driver is almost ready for encapsulation offloading support. There
15 are only a few places where the driver assumes the frame format is IEEE
16 802.11 that need to be fixed.
17
18 Encapsulation offloading is currently disabled by default and the driver
19 utilizes mac80211 encapsulation support. To activate offloading, the
20 frame_mode=2 parameter should be passed during module loading.
21
22 On a QCA9563+QCA9888-based access point in bridged mode, encapsulation
23 offloading increases TCP 16-streams DL throughput from 365 to 396 mbps
24 (+8%) and UDP DL throughput from 436 to 483 mbps (+11%).
25
26 Tested-on: QCA9888 hw2.0 PCI 10.4-3.9.0.2-00131
27 Tested-on: QCA6174 hw3.2 PCI WLAN.RM.4.4.1-00157-QCARMSWPZ-1
28 Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
29 Tested-by: Oldřich Jedlička <oldium.pro@gmail.com> # TP-Link Archer C7 v4 & v5 (QCA9563 + QCA9880)
30 Tested-by: Edward Matijevic <motolav@gmail.com> # TP-Link Archer C2600 (IPQ8064 + QCA9980 10.4.1.00030-1)
31 Tested-by: Edward Matijevic <motolav@gmail.com> # QCA9377 PCI in Sta mode
32 Tested-by: Zhijun You <hujy652@gmail.com> # NETGEAR R7800 (QCA9984 10.4-3.9.0.2-00159)
33 Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
34 Link: https://lore.kernel.org/r/20220516032519.29831-5-ryazanov.s.a@gmail.com
35 ---
36 drivers/net/wireless/ath/ath10k/core.c | 2 +-
37 drivers/net/wireless/ath/ath10k/mac.c | 67 +++++++++++++++++++++++++++-------
38 2 files changed, 55 insertions(+), 14 deletions(-)
39
40 --- a/drivers/net/wireless/ath/ath10k/core.c
41 +++ b/drivers/net/wireless/ath/ath10k/core.c
42 @@ -54,7 +54,7 @@ MODULE_PARM_DESC(uart_print, "Uart targe
43 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
44 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
45 MODULE_PARM_DESC(frame_mode,
46 - "Datapath frame mode (0: raw, 1: native wifi (default))");
47 + "Datapath frame mode (0: raw, 1: native wifi (default), 2: ethernet)");
48 MODULE_PARM_DESC(coredump_mask, "Bitfield of what to include in firmware crash file");
49 MODULE_PARM_DESC(fw_diag_log, "Diag based fw log debugging");
50
51 --- a/drivers/net/wireless/ath/ath10k/mac.c
52 +++ b/drivers/net/wireless/ath/ath10k/mac.c
53 @@ -3710,6 +3710,9 @@ ath10k_mac_tx_h_get_txmode(struct ath10k
54 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
55 __le16 fc = hdr->frame_control;
56
57 + if (IEEE80211_SKB_CB(skb)->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
58 + return ATH10K_HW_TXRX_ETHERNET;
59 +
60 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
61 return ATH10K_HW_TXRX_RAW;
62
63 @@ -3870,6 +3873,12 @@ static void ath10k_mac_tx_h_fill_cb(stru
64 bool noack = false;
65
66 cb->flags = 0;
67 +
68 + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
69 + cb->flags |= ATH10K_SKB_F_QOS; /* Assume data frames are QoS */
70 + goto finish_cb_fill;
71 + }
72 +
73 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
74 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
75
76 @@ -3908,6 +3917,7 @@ static void ath10k_mac_tx_h_fill_cb(stru
77 cb->flags |= ATH10K_SKB_F_RAW_TX;
78 }
79
80 +finish_cb_fill:
81 cb->vif = vif;
82 cb->txq = txq;
83 cb->airtime_est = airtime;
84 @@ -4031,7 +4041,11 @@ static int ath10k_mac_tx(struct ath10k *
85 ath10k_tx_h_seq_no(vif, skb);
86 break;
87 case ATH10K_HW_TXRX_ETHERNET:
88 - ath10k_tx_h_8023(skb);
89 + /* Convert 802.11->802.3 header only if the frame was erlier
90 + * encapsulated to 802.11 by mac80211. Otherwise pass it as is.
91 + */
92 + if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
93 + ath10k_tx_h_8023(skb);
94 break;
95 case ATH10K_HW_TXRX_RAW:
96 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) &&
97 @@ -4643,12 +4657,10 @@ static void ath10k_mac_op_tx(struct ieee
98 struct ieee80211_vif *vif = info->control.vif;
99 struct ieee80211_sta *sta = control->sta;
100 struct ieee80211_txq *txq = NULL;
101 - struct ieee80211_hdr *hdr = (void *)skb->data;
102 enum ath10k_hw_txrx_mode txmode;
103 enum ath10k_mac_tx_path txpath;
104 bool is_htt;
105 bool is_mgmt;
106 - bool is_presp;
107 int ret;
108 u16 airtime;
109
110 @@ -4662,8 +4674,14 @@ static void ath10k_mac_op_tx(struct ieee
111 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
112
113 if (is_htt) {
114 + bool is_presp = false;
115 +
116 spin_lock_bh(&ar->htt.tx_lock);
117 - is_presp = ieee80211_is_probe_resp(hdr->frame_control);
118 + if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
119 + struct ieee80211_hdr *hdr = (void *)skb->data;
120 +
121 + is_presp = ieee80211_is_probe_resp(hdr->frame_control);
122 + }
123
124 ret = ath10k_htt_tx_inc_pending(htt);
125 if (ret) {
126 @@ -5463,6 +5481,30 @@ static int ath10k_mac_set_txbf_conf(stru
127 ar->wmi.vdev_param->txbf, value);
128 }
129
130 +static void ath10k_update_vif_offload(struct ieee80211_hw *hw,
131 + struct ieee80211_vif *vif)
132 +{
133 + struct ath10k_vif *arvif = (void *)vif->drv_priv;
134 + struct ath10k *ar = hw->priv;
135 + u32 vdev_param;
136 + int ret;
137 +
138 + if (ath10k_frame_mode != ATH10K_HW_TXRX_ETHERNET ||
139 + ar->wmi.vdev_param->tx_encap_type == WMI_VDEV_PARAM_UNSUPPORTED ||
140 + (vif->type != NL80211_IFTYPE_STATION &&
141 + vif->type != NL80211_IFTYPE_AP))
142 + vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
143 +
144 + vdev_param = ar->wmi.vdev_param->tx_encap_type;
145 + ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
146 + ATH10K_HW_TXRX_NATIVE_WIFI);
147 + /* 10.X firmware does not support this VDEV parameter. Do not warn */
148 + if (ret && ret != -EOPNOTSUPP) {
149 + ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
150 + arvif->vdev_id, ret);
151 + }
152 +}
153 +
154 /*
155 * TODO:
156 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
157 @@ -5672,15 +5714,7 @@ static int ath10k_add_interface(struct i
158
159 arvif->def_wep_key_idx = -1;
160
161 - vdev_param = ar->wmi.vdev_param->tx_encap_type;
162 - ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
163 - ATH10K_HW_TXRX_NATIVE_WIFI);
164 - /* 10.X firmware does not support this VDEV parameter. Do not warn */
165 - if (ret && ret != -EOPNOTSUPP) {
166 - ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
167 - arvif->vdev_id, ret);
168 - goto err_vdev_delete;
169 - }
170 + ath10k_update_vif_offload(hw, vif);
171
172 /* Configuring number of spatial stream for monitor interface is causing
173 * target assert in qca9888 and qca6174.
174 @@ -9368,6 +9402,7 @@ static const struct ieee80211_ops ath10k
175 .stop = ath10k_stop,
176 .config = ath10k_config,
177 .add_interface = ath10k_add_interface,
178 + .update_vif_offload = ath10k_update_vif_offload,
179 .remove_interface = ath10k_remove_interface,
180 .configure_filter = ath10k_configure_filter,
181 .bss_info_changed = ath10k_bss_info_changed,
182 @@ -10037,6 +10072,12 @@ int ath10k_mac_register(struct ath10k *a
183 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
184 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
185
186 + if (ath10k_frame_mode == ATH10K_HW_TXRX_ETHERNET) {
187 + if (ar->wmi.vdev_param->tx_encap_type !=
188 + WMI_VDEV_PARAM_UNSUPPORTED)
189 + ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
190 + }
191 +
192 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
193 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
194 ar->hw->wiphy->max_remain_on_channel_duration = 5000;