Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | a8d7606 | 2012-01-07 20:46:42 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 14 | * The full GNU General Public License is included in this distribution in the |
| 15 | * file called LICENSE. |
| 16 | * |
| 17 | * Contact Information: |
| 18 | * wlanfae <wlanfae@realtek.com> |
| 19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 20 | * Hsinchu 300, Taiwan. |
| 21 | * |
| 22 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 23 | * |
| 24 | *****************************************************************************/ |
| 25 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 26 | #include "wifi.h" |
| 27 | #include "rc.h" |
| 28 | #include "base.h" |
| 29 | #include "efuse.h" |
| 30 | #include "cam.h" |
| 31 | #include "ps.h" |
| 32 | #include "regd.h" |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 33 | #include "pci.h" |
Larry Finger | d273bb2 | 2012-01-27 13:59:25 -0600 | [diff] [blame] | 34 | #include <linux/ip.h> |
| 35 | #include <linux/module.h> |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 36 | #include <linux/udp.h> |
Larry Finger | d273bb2 | 2012-01-27 13:59:25 -0600 | [diff] [blame] | 37 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 38 | /* |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 39 | *NOTICE!!!: This file will be very big, we should |
| 40 | *keep it clear under following roles: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 41 | * |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 42 | *This file include following parts, so, if you add new |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 43 | *functions into this file, please check which part it |
| 44 | *should includes. or check if you should add new part |
| 45 | *for this file: |
| 46 | * |
| 47 | *1) mac80211 init functions |
| 48 | *2) tx information functions |
| 49 | *3) functions called by core.c |
| 50 | *4) wq & timer callback functions |
| 51 | *5) frame process functions |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 52 | *6) IOT functions |
| 53 | *7) sysfs functions |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 54 | *8) vif functions |
| 55 | *9) ... |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 56 | */ |
| 57 | |
| 58 | /********************************************************* |
| 59 | * |
| 60 | * mac80211 init functions |
| 61 | * |
| 62 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 63 | static struct ieee80211_channel rtl_channeltable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 64 | {.center_freq = 2412, .hw_value = 1,}, |
| 65 | {.center_freq = 2417, .hw_value = 2,}, |
| 66 | {.center_freq = 2422, .hw_value = 3,}, |
| 67 | {.center_freq = 2427, .hw_value = 4,}, |
| 68 | {.center_freq = 2432, .hw_value = 5,}, |
| 69 | {.center_freq = 2437, .hw_value = 6,}, |
| 70 | {.center_freq = 2442, .hw_value = 7,}, |
| 71 | {.center_freq = 2447, .hw_value = 8,}, |
| 72 | {.center_freq = 2452, .hw_value = 9,}, |
| 73 | {.center_freq = 2457, .hw_value = 10,}, |
| 74 | {.center_freq = 2462, .hw_value = 11,}, |
| 75 | {.center_freq = 2467, .hw_value = 12,}, |
| 76 | {.center_freq = 2472, .hw_value = 13,}, |
| 77 | {.center_freq = 2484, .hw_value = 14,}, |
| 78 | }; |
| 79 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 80 | static struct ieee80211_channel rtl_channeltable_5g[] = { |
| 81 | {.center_freq = 5180, .hw_value = 36,}, |
| 82 | {.center_freq = 5200, .hw_value = 40,}, |
| 83 | {.center_freq = 5220, .hw_value = 44,}, |
| 84 | {.center_freq = 5240, .hw_value = 48,}, |
| 85 | {.center_freq = 5260, .hw_value = 52,}, |
| 86 | {.center_freq = 5280, .hw_value = 56,}, |
| 87 | {.center_freq = 5300, .hw_value = 60,}, |
| 88 | {.center_freq = 5320, .hw_value = 64,}, |
| 89 | {.center_freq = 5500, .hw_value = 100,}, |
| 90 | {.center_freq = 5520, .hw_value = 104,}, |
| 91 | {.center_freq = 5540, .hw_value = 108,}, |
| 92 | {.center_freq = 5560, .hw_value = 112,}, |
| 93 | {.center_freq = 5580, .hw_value = 116,}, |
| 94 | {.center_freq = 5600, .hw_value = 120,}, |
| 95 | {.center_freq = 5620, .hw_value = 124,}, |
| 96 | {.center_freq = 5640, .hw_value = 128,}, |
| 97 | {.center_freq = 5660, .hw_value = 132,}, |
| 98 | {.center_freq = 5680, .hw_value = 136,}, |
| 99 | {.center_freq = 5700, .hw_value = 140,}, |
| 100 | {.center_freq = 5745, .hw_value = 149,}, |
| 101 | {.center_freq = 5765, .hw_value = 153,}, |
| 102 | {.center_freq = 5785, .hw_value = 157,}, |
| 103 | {.center_freq = 5805, .hw_value = 161,}, |
| 104 | {.center_freq = 5825, .hw_value = 165,}, |
| 105 | }; |
| 106 | |
| 107 | static struct ieee80211_rate rtl_ratetable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 108 | {.bitrate = 10, .hw_value = 0x00,}, |
| 109 | {.bitrate = 20, .hw_value = 0x01,}, |
| 110 | {.bitrate = 55, .hw_value = 0x02,}, |
| 111 | {.bitrate = 110, .hw_value = 0x03,}, |
| 112 | {.bitrate = 60, .hw_value = 0x04,}, |
| 113 | {.bitrate = 90, .hw_value = 0x05,}, |
| 114 | {.bitrate = 120, .hw_value = 0x06,}, |
| 115 | {.bitrate = 180, .hw_value = 0x07,}, |
| 116 | {.bitrate = 240, .hw_value = 0x08,}, |
| 117 | {.bitrate = 360, .hw_value = 0x09,}, |
| 118 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 119 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 120 | }; |
| 121 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 122 | static struct ieee80211_rate rtl_ratetable_5g[] = { |
| 123 | {.bitrate = 60, .hw_value = 0x04,}, |
| 124 | {.bitrate = 90, .hw_value = 0x05,}, |
| 125 | {.bitrate = 120, .hw_value = 0x06,}, |
| 126 | {.bitrate = 180, .hw_value = 0x07,}, |
| 127 | {.bitrate = 240, .hw_value = 0x08,}, |
| 128 | {.bitrate = 360, .hw_value = 0x09,}, |
| 129 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 130 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 131 | }; |
| 132 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 133 | static const struct ieee80211_supported_band rtl_band_2ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 134 | .band = NL80211_BAND_2GHZ, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 135 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 136 | .channels = rtl_channeltable_2g, |
| 137 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 138 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 139 | .bitrates = rtl_ratetable_2g, |
| 140 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 141 | |
| 142 | .ht_cap = {0}, |
| 143 | }; |
| 144 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 145 | static struct ieee80211_supported_band rtl_band_5ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 146 | .band = NL80211_BAND_5GHZ, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 147 | |
| 148 | .channels = rtl_channeltable_5g, |
| 149 | .n_channels = ARRAY_SIZE(rtl_channeltable_5g), |
| 150 | |
| 151 | .bitrates = rtl_ratetable_5g, |
| 152 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), |
| 153 | |
| 154 | .ht_cap = {0}, |
| 155 | }; |
| 156 | |
| 157 | static const u8 tid_to_ac[] = { |
| 158 | 2, /* IEEE80211_AC_BE */ |
| 159 | 3, /* IEEE80211_AC_BK */ |
| 160 | 3, /* IEEE80211_AC_BK */ |
| 161 | 2, /* IEEE80211_AC_BE */ |
| 162 | 1, /* IEEE80211_AC_VI */ |
| 163 | 1, /* IEEE80211_AC_VI */ |
| 164 | 0, /* IEEE80211_AC_VO */ |
| 165 | 0, /* IEEE80211_AC_VO */ |
| 166 | }; |
| 167 | |
Larry Finger | 2a00def | 2012-07-11 14:32:33 -0500 | [diff] [blame] | 168 | u8 rtl_tid_to_ac(u8 tid) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 169 | { |
| 170 | return tid_to_ac[tid]; |
| 171 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 172 | EXPORT_SYMBOL_GPL(rtl_tid_to_ac); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 173 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 174 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, |
| 175 | struct ieee80211_sta_ht_cap *ht_cap) |
| 176 | { |
| 177 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 178 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 179 | |
| 180 | ht_cap->ht_supported = true; |
| 181 | ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 182 | IEEE80211_HT_CAP_SGI_40 | |
| 183 | IEEE80211_HT_CAP_SGI_20 | |
| 184 | IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; |
| 185 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 186 | if (rtlpriv->rtlhal.disable_amsdu_8k) |
| 187 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; |
| 188 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 189 | /* |
| 190 | *Maximum length of AMPDU that the STA can receive. |
| 191 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) |
| 192 | */ |
| 193 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 194 | |
| 195 | /*Minimum MPDU start spacing , */ |
| 196 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 197 | |
| 198 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 199 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 200 | /*hw->wiphy->bands[NL80211_BAND_2GHZ] |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 201 | *base on ant_num |
| 202 | *rx_mask: RX mask |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 203 | *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 |
| 204 | *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15 |
| 205 | *if rx_ant >= 3 rx_mask[2]= 0xff; |
| 206 | *if BW_40 rx_mask[4]= 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 207 | *highest supported RX rate |
| 208 | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 209 | if (rtlpriv->dm.supp_phymode_switch) { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 210 | pr_info("Support phy mode switch\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 211 | |
| 212 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 213 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 214 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 215 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 216 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 217 | } else { |
| 218 | if (get_rf_type(rtlphy) == RF_1T2R || |
| 219 | get_rf_type(rtlphy) == RF_2T2R) { |
| 220 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 221 | "1T2R or 2T2R\n"); |
| 222 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 223 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 224 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 225 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 226 | ht_cap->mcs.rx_highest = |
| 227 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
| 228 | } else if (get_rf_type(rtlphy) == RF_1T1R) { |
| 229 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 230 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 231 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 232 | ht_cap->mcs.rx_mask[1] = 0x00; |
| 233 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 234 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 235 | ht_cap->mcs.rx_highest = |
| 236 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
| 237 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 241 | static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw, |
| 242 | struct ieee80211_sta_vht_cap *vht_cap) |
| 243 | { |
| 244 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 245 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 246 | |
Ping-Ke Shih | 1ca72c3 | 2018-01-29 11:26:33 +0800 | [diff] [blame] | 247 | if (!(rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT)) |
| 248 | return; |
| 249 | |
Ping-Ke Shih | ba3cca4 | 2018-01-19 14:45:49 +0800 | [diff] [blame] | 250 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE || |
| 251 | rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 252 | u16 mcs_map; |
| 253 | |
| 254 | vht_cap->vht_supported = true; |
| 255 | vht_cap->cap = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 256 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 257 | IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 258 | IEEE80211_VHT_CAP_TXSTBC | |
| 259 | IEEE80211_VHT_CAP_RXSTBC_1 | |
| 260 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 261 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 262 | IEEE80211_VHT_CAP_HTC_VHT | |
| 263 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | |
| 264 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | |
| 265 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | |
| 266 | 0; |
| 267 | |
| 268 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 269 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | |
| 270 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | |
| 271 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | |
| 272 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | |
| 273 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | |
| 274 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | |
| 275 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; |
| 276 | |
| 277 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 278 | vht_cap->vht_mcs.rx_highest = |
| 279 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); |
| 280 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 281 | vht_cap->vht_mcs.tx_highest = |
| 282 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); |
| 283 | } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) { |
| 284 | u16 mcs_map; |
| 285 | |
| 286 | vht_cap->vht_supported = true; |
| 287 | vht_cap->cap = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 288 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 289 | IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 290 | IEEE80211_VHT_CAP_TXSTBC | |
| 291 | IEEE80211_VHT_CAP_RXSTBC_1 | |
| 292 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 293 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 294 | IEEE80211_VHT_CAP_HTC_VHT | |
| 295 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | |
| 296 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | |
| 297 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | |
| 298 | 0; |
| 299 | |
| 300 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 301 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | |
| 302 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | |
| 303 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | |
| 304 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | |
| 305 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | |
| 306 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | |
| 307 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; |
| 308 | |
| 309 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 310 | vht_cap->vht_mcs.rx_highest = |
| 311 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); |
| 312 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 313 | vht_cap->vht_mcs.tx_highest = |
| 314 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); |
| 315 | } |
| 316 | } |
| 317 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 318 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
| 319 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 320 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 321 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 322 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 323 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 324 | struct ieee80211_supported_band *sband; |
| 325 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 326 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && |
| 327 | rtlhal->bandset == BAND_ON_BOTH) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 328 | /* 1: 2.4 G bands */ |
| 329 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 330 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 331 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 332 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 333 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 334 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 335 | sizeof(struct ieee80211_supported_band)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 336 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 337 | /* <3> init ht cap base on ant_num */ |
| 338 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 339 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 340 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 341 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 342 | |
| 343 | /* 2: 5 G bands */ |
| 344 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 345 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 346 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 347 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 348 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 349 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 350 | sizeof(struct ieee80211_supported_band)); |
| 351 | |
| 352 | /* <3> init ht cap base on ant_num */ |
| 353 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 354 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 355 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 356 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 357 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 358 | } else { |
| 359 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 360 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 361 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 362 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 363 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 364 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 365 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 366 | &rtl_band_2ghz, |
| 367 | sizeof(struct ieee80211_supported_band)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 368 | |
| 369 | /* <3> init ht cap base on ant_num */ |
| 370 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 371 | |
| 372 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 373 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 374 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 375 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 376 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 377 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 378 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 379 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 380 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 381 | &rtl_band_5ghz, |
| 382 | sizeof(struct ieee80211_supported_band)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 383 | |
| 384 | /* <3> init ht cap base on ant_num */ |
| 385 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 386 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 387 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 388 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 389 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 390 | } else { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 391 | pr_err("Err BAND %d\n", |
| 392 | rtlhal->current_bandtype); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 393 | } |
| 394 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 395 | /* <5> set hw caps */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 396 | ieee80211_hw_set(hw, SIGNAL_DBM); |
| 397 | ieee80211_hw_set(hw, RX_INCLUDES_FCS); |
| 398 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 399 | ieee80211_hw_set(hw, MFP_CAPABLE); |
| 400 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); |
Ping-Ke Shih | 5f90669 | 2018-01-18 09:26:14 +0800 | [diff] [blame] | 401 | ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); |
Ping-Ke Shih | 6942bdc | 2018-01-29 11:26:32 +0800 | [diff] [blame] | 402 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 403 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 404 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 405 | if (rtlpriv->psc.swctrl_lps) { |
| 406 | ieee80211_hw_set(hw, SUPPORTS_PS); |
| 407 | ieee80211_hw_set(hw, PS_NULLFUNC_STACK); |
| 408 | } |
Ping-Ke Shih | e332e2a2 | 2017-06-18 11:12:42 -0500 | [diff] [blame] | 409 | if (rtlpriv->psc.fwctrl_lps) { |
| 410 | ieee80211_hw_set(hw, SUPPORTS_PS); |
| 411 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); |
| 412 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 413 | hw->wiphy->interface_modes = |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 414 | BIT(NL80211_IFTYPE_AP) | |
| 415 | BIT(NL80211_IFTYPE_STATION) | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 416 | BIT(NL80211_IFTYPE_ADHOC) | |
| 417 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 418 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 419 | BIT(NL80211_IFTYPE_P2P_GO); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 420 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 421 | |
| 422 | hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 423 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 424 | hw->wiphy->rts_threshold = 2347; |
| 425 | |
| 426 | hw->queues = AC_MAX; |
| 427 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; |
| 428 | |
| 429 | /* TODO: Correct this value for our hw */ |
Souptick Joarder | 9d54619 | 2017-08-02 17:59:15 +0530 | [diff] [blame] | 430 | hw->max_listen_interval = MAX_LISTEN_INTERVAL; |
| 431 | hw->max_rate_tries = MAX_RATE_TRIES; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 432 | /* hw->max_rates = 1; */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 433 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 434 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 435 | /* wowlan is not supported by kernel if CONFIG_PM is not defined */ |
| 436 | #ifdef CONFIG_PM |
| 437 | if (rtlpriv->psc.wo_wlan_mode) { |
| 438 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET) |
| 439 | rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT; |
| 440 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) { |
| 441 | rtlpriv->wowlan.n_patterns = |
| 442 | MAX_SUPPORT_WOL_PATTERN_NUM; |
| 443 | rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE; |
| 444 | rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE; |
| 445 | } |
| 446 | hw->wiphy->wowlan = &rtlpriv->wowlan; |
| 447 | } |
| 448 | #endif |
| 449 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 450 | /* <6> mac address */ |
| 451 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { |
| 452 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); |
| 453 | } else { |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 454 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
| 455 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); |
| 456 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 457 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) |
| 461 | { |
| 462 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 463 | |
| 464 | /* <1> timer */ |
Kees Cook | 7c51d17c | 2017-10-24 02:28:29 -0700 | [diff] [blame] | 465 | timer_setup(&rtlpriv->works.watchdog_timer, |
| 466 | rtl_watch_dog_timer_callback, 0); |
| 467 | timer_setup(&rtlpriv->works.dualmac_easyconcurrent_retrytimer, |
| 468 | rtl_easy_concurrent_retrytimer_callback, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 469 | /* <2> work queue */ |
| 470 | rtlpriv->works.hw = hw; |
Kees Cook | 598a0df | 2014-10-20 14:57:08 -0700 | [diff] [blame] | 471 | rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 472 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
| 473 | (void *)rtl_watchdog_wq_callback); |
| 474 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, |
| 475 | (void *)rtl_ips_nic_off_wq_callback); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 476 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
| 477 | (void *)rtl_swlps_wq_callback); |
| 478 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, |
| 479 | (void *)rtl_swlps_rfon_wq_callback); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 480 | INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, |
| 481 | (void *)rtl_fwevt_wq_callback); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 482 | INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq, |
| 483 | (void *)rtl_c2hcmd_wq_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 484 | |
| 485 | } |
| 486 | |
| 487 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) |
| 488 | { |
| 489 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 490 | |
| 491 | del_timer_sync(&rtlpriv->works.watchdog_timer); |
| 492 | |
| 493 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); |
| 494 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 495 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 496 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 497 | cancel_delayed_work(&rtlpriv->works.fwevt_wq); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 498 | cancel_delayed_work(&rtlpriv->works.c2hcmd_wq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 499 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 500 | EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 501 | |
| 502 | void rtl_init_rfkill(struct ieee80211_hw *hw) |
| 503 | { |
| 504 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 505 | |
| 506 | bool radio_state; |
| 507 | bool blocked; |
| 508 | u8 valid = 0; |
| 509 | |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 510 | /*set init state to on */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 511 | rtlpriv->rfkill.rfkill_state = true; |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 512 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
| 513 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 514 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 515 | |
Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 516 | if (valid) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 517 | pr_info("rtlwifi: wireless switch is %s\n", |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 518 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 519 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 520 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 521 | |
| 522 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 523 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 524 | } |
| 525 | |
| 526 | wiphy_rfkill_start_polling(hw->wiphy); |
| 527 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 528 | EXPORT_SYMBOL(rtl_init_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 529 | |
| 530 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) |
| 531 | { |
| 532 | wiphy_rfkill_stop_polling(hw->wiphy); |
| 533 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 534 | EXPORT_SYMBOL_GPL(rtl_deinit_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 535 | |
| 536 | int rtl_init_core(struct ieee80211_hw *hw) |
| 537 | { |
| 538 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 539 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 540 | |
| 541 | /* <1> init mac80211 */ |
| 542 | _rtl_init_mac80211(hw); |
| 543 | rtlmac->hw = hw; |
| 544 | |
| 545 | /* <2> rate control register */ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 546 | hw->rate_control_algorithm = "rtl_rc"; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * <3> init CRDA must come after init |
| 550 | * mac80211 hw in _rtl_init_mac80211. |
| 551 | */ |
| 552 | if (rtl_regd_init(hw, rtl_reg_notifier)) { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 553 | pr_err("REGD init failed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 554 | return 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* <4> locks */ |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 558 | mutex_init(&rtlpriv->locks.conf_mutex); |
Ping-Ke Shih | a3fa366 | 2018-01-17 14:15:21 +0800 | [diff] [blame] | 559 | mutex_init(&rtlpriv->locks.ips_mutex); |
| 560 | mutex_init(&rtlpriv->locks.lps_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 561 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
| 562 | spin_lock_init(&rtlpriv->locks.h2c_lock); |
| 563 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); |
| 564 | spin_lock_init(&rtlpriv->locks.rf_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 565 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 566 | spin_lock_init(&rtlpriv->locks.entry_list_lock); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 567 | spin_lock_init(&rtlpriv->locks.c2hcmd_lock); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 568 | spin_lock_init(&rtlpriv->locks.scan_list_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 569 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 570 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 571 | spin_lock_init(&rtlpriv->locks.iqk_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 572 | /* <5> init list */ |
| 573 | INIT_LIST_HEAD(&rtlpriv->entry_list); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 574 | INIT_LIST_HEAD(&rtlpriv->scan_list.list); |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 575 | skb_queue_head_init(&rtlpriv->tx_report.queue); |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 576 | skb_queue_head_init(&rtlpriv->c2hcmd_queue); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 577 | |
| 578 | rtlmac->link_state = MAC80211_NOLINK; |
| 579 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 580 | /* <6> init deferred work */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 581 | _rtl_init_deferred_work(hw); |
| 582 | |
| 583 | return 0; |
| 584 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 585 | EXPORT_SYMBOL_GPL(rtl_init_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 586 | |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 587 | static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw); |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 588 | static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw, |
| 589 | bool timeout); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 590 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 591 | void rtl_deinit_core(struct ieee80211_hw *hw) |
| 592 | { |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 593 | rtl_c2hcmd_launcher(hw, 0); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 594 | rtl_free_entries_from_scan_list(hw); |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 595 | rtl_free_entries_from_ack_queue(hw, false); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 596 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 597 | EXPORT_SYMBOL_GPL(rtl_deinit_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 598 | |
| 599 | void rtl_init_rx_config(struct ieee80211_hw *hw) |
| 600 | { |
| 601 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 602 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 603 | |
| 604 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 605 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 606 | EXPORT_SYMBOL_GPL(rtl_init_rx_config); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 607 | |
| 608 | /********************************************************* |
| 609 | * |
| 610 | * tx information functions |
| 611 | * |
| 612 | *********************************************************/ |
| 613 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, |
| 614 | struct rtl_tcb_desc *tcb_desc, |
| 615 | struct ieee80211_tx_info *info) |
| 616 | { |
| 617 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 618 | u8 rate_flag = info->control.rates[0].flags; |
| 619 | |
| 620 | tcb_desc->use_shortpreamble = false; |
| 621 | |
| 622 | /* 1M can only use Long Preamble. 11B spec */ |
| 623 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) |
| 624 | return; |
| 625 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 626 | tcb_desc->use_shortpreamble = true; |
| 627 | |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 632 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 633 | struct rtl_tcb_desc *tcb_desc, |
| 634 | struct ieee80211_tx_info *info) |
| 635 | { |
| 636 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 637 | u8 rate_flag = info->control.rates[0].flags; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 638 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 639 | u8 sgi_80 = 0, bw_80 = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 640 | tcb_desc->use_shortgi = false; |
| 641 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 642 | if (sta == NULL) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 643 | return; |
| 644 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 645 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
| 646 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 647 | sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 648 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 649 | if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 650 | return; |
| 651 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 652 | if (!sgi_40 && !sgi_20) |
| 653 | return; |
| 654 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 655 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 656 | bw_40 = mac->bw_40; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 657 | bw_80 = mac->bw_80; |
| 658 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 659 | mac->opmode == NL80211_IFTYPE_ADHOC || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 660 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
| 661 | bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 662 | bw_80 = sta->vht_cap.vht_supported; |
| 663 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 664 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 665 | if (bw_80) { |
| 666 | if (sgi_80) |
| 667 | tcb_desc->use_shortgi = true; |
| 668 | else |
| 669 | tcb_desc->use_shortgi = false; |
| 670 | } else { |
| 671 | if (bw_40 && sgi_40) |
| 672 | tcb_desc->use_shortgi = true; |
| 673 | else if (!bw_40 && sgi_20) |
| 674 | tcb_desc->use_shortgi = true; |
| 675 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 676 | |
| 677 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) |
| 678 | tcb_desc->use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, |
| 682 | struct rtl_tcb_desc *tcb_desc, |
| 683 | struct ieee80211_tx_info *info) |
| 684 | { |
| 685 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 686 | u8 rate_flag = info->control.rates[0].flags; |
| 687 | |
| 688 | /* Common Settings */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 689 | tcb_desc->rts_stbc = false; |
| 690 | tcb_desc->cts_enable = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 691 | tcb_desc->rts_sc = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 692 | tcb_desc->rts_bw = false; |
| 693 | tcb_desc->rts_use_shortpreamble = false; |
| 694 | tcb_desc->rts_use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 695 | |
| 696 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 697 | /* Use CTS-to-SELF in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 698 | tcb_desc->rts_enable = true; |
| 699 | tcb_desc->cts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 700 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 701 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 702 | /* Use RTS-CTS in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 703 | tcb_desc->rts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 704 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 705 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 706 | } |
| 707 | |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 708 | u8 rtl_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index, |
| 709 | enum wireless_mode wirelessmode) |
| 710 | { |
| 711 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 712 | struct rtl_phy *rtlphy = &rtlpriv->phy; |
| 713 | u8 ret = 0; |
| 714 | |
| 715 | switch (rate_index) { |
| 716 | case RATR_INX_WIRELESS_NGB: |
| 717 | if (rtlphy->rf_type == RF_1T1R) |
| 718 | ret = RATEID_IDX_BGN_40M_1SS; |
| 719 | else |
| 720 | ret = RATEID_IDX_BGN_40M_2SS; |
| 721 | ; break; |
| 722 | case RATR_INX_WIRELESS_N: |
| 723 | case RATR_INX_WIRELESS_NG: |
| 724 | if (rtlphy->rf_type == RF_1T1R) |
| 725 | ret = RATEID_IDX_GN_N1SS; |
| 726 | else |
| 727 | ret = RATEID_IDX_GN_N2SS; |
| 728 | ; break; |
| 729 | case RATR_INX_WIRELESS_NB: |
| 730 | if (rtlphy->rf_type == RF_1T1R) |
| 731 | ret = RATEID_IDX_BGN_20M_1SS_BN; |
| 732 | else |
| 733 | ret = RATEID_IDX_BGN_20M_2SS_BN; |
| 734 | ; break; |
| 735 | case RATR_INX_WIRELESS_GB: |
| 736 | ret = RATEID_IDX_BG; |
| 737 | break; |
| 738 | case RATR_INX_WIRELESS_G: |
| 739 | ret = RATEID_IDX_G; |
| 740 | break; |
| 741 | case RATR_INX_WIRELESS_B: |
| 742 | ret = RATEID_IDX_B; |
| 743 | break; |
| 744 | case RATR_INX_WIRELESS_MC: |
| 745 | if (wirelessmode == WIRELESS_MODE_B || |
| 746 | wirelessmode == WIRELESS_MODE_G || |
| 747 | wirelessmode == WIRELESS_MODE_N_24G || |
| 748 | wirelessmode == WIRELESS_MODE_AC_24G) |
| 749 | ret = RATEID_IDX_BG; |
| 750 | else |
| 751 | ret = RATEID_IDX_G; |
| 752 | break; |
| 753 | case RATR_INX_WIRELESS_AC_5N: |
| 754 | if (rtlphy->rf_type == RF_1T1R) |
| 755 | ret = RATEID_IDX_VHT_1SS; |
| 756 | else |
| 757 | ret = RATEID_IDX_VHT_2SS; |
| 758 | break; |
| 759 | case RATR_INX_WIRELESS_AC_24N: |
| 760 | if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) { |
| 761 | if (rtlphy->rf_type == RF_1T1R) |
| 762 | ret = RATEID_IDX_VHT_1SS; |
| 763 | else |
| 764 | ret = RATEID_IDX_VHT_2SS; |
| 765 | } else { |
| 766 | if (rtlphy->rf_type == RF_1T1R) |
| 767 | ret = RATEID_IDX_MIX1; |
| 768 | else |
| 769 | ret = RATEID_IDX_MIX2; |
| 770 | } |
| 771 | break; |
| 772 | default: |
| 773 | ret = RATEID_IDX_BGN_40M_2SS; |
| 774 | break; |
| 775 | } |
| 776 | return ret; |
| 777 | } |
| 778 | EXPORT_SYMBOL(rtl_mrate_idx_to_arfr_id); |
| 779 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 780 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 781 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 782 | struct rtl_tcb_desc *tcb_desc) |
| 783 | { |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 784 | #define SET_RATE_ID(rate_id) \ |
| 785 | ({typeof(rate_id) _id = rate_id; \ |
| 786 | ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \ |
| 787 | rtl_mrate_idx_to_arfr_id(hw, _id, \ |
| 788 | (sta_entry ? sta_entry->wireless_mode : \ |
| 789 | WIRELESS_MODE_G)) : \ |
| 790 | _id); }) |
| 791 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 792 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 793 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 794 | struct rtl_sta_info *sta_entry = NULL; |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 795 | u8 ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 796 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 797 | if (sta) { |
| 798 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 799 | ratr_index = sta_entry->ratr_index; |
| 800 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 801 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 802 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 803 | tcb_desc->ratr_index = 0; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 804 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 805 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 806 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 807 | tcb_desc->hw_rate = |
| 808 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; |
| 809 | tcb_desc->use_driver_rate = 1; |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 810 | tcb_desc->ratr_index = |
| 811 | SET_RATE_ID(RATR_INX_WIRELESS_MC); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 812 | } else { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 813 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 814 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 815 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
| 816 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 820 | if (rtlpriv->dm.useramask) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 821 | tcb_desc->ratr_index = ratr_index; |
| 822 | /* TODO we will differentiate adhoc and station future */ |
| 823 | if (mac->opmode == NL80211_IFTYPE_STATION || |
| 824 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 825 | tcb_desc->mac_id = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 826 | |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 827 | if (sta && |
| 828 | (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID)) |
| 829 | ; /* use sta_entry->ratr_index */ |
| 830 | else if (mac->mode == WIRELESS_MODE_AC_5G) |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 831 | tcb_desc->ratr_index = |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 832 | SET_RATE_ID(RATR_INX_WIRELESS_AC_5N); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 833 | else if (mac->mode == WIRELESS_MODE_AC_24G) |
| 834 | tcb_desc->ratr_index = |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 835 | SET_RATE_ID(RATR_INX_WIRELESS_AC_24N); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 836 | else if (mac->mode == WIRELESS_MODE_N_24G) |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 837 | tcb_desc->ratr_index = |
| 838 | SET_RATE_ID(RATR_INX_WIRELESS_NGB); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 839 | else if (mac->mode == WIRELESS_MODE_N_5G) |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 840 | tcb_desc->ratr_index = |
| 841 | SET_RATE_ID(RATR_INX_WIRELESS_NG); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 842 | else if (mac->mode & WIRELESS_MODE_G) |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 843 | tcb_desc->ratr_index = |
| 844 | SET_RATE_ID(RATR_INX_WIRELESS_GB); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 845 | else if (mac->mode & WIRELESS_MODE_B) |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 846 | tcb_desc->ratr_index = |
| 847 | SET_RATE_ID(RATR_INX_WIRELESS_B); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 848 | else if (mac->mode & WIRELESS_MODE_A) |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 849 | tcb_desc->ratr_index = |
| 850 | SET_RATE_ID(RATR_INX_WIRELESS_G); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 851 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 852 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 853 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 854 | if (NULL != sta) { |
| 855 | if (sta->aid > 0) |
| 856 | tcb_desc->mac_id = sta->aid + 1; |
| 857 | else |
| 858 | tcb_desc->mac_id = 1; |
| 859 | } else { |
| 860 | tcb_desc->mac_id = 0; |
| 861 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 862 | } |
| 863 | } |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 864 | #undef SET_RATE_ID |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 868 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 869 | struct rtl_tcb_desc *tcb_desc) |
| 870 | { |
| 871 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 872 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 873 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 874 | tcb_desc->packet_bw = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 875 | if (!sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 876 | return; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 877 | if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 878 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 879 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 880 | if (!(sta->ht_cap.ht_supported) || |
| 881 | !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 882 | return; |
| 883 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 884 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) |
| 885 | return; |
| 886 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 887 | if (tcb_desc->multicast || tcb_desc->broadcast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 888 | return; |
| 889 | |
| 890 | /*use legency rate, shall use 20MHz */ |
| 891 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) |
| 892 | return; |
| 893 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 894 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40; |
| 895 | |
Ping-Ke Shih | 1ca72c3 | 2018-01-29 11:26:33 +0800 | [diff] [blame] | 896 | if (rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 897 | if (mac->opmode == NL80211_IFTYPE_AP || |
| 898 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 899 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
| 900 | if (!(sta->vht_cap.vht_supported)) |
| 901 | return; |
| 902 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 903 | if (!mac->bw_80 || |
| 904 | !(sta->vht_cap.vht_supported)) |
| 905 | return; |
| 906 | } |
| 907 | if (tcb_desc->hw_rate <= |
| 908 | rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]) |
| 909 | return; |
| 910 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80; |
| 911 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 912 | } |
| 913 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 914 | static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw, |
| 915 | struct ieee80211_sta *sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 916 | { |
| 917 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 918 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 919 | u8 hw_rate; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 920 | u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 921 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 922 | if ((get_rf_type(rtlphy) == RF_2T2R) && |
| 923 | (tx_mcs_map & 0x000c) != 0x000c) { |
| 924 | if ((tx_mcs_map & 0x000c) >> 2 == |
| 925 | IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 926 | hw_rate = |
| 927 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7]; |
| 928 | else if ((tx_mcs_map & 0x000c) >> 2 == |
| 929 | IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 930 | hw_rate = |
Larry Finger | a7986ce | 2017-10-14 20:54:02 -0500 | [diff] [blame] | 931 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8]; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 932 | else |
| 933 | hw_rate = |
| 934 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; |
| 935 | } else { |
| 936 | if ((tx_mcs_map & 0x0003) == |
| 937 | IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 938 | hw_rate = |
| 939 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7]; |
| 940 | else if ((tx_mcs_map & 0x0003) == |
| 941 | IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 942 | hw_rate = |
Larry Finger | a7986ce | 2017-10-14 20:54:02 -0500 | [diff] [blame] | 943 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8]; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 944 | else |
| 945 | hw_rate = |
| 946 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; |
| 947 | } |
| 948 | |
| 949 | return hw_rate; |
| 950 | } |
| 951 | |
| 952 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw, |
| 953 | struct ieee80211_sta *sta) |
| 954 | { |
| 955 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 956 | struct rtl_phy *rtlphy = &rtlpriv->phy; |
| 957 | u8 hw_rate; |
| 958 | |
Frank A. Cancio Bello | d63589c | 2017-12-29 16:31:08 +0800 | [diff] [blame] | 959 | if (get_rf_type(rtlphy) == RF_2T2R && |
| 960 | sta->ht_cap.mcs.rx_mask[1] != 0) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 961 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
| 962 | else |
| 963 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; |
| 964 | |
| 965 | return hw_rate; |
| 966 | } |
| 967 | |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 968 | /* mac80211's rate_idx is like this: |
| 969 | * |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 970 | * 2.4G band:rx_status->band == NL80211_BAND_2GHZ |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 971 | * |
| 972 | * B/G rate: |
| 973 | * (rx_status->flag & RX_FLAG_HT) = 0, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 974 | * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11, |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 975 | * |
| 976 | * N rate: |
| 977 | * (rx_status->flag & RX_FLAG_HT) = 1, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 978 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 979 | * |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 980 | * 5G band:rx_status->band == NL80211_BAND_5GHZ |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 981 | * A rate: |
| 982 | * (rx_status->flag & RX_FLAG_HT) = 0, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 983 | * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7, |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 984 | * |
| 985 | * N rate: |
| 986 | * (rx_status->flag & RX_FLAG_HT) = 1, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 987 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 988 | * |
| 989 | * VHT rates: |
| 990 | * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9 |
| 991 | * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9 |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 992 | */ |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 993 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht, |
| 994 | u8 desc_rate) |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 995 | { |
| 996 | int rate_idx; |
| 997 | |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 998 | if (isvht) { |
| 999 | switch (desc_rate) { |
| 1000 | case DESC_RATEVHT1SS_MCS0: |
| 1001 | rate_idx = 0; |
| 1002 | break; |
| 1003 | case DESC_RATEVHT1SS_MCS1: |
| 1004 | rate_idx = 1; |
| 1005 | break; |
| 1006 | case DESC_RATEVHT1SS_MCS2: |
| 1007 | rate_idx = 2; |
| 1008 | break; |
| 1009 | case DESC_RATEVHT1SS_MCS3: |
| 1010 | rate_idx = 3; |
| 1011 | break; |
| 1012 | case DESC_RATEVHT1SS_MCS4: |
| 1013 | rate_idx = 4; |
| 1014 | break; |
| 1015 | case DESC_RATEVHT1SS_MCS5: |
| 1016 | rate_idx = 5; |
| 1017 | break; |
| 1018 | case DESC_RATEVHT1SS_MCS6: |
| 1019 | rate_idx = 6; |
| 1020 | break; |
| 1021 | case DESC_RATEVHT1SS_MCS7: |
| 1022 | rate_idx = 7; |
| 1023 | break; |
| 1024 | case DESC_RATEVHT1SS_MCS8: |
| 1025 | rate_idx = 8; |
| 1026 | break; |
| 1027 | case DESC_RATEVHT1SS_MCS9: |
| 1028 | rate_idx = 9; |
| 1029 | break; |
| 1030 | case DESC_RATEVHT2SS_MCS0: |
| 1031 | rate_idx = 0; |
| 1032 | break; |
| 1033 | case DESC_RATEVHT2SS_MCS1: |
| 1034 | rate_idx = 1; |
| 1035 | break; |
| 1036 | case DESC_RATEVHT2SS_MCS2: |
| 1037 | rate_idx = 2; |
| 1038 | break; |
| 1039 | case DESC_RATEVHT2SS_MCS3: |
| 1040 | rate_idx = 3; |
| 1041 | break; |
| 1042 | case DESC_RATEVHT2SS_MCS4: |
| 1043 | rate_idx = 4; |
| 1044 | break; |
| 1045 | case DESC_RATEVHT2SS_MCS5: |
| 1046 | rate_idx = 5; |
| 1047 | break; |
| 1048 | case DESC_RATEVHT2SS_MCS6: |
| 1049 | rate_idx = 6; |
| 1050 | break; |
| 1051 | case DESC_RATEVHT2SS_MCS7: |
| 1052 | rate_idx = 7; |
| 1053 | break; |
| 1054 | case DESC_RATEVHT2SS_MCS8: |
| 1055 | rate_idx = 8; |
| 1056 | break; |
| 1057 | case DESC_RATEVHT2SS_MCS9: |
| 1058 | rate_idx = 9; |
| 1059 | break; |
| 1060 | default: |
| 1061 | rate_idx = 0; |
| 1062 | break; |
| 1063 | } |
| 1064 | return rate_idx; |
| 1065 | } |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1066 | if (false == isht) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1067 | if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1068 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1069 | case DESC_RATE1M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1070 | rate_idx = 0; |
| 1071 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1072 | case DESC_RATE2M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1073 | rate_idx = 1; |
| 1074 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1075 | case DESC_RATE5_5M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1076 | rate_idx = 2; |
| 1077 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1078 | case DESC_RATE11M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1079 | rate_idx = 3; |
| 1080 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1081 | case DESC_RATE6M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1082 | rate_idx = 4; |
| 1083 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1084 | case DESC_RATE9M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1085 | rate_idx = 5; |
| 1086 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1087 | case DESC_RATE12M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1088 | rate_idx = 6; |
| 1089 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1090 | case DESC_RATE18M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1091 | rate_idx = 7; |
| 1092 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1093 | case DESC_RATE24M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1094 | rate_idx = 8; |
| 1095 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1096 | case DESC_RATE36M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1097 | rate_idx = 9; |
| 1098 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1099 | case DESC_RATE48M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1100 | rate_idx = 10; |
| 1101 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1102 | case DESC_RATE54M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1103 | rate_idx = 11; |
| 1104 | break; |
| 1105 | default: |
| 1106 | rate_idx = 0; |
| 1107 | break; |
| 1108 | } |
| 1109 | } else { |
| 1110 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1111 | case DESC_RATE6M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1112 | rate_idx = 0; |
| 1113 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1114 | case DESC_RATE9M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1115 | rate_idx = 1; |
| 1116 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1117 | case DESC_RATE12M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1118 | rate_idx = 2; |
| 1119 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1120 | case DESC_RATE18M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1121 | rate_idx = 3; |
| 1122 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1123 | case DESC_RATE24M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1124 | rate_idx = 4; |
| 1125 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1126 | case DESC_RATE36M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1127 | rate_idx = 5; |
| 1128 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1129 | case DESC_RATE48M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1130 | rate_idx = 6; |
| 1131 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1132 | case DESC_RATE54M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1133 | rate_idx = 7; |
| 1134 | break; |
| 1135 | default: |
| 1136 | rate_idx = 0; |
| 1137 | break; |
| 1138 | } |
| 1139 | } |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1140 | } else { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1141 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1142 | case DESC_RATEMCS0: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1143 | rate_idx = 0; |
| 1144 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1145 | case DESC_RATEMCS1: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1146 | rate_idx = 1; |
| 1147 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1148 | case DESC_RATEMCS2: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1149 | rate_idx = 2; |
| 1150 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1151 | case DESC_RATEMCS3: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1152 | rate_idx = 3; |
| 1153 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1154 | case DESC_RATEMCS4: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1155 | rate_idx = 4; |
| 1156 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1157 | case DESC_RATEMCS5: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1158 | rate_idx = 5; |
| 1159 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1160 | case DESC_RATEMCS6: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1161 | rate_idx = 6; |
| 1162 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1163 | case DESC_RATEMCS7: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1164 | rate_idx = 7; |
| 1165 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1166 | case DESC_RATEMCS8: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1167 | rate_idx = 8; |
| 1168 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1169 | case DESC_RATEMCS9: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1170 | rate_idx = 9; |
| 1171 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1172 | case DESC_RATEMCS10: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1173 | rate_idx = 10; |
| 1174 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1175 | case DESC_RATEMCS11: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1176 | rate_idx = 11; |
| 1177 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1178 | case DESC_RATEMCS12: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1179 | rate_idx = 12; |
| 1180 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1181 | case DESC_RATEMCS13: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1182 | rate_idx = 13; |
| 1183 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1184 | case DESC_RATEMCS14: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1185 | rate_idx = 14; |
| 1186 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1187 | case DESC_RATEMCS15: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1188 | rate_idx = 15; |
| 1189 | break; |
| 1190 | default: |
| 1191 | rate_idx = 0; |
| 1192 | break; |
| 1193 | } |
| 1194 | } |
| 1195 | return rate_idx; |
| 1196 | } |
| 1197 | EXPORT_SYMBOL(rtlwifi_rate_mapping); |
| 1198 | |
Ping-Ke Shih | cdc9c7a | 2017-09-29 14:47:54 -0500 | [diff] [blame] | 1199 | static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw, |
| 1200 | struct ieee80211_tx_info *info) |
| 1201 | { |
| 1202 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1203 | struct ieee80211_tx_rate *r = &info->status.rates[0]; |
| 1204 | struct ieee80211_rate *txrate; |
| 1205 | u8 hw_value = 0x0; |
| 1206 | |
| 1207 | if (r->flags & IEEE80211_TX_RC_MCS) { |
| 1208 | /* HT MCS0-15 */ |
| 1209 | hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 + |
| 1210 | r->idx; |
| 1211 | } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) { |
| 1212 | /* VHT MCS0-9, NSS */ |
| 1213 | if (ieee80211_rate_get_vht_nss(r) == 2) |
| 1214 | hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; |
| 1215 | else |
| 1216 | hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; |
| 1217 | |
| 1218 | hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r); |
| 1219 | } else { |
| 1220 | /* legacy */ |
| 1221 | txrate = ieee80211_get_tx_rate(hw, info); |
| 1222 | |
| 1223 | if (txrate) |
| 1224 | hw_value = txrate->hw_value; |
| 1225 | } |
| 1226 | |
| 1227 | /* check 5G band */ |
| 1228 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G && |
| 1229 | hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M]) |
| 1230 | hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M]; |
| 1231 | |
| 1232 | return hw_value; |
| 1233 | } |
| 1234 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1235 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
| 1236 | struct ieee80211_tx_info *info, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1237 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1238 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
| 1239 | { |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 1240 | #define SET_RATE_ID(rate_id) \ |
| 1241 | ({typeof(rate_id) _id = rate_id; \ |
| 1242 | ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \ |
| 1243 | rtl_mrate_idx_to_arfr_id(hw, _id, \ |
| 1244 | (sta_entry ? sta_entry->wireless_mode : \ |
| 1245 | WIRELESS_MODE_G)) : \ |
| 1246 | _id); }) |
| 1247 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1248 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1249 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1250 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 1251 | struct rtl_sta_info *sta_entry = |
| 1252 | (sta ? (struct rtl_sta_info *)sta->drv_priv : NULL); |
Ping-Ke Shih | cdc9c7a | 2017-09-29 14:47:54 -0500 | [diff] [blame] | 1253 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1254 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1255 | |
Ping-Ke Shih | cdc9c7a | 2017-09-29 14:47:54 -0500 | [diff] [blame] | 1256 | tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1257 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1258 | if (rtl_is_tx_report_skb(hw, skb)) |
| 1259 | tcb_desc->use_spe_rpt = 1; |
| 1260 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1261 | if (ieee80211_is_data(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1262 | /* |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1263 | *we set data rate INX 0 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1264 | *in rtl_rc.c if skb is special data or |
| 1265 | *mgt which need low data rate. |
| 1266 | */ |
| 1267 | |
| 1268 | /* |
| 1269 | *So tcb_desc->hw_rate is just used for |
| 1270 | *special data and mgt frames |
| 1271 | */ |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 1272 | if (info->control.rates[0].idx == 0 || |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1273 | ieee80211_is_nullfunc(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1274 | tcb_desc->use_driver_rate = true; |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 1275 | tcb_desc->ratr_index = |
| 1276 | SET_RATE_ID(RATR_INX_WIRELESS_MC); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1277 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1278 | tcb_desc->disable_ratefallback = 1; |
| 1279 | } else { |
| 1280 | /* |
| 1281 | *because hw will nerver use hw_rate |
| 1282 | *when tcb_desc->use_driver_rate = false |
| 1283 | *so we never set highest N rate here, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1284 | *and N rate will all be controlled by FW |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1285 | *when tcb_desc->use_driver_rate = false |
| 1286 | */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1287 | if (sta && sta->vht_cap.vht_supported) { |
| 1288 | tcb_desc->hw_rate = |
| 1289 | _rtl_get_vht_highest_n_rate(hw, sta); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1290 | } else { |
Frank A. Cancio Bello | d63589c | 2017-12-29 16:31:08 +0800 | [diff] [blame] | 1291 | if (sta && sta->ht_cap.ht_supported) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1292 | tcb_desc->hw_rate = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1293 | _rtl_get_highest_n_rate(hw, sta); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1294 | } else { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1295 | if (rtlmac->mode == WIRELESS_MODE_B) { |
| 1296 | tcb_desc->hw_rate = |
| 1297 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; |
| 1298 | } else { |
| 1299 | tcb_desc->hw_rate = |
| 1300 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; |
| 1301 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
Ping-Ke Shih | e7c5286 | 2017-07-02 13:12:36 -0500 | [diff] [blame] | 1306 | if (is_multicast_ether_addr(hdr->addr1)) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1307 | tcb_desc->multicast = 1; |
Ping-Ke Shih | e7c5286 | 2017-07-02 13:12:36 -0500 | [diff] [blame] | 1308 | else if (is_broadcast_ether_addr(hdr->addr1)) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1309 | tcb_desc->broadcast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1310 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1311 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
| 1312 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1313 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1314 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1315 | _rtl_query_protection_mode(hw, tcb_desc, info); |
| 1316 | } else { |
| 1317 | tcb_desc->use_driver_rate = true; |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 1318 | tcb_desc->ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1319 | tcb_desc->disable_ratefallback = 1; |
| 1320 | tcb_desc->mac_id = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1321 | tcb_desc->packet_bw = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1322 | } |
Ping-Ke Shih | a75f3ee | 2018-01-19 14:45:51 +0800 | [diff] [blame] | 1323 | #undef SET_RATE_ID |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1324 | } |
| 1325 | EXPORT_SYMBOL(rtl_get_tcb_desc); |
| 1326 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1327 | bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1328 | { |
| 1329 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1330 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1331 | __le16 fc = rtl_get_fc(skb); |
| 1332 | |
| 1333 | if (rtlpriv->dm.supp_phymode_switch && |
| 1334 | mac->link_state < MAC80211_LINKED && |
| 1335 | (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) { |
| 1336 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 1337 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
| 1338 | } |
| 1339 | if (ieee80211_is_auth(fc)) { |
| 1340 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1341 | |
| 1342 | mac->link_state = MAC80211_LINKING; |
| 1343 | /* Dul mac */ |
| 1344 | rtlpriv->phy.need_iqk = true; |
| 1345 | |
| 1346 | } |
| 1347 | |
| 1348 | return true; |
| 1349 | } |
| 1350 | EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc); |
| 1351 | |
| 1352 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa, |
| 1353 | u8 *bssid, u16 tid); |
| 1354 | |
| 1355 | static void process_agg_start(struct ieee80211_hw *hw, |
| 1356 | struct ieee80211_hdr *hdr, u16 tid) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1357 | { |
| 1358 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1359 | struct ieee80211_rx_status rx_status = { 0 }; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1360 | struct sk_buff *skb_delba = NULL; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1361 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1362 | skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); |
| 1363 | if (skb_delba) { |
| 1364 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 1365 | rx_status.band = hw->conf.chandef.chan->band; |
| 1366 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 1367 | rx_status.flag |= RX_FLAG_MACTIME_START; |
| 1368 | rx_status.rate_idx = 0; |
| 1369 | rx_status.signal = 50 + 10; |
| 1370 | memcpy(IEEE80211_SKB_RXCB(skb_delba), |
| 1371 | &rx_status, sizeof(rx_status)); |
| 1372 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1373 | "fake del\n", |
| 1374 | skb_delba->data, |
| 1375 | skb_delba->len); |
| 1376 | ieee80211_rx_irqsafe(hw, skb_delba); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1377 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1378 | } |
| 1379 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1380 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1381 | { |
| 1382 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1383 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1384 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1385 | __le16 fc = rtl_get_fc(skb); |
| 1386 | u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1387 | u8 category; |
| 1388 | |
| 1389 | if (!ieee80211_is_action(fc)) |
| 1390 | return true; |
| 1391 | |
| 1392 | category = *act; |
| 1393 | act++; |
| 1394 | switch (category) { |
| 1395 | case ACT_CAT_BA: |
| 1396 | switch (*act) { |
| 1397 | case ACT_ADDBAREQ: |
| 1398 | if (mac->act_scanning) |
| 1399 | return false; |
| 1400 | |
| 1401 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1402 | "%s ACT_ADDBAREQ From :%pM\n", |
| 1403 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1404 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1405 | skb->data, skb->len); |
| 1406 | if (!is_tx) { |
| 1407 | struct ieee80211_sta *sta = NULL; |
| 1408 | struct rtl_sta_info *sta_entry = NULL; |
| 1409 | struct rtl_tid_data *tid_data; |
| 1410 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1411 | u16 capab = 0, tid = 0; |
| 1412 | |
| 1413 | rcu_read_lock(); |
| 1414 | sta = rtl_find_sta(hw, hdr->addr3); |
| 1415 | if (sta == NULL) { |
| 1416 | RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV, |
| 1417 | DBG_DMESG, "sta is NULL\n"); |
| 1418 | rcu_read_unlock(); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1419 | return true; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | sta_entry = |
| 1423 | (struct rtl_sta_info *)sta->drv_priv; |
| 1424 | if (!sta_entry) { |
| 1425 | rcu_read_unlock(); |
| 1426 | return true; |
| 1427 | } |
| 1428 | capab = |
| 1429 | le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1430 | tid = (capab & |
| 1431 | IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
Dan Carpenter | 5e0c1f0 | 2017-12-29 16:31:03 +0800 | [diff] [blame] | 1432 | if (tid >= MAX_TID_COUNT) { |
| 1433 | rcu_read_unlock(); |
| 1434 | return true; |
| 1435 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1436 | tid_data = &sta_entry->tids[tid]; |
| 1437 | if (tid_data->agg.rx_agg_state == |
| 1438 | RTL_RX_AGG_START) |
| 1439 | process_agg_start(hw, hdr, tid); |
| 1440 | rcu_read_unlock(); |
| 1441 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1442 | break; |
| 1443 | case ACT_ADDBARSP: |
| 1444 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1445 | "%s ACT_ADDBARSP From :%pM\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1446 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1447 | break; |
| 1448 | case ACT_DELBA: |
| 1449 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1450 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1451 | break; |
| 1452 | } |
| 1453 | break; |
| 1454 | default: |
| 1455 | break; |
| 1456 | } |
| 1457 | |
| 1458 | return true; |
| 1459 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1460 | EXPORT_SYMBOL_GPL(rtl_action_proc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1461 | |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1462 | static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc, |
| 1463 | int type) |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1464 | { |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1465 | struct ieee80211_hw *hw = rtlpriv->hw; |
| 1466 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1467 | rtlpriv->ra.is_special_data = true; |
| 1468 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1469 | rtlpriv->btcoexist.btc_ops->btc_special_packet_notify( |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1470 | rtlpriv, type); |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1471 | rtl_lps_leave(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1472 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1473 | } |
| 1474 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1475 | static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw, |
| 1476 | struct sk_buff *skb, bool is_enc) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1477 | { |
| 1478 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1479 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1480 | u8 encrypt_header_len = 0; |
| 1481 | u8 offset; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1482 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1483 | switch (rtlpriv->sec.pairwise_enc_algorithm) { |
| 1484 | case WEP40_ENCRYPTION: |
| 1485 | case WEP104_ENCRYPTION: |
| 1486 | encrypt_header_len = 4;/*WEP_IV_LEN*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1487 | break; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1488 | case TKIP_ENCRYPTION: |
| 1489 | encrypt_header_len = 8;/*TKIP_IV_LEN*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1490 | break; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1491 | case AESCCMP_ENCRYPTION: |
| 1492 | encrypt_header_len = 8;/*CCMP_HDR_LEN;*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1493 | break; |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1494 | default: |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1495 | break; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1496 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1497 | |
Taehee Yoo | cad737d | 2015-03-28 00:22:39 +0900 | [diff] [blame] | 1498 | offset = mac_hdr_len + SNAP_SIZE; |
| 1499 | if (is_enc) |
| 1500 | offset += encrypt_header_len; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1501 | |
| 1502 | return skb->data + offset; |
| 1503 | } |
| 1504 | |
| 1505 | /*should call before software enc*/ |
| 1506 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx, |
| 1507 | bool is_enc) |
| 1508 | { |
| 1509 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1510 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1511 | __le16 fc = rtl_get_fc(skb); |
| 1512 | u16 ether_type; |
| 1513 | const u8 *ether_type_ptr; |
| 1514 | const struct iphdr *ip; |
| 1515 | |
| 1516 | if (!ieee80211_is_data(fc)) |
| 1517 | goto end; |
| 1518 | |
| 1519 | ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc); |
| 1520 | ether_type = be16_to_cpup((__be16 *)ether_type_ptr); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1521 | |
| 1522 | if (ETH_P_IP == ether_type) { |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1523 | ip = (struct iphdr *)((u8 *)ether_type_ptr + |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1524 | PROTOC_TYPE_SIZE); |
| 1525 | if (IPPROTO_UDP == ip->protocol) { |
| 1526 | struct udphdr *udp = (struct udphdr *)((u8 *)ip + |
| 1527 | (ip->ihl << 2)); |
| 1528 | if (((((u8 *)udp)[1] == 68) && |
| 1529 | (((u8 *)udp)[3] == 67)) || |
| 1530 | ((((u8 *)udp)[1] == 67) && |
| 1531 | (((u8 *)udp)[3] == 68))) { |
| 1532 | /* 68 : UDP BOOTP client |
| 1533 | * 67 : UDP BOOTP server |
| 1534 | */ |
| 1535 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), |
| 1536 | DBG_DMESG, "dhcp %s !!\n", |
| 1537 | (is_tx) ? "Tx" : "Rx"); |
| 1538 | |
| 1539 | if (is_tx) |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1540 | setup_special_tx(rtlpriv, ppsc, |
| 1541 | PACKET_DHCP); |
| 1542 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1543 | return true; |
| 1544 | } |
| 1545 | } |
| 1546 | } else if (ETH_P_ARP == ether_type) { |
| 1547 | if (is_tx) |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1548 | setup_special_tx(rtlpriv, ppsc, PACKET_ARP); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1549 | |
| 1550 | return true; |
| 1551 | } else if (ETH_P_PAE == ether_type) { |
Ping-Ke Shih | 11f35c9 | 2017-07-02 13:12:30 -0500 | [diff] [blame] | 1552 | /* EAPOL is seens as in-4way */ |
| 1553 | rtlpriv->btcoexist.btc_info.in_4way = true; |
| 1554 | rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies; |
Ping-Ke Shih | 11f35c9 | 2017-07-02 13:12:30 -0500 | [diff] [blame] | 1555 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1556 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
| 1557 | "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx"); |
| 1558 | |
| 1559 | if (is_tx) { |
| 1560 | rtlpriv->ra.is_special_data = true; |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1561 | rtl_lps_leave(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1562 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1563 | |
| 1564 | setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | return true; |
Larry Finger | c8f0345 | 2015-02-24 09:23:01 -0600 | [diff] [blame] | 1568 | } else if (ETH_P_IPV6 == ether_type) { |
| 1569 | /* TODO: Handle any IPv6 cases that need special handling. |
| 1570 | * For now, always return false |
| 1571 | */ |
| 1572 | goto end; |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1573 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1574 | |
| 1575 | end: |
| 1576 | rtlpriv->ra.is_special_data = false; |
| 1577 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1578 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1579 | EXPORT_SYMBOL_GPL(rtl_is_special_data); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1580 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1581 | void rtl_tx_ackqueue(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1582 | { |
| 1583 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1584 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1585 | |
| 1586 | __skb_queue_tail(&tx_report->queue, skb); |
| 1587 | } |
| 1588 | EXPORT_SYMBOL_GPL(rtl_tx_ackqueue); |
| 1589 | |
| 1590 | static void rtl_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1591 | bool ack) |
| 1592 | { |
| 1593 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1594 | struct ieee80211_tx_info *info; |
| 1595 | |
| 1596 | info = IEEE80211_SKB_CB(skb); |
| 1597 | ieee80211_tx_info_clear_status(info); |
| 1598 | if (ack) { |
| 1599 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD, |
| 1600 | "tx report: ack\n"); |
| 1601 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 1602 | } else { |
| 1603 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD, |
| 1604 | "tx report: not ack\n"); |
| 1605 | info->flags &= ~IEEE80211_TX_STAT_ACK; |
| 1606 | } |
| 1607 | ieee80211_tx_status_irqsafe(hw, skb); |
| 1608 | } |
| 1609 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1610 | bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1611 | { |
| 1612 | u16 ether_type; |
| 1613 | const u8 *ether_type_ptr; |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1614 | __le16 fc = rtl_get_fc(skb); |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1615 | |
| 1616 | ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true); |
| 1617 | ether_type = be16_to_cpup((__be16 *)ether_type_ptr); |
| 1618 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1619 | if (ether_type == ETH_P_PAE || ieee80211_is_nullfunc(fc)) |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1620 | return true; |
| 1621 | |
| 1622 | return false; |
| 1623 | } |
| 1624 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1625 | static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw, |
| 1626 | struct rtlwifi_tx_info *tx_info) |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1627 | { |
| 1628 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1629 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1630 | u16 sn; |
| 1631 | |
Ping-Ke Shih | 5f380ce | 2018-01-29 11:26:34 +0800 | [diff] [blame] | 1632 | /* SW_DEFINE[11:8] are reserved (driver fills zeros) |
| 1633 | * SW_DEFINE[7:2] are used by driver |
| 1634 | * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros) |
| 1635 | */ |
| 1636 | sn = (atomic_inc_return(&tx_report->sn) & 0x003F) << 2; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1637 | |
| 1638 | tx_report->last_sent_sn = sn; |
| 1639 | tx_report->last_sent_time = jiffies; |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1640 | tx_info->sn = sn; |
| 1641 | tx_info->send_time = tx_report->last_sent_time; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1642 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG, |
| 1643 | "Send TX-Report sn=0x%X\n", sn); |
| 1644 | |
| 1645 | return sn; |
| 1646 | } |
| 1647 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1648 | void rtl_set_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc, |
| 1649 | struct ieee80211_hw *hw, struct rtlwifi_tx_info *tx_info) |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1650 | { |
| 1651 | if (ptcb_desc->use_spe_rpt) { |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1652 | u16 sn = rtl_get_tx_report_sn(hw, tx_info); |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1653 | |
| 1654 | SET_TX_DESC_SPE_RPT(pdesc, 1); |
| 1655 | SET_TX_DESC_SW_DEFINE(pdesc, sn); |
| 1656 | } |
| 1657 | } |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1658 | EXPORT_SYMBOL_GPL(rtl_set_tx_report); |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1659 | |
| 1660 | void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len) |
| 1661 | { |
| 1662 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1663 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1664 | struct rtlwifi_tx_info *tx_info; |
| 1665 | struct sk_buff_head *queue = &tx_report->queue; |
| 1666 | struct sk_buff *skb; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1667 | u16 sn; |
Ping-Ke Shih | 5f380ce | 2018-01-29 11:26:34 +0800 | [diff] [blame] | 1668 | u8 st, retry; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1669 | |
Ping-Ke Shih | 5f380ce | 2018-01-29 11:26:34 +0800 | [diff] [blame] | 1670 | if (rtlpriv->cfg->spec_ver & RTL_SPEC_EXT_C2H) { |
| 1671 | sn = GET_TX_REPORT_SN_V2(tmp_buf); |
| 1672 | st = GET_TX_REPORT_ST_V2(tmp_buf); |
| 1673 | retry = GET_TX_REPORT_RETRY_V2(tmp_buf); |
| 1674 | } else { |
| 1675 | sn = GET_TX_REPORT_SN_V1(tmp_buf); |
| 1676 | st = GET_TX_REPORT_ST_V1(tmp_buf); |
| 1677 | retry = GET_TX_REPORT_RETRY_V1(tmp_buf); |
| 1678 | } |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1679 | |
| 1680 | tx_report->last_recv_sn = sn; |
| 1681 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1682 | skb_queue_walk(queue, skb) { |
| 1683 | tx_info = rtl_tx_skb_cb_info(skb); |
| 1684 | if (tx_info->sn == sn) { |
| 1685 | skb_unlink(skb, queue); |
| 1686 | rtl_tx_status(hw, skb, st == 0); |
| 1687 | break; |
| 1688 | } |
| 1689 | } |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1690 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG, |
| 1691 | "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n", |
Ping-Ke Shih | 5f380ce | 2018-01-29 11:26:34 +0800 | [diff] [blame] | 1692 | st, sn, retry); |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1693 | } |
| 1694 | EXPORT_SYMBOL_GPL(rtl_tx_report_handler); |
| 1695 | |
| 1696 | bool rtl_check_tx_report_acked(struct ieee80211_hw *hw) |
| 1697 | { |
| 1698 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1699 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1700 | |
| 1701 | if (tx_report->last_sent_sn == tx_report->last_recv_sn) |
| 1702 | return true; |
| 1703 | |
| 1704 | if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) { |
| 1705 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING, |
Ping-Ke Shih | 5f380ce | 2018-01-29 11:26:34 +0800 | [diff] [blame] | 1706 | "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n", |
| 1707 | tx_report->last_sent_sn, tx_report->last_recv_sn); |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1708 | return true; /* 3 sec. (timeout) seen as acked */ |
| 1709 | } |
| 1710 | |
| 1711 | return false; |
| 1712 | } |
| 1713 | |
| 1714 | void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms) |
| 1715 | { |
| 1716 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1717 | int i; |
| 1718 | |
| 1719 | for (i = 0; i < wait_ms; i++) { |
| 1720 | if (rtl_check_tx_report_acked(hw)) |
| 1721 | break; |
| 1722 | usleep_range(1000, 2000); |
| 1723 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
| 1724 | "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms); |
| 1725 | } |
| 1726 | } |
Ping-Ke Shih | c1816f1 | 2017-09-29 14:47:55 -0500 | [diff] [blame] | 1727 | |
| 1728 | u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw, |
| 1729 | struct ieee80211_vif *vif, |
| 1730 | enum wireless_mode wirelessmode, |
| 1731 | struct ieee80211_tx_queue_params *param) |
| 1732 | { |
| 1733 | u32 reg = 0; |
| 1734 | u8 sifstime = 10; |
| 1735 | u8 slottime = 20; |
| 1736 | |
| 1737 | /* AIFS = AIFSN * slot time + SIFS */ |
| 1738 | switch (wirelessmode) { |
| 1739 | case WIRELESS_MODE_A: |
| 1740 | case WIRELESS_MODE_N_24G: |
| 1741 | case WIRELESS_MODE_N_5G: |
| 1742 | case WIRELESS_MODE_AC_5G: |
| 1743 | case WIRELESS_MODE_AC_24G: |
| 1744 | sifstime = 16; |
| 1745 | slottime = 9; |
| 1746 | break; |
| 1747 | case WIRELESS_MODE_G: |
| 1748 | slottime = (vif->bss_conf.use_short_slot ? 9 : 20); |
| 1749 | break; |
| 1750 | default: |
| 1751 | break; |
| 1752 | } |
| 1753 | |
| 1754 | reg |= (param->txop & 0x7FF) << 16; |
| 1755 | reg |= (fls(param->cw_max) & 0xF) << 12; |
| 1756 | reg |= (fls(param->cw_min) & 0xF) << 8; |
| 1757 | reg |= (param->aifs & 0x0F) * slottime + sifstime; |
| 1758 | |
| 1759 | return reg; |
| 1760 | } |
| 1761 | EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param); |
| 1762 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1763 | /********************************************************* |
| 1764 | * |
| 1765 | * functions called by core.c |
| 1766 | * |
| 1767 | *********************************************************/ |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1768 | int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1769 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1770 | { |
| 1771 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1772 | struct rtl_tid_data *tid_data; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1773 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1774 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1775 | if (sta == NULL) |
| 1776 | return -EINVAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1777 | |
| 1778 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1779 | return -EINVAL; |
| 1780 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1781 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1782 | if (!sta_entry) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1783 | return -ENXIO; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1784 | tid_data = &sta_entry->tids[tid]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1785 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1786 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1787 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, |
Ping-Ke Shih | 1d1aa8f | 2017-10-24 10:03:31 +0800 | [diff] [blame] | 1788 | *ssn); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1789 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1790 | tid_data->agg.agg_state = RTL_AGG_START; |
| 1791 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1792 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1793 | return 0; |
| 1794 | } |
| 1795 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1796 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1797 | struct ieee80211_sta *sta, u16 tid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1798 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1799 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1800 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1801 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1802 | if (sta == NULL) |
| 1803 | return -EINVAL; |
| 1804 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1805 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1806 | "on ra = %pM tid = %d\n", sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1807 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1808 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1809 | return -EINVAL; |
| 1810 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1811 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1812 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1813 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1814 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1815 | return 0; |
| 1816 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1817 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1818 | int rtl_rx_agg_start(struct ieee80211_hw *hw, |
| 1819 | struct ieee80211_sta *sta, u16 tid) |
| 1820 | { |
| 1821 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1822 | struct rtl_tid_data *tid_data; |
| 1823 | struct rtl_sta_info *sta_entry = NULL; |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1824 | u8 reject_agg; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1825 | |
| 1826 | if (sta == NULL) |
| 1827 | return -EINVAL; |
| 1828 | |
| 1829 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1830 | return -EINVAL; |
| 1831 | |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1832 | if (rtlpriv->cfg->ops->get_btc_status()) { |
| 1833 | rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv, |
| 1834 | &reject_agg, |
| 1835 | NULL, NULL); |
| 1836 | if (reject_agg) |
| 1837 | return -EINVAL; |
| 1838 | } |
| 1839 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1840 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1841 | if (!sta_entry) |
| 1842 | return -ENXIO; |
| 1843 | tid_data = &sta_entry->tids[tid]; |
| 1844 | |
| 1845 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, |
Ping-Ke Shih | 1d1aa8f | 2017-10-24 10:03:31 +0800 | [diff] [blame] | 1846 | "on ra = %pM tid = %d\n", sta->addr, tid); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1847 | |
| 1848 | tid_data->agg.rx_agg_state = RTL_RX_AGG_START; |
| 1849 | return 0; |
| 1850 | } |
| 1851 | |
| 1852 | int rtl_rx_agg_stop(struct ieee80211_hw *hw, |
| 1853 | struct ieee80211_sta *sta, u16 tid) |
| 1854 | { |
| 1855 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1856 | struct rtl_sta_info *sta_entry = NULL; |
| 1857 | |
| 1858 | if (sta == NULL) |
| 1859 | return -EINVAL; |
| 1860 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1861 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1862 | "on ra = %pM tid = %d\n", sta->addr, tid); |
| 1863 | |
| 1864 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1865 | return -EINVAL; |
| 1866 | |
| 1867 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1868 | sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; |
| 1869 | |
| 1870 | return 0; |
| 1871 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1872 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
| 1873 | struct ieee80211_sta *sta, u16 tid) |
| 1874 | { |
| 1875 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1876 | struct rtl_sta_info *sta_entry = NULL; |
| 1877 | |
| 1878 | if (sta == NULL) |
| 1879 | return -EINVAL; |
| 1880 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1881 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1882 | "on ra = %pM tid = %d\n", sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1883 | |
| 1884 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1885 | return -EINVAL; |
| 1886 | |
| 1887 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1888 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1889 | |
| 1890 | return 0; |
| 1891 | } |
| 1892 | |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1893 | void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv) |
| 1894 | { |
| 1895 | struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; |
Nicolas Iooss | e477916 | 2017-12-10 20:51:59 +0100 | [diff] [blame] | 1896 | u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0; |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1897 | |
| 1898 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1899 | btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg, |
| 1900 | &ctrl_agg_size, &agg_size); |
| 1901 | |
| 1902 | RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, |
| 1903 | "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d", |
| 1904 | reject_agg, ctrl_agg_size, agg_size); |
| 1905 | |
| 1906 | rtlpriv->hw->max_rx_aggregation_subframes = |
| 1907 | (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF); |
| 1908 | } |
| 1909 | EXPORT_SYMBOL(rtl_rx_ampdu_apply); |
| 1910 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1911 | /********************************************************* |
| 1912 | * |
| 1913 | * wq & timer callback functions |
| 1914 | * |
| 1915 | *********************************************************/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1916 | /* this function is used for roaming */ |
| 1917 | void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1918 | { |
| 1919 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1920 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1921 | |
| 1922 | if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) |
| 1923 | return; |
| 1924 | |
| 1925 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) |
| 1926 | return; |
| 1927 | |
| 1928 | /* check if this really is a beacon */ |
| 1929 | if (!ieee80211_is_beacon(hdr->frame_control) && |
| 1930 | !ieee80211_is_probe_resp(hdr->frame_control)) |
| 1931 | return; |
| 1932 | |
| 1933 | /* min. beacon length + FCS_LEN */ |
| 1934 | if (skb->len <= 40 + FCS_LEN) |
| 1935 | return; |
| 1936 | |
| 1937 | /* and only beacons from the associated BSSID, please */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1938 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1939 | return; |
| 1940 | |
| 1941 | rtlpriv->link_info.bcn_rx_inperiod++; |
| 1942 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1943 | EXPORT_SYMBOL_GPL(rtl_beacon_statistic); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1944 | |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 1945 | static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw) |
| 1946 | { |
| 1947 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1948 | struct rtl_bssid_entry *entry, *next; |
| 1949 | |
| 1950 | list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) { |
| 1951 | list_del(&entry->list); |
| 1952 | kfree(entry); |
| 1953 | rtlpriv->scan_list.num--; |
| 1954 | } |
| 1955 | } |
| 1956 | |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 1957 | static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw, |
| 1958 | bool chk_timeout) |
| 1959 | { |
| 1960 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1961 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1962 | struct sk_buff_head *queue = &tx_report->queue; |
| 1963 | struct sk_buff *skb, *tmp; |
| 1964 | struct rtlwifi_tx_info *tx_info; |
| 1965 | |
| 1966 | skb_queue_walk_safe(queue, skb, tmp) { |
| 1967 | tx_info = rtl_tx_skb_cb_info(skb); |
| 1968 | if (chk_timeout && |
| 1969 | time_after(tx_info->send_time + HZ, jiffies)) |
| 1970 | continue; |
| 1971 | skb_unlink(skb, queue); |
| 1972 | rtl_tx_status(hw, skb, false); |
| 1973 | } |
| 1974 | } |
| 1975 | |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 1976 | void rtl_scan_list_expire(struct ieee80211_hw *hw) |
| 1977 | { |
| 1978 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1979 | struct rtl_bssid_entry *entry, *next; |
| 1980 | unsigned long flags; |
| 1981 | |
| 1982 | spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags); |
| 1983 | |
| 1984 | list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) { |
| 1985 | /* 180 seconds */ |
| 1986 | if (jiffies_to_msecs(jiffies - entry->age) < 180000) |
| 1987 | continue; |
| 1988 | |
| 1989 | list_del(&entry->list); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 1990 | rtlpriv->scan_list.num--; |
| 1991 | |
| 1992 | RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD, |
| 1993 | "BSSID=%pM is expire in scan list (total=%d)\n", |
| 1994 | entry->bssid, rtlpriv->scan_list.num); |
Colin Ian King | d0116f6 | 2017-06-30 11:08:43 +0100 | [diff] [blame] | 1995 | kfree(entry); |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags); |
| 1999 | |
| 2000 | rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num; |
| 2001 | } |
| 2002 | |
| 2003 | void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 2004 | { |
| 2005 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2006 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 2007 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 2008 | unsigned long flags; |
| 2009 | |
| 2010 | struct rtl_bssid_entry *entry; |
| 2011 | bool entry_found = false; |
| 2012 | |
| 2013 | /* check if it is scanning */ |
| 2014 | if (!mac->act_scanning) |
| 2015 | return; |
| 2016 | |
| 2017 | /* check if this really is a beacon */ |
| 2018 | if (!ieee80211_is_beacon(hdr->frame_control) && |
| 2019 | !ieee80211_is_probe_resp(hdr->frame_control)) |
| 2020 | return; |
| 2021 | |
| 2022 | spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags); |
| 2023 | |
| 2024 | list_for_each_entry(entry, &rtlpriv->scan_list.list, list) { |
| 2025 | if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) { |
| 2026 | list_del_init(&entry->list); |
| 2027 | entry_found = true; |
| 2028 | RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD, |
| 2029 | "Update BSSID=%pM to scan list (total=%d)\n", |
| 2030 | hdr->addr3, rtlpriv->scan_list.num); |
| 2031 | break; |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | if (!entry_found) { |
| 2036 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 2037 | |
| 2038 | if (!entry) |
| 2039 | goto label_err; |
| 2040 | |
| 2041 | memcpy(entry->bssid, hdr->addr3, ETH_ALEN); |
| 2042 | rtlpriv->scan_list.num++; |
| 2043 | |
| 2044 | RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD, |
| 2045 | "Add BSSID=%pM to scan list (total=%d)\n", |
| 2046 | hdr->addr3, rtlpriv->scan_list.num); |
| 2047 | } |
| 2048 | |
| 2049 | entry->age = jiffies; |
| 2050 | |
| 2051 | list_add_tail(&entry->list, &rtlpriv->scan_list.list); |
| 2052 | |
| 2053 | label_err: |
| 2054 | spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags); |
| 2055 | } |
| 2056 | EXPORT_SYMBOL(rtl_collect_scan_list); |
| 2057 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2058 | void rtl_watchdog_wq_callback(void *data) |
| 2059 | { |
| 2060 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 2061 | struct rtl_works, |
| 2062 | watchdog_wq); |
| 2063 | struct ieee80211_hw *hw = rtlworks->hw; |
| 2064 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2065 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2066 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2067 | bool busytraffic = false; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2068 | bool tx_busy_traffic = false; |
| 2069 | bool rx_busy_traffic = false; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2070 | bool higher_busytraffic = false; |
| 2071 | bool higher_busyrxtraffic = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2072 | u8 idx, tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2073 | u32 rx_cnt_inp4eriod = 0; |
| 2074 | u32 tx_cnt_inp4eriod = 0; |
| 2075 | u32 aver_rx_cnt_inperiod = 0; |
| 2076 | u32 aver_tx_cnt_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2077 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
| 2078 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2079 | |
| 2080 | if (is_hal_stop(rtlhal)) |
| 2081 | return; |
| 2082 | |
| 2083 | /* <1> Determine if action frame is allowed */ |
| 2084 | if (mac->link_state > MAC80211_NOLINK) { |
| 2085 | if (mac->cnt_after_linked < 20) |
| 2086 | mac->cnt_after_linked++; |
| 2087 | } else { |
| 2088 | mac->cnt_after_linked = 0; |
| 2089 | } |
| 2090 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2091 | /* <2> to check if traffic busy, if |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2092 | * busytraffic we don't change channel |
| 2093 | */ |
| 2094 | if (mac->link_state >= MAC80211_LINKED) { |
| 2095 | |
| 2096 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ |
| 2097 | for (idx = 0; idx <= 2; idx++) { |
| 2098 | rtlpriv->link_info.num_rx_in4period[idx] = |
| 2099 | rtlpriv->link_info.num_rx_in4period[idx + 1]; |
| 2100 | rtlpriv->link_info.num_tx_in4period[idx] = |
| 2101 | rtlpriv->link_info.num_tx_in4period[idx + 1]; |
| 2102 | } |
| 2103 | rtlpriv->link_info.num_rx_in4period[3] = |
| 2104 | rtlpriv->link_info.num_rx_inperiod; |
| 2105 | rtlpriv->link_info.num_tx_in4period[3] = |
| 2106 | rtlpriv->link_info.num_tx_inperiod; |
| 2107 | for (idx = 0; idx <= 3; idx++) { |
| 2108 | rx_cnt_inp4eriod += |
| 2109 | rtlpriv->link_info.num_rx_in4period[idx]; |
| 2110 | tx_cnt_inp4eriod += |
| 2111 | rtlpriv->link_info.num_tx_in4period[idx]; |
| 2112 | } |
| 2113 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; |
| 2114 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; |
| 2115 | |
| 2116 | /* (2) check traffic busy */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2117 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2118 | busytraffic = true; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2119 | if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) |
| 2120 | rx_busy_traffic = true; |
| 2121 | else |
| 2122 | tx_busy_traffic = false; |
| 2123 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2124 | |
| 2125 | /* Higher Tx/Rx data. */ |
| 2126 | if (aver_rx_cnt_inperiod > 4000 || |
| 2127 | aver_tx_cnt_inperiod > 4000) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2128 | higher_busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2129 | |
| 2130 | /* Extremely high Rx data. */ |
| 2131 | if (aver_rx_cnt_inperiod > 5000) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2132 | higher_busyrxtraffic = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | /* check every tid's tx traffic */ |
| 2136 | for (tid = 0; tid <= 7; tid++) { |
| 2137 | for (idx = 0; idx <= 2; idx++) |
| 2138 | rtlpriv->link_info.tidtx_in4period[tid][idx] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2139 | rtlpriv->link_info.tidtx_in4period[tid] |
| 2140 | [idx + 1]; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2141 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
| 2142 | rtlpriv->link_info.tidtx_inperiod[tid]; |
| 2143 | |
| 2144 | for (idx = 0; idx <= 3; idx++) |
| 2145 | tidtx_inp4eriod[tid] += |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2146 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2147 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
| 2148 | if (aver_tidtx_inperiod[tid] > 5000) |
| 2149 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2150 | true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2151 | else |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2152 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2153 | false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2154 | } |
| 2155 | |
Ping-Ke Shih | 42213f2 | 2017-06-18 11:12:49 -0500 | [diff] [blame] | 2156 | /* PS is controlled by coex. */ |
| 2157 | if (rtlpriv->cfg->ops->get_btc_status() && |
| 2158 | rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv)) |
| 2159 | goto label_lps_done; |
| 2160 | |
Frank A. Cancio Bello | d63589c | 2017-12-29 16:31:08 +0800 | [diff] [blame] | 2161 | if (rtlpriv->link_info.num_rx_inperiod + |
| 2162 | rtlpriv->link_info.num_tx_inperiod > 8 || |
| 2163 | rtlpriv->link_info.num_rx_inperiod > 2) |
Larry Finger | fd09ff9 | 2014-09-22 09:39:18 -0500 | [diff] [blame] | 2164 | rtl_lps_leave(hw); |
wang yanqing | 873ffe1 | 2016-05-03 00:38:36 +0800 | [diff] [blame] | 2165 | else |
| 2166 | rtl_lps_enter(hw); |
Ping-Ke Shih | 42213f2 | 2017-06-18 11:12:49 -0500 | [diff] [blame] | 2167 | |
| 2168 | label_lps_done: |
| 2169 | ; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | rtlpriv->link_info.num_rx_inperiod = 0; |
| 2173 | rtlpriv->link_info.num_tx_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2174 | for (tid = 0; tid <= 7; tid++) |
| 2175 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2176 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2177 | rtlpriv->link_info.busytraffic = busytraffic; |
| 2178 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2179 | rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; |
| 2180 | rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 2181 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2182 | |
Ping-Ke Shih | 74451b9 | 2017-09-29 14:47:56 -0500 | [diff] [blame] | 2183 | rtlpriv->stats.txbytesunicast_inperiod = |
| 2184 | rtlpriv->stats.txbytesunicast - |
| 2185 | rtlpriv->stats.txbytesunicast_last; |
| 2186 | rtlpriv->stats.rxbytesunicast_inperiod = |
| 2187 | rtlpriv->stats.rxbytesunicast - |
| 2188 | rtlpriv->stats.rxbytesunicast_last; |
| 2189 | rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast; |
| 2190 | rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast; |
| 2191 | |
| 2192 | rtlpriv->stats.txbytesunicast_inperiod_tp = |
| 2193 | (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 / |
| 2194 | 1024 / 1024); |
| 2195 | rtlpriv->stats.rxbytesunicast_inperiod_tp = |
| 2196 | (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 / |
| 2197 | 1024 / 1024); |
| 2198 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2199 | /* <3> DM */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2200 | if (!rtlpriv->cfg->mod_params->disable_watchdog) |
| 2201 | rtlpriv->cfg->ops->dm_watchdog(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2202 | |
| 2203 | /* <4> roaming */ |
| 2204 | if (mac->link_state == MAC80211_LINKED && |
| 2205 | mac->opmode == NL80211_IFTYPE_STATION) { |
| 2206 | if ((rtlpriv->link_info.bcn_rx_inperiod + |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2207 | rtlpriv->link_info.num_rx_inperiod) == 0) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2208 | rtlpriv->link_info.roam_times++; |
| 2209 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
| 2210 | "AP off for %d s\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2211 | (rtlpriv->link_info.roam_times * 2)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2212 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2213 | /* if we can't recv beacon for 10s, |
| 2214 | * we should reconnect this AP |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2215 | */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2216 | if (rtlpriv->link_info.roam_times >= 5) { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 2217 | pr_err("AP off, try to reconnect now\n"); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2218 | rtlpriv->link_info.roam_times = 0; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2219 | ieee80211_connection_loss( |
| 2220 | rtlpriv->mac80211.vif); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2221 | } |
| 2222 | } else { |
| 2223 | rtlpriv->link_info.roam_times = 0; |
| 2224 | } |
| 2225 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2226 | |
| 2227 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 2228 | rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv); |
| 2229 | |
Ping-Ke Shih | 11f35c9 | 2017-07-02 13:12:30 -0500 | [diff] [blame] | 2230 | if (rtlpriv->btcoexist.btc_info.in_4way) { |
| 2231 | if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts + |
| 2232 | msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME))) |
| 2233 | rtlpriv->btcoexist.btc_info.in_4way = false; |
| 2234 | } |
| 2235 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2236 | rtlpriv->link_info.bcn_rx_inperiod = 0; |
Ping-Ke Shih | c76ab8e | 2017-06-21 12:15:37 -0500 | [diff] [blame] | 2237 | |
| 2238 | /* <6> scan list */ |
| 2239 | rtl_scan_list_expire(hw); |
Tzu-En Huang | 6acfbb8 | 2018-05-18 17:29:54 +0800 | [diff] [blame] | 2240 | |
| 2241 | /* <7> check ack queue */ |
| 2242 | rtl_free_entries_from_ack_queue(hw, true); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2243 | } |
| 2244 | |
Kees Cook | 7c51d17c | 2017-10-24 02:28:29 -0700 | [diff] [blame] | 2245 | void rtl_watch_dog_timer_callback(struct timer_list *t) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2246 | { |
Kees Cook | 7c51d17c | 2017-10-24 02:28:29 -0700 | [diff] [blame] | 2247 | struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2248 | |
| 2249 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 2250 | &rtlpriv->works.watchdog_wq, 0); |
| 2251 | |
| 2252 | mod_timer(&rtlpriv->works.watchdog_timer, |
| 2253 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); |
| 2254 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2255 | void rtl_fwevt_wq_callback(void *data) |
| 2256 | { |
| 2257 | struct rtl_works *rtlworks = |
| 2258 | container_of_dwork_rtl(data, struct rtl_works, fwevt_wq); |
| 2259 | struct ieee80211_hw *hw = rtlworks->hw; |
| 2260 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2261 | |
| 2262 | rtlpriv->cfg->ops->c2h_command_handle(hw); |
| 2263 | } |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2264 | |
Ping-Ke Shih | 0a9f8f0 | 2018-05-18 17:30:07 +0800 | [diff] [blame] | 2265 | static void rtl_c2h_content_parsing(struct ieee80211_hw *hw, |
| 2266 | struct sk_buff *skb); |
| 2267 | |
| 2268 | static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 2269 | { |
| 2270 | u8 cmd_id = GET_C2H_CMD_ID(skb->data); |
| 2271 | |
| 2272 | switch (cmd_id) { |
| 2273 | case C2H_BT_MP: |
| 2274 | return true; |
| 2275 | default: |
| 2276 | break; |
| 2277 | } |
| 2278 | |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2282 | void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb) |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2283 | { |
| 2284 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2285 | unsigned long flags; |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2286 | |
Ping-Ke Shih | 0a9f8f0 | 2018-05-18 17:30:07 +0800 | [diff] [blame] | 2287 | if (rtl_c2h_fast_cmd(hw, skb)) { |
| 2288 | rtl_c2h_content_parsing(hw, skb); |
| 2289 | return; |
| 2290 | } |
| 2291 | |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2292 | /* enqueue */ |
| 2293 | spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags); |
| 2294 | |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2295 | __skb_queue_tail(&rtlpriv->c2hcmd_queue, skb); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2296 | |
| 2297 | spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags); |
| 2298 | |
| 2299 | /* wake up wq */ |
| 2300 | queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2301 | } |
| 2302 | EXPORT_SYMBOL(rtl_c2hcmd_enqueue); |
| 2303 | |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2304 | static void rtl_c2h_content_parsing(struct ieee80211_hw *hw, |
| 2305 | struct sk_buff *skb) |
Ping-Ke Shih | daf026a | 2018-05-18 17:30:02 +0800 | [diff] [blame] | 2306 | { |
| 2307 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2308 | struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops; |
| 2309 | const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2310 | u8 cmd_id, cmd_seq, cmd_len; |
| 2311 | u8 *cmd_buf = NULL; |
| 2312 | |
Ping-Ke Shih | 9644032 | 2018-05-18 17:30:06 +0800 | [diff] [blame] | 2313 | cmd_id = GET_C2H_CMD_ID(skb->data); |
| 2314 | cmd_seq = GET_C2H_SEQ(skb->data); |
| 2315 | cmd_len = skb->len - C2H_DATA_OFFSET; |
| 2316 | cmd_buf = GET_C2H_DATA_PTR(skb->data); |
Ping-Ke Shih | daf026a | 2018-05-18 17:30:02 +0800 | [diff] [blame] | 2317 | |
| 2318 | switch (cmd_id) { |
| 2319 | case C2H_DBG: |
| 2320 | RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "[C2H], C2H_DBG!!\n"); |
| 2321 | break; |
| 2322 | case C2H_TXBF: |
| 2323 | RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, |
| 2324 | "[C2H], C2H_TXBF!!\n"); |
| 2325 | break; |
| 2326 | case C2H_TX_REPORT: |
| 2327 | rtl_tx_report_handler(hw, cmd_buf, cmd_len); |
| 2328 | break; |
| 2329 | case C2H_RA_RPT: |
| 2330 | if (hal_ops->c2h_ra_report_handler) |
| 2331 | hal_ops->c2h_ra_report_handler(hw, cmd_buf, cmd_len); |
| 2332 | break; |
| 2333 | case C2H_BT_INFO: |
| 2334 | RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, |
| 2335 | "[C2H], C2H_BT_INFO!!\n"); |
| 2336 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 2337 | btc_ops->btc_btinfo_notify(rtlpriv, cmd_buf, cmd_len); |
| 2338 | break; |
| 2339 | case C2H_BT_MP: |
| 2340 | RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, |
| 2341 | "[C2H], C2H_BT_MP!!\n"); |
| 2342 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 2343 | btc_ops->btc_btmpinfo_notify(rtlpriv, cmd_buf, cmd_len); |
| 2344 | break; |
| 2345 | default: |
| 2346 | RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, |
| 2347 | "[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id); |
| 2348 | break; |
| 2349 | } |
| 2350 | } |
Ping-Ke Shih | daf026a | 2018-05-18 17:30:02 +0800 | [diff] [blame] | 2351 | |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2352 | void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec) |
| 2353 | { |
| 2354 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2355 | struct sk_buff *skb; |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2356 | unsigned long flags; |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2357 | int i; |
| 2358 | |
| 2359 | for (i = 0; i < 200; i++) { |
| 2360 | /* dequeue a task */ |
| 2361 | spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags); |
| 2362 | |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2363 | skb = __skb_dequeue(&rtlpriv->c2hcmd_queue); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2364 | |
| 2365 | spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags); |
| 2366 | |
| 2367 | /* do it */ |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2368 | if (!skb) |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2369 | break; |
| 2370 | |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2371 | RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG, "C2H rx_desc_shift=%d\n", |
| 2372 | *((u8 *)skb->cb)); |
| 2373 | RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_DMESG, |
| 2374 | "C2H data: ", skb->data, skb->len); |
| 2375 | |
Ping-Ke Shih | b4f6ee4 | 2018-05-18 17:30:04 +0800 | [diff] [blame] | 2376 | if (exec) |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2377 | rtl_c2h_content_parsing(hw, skb); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2378 | |
| 2379 | /* free */ |
Ping-Ke Shih | 9ae6ed2 | 2018-05-18 17:30:05 +0800 | [diff] [blame] | 2380 | dev_kfree_skb_any(skb); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | void rtl_c2hcmd_wq_callback(void *data) |
| 2385 | { |
| 2386 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 2387 | struct rtl_works, |
| 2388 | c2hcmd_wq); |
| 2389 | struct ieee80211_hw *hw = rtlworks->hw; |
| 2390 | |
| 2391 | rtl_c2hcmd_launcher(hw, 1); |
| 2392 | } |
| 2393 | |
Kees Cook | 7c51d17c | 2017-10-24 02:28:29 -0700 | [diff] [blame] | 2394 | void rtl_easy_concurrent_retrytimer_callback(struct timer_list *t) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2395 | { |
Kees Cook | 7c51d17c | 2017-10-24 02:28:29 -0700 | [diff] [blame] | 2396 | struct rtl_priv *rtlpriv = |
| 2397 | from_timer(rtlpriv, t, works.dualmac_easyconcurrent_retrytimer); |
| 2398 | struct ieee80211_hw *hw = rtlpriv->hw; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2399 | struct rtl_priv *buddy_priv = rtlpriv->buddy_priv; |
| 2400 | |
| 2401 | if (buddy_priv == NULL) |
| 2402 | return; |
| 2403 | |
| 2404 | rtlpriv->cfg->ops->dualmac_easy_concurrent(hw); |
| 2405 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2406 | /********************************************************* |
| 2407 | * |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2408 | * frame process functions |
| 2409 | * |
| 2410 | *********************************************************/ |
| 2411 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) |
| 2412 | { |
| 2413 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 2414 | u8 *pos, *end; |
| 2415 | |
| 2416 | pos = (u8 *)mgmt->u.beacon.variable; |
| 2417 | end = data + len; |
| 2418 | while (pos < end) { |
| 2419 | if (pos + 2 + pos[1] > end) |
| 2420 | return NULL; |
| 2421 | |
| 2422 | if (pos[0] == ie) |
| 2423 | return pos; |
| 2424 | |
| 2425 | pos += 2 + pos[1]; |
| 2426 | } |
| 2427 | return NULL; |
| 2428 | } |
| 2429 | |
| 2430 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ |
| 2431 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 2432 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2433 | enum ieee80211_smps_mode smps, |
| 2434 | u8 *da, u8 *bssid) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2435 | { |
| 2436 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 2437 | struct sk_buff *skb; |
| 2438 | struct ieee80211_mgmt *action_frame; |
| 2439 | |
| 2440 | /* 27 = header + category + action + smps mode */ |
| 2441 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); |
| 2442 | if (!skb) |
| 2443 | return NULL; |
| 2444 | |
| 2445 | skb_reserve(skb, hw->extra_tx_headroom); |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 2446 | action_frame = skb_put_zero(skb, 27); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2447 | memcpy(action_frame->da, da, ETH_ALEN); |
| 2448 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); |
| 2449 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 2450 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2451 | IEEE80211_STYPE_ACTION); |
| 2452 | action_frame->u.action.category = WLAN_CATEGORY_HT; |
| 2453 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; |
| 2454 | switch (smps) { |
| 2455 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ |
| 2456 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ |
| 2457 | WARN_ON(1); |
Gustavo A. R. Silva | 032cf9a | 2017-12-29 16:31:07 +0800 | [diff] [blame] | 2458 | /* fall through */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2459 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
| 2460 | action_frame->u.action.u.ht_smps.smps_control = |
| 2461 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ |
| 2462 | break; |
| 2463 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ |
| 2464 | action_frame->u.action.u.ht_smps.smps_control = |
| 2465 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ |
| 2466 | break; |
| 2467 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ |
| 2468 | action_frame->u.action.u.ht_smps.smps_control = |
| 2469 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ |
| 2470 | break; |
| 2471 | } |
| 2472 | |
| 2473 | return skb; |
| 2474 | } |
| 2475 | |
| 2476 | int rtl_send_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2477 | struct ieee80211_sta *sta, |
| 2478 | enum ieee80211_smps_mode smps) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2479 | { |
| 2480 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2481 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2482 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2483 | struct sk_buff *skb = NULL; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2484 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2485 | u8 bssid[ETH_ALEN] = {0}; |
| 2486 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2487 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 2488 | |
| 2489 | if (rtlpriv->mac80211.act_scanning) |
| 2490 | goto err_free; |
| 2491 | |
| 2492 | if (!sta) |
| 2493 | goto err_free; |
| 2494 | |
| 2495 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 2496 | goto err_free; |
| 2497 | |
| 2498 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 2499 | goto err_free; |
| 2500 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2501 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) |
| 2502 | memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); |
| 2503 | else |
| 2504 | memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); |
| 2505 | |
| 2506 | skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2507 | /* this is a type = mgmt * stype = action frame */ |
| 2508 | if (skb) { |
| 2509 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2510 | struct rtl_sta_info *sta_entry = |
| 2511 | (struct rtl_sta_info *) sta->drv_priv; |
| 2512 | sta_entry->mimo_ps = smps; |
Ping-Ke Shih | 1d22b17 | 2017-09-29 14:47:59 -0500 | [diff] [blame] | 2513 | /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2514 | |
| 2515 | info->control.rates[0].idx = 0; |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2516 | info->band = hw->conf.chandef.chan->band; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 2517 | rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2518 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2519 | return 1; |
| 2520 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2521 | err_free: |
| 2522 | return 0; |
| 2523 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2524 | EXPORT_SYMBOL(rtl_send_smps_action); |
| 2525 | |
Larry Finger | 4f4826d | 2013-09-26 13:25:27 -0500 | [diff] [blame] | 2526 | void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) |
| 2527 | { |
| 2528 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2529 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2530 | enum io_type iotype; |
| 2531 | |
| 2532 | if (!is_hal_stop(rtlhal)) { |
| 2533 | switch (operation) { |
| 2534 | case SCAN_OPT_BACKUP: |
| 2535 | iotype = IO_CMD_PAUSE_DM_BY_SCAN; |
| 2536 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 2537 | HW_VAR_IO_CMD, |
| 2538 | (u8 *)&iotype); |
| 2539 | break; |
| 2540 | case SCAN_OPT_RESTORE: |
| 2541 | iotype = IO_CMD_RESUME_DM_BY_SCAN; |
| 2542 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 2543 | HW_VAR_IO_CMD, |
| 2544 | (u8 *)&iotype); |
| 2545 | break; |
| 2546 | default: |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 2547 | pr_err("Unknown Scan Backup operation.\n"); |
Larry Finger | 4f4826d | 2013-09-26 13:25:27 -0500 | [diff] [blame] | 2548 | break; |
| 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | EXPORT_SYMBOL(rtl_phy_scan_operation_backup); |
| 2553 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2554 | /* because mac80211 have issues when can receive del ba |
| 2555 | * so here we just make a fake del_ba if we receive a ba_req |
| 2556 | * but rx_agg was opened to let mac80211 release some ba |
| 2557 | * related resources, so please this del_ba for tx |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2558 | */ |
| 2559 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, |
| 2560 | u8 *sa, u8 *bssid, u16 tid) |
| 2561 | { |
| 2562 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 2563 | struct sk_buff *skb; |
| 2564 | struct ieee80211_mgmt *action_frame; |
| 2565 | u16 params; |
| 2566 | |
| 2567 | /* 27 = header + category + action + smps mode */ |
| 2568 | skb = dev_alloc_skb(34 + hw->extra_tx_headroom); |
| 2569 | if (!skb) |
| 2570 | return NULL; |
| 2571 | |
| 2572 | skb_reserve(skb, hw->extra_tx_headroom); |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 2573 | action_frame = skb_put_zero(skb, 34); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2574 | memcpy(action_frame->sa, sa, ETH_ALEN); |
| 2575 | memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); |
| 2576 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 2577 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2578 | IEEE80211_STYPE_ACTION); |
| 2579 | action_frame->u.action.category = WLAN_CATEGORY_BACK; |
| 2580 | action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 2581 | params = (u16)(1 << 11); /* bit 11 initiator */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2582 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2583 | |
| 2584 | action_frame->u.action.u.delba.params = cpu_to_le16(params); |
| 2585 | action_frame->u.action.u.delba.reason_code = |
| 2586 | cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); |
| 2587 | |
| 2588 | return skb; |
| 2589 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2590 | |
| 2591 | /********************************************************* |
| 2592 | * |
| 2593 | * IOT functions |
| 2594 | * |
| 2595 | *********************************************************/ |
| 2596 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2597 | struct octet_string vendor_ie) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2598 | { |
| 2599 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2600 | bool matched = false; |
| 2601 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; |
| 2602 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; |
| 2603 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; |
| 2604 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; |
| 2605 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; |
| 2606 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; |
| 2607 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; |
| 2608 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; |
| 2609 | |
| 2610 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || |
| 2611 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { |
| 2612 | rtlpriv->mac80211.vendor = PEER_ATH; |
| 2613 | matched = true; |
| 2614 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || |
| 2615 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || |
| 2616 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { |
| 2617 | rtlpriv->mac80211.vendor = PEER_BROAD; |
| 2618 | matched = true; |
| 2619 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { |
| 2620 | rtlpriv->mac80211.vendor = PEER_RAL; |
| 2621 | matched = true; |
| 2622 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { |
| 2623 | rtlpriv->mac80211.vendor = PEER_CISCO; |
| 2624 | matched = true; |
| 2625 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { |
| 2626 | rtlpriv->mac80211.vendor = PEER_MARV; |
| 2627 | matched = true; |
| 2628 | } |
| 2629 | |
| 2630 | return matched; |
| 2631 | } |
| 2632 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 2633 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2634 | unsigned int len) |
| 2635 | { |
| 2636 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 2637 | struct octet_string vendor_ie; |
| 2638 | u8 *pos, *end; |
| 2639 | |
| 2640 | pos = (u8 *)mgmt->u.beacon.variable; |
| 2641 | end = data + len; |
| 2642 | while (pos < end) { |
| 2643 | if (pos[0] == 221) { |
| 2644 | vendor_ie.length = pos[1]; |
| 2645 | vendor_ie.octet = &pos[2]; |
| 2646 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) |
| 2647 | return true; |
| 2648 | } |
| 2649 | |
| 2650 | if (pos + 2 + pos[1] > end) |
| 2651 | return false; |
| 2652 | |
| 2653 | pos += 2 + pos[1]; |
| 2654 | } |
| 2655 | return false; |
| 2656 | } |
| 2657 | |
| 2658 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) |
| 2659 | { |
| 2660 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2661 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 2662 | struct ieee80211_hdr *hdr = (void *)data; |
| 2663 | u32 vendor = PEER_UNKNOWN; |
| 2664 | |
| 2665 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; |
| 2666 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; |
| 2667 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; |
| 2668 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; |
| 2669 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; |
| 2670 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; |
| 2671 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; |
| 2672 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; |
| 2673 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; |
| 2674 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; |
| 2675 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; |
| 2676 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; |
| 2677 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; |
| 2678 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; |
| 2679 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; |
| 2680 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; |
| 2681 | |
| 2682 | if (mac->opmode != NL80211_IFTYPE_STATION) |
| 2683 | return; |
| 2684 | |
| 2685 | if (mac->link_state == MAC80211_NOLINK) { |
| 2686 | mac->vendor = PEER_UNKNOWN; |
| 2687 | return; |
| 2688 | } |
| 2689 | |
| 2690 | if (mac->cnt_after_linked > 2) |
| 2691 | return; |
| 2692 | |
| 2693 | /* check if this really is a beacon */ |
| 2694 | if (!ieee80211_is_beacon(hdr->frame_control)) |
| 2695 | return; |
| 2696 | |
| 2697 | /* min. beacon length + FCS_LEN */ |
| 2698 | if (len <= 40 + FCS_LEN) |
| 2699 | return; |
| 2700 | |
| 2701 | /* and only beacons from the associated BSSID, please */ |
Julia Lawall | 90908e1 | 2013-12-30 19:15:02 +0100 | [diff] [blame] | 2702 | if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2703 | return; |
| 2704 | |
| 2705 | if (rtl_find_221_ie(hw, data, len)) |
| 2706 | vendor = mac->vendor; |
| 2707 | |
| 2708 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || |
| 2709 | (memcmp(mac->bssid, ap5_2, 3) == 0) || |
| 2710 | (memcmp(mac->bssid, ap5_3, 3) == 0) || |
| 2711 | (memcmp(mac->bssid, ap5_4, 3) == 0) || |
| 2712 | (memcmp(mac->bssid, ap5_5, 3) == 0) || |
| 2713 | (memcmp(mac->bssid, ap5_6, 3) == 0) || |
| 2714 | vendor == PEER_ATH) { |
| 2715 | vendor = PEER_ATH; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2716 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2717 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
| 2718 | (memcmp(mac->bssid, ap4_5, 3) == 0) || |
| 2719 | (memcmp(mac->bssid, ap4_1, 3) == 0) || |
| 2720 | (memcmp(mac->bssid, ap4_2, 3) == 0) || |
| 2721 | (memcmp(mac->bssid, ap4_3, 3) == 0) || |
| 2722 | vendor == PEER_RAL) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2723 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2724 | vendor = PEER_RAL; |
| 2725 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || |
| 2726 | vendor == PEER_CISCO) { |
| 2727 | vendor = PEER_CISCO; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2728 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2729 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
| 2730 | (memcmp(mac->bssid, ap3_2, 3) == 0) || |
| 2731 | (memcmp(mac->bssid, ap3_3, 3) == 0) || |
| 2732 | vendor == PEER_BROAD) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2733 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2734 | vendor = PEER_BROAD; |
| 2735 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || |
| 2736 | vendor == PEER_MARV) { |
| 2737 | vendor = PEER_MARV; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2738 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | mac->vendor = vendor; |
| 2742 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2743 | EXPORT_SYMBOL_GPL(rtl_recognize_peer); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2744 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2745 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); |
| 2746 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); |
| 2747 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); |
| 2748 | MODULE_LICENSE("GPL"); |
| 2749 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); |
| 2750 | |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2751 | struct rtl_global_var rtl_global_var = {}; |
| 2752 | EXPORT_SYMBOL_GPL(rtl_global_var); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2753 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2754 | static int __init rtl_core_module_init(void) |
| 2755 | { |
Ping-Ke Shih | 4a7093b | 2018-01-29 11:26:35 +0800 | [diff] [blame] | 2756 | BUILD_BUG_ON(TX_PWR_BY_RATE_NUM_RATE < TX_PWR_BY_RATE_NUM_SECTION); |
Ping-Ke Shih | 81b813e | 2018-01-29 11:26:36 +0800 | [diff] [blame] | 2757 | BUILD_BUG_ON(MAX_RATE_SECTION_NUM != MAX_RATE_SECTION); |
| 2758 | BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_24G != MAX_RATE_SECTION); |
| 2759 | BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_5G != (MAX_RATE_SECTION - 1)); |
Ping-Ke Shih | 4a7093b | 2018-01-29 11:26:35 +0800 | [diff] [blame] | 2760 | |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 2761 | if (rtl_rate_control_register()) |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2762 | pr_err("rtl: Unable to register rtl_rc, use default RC !!\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2763 | |
Ping-Ke Shih | 610247f | 2017-12-29 16:31:10 +0800 | [diff] [blame] | 2764 | /* add debugfs */ |
| 2765 | rtl_debugfs_add_topdir(); |
| 2766 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2767 | /* init some global vars */ |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2768 | INIT_LIST_HEAD(&rtl_global_var.glb_priv_list); |
| 2769 | spin_lock_init(&rtl_global_var.glb_list_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2770 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2771 | return 0; |
| 2772 | } |
| 2773 | |
| 2774 | static void __exit rtl_core_module_exit(void) |
| 2775 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2776 | /*RC*/ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 2777 | rtl_rate_control_unregister(); |
Ping-Ke Shih | 610247f | 2017-12-29 16:31:10 +0800 | [diff] [blame] | 2778 | |
| 2779 | /* remove debugfs */ |
| 2780 | rtl_debugfs_remove_topdir(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | module_init(rtl_core_module_init); |
| 2784 | module_exit(rtl_core_module_exit); |