406165ab9ca2b21637953d02cd1e8f922f6edf99
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / ath / 972-ath10k_fix-crash-due-to-wrong-handling-of-peer_bw_rxnss_override-parameter.patch
1 From: Sebastian Gottschall <s.gottschall@dd-wrt.com>
2
3 current handling of peer_bw_rxnss_override parameter is based on guessing the VHT160/8080 capability by rx rate. this is wrong and may lead
4 to a non initialized peer_bw_rxnss_override parameter which is required since VHT160 operation mode only supports 2x2 chainmasks in addition the original code
5 initialized the parameter with wrong masked values.
6 This patch uses the peer phymode and peer nss information for correct initialisation of the peer_bw_rxnss_override parameter.
7 if this peer information is not available, we initialize the parameter by minimum nss which is suggested by QCA as temporary workaround according
8 to the QCA sourcecodes.
9
10 Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
11
12 v2: remove debug messages
13 v3: apply some cosmetics, update documentation
14 v4: fix compile warning and truncate nss to maximum of 2x2 since current chipsets only support 2x2 at vht160
15 v5: handle maximum nss for chipsets supportig vht160 with 1x1 only
16 v7: use more simple code variant and take care about hw/sw chainmask configuration
17 v8: fix some code style issues
18 v9: use SM/MS macros from code.h to simplify shift/mask handling
19 ---
20 drivers/net/wireless/ath/ath10k/mac.c | 54 +++++++++++++++++++--------
21 drivers/net/wireless/ath/ath10k/wmi.c | 7 +---
22 drivers/net/wireless/ath/ath10k/wmi.h | 14 ++++++-
23 3 files changed, 52 insertions(+), 23 deletions(-)
24 --- a/drivers/net/wireless/ath/ath10k/mac.c
25 +++ b/drivers/net/wireless/ath/ath10k/mac.c
26 @@ -2473,7 +2473,7 @@ static void ath10k_peer_assoc_h_vht(stru
27 const u16 *vht_mcs_mask;
28 u8 ampdu_factor;
29 u8 max_nss, vht_mcs;
30 - int i;
31 + int i, nss160;
32
33 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
34 return;
35 @@ -2533,23 +2533,45 @@ static void ath10k_peer_assoc_h_vht(stru
36 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
37 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
38 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
39 + arg->peer_bw_rxnss_override = 0;
40 + nss160 = 1; /* 1x1 default config for VHT160 */
41
42 - ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
43 - sta->addr, arg->peer_max_mpdu, arg->peer_flags);
44 + /* only local 4x4 configuration do support 2x2 for VHT160,
45 + * everything else must use 1x1
46 + */
47
48 - if (arg->peer_vht_rates.rx_max_rate &&
49 - (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
50 - switch (arg->peer_vht_rates.rx_max_rate) {
51 - case 1560:
52 - /* Must be 2x2 at 160Mhz is all it can do. */
53 - arg->peer_bw_rxnss_override = 2;
54 - break;
55 - case 780:
56 - /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
57 - arg->peer_bw_rxnss_override = 1;
58 - break;
59 - }
60 + if (ar->cfg_rx_chainmask == 15)
61 + nss160 = arg->peer_num_spatial_streams <= 2 ? 1 : 2;
62 +
63 + /* if peer provides 1x1 nss160 information using max rate
64 + * vht information, we reduce local nss160 to 1x1.
65 + * consider that it has been observed that some client
66 + * devices provide zero here, no matter which transmission
67 + * rate is possible. in that case the local nss configuration
68 + * will be used at maxmimum configuration possible. (see above)
69 + */
70 +
71 + if (arg->peer_vht_rates.rx_max_rate == 780)
72 + nss160 = 1;
73 +
74 + /* in case if peer is connected with vht160 or vht80+80,
75 + * we need to properly adjust rxnss parameters otherwise
76 + * firmware will raise a assert
77 + */
78 + switch (arg->peer_phymode) {
79 + case MODE_11AC_VHT80_80:
80 + arg->peer_bw_rxnss_override = BW_NSS_FWCONF_80_80(nss160);
81 + /* fall through */
82 + case MODE_11AC_VHT160:
83 + arg->peer_bw_rxnss_override |= BW_NSS_FWCONF_160(nss160);
84 + break;
85 + default:
86 + break;
87 }
88 +
89 + ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x peer_bw_rxnss_override 0x%x\n",
90 + sta->addr, arg->peer_max_mpdu, arg->peer_flags,
91 + arg->peer_bw_rxnss_override);
92 }
93
94 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
95 @@ -2701,9 +2723,9 @@ static int ath10k_peer_assoc_prepare(str
96 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
97 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
98 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
99 + ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
100 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
101 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
102 - ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
103
104 return 0;
105 }
106 --- a/drivers/net/wireless/ath/ath10k/wmi.c
107 +++ b/drivers/net/wireless/ath/ath10k/wmi.c
108 @@ -7357,12 +7357,7 @@ ath10k_wmi_peer_assoc_fill_10_4(struct a
109 struct wmi_10_4_peer_assoc_complete_cmd *cmd = buf;
110
111 ath10k_wmi_peer_assoc_fill_10_2(ar, buf, arg);
112 - if (arg->peer_bw_rxnss_override)
113 - cmd->peer_bw_rxnss_override =
114 - __cpu_to_le32((arg->peer_bw_rxnss_override - 1) |
115 - BIT(PEER_BW_RXNSS_OVERRIDE_OFFSET));
116 - else
117 - cmd->peer_bw_rxnss_override = 0;
118 + cmd->peer_bw_rxnss_override = __cpu_to_le32(arg->peer_bw_rxnss_override);
119 }
120
121 static int
122 --- a/drivers/net/wireless/ath/ath10k/wmi.h
123 +++ b/drivers/net/wireless/ath/ath10k/wmi.h
124 @@ -6357,7 +6357,19 @@ struct wmi_10_2_peer_assoc_complete_cmd
125 __le32 info0; /* WMI_PEER_ASSOC_INFO0_ */
126 } __packed;
127
128 -#define PEER_BW_RXNSS_OVERRIDE_OFFSET 31
129 +#define BW_NSS_FWCONF_MAP_ENABLE BIT(31)
130 +#define BW_NSS_FWCONF_MAP_160MHZ_LSB (0)
131 +#define BW_NSS_FWCONF_MAP_160MHZ_MASK (0x00000007)
132 +#define BW_NSS_FWCONF_MAP_80_80MHZ_LSB (3)
133 +#define BW_NSS_FWCONF_MAP_80_80MHZ_MASK (0x00000038)
134 +#define BW_NSS_FWCONF_MAP_MASK (0x0000003F)
135 +
136 +#define GET_BW_NSS_FWCONF_160(x) (MS(x, BW_NSS_FWCONF_MAP_160MHZ) + 1)
137 +#define GET_BW_NSS_FWCONF_80_80(x) (MS(x, BW_NSS_FWCONF_MAP_80_80MHZ) + 1)
138 +
139 +/* Values defined to set 160 MHz Bandwidth NSS Mapping into FW*/
140 +#define BW_NSS_FWCONF_160(x) (BW_NSS_FWCONF_MAP_ENABLE | SM(x - 1, BW_NSS_FWCONF_MAP_160MHZ))
141 +#define BW_NSS_FWCONF_80_80(x) (BW_NSS_FWCONF_MAP_ENABLE | SM(x - 1, BW_NSS_FWCONF_MAP_80_80MHZ))
142
143 struct wmi_10_4_peer_assoc_complete_cmd {
144 struct wmi_10_2_peer_assoc_complete_cmd cmd;