Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2009-2013 Realtek Corporation. |
| 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 | f0eb856 | 2013-03-24 22:06:42 -0500 | [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 | |
Chen, Chien-Chia | 2a2ac75 | 2013-04-02 22:01:55 +0800 | [diff] [blame] | 26 | #include "../wifi.h" |
| 27 | #include "../pci.h" |
| 28 | #include "../base.h" |
| 29 | #include "../stats.h" |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 30 | #include "reg.h" |
| 31 | #include "def.h" |
| 32 | #include "phy.h" |
| 33 | #include "trx.h" |
| 34 | #include "led.h" |
| 35 | #include "dm.h" |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 36 | #include "phy.h" |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 37 | |
| 38 | static u8 _rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue) |
| 39 | { |
| 40 | __le16 fc = rtl_get_fc(skb); |
| 41 | |
| 42 | if (unlikely(ieee80211_is_beacon(fc))) |
| 43 | return QSLT_BEACON; |
| 44 | if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) |
| 45 | return QSLT_MGNT; |
| 46 | |
| 47 | return skb->priority; |
| 48 | } |
| 49 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 50 | /* mac80211's rate_idx is like this: |
| 51 | * |
| 52 | * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ |
| 53 | * |
| 54 | * B/G rate: |
| 55 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 56 | * DESC92C_RATE1M-->DESC92C_RATE54M ==> idx is 0-->11, |
| 57 | * |
| 58 | * N rate: |
| 59 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 60 | * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15 |
| 61 | * |
| 62 | * 5G band:rx_status->band == IEEE80211_BAND_5GHZ |
| 63 | * A rate: |
| 64 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 65 | * DESC92C_RATE6M-->DESC92C_RATE54M ==> idx is 0-->7, |
| 66 | * |
| 67 | * N rate: |
| 68 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 69 | * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15 |
| 70 | */ |
| 71 | static int _rtl88ee_rate_mapping(struct ieee80211_hw *hw, |
| 72 | bool isht, u8 desc_rate) |
| 73 | { |
| 74 | int rate_idx; |
| 75 | |
| 76 | if (!isht) { |
| 77 | if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
| 78 | switch (desc_rate) { |
| 79 | case DESC92C_RATE1M: |
| 80 | rate_idx = 0; |
| 81 | break; |
| 82 | case DESC92C_RATE2M: |
| 83 | rate_idx = 1; |
| 84 | break; |
| 85 | case DESC92C_RATE5_5M: |
| 86 | rate_idx = 2; |
| 87 | break; |
| 88 | case DESC92C_RATE11M: |
| 89 | rate_idx = 3; |
| 90 | break; |
| 91 | case DESC92C_RATE6M: |
| 92 | rate_idx = 4; |
| 93 | break; |
| 94 | case DESC92C_RATE9M: |
| 95 | rate_idx = 5; |
| 96 | break; |
| 97 | case DESC92C_RATE12M: |
| 98 | rate_idx = 6; |
| 99 | break; |
| 100 | case DESC92C_RATE18M: |
| 101 | rate_idx = 7; |
| 102 | break; |
| 103 | case DESC92C_RATE24M: |
| 104 | rate_idx = 8; |
| 105 | break; |
| 106 | case DESC92C_RATE36M: |
| 107 | rate_idx = 9; |
| 108 | break; |
| 109 | case DESC92C_RATE48M: |
| 110 | rate_idx = 10; |
| 111 | break; |
| 112 | case DESC92C_RATE54M: |
| 113 | rate_idx = 11; |
| 114 | break; |
| 115 | default: |
| 116 | rate_idx = 0; |
| 117 | break; |
| 118 | } |
| 119 | } else { |
| 120 | switch (desc_rate) { |
| 121 | case DESC92C_RATE6M: |
| 122 | rate_idx = 0; |
| 123 | break; |
| 124 | case DESC92C_RATE9M: |
| 125 | rate_idx = 1; |
| 126 | break; |
| 127 | case DESC92C_RATE12M: |
| 128 | rate_idx = 2; |
| 129 | break; |
| 130 | case DESC92C_RATE18M: |
| 131 | rate_idx = 3; |
| 132 | break; |
| 133 | case DESC92C_RATE24M: |
| 134 | rate_idx = 4; |
| 135 | break; |
| 136 | case DESC92C_RATE36M: |
| 137 | rate_idx = 5; |
| 138 | break; |
| 139 | case DESC92C_RATE48M: |
| 140 | rate_idx = 6; |
| 141 | break; |
| 142 | case DESC92C_RATE54M: |
| 143 | rate_idx = 7; |
| 144 | break; |
| 145 | default: |
| 146 | rate_idx = 0; |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | } else { |
| 151 | switch (desc_rate) { |
| 152 | case DESC92C_RATEMCS0: |
| 153 | rate_idx = 0; |
| 154 | break; |
| 155 | case DESC92C_RATEMCS1: |
| 156 | rate_idx = 1; |
| 157 | break; |
| 158 | case DESC92C_RATEMCS2: |
| 159 | rate_idx = 2; |
| 160 | break; |
| 161 | case DESC92C_RATEMCS3: |
| 162 | rate_idx = 3; |
| 163 | break; |
| 164 | case DESC92C_RATEMCS4: |
| 165 | rate_idx = 4; |
| 166 | break; |
| 167 | case DESC92C_RATEMCS5: |
| 168 | rate_idx = 5; |
| 169 | break; |
| 170 | case DESC92C_RATEMCS6: |
| 171 | rate_idx = 6; |
| 172 | break; |
| 173 | case DESC92C_RATEMCS7: |
| 174 | rate_idx = 7; |
| 175 | break; |
| 176 | case DESC92C_RATEMCS8: |
| 177 | rate_idx = 8; |
| 178 | break; |
| 179 | case DESC92C_RATEMCS9: |
| 180 | rate_idx = 9; |
| 181 | break; |
| 182 | case DESC92C_RATEMCS10: |
| 183 | rate_idx = 10; |
| 184 | break; |
| 185 | case DESC92C_RATEMCS11: |
| 186 | rate_idx = 11; |
| 187 | break; |
| 188 | case DESC92C_RATEMCS12: |
| 189 | rate_idx = 12; |
| 190 | break; |
| 191 | case DESC92C_RATEMCS13: |
| 192 | rate_idx = 13; |
| 193 | break; |
| 194 | case DESC92C_RATEMCS14: |
| 195 | rate_idx = 14; |
| 196 | break; |
| 197 | case DESC92C_RATEMCS15: |
| 198 | rate_idx = 15; |
| 199 | break; |
| 200 | default: |
| 201 | rate_idx = 0; |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | return rate_idx; |
| 206 | } |
| 207 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 208 | static void _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw, |
| 209 | struct rtl_stats *pstatus, u8 *pdesc, |
| 210 | struct rx_fwinfo_88e *p_drvinfo, |
| 211 | bool bpacket_match_bssid, |
| 212 | bool bpacket_toself, bool packet_beacon) |
| 213 | { |
| 214 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 215 | struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); |
| 216 | struct phy_sts_cck_8192s_t *cck_buf; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 217 | struct phy_status_rpt *phystrpt = |
| 218 | (struct phy_status_rpt *)p_drvinfo; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 219 | struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw)); |
| 220 | char rx_pwr_all = 0, rx_pwr[4]; |
| 221 | u8 rf_rx_num = 0, evm, pwdb_all; |
| 222 | u8 i, max_spatial_stream; |
| 223 | u32 rssi, total_rssi = 0; |
| 224 | bool is_cck = pstatus->is_cck; |
| 225 | u8 lan_idx, vga_idx; |
| 226 | |
| 227 | /* Record it for next packet processing */ |
| 228 | pstatus->packet_matchbssid = bpacket_match_bssid; |
| 229 | pstatus->packet_toself = bpacket_toself; |
| 230 | pstatus->packet_beacon = packet_beacon; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 231 | pstatus->rx_mimo_signalquality[0] = -1; |
| 232 | pstatus->rx_mimo_signalquality[1] = -1; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 233 | |
| 234 | if (is_cck) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 235 | u8 cck_highpwr; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 236 | u8 cck_agc_rpt; |
| 237 | /* CCK Driver info Structure is not the same as OFDM packet. */ |
| 238 | cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo; |
| 239 | cck_agc_rpt = cck_buf->cck_agc_rpt; |
| 240 | |
| 241 | /* (1)Hardware does not provide RSSI for CCK |
| 242 | * (2)PWDB, Average PWDB cacluated by |
| 243 | * hardware (for rate adaptive) |
| 244 | */ |
| 245 | if (ppsc->rfpwr_state == ERFON) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 246 | cck_highpwr = |
| 247 | (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 248 | BIT(9)); |
| 249 | else |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 250 | cck_highpwr = false; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 251 | |
| 252 | lan_idx = ((cck_agc_rpt & 0xE0) >> 5); |
| 253 | vga_idx = (cck_agc_rpt & 0x1f); |
| 254 | switch (lan_idx) { |
| 255 | case 7: |
| 256 | if (vga_idx <= 27) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 257 | /*VGA_idx = 27~2*/ |
| 258 | rx_pwr_all = -100 + 2*(27-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 259 | else |
| 260 | rx_pwr_all = -100; |
| 261 | break; |
| 262 | case 6: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 263 | /*VGA_idx = 2~0*/ |
| 264 | rx_pwr_all = -48 + 2*(2-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 265 | break; |
| 266 | case 5: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 267 | /*VGA_idx = 7~5*/ |
| 268 | rx_pwr_all = -42 + 2*(7-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 269 | break; |
| 270 | case 4: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 271 | /*VGA_idx = 7~4*/ |
| 272 | rx_pwr_all = -36 + 2*(7-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 273 | break; |
| 274 | case 3: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 275 | /*VGA_idx = 7~0*/ |
| 276 | rx_pwr_all = -24 + 2*(7-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 277 | break; |
| 278 | case 2: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 279 | if (cck_highpwr) |
| 280 | /*VGA_idx = 5~0*/ |
| 281 | rx_pwr_all = -12 + 2*(5-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 282 | else |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 283 | rx_pwr_all = -6 + 2*(5-vga_idx); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 284 | break; |
| 285 | case 1: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 286 | rx_pwr_all = 8-2*vga_idx; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 287 | break; |
| 288 | case 0: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 289 | rx_pwr_all = 14-2*vga_idx; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 290 | break; |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | rx_pwr_all += 6; |
| 295 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 296 | /* CCK gain is smaller than OFDM/MCS gain, */ |
| 297 | /* so we add gain diff by experiences, the val is 6 */ |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 298 | pwdb_all += 6; |
| 299 | if (pwdb_all > 100) |
| 300 | pwdb_all = 100; |
| 301 | /* modify the offset to make the same |
| 302 | * gain index with OFDM. |
| 303 | */ |
| 304 | if (pwdb_all > 34 && pwdb_all <= 42) |
| 305 | pwdb_all -= 2; |
| 306 | else if (pwdb_all > 26 && pwdb_all <= 34) |
| 307 | pwdb_all -= 6; |
| 308 | else if (pwdb_all > 14 && pwdb_all <= 26) |
| 309 | pwdb_all -= 8; |
| 310 | else if (pwdb_all > 4 && pwdb_all <= 14) |
| 311 | pwdb_all -= 4; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 312 | if (!cck_highpwr) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 313 | if (pwdb_all >= 80) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 314 | pwdb_all = ((pwdb_all-80)<<1) + |
| 315 | ((pwdb_all-80)>>1) + 80; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 316 | else if ((pwdb_all <= 78) && (pwdb_all >= 20)) |
| 317 | pwdb_all += 3; |
| 318 | if (pwdb_all > 100) |
| 319 | pwdb_all = 100; |
| 320 | } |
| 321 | |
| 322 | pstatus->rx_pwdb_all = pwdb_all; |
| 323 | pstatus->recvsignalpower = rx_pwr_all; |
| 324 | |
| 325 | /* (3) Get Signal Quality (EVM) */ |
| 326 | if (bpacket_match_bssid) { |
| 327 | u8 sq; |
| 328 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 329 | if (pstatus->rx_pwdb_all > 40) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 330 | sq = 100; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 331 | else { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 332 | sq = cck_buf->sq_rpt; |
| 333 | if (sq > 64) |
| 334 | sq = 0; |
| 335 | else if (sq < 20) |
| 336 | sq = 100; |
| 337 | else |
| 338 | sq = ((64 - sq) * 100) / 44; |
| 339 | } |
| 340 | |
| 341 | pstatus->signalquality = sq; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 342 | pstatus->rx_mimo_signalquality[0] = sq; |
| 343 | pstatus->rx_mimo_signalquality[1] = -1; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 344 | } |
| 345 | } else { |
| 346 | rtlpriv->dm.rfpath_rxenable[0] = |
| 347 | rtlpriv->dm.rfpath_rxenable[1] = true; |
| 348 | |
| 349 | /* (1)Get RSSI for HT rate */ |
| 350 | for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) { |
| 351 | /* we will judge RF RX path now. */ |
| 352 | if (rtlpriv->dm.rfpath_rxenable[i]) |
| 353 | rf_rx_num++; |
| 354 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 355 | rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & |
| 356 | 0x3f) * 2) - 110; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 357 | |
| 358 | /* Translate DBM to percentage. */ |
| 359 | rssi = rtl_query_rxpwrpercentage(rx_pwr[i]); |
| 360 | total_rssi += rssi; |
| 361 | |
| 362 | /* Get Rx snr value in DB */ |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 363 | rtlpriv->stats.rx_snr_db[i] = |
| 364 | (long)(p_drvinfo->rxsnr[i] / 2); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 365 | |
| 366 | /* Record Signal Strength for next packet */ |
| 367 | if (bpacket_match_bssid) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 368 | pstatus->rx_mimo_signalstrength[i] = (u8)rssi; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* (2)PWDB, Average PWDB cacluated by |
| 372 | * hardware (for rate adaptive) |
| 373 | */ |
| 374 | rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110; |
| 375 | |
| 376 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); |
| 377 | pstatus->rx_pwdb_all = pwdb_all; |
| 378 | pstatus->rxpower = rx_pwr_all; |
| 379 | pstatus->recvsignalpower = rx_pwr_all; |
| 380 | |
| 381 | /* (3)EVM of HT rate */ |
| 382 | if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 && |
| 383 | pstatus->rate <= DESC92C_RATEMCS15) |
| 384 | max_spatial_stream = 2; |
| 385 | else |
| 386 | max_spatial_stream = 1; |
| 387 | |
| 388 | for (i = 0; i < max_spatial_stream; i++) { |
| 389 | evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]); |
| 390 | |
| 391 | if (bpacket_match_bssid) { |
| 392 | /* Fill value in RFD, Get the first |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 393 | * spatial stream onlyi |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 394 | */ |
| 395 | if (i == 0) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 396 | pstatus->signalquality = |
| 397 | (u8)(evm & 0xff); |
| 398 | pstatus->rx_mimo_signalquality[i] = |
| 399 | (u8)(evm & 0xff); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /* UI BSS List signal strength(in percentage), |
| 405 | * make it good looking, from 0~100. |
| 406 | */ |
| 407 | if (is_cck) |
| 408 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 409 | pwdb_all)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 410 | else if (rf_rx_num != 0) |
| 411 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 412 | total_rssi /= rf_rx_num)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 413 | /*HW antenna diversity*/ |
| 414 | rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel; |
| 415 | rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b; |
| 416 | rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2; |
| 417 | } |
| 418 | |
| 419 | static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw, |
| 420 | struct rtl_stats *pstatus) |
| 421 | { |
| 422 | struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw)); |
| 423 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 424 | u8 antsel_tr_mux; |
| 425 | struct fast_ant_training *pfat_table = &rtldm->fat_table; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 426 | |
| 427 | if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 428 | if (pfat_table->fat_state == FAT_TRAINING_STATE) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 429 | if (pstatus->packet_toself) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 430 | antsel_tr_mux = |
| 431 | (pfat_table->antsel_rx_keep_2 << 2) | |
| 432 | (pfat_table->antsel_rx_keep_1 << 1) | |
| 433 | pfat_table->antsel_rx_keep_0; |
| 434 | pfat_table->ant_sum[antsel_tr_mux] += |
| 435 | pstatus->rx_pwdb_all; |
| 436 | pfat_table->ant_cnt[antsel_tr_mux]++; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) || |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 440 | (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 441 | if (pstatus->packet_toself || pstatus->packet_matchbssid) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 442 | antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) | |
| 443 | (pfat_table->antsel_rx_keep_1 << 1) | |
| 444 | pfat_table->antsel_rx_keep_0; |
| 445 | rtl88e_dm_ant_sel_statistics(hw, antsel_tr_mux, 0, |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 446 | pstatus->rx_pwdb_all); |
| 447 | } |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 448 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 453 | struct sk_buff *skb, |
| 454 | struct rtl_stats *pstatus, |
| 455 | u8 *pdesc, |
| 456 | struct rx_fwinfo_88e *p_drvinfo) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 457 | { |
| 458 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 459 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 460 | struct ieee80211_hdr *hdr; |
| 461 | u8 *tmp_buf; |
| 462 | u8 *praddr; |
| 463 | u8 *psaddr; |
| 464 | __le16 fc; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 465 | bool packet_matchbssid, packet_toself, packet_beacon; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 466 | |
| 467 | tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift; |
| 468 | |
| 469 | hdr = (struct ieee80211_hdr *)tmp_buf; |
| 470 | fc = hdr->frame_control; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 471 | praddr = hdr->addr1; |
| 472 | psaddr = ieee80211_get_SA(hdr); |
| 473 | memcpy(pstatus->psaddr, psaddr, ETH_ALEN); |
| 474 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 475 | packet_matchbssid = ((!ieee80211_is_ctl(fc)) && |
| 476 | (ether_addr_equal(mac->bssid, ieee80211_has_tods(fc) ? |
| 477 | hdr->addr1 : ieee80211_has_fromds(fc) ? |
| 478 | hdr->addr2 : hdr->addr3)) && |
| 479 | (!pstatus->hwerror) && |
| 480 | (!pstatus->crc) && (!pstatus->icv)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 481 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 482 | packet_toself = packet_matchbssid && |
| 483 | (ether_addr_equal(praddr, rtlefuse->dev_addr)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 484 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 485 | if (ieee80211_is_beacon(hdr->frame_control)) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 486 | packet_beacon = true; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 487 | else |
| 488 | packet_beacon = false; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 489 | |
| 490 | _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 491 | packet_matchbssid, packet_toself, |
| 492 | packet_beacon); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 493 | _rtl88ee_smart_antenna(hw, pstatus); |
| 494 | rtl_process_phyinfo(hw, tmp_buf, pstatus); |
| 495 | } |
| 496 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 497 | static void _rtl88ee_insert_emcontent(struct rtl_tcb_desc *ptcb_desc, |
| 498 | u8 *virtualaddress) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 499 | { |
| 500 | u32 dwtmp = 0; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 501 | memset(virtualaddress, 0, 8); |
| 502 | |
| 503 | SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num); |
| 504 | if (ptcb_desc->empkt_num == 1) { |
| 505 | dwtmp = ptcb_desc->empkt_len[0]; |
| 506 | } else { |
| 507 | dwtmp = ptcb_desc->empkt_len[0]; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 508 | dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 509 | dwtmp += ptcb_desc->empkt_len[1]; |
| 510 | } |
| 511 | SET_EARLYMODE_LEN0(virtualaddress, dwtmp); |
| 512 | |
| 513 | if (ptcb_desc->empkt_num <= 3) { |
| 514 | dwtmp = ptcb_desc->empkt_len[2]; |
| 515 | } else { |
| 516 | dwtmp = ptcb_desc->empkt_len[2]; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 517 | dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 518 | dwtmp += ptcb_desc->empkt_len[3]; |
| 519 | } |
| 520 | SET_EARLYMODE_LEN1(virtualaddress, dwtmp); |
| 521 | if (ptcb_desc->empkt_num <= 5) { |
| 522 | dwtmp = ptcb_desc->empkt_len[4]; |
| 523 | } else { |
| 524 | dwtmp = ptcb_desc->empkt_len[4]; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 525 | dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 526 | dwtmp += ptcb_desc->empkt_len[5]; |
| 527 | } |
| 528 | SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF); |
| 529 | SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4); |
| 530 | if (ptcb_desc->empkt_num <= 7) { |
| 531 | dwtmp = ptcb_desc->empkt_len[6]; |
| 532 | } else { |
| 533 | dwtmp = ptcb_desc->empkt_len[6]; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 534 | dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 535 | dwtmp += ptcb_desc->empkt_len[7]; |
| 536 | } |
| 537 | SET_EARLYMODE_LEN3(virtualaddress, dwtmp); |
| 538 | if (ptcb_desc->empkt_num <= 9) { |
| 539 | dwtmp = ptcb_desc->empkt_len[8]; |
| 540 | } else { |
| 541 | dwtmp = ptcb_desc->empkt_len[8]; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 542 | dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 543 | dwtmp += ptcb_desc->empkt_len[9]; |
| 544 | } |
| 545 | SET_EARLYMODE_LEN4(virtualaddress, dwtmp); |
| 546 | } |
| 547 | |
| 548 | bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw, |
| 549 | struct rtl_stats *status, |
| 550 | struct ieee80211_rx_status *rx_status, |
| 551 | u8 *pdesc, struct sk_buff *skb) |
| 552 | { |
| 553 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 554 | struct rx_fwinfo_88e *p_drvinfo; |
| 555 | struct ieee80211_hdr *hdr; |
| 556 | |
| 557 | u32 phystatus = GET_RX_DESC_PHYST(pdesc); |
| 558 | status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc); |
| 559 | if (status->packet_report_type == TX_REPORT2) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 560 | status->length = (u16)GET_RX_RPT2_DESC_PKT_LEN(pdesc); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 561 | else |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 562 | status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc); |
| 563 | status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) * |
| 564 | RX_DRV_INFO_SIZE_UNIT; |
| 565 | status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03); |
| 566 | status->icv = (u16)GET_RX_DESC_ICV(pdesc); |
| 567 | status->crc = (u16)GET_RX_DESC_CRC32(pdesc); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 568 | status->hwerror = (status->crc | status->icv); |
| 569 | status->decrypted = !GET_RX_DESC_SWDEC(pdesc); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 570 | status->rate = (u8)GET_RX_DESC_RXMCS(pdesc); |
| 571 | status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 572 | status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 573 | status->isfirst_ampdu = (bool)((GET_RX_DESC_PAGGR(pdesc) == 1) && |
| 574 | (GET_RX_DESC_FAGGR(pdesc) == 1)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 575 | if (status->packet_report_type == NORMAL_RX) |
| 576 | status->timestamp_low = GET_RX_DESC_TSFL(pdesc); |
| 577 | status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc); |
| 578 | status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc); |
| 579 | |
| 580 | status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate); |
| 581 | |
| 582 | status->macid = GET_RX_DESC_MACID(pdesc); |
| 583 | if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc)) |
| 584 | status->wake_match = BIT(2); |
| 585 | else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc)) |
| 586 | status->wake_match = BIT(1); |
| 587 | else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc)) |
| 588 | status->wake_match = BIT(0); |
| 589 | else |
| 590 | status->wake_match = 0; |
| 591 | if (status->wake_match) |
| 592 | RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 593 | "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n", |
| 594 | status->wake_match); |
John W. Linville | 655d8e2 | 2013-04-10 14:09:54 -0400 | [diff] [blame] | 595 | rx_status->freq = hw->conf.chandef.chan->center_freq; |
| 596 | rx_status->band = hw->conf.chandef.chan->band; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 597 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 598 | hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size |
| 599 | + status->rx_bufshift); |
| 600 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 601 | if (status->crc) |
| 602 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 603 | |
| 604 | if (status->rx_is40Mhzpacket) |
| 605 | rx_status->flag |= RX_FLAG_40MHZ; |
| 606 | |
| 607 | if (status->is_ht) |
| 608 | rx_status->flag |= RX_FLAG_HT; |
| 609 | |
| 610 | rx_status->flag |= RX_FLAG_MACTIME_START; |
| 611 | |
| 612 | /* hw will set status->decrypted true, if it finds the |
| 613 | * frame is open data frame or mgmt frame. |
| 614 | * So hw will not decryption robust managment frame |
| 615 | * for IEEE80211w but still set status->decrypted |
| 616 | * true, so here we should set it back to undecrypted |
| 617 | * for IEEE80211w frame, and mac80211 sw will help |
| 618 | * to decrypt it |
| 619 | */ |
| 620 | if (status->decrypted) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 621 | if (!hdr) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 622 | WARN_ON_ONCE(true); |
| 623 | pr_err("decrypted is true but hdr NULL, from skb %p\n", |
| 624 | rtl_get_hdr(skb)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 625 | return false; |
| 626 | } |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 627 | |
| 628 | if ((!_ieee80211_is_robust_mgmt_frame(hdr)) && |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 629 | (ieee80211_has_protected(hdr->frame_control))) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 630 | rx_status->flag |= RX_FLAG_DECRYPTED; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 631 | else |
| 632 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* rate_idx: index of data rate into band's |
| 636 | * supported rates or MCS index if HT rates |
| 637 | * are use (RX_FLAG_HT) |
| 638 | * Notice: this is diff with windows define |
| 639 | */ |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 640 | rx_status->rate_idx = _rtl88ee_rate_mapping(hw, |
| 641 | status->is_ht, status->rate); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 642 | |
| 643 | rx_status->mactime = status->timestamp_low; |
| 644 | if (phystatus == true) { |
| 645 | p_drvinfo = (struct rx_fwinfo_88e *)(skb->data + |
| 646 | status->rx_bufshift); |
| 647 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 648 | _rtl88ee_translate_rx_signal_stuff(hw, |
| 649 | skb, status, pdesc, |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 650 | p_drvinfo); |
| 651 | } |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 652 | rx_status->signal = status->recvsignalpower + 10; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 653 | if (status->packet_report_type == TX_REPORT2) { |
| 654 | status->macid_valid_entry[0] = |
| 655 | GET_RX_RPT2_DESC_MACID_VALID_1(pdesc); |
| 656 | status->macid_valid_entry[1] = |
| 657 | GET_RX_RPT2_DESC_MACID_VALID_2(pdesc); |
| 658 | } |
| 659 | return true; |
| 660 | } |
| 661 | |
| 662 | void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw, |
| 663 | struct ieee80211_hdr *hdr, u8 *pdesc_tx, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 664 | u8 *txbd, struct ieee80211_tx_info *info, |
| 665 | struct ieee80211_sta *sta, |
| 666 | struct sk_buff *skb, |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 667 | u8 hw_queue, struct rtl_tcb_desc *ptcb_desc) |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 668 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 669 | { |
| 670 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 671 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 672 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 673 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 674 | u8 *pdesc = (u8 *)pdesc_tx; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 675 | u16 seq_number; |
| 676 | __le16 fc = hdr->frame_control; |
| 677 | unsigned int buf_len = 0; |
| 678 | unsigned int skb_len = skb->len; |
| 679 | u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue); |
| 680 | bool firstseg = ((hdr->seq_ctrl & |
| 681 | cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0); |
| 682 | bool lastseg = ((hdr->frame_control & |
| 683 | cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0); |
| 684 | dma_addr_t mapping; |
| 685 | u8 bw_40 = 0; |
| 686 | u8 short_gi = 0; |
| 687 | |
| 688 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 689 | bw_40 = mac->bw_40; |
| 690 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
| 691 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
| 692 | if (sta) |
| 693 | bw_40 = sta->ht_cap.cap & |
| 694 | IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 695 | } |
| 696 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; |
| 697 | rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc); |
| 698 | /* reserve 8 byte for AMPDU early mode */ |
| 699 | if (rtlhal->earlymode_enable) { |
| 700 | skb_push(skb, EM_HDR_LEN); |
| 701 | memset(skb->data, 0, EM_HDR_LEN); |
| 702 | } |
| 703 | buf_len = skb->len; |
| 704 | mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len, |
| 705 | PCI_DMA_TODEVICE); |
| 706 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 707 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 708 | "DMA mapping error"); |
| 709 | return; |
| 710 | } |
| 711 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e)); |
| 712 | if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) { |
| 713 | firstseg = true; |
| 714 | lastseg = true; |
| 715 | } |
| 716 | if (firstseg) { |
| 717 | if (rtlhal->earlymode_enable) { |
| 718 | SET_TX_DESC_PKT_OFFSET(pdesc, 1); |
| 719 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN + |
| 720 | EM_HDR_LEN); |
| 721 | if (ptcb_desc->empkt_num) { |
| 722 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 723 | "Insert 8 byte.pTcb->EMPktNum:%d\n", |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 724 | ptcb_desc->empkt_num); |
| 725 | _rtl88ee_insert_emcontent(ptcb_desc, |
| 726 | (u8 *)(skb->data)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 727 | } |
| 728 | } else { |
| 729 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); |
| 730 | } |
| 731 | |
| 732 | ptcb_desc->use_driver_rate = true; |
| 733 | SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate); |
| 734 | if (ptcb_desc->hw_rate > DESC92C_RATEMCS0) |
| 735 | short_gi = (ptcb_desc->use_shortgi) ? 1 : 0; |
| 736 | else |
| 737 | short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 738 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 739 | SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi); |
| 740 | |
| 741 | if (info->flags & IEEE80211_TX_CTL_AMPDU) { |
| 742 | SET_TX_DESC_AGG_ENABLE(pdesc, 1); |
| 743 | SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14); |
| 744 | } |
| 745 | SET_TX_DESC_SEQ(pdesc, seq_number); |
| 746 | SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable && |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 747 | !ptcb_desc->cts_enable) ? 1 : 0)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 748 | SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0); |
| 749 | SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0)); |
| 750 | SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0)); |
| 751 | |
| 752 | SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate); |
| 753 | SET_TX_DESC_RTS_BW(pdesc, 0); |
| 754 | SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc); |
| 755 | SET_TX_DESC_RTS_SHORT(pdesc, |
| 756 | ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ? |
| 757 | (ptcb_desc->rts_use_shortpreamble ? 1 : 0) : |
| 758 | (ptcb_desc->rts_use_shortgi ? 1 : 0))); |
| 759 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 760 | if (ptcb_desc->tx_enable_sw_calc_duration) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 761 | SET_TX_DESC_NAV_USE_HDR(pdesc, 1); |
| 762 | |
| 763 | if (bw_40) { |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 764 | if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 765 | SET_TX_DESC_DATA_BW(pdesc, 1); |
| 766 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3); |
| 767 | } else { |
| 768 | SET_TX_DESC_DATA_BW(pdesc, 0); |
| 769 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 770 | mac->cur_40_prime_sc); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 771 | } |
| 772 | } else { |
| 773 | SET_TX_DESC_DATA_BW(pdesc, 0); |
| 774 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); |
| 775 | } |
| 776 | |
| 777 | SET_TX_DESC_LINIP(pdesc, 0); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 778 | SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 779 | if (sta) { |
| 780 | u8 ampdu_density = sta->ht_cap.ampdu_density; |
| 781 | SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density); |
| 782 | } |
| 783 | if (info->control.hw_key) { |
| 784 | struct ieee80211_key_conf *keyconf; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 785 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 786 | keyconf = info->control.hw_key; |
| 787 | switch (keyconf->cipher) { |
| 788 | case WLAN_CIPHER_SUITE_WEP40: |
| 789 | case WLAN_CIPHER_SUITE_WEP104: |
| 790 | case WLAN_CIPHER_SUITE_TKIP: |
| 791 | SET_TX_DESC_SEC_TYPE(pdesc, 0x1); |
| 792 | break; |
| 793 | case WLAN_CIPHER_SUITE_CCMP: |
| 794 | SET_TX_DESC_SEC_TYPE(pdesc, 0x3); |
| 795 | break; |
| 796 | default: |
| 797 | SET_TX_DESC_SEC_TYPE(pdesc, 0x0); |
| 798 | break; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 799 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
| 803 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel); |
| 804 | SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); |
| 805 | SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF); |
| 806 | SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ? |
| 807 | 1 : 0); |
| 808 | SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0); |
| 809 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 810 | /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/ |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 811 | /* Set TxRate and RTSRate in TxDesc */ |
| 812 | /* This prevent Tx initial rate of new-coming packets */ |
| 813 | /* from being overwritten by retried packet rate.*/ |
| 814 | if (!ptcb_desc->use_driver_rate) { |
| 815 | /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */ |
| 816 | /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */ |
| 817 | } |
| 818 | if (ieee80211_is_data_qos(fc)) { |
| 819 | if (mac->rdg_en) { |
| 820 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 821 | "Enable RDG function.\n"); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 822 | SET_TX_DESC_RDG_ENABLE(pdesc, 1); |
| 823 | SET_TX_DESC_HTC(pdesc, 1); |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); |
| 829 | SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 830 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 831 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
| 832 | if (rtlpriv->dm.useramask) { |
| 833 | SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index); |
| 834 | SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id); |
| 835 | } else { |
| 836 | SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index); |
| 837 | SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index); |
| 838 | } |
| 839 | if (ieee80211_is_data_qos(fc)) |
| 840 | SET_TX_DESC_QOS(pdesc, 1); |
| 841 | |
| 842 | if (!ieee80211_is_data_qos(fc)) |
| 843 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); |
| 844 | SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1)); |
| 845 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 846 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) { |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 847 | SET_TX_DESC_BMC(pdesc, 1); |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 848 | } |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 849 | |
| 850 | rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id); |
| 851 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n"); |
| 852 | } |
| 853 | |
| 854 | void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw, |
| 855 | u8 *pdesc, bool firstseg, |
| 856 | bool lastseg, struct sk_buff *skb) |
| 857 | { |
| 858 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 859 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 860 | u8 fw_queue = QSLT_BEACON; |
| 861 | |
| 862 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, |
| 863 | skb->data, skb->len, |
| 864 | PCI_DMA_TODEVICE); |
| 865 | |
| 866 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); |
| 867 | __le16 fc = hdr->frame_control; |
| 868 | |
| 869 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 870 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 871 | "DMA mapping error"); |
| 872 | return; |
| 873 | } |
| 874 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE); |
| 875 | |
| 876 | if (firstseg) |
| 877 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); |
| 878 | |
| 879 | SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M); |
| 880 | |
| 881 | SET_TX_DESC_SEQ(pdesc, 0); |
| 882 | |
| 883 | SET_TX_DESC_LINIP(pdesc, 0); |
| 884 | |
| 885 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue); |
| 886 | |
| 887 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 888 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 889 | |
| 890 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len)); |
| 891 | |
| 892 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
| 893 | |
| 894 | SET_TX_DESC_RATE_ID(pdesc, 7); |
| 895 | SET_TX_DESC_MACID(pdesc, 0); |
| 896 | |
| 897 | SET_TX_DESC_OWN(pdesc, 1); |
| 898 | |
Joe Perches | 1851cb4 | 2014-03-24 13:15:40 -0700 | [diff] [blame] | 899 | SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len)); |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 900 | |
| 901 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 902 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 903 | |
| 904 | SET_TX_DESC_OFFSET(pdesc, 0x20); |
| 905 | |
| 906 | SET_TX_DESC_USE_RATE(pdesc, 1); |
| 907 | |
| 908 | if (!ieee80211_is_data_qos(fc)) |
| 909 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); |
| 910 | |
| 911 | RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, |
| 912 | "H2C Tx Cmd Content\n", |
| 913 | pdesc, TX_DESC_SIZE); |
| 914 | } |
| 915 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 916 | void rtl88ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc, |
| 917 | bool istx, u8 desc_name, u8 *val) |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 918 | { |
| 919 | if (istx == true) { |
| 920 | switch (desc_name) { |
| 921 | case HW_DESC_OWN: |
| 922 | SET_TX_DESC_OWN(pdesc, 1); |
| 923 | break; |
| 924 | case HW_DESC_TX_NEXTDESC_ADDR: |
| 925 | SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val); |
| 926 | break; |
| 927 | default: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 928 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 929 | desc_name); |
| 930 | break; |
| 931 | } |
| 932 | } else { |
| 933 | switch (desc_name) { |
| 934 | case HW_DESC_RXOWN: |
| 935 | SET_RX_DESC_OWN(pdesc, 1); |
| 936 | break; |
| 937 | case HW_DESC_RXBUFF_ADDR: |
| 938 | SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val); |
| 939 | break; |
| 940 | case HW_DESC_RXPKT_LEN: |
| 941 | SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val); |
| 942 | break; |
| 943 | case HW_DESC_RXERO: |
| 944 | SET_RX_DESC_EOR(pdesc, 1); |
| 945 | break; |
| 946 | default: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 947 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 948 | desc_name); |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name) |
| 955 | { |
| 956 | u32 ret = 0; |
| 957 | |
| 958 | if (istx == true) { |
| 959 | switch (desc_name) { |
| 960 | case HW_DESC_OWN: |
| 961 | ret = GET_TX_DESC_OWN(pdesc); |
| 962 | break; |
| 963 | case HW_DESC_TXBUFF_ADDR: |
| 964 | ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc); |
| 965 | break; |
| 966 | default: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 967 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 968 | desc_name); |
| 969 | break; |
| 970 | } |
| 971 | } else { |
| 972 | switch (desc_name) { |
| 973 | case HW_DESC_OWN: |
| 974 | ret = GET_RX_DESC_OWN(pdesc); |
| 975 | break; |
| 976 | case HW_DESC_RXPKT_LEN: |
| 977 | ret = GET_RX_DESC_PKT_LEN(pdesc); |
| 978 | break; |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 979 | case HW_DESC_RXBUFF_ADDR: |
| 980 | ret = GET_RX_DESC_BUFF_ADDR(pdesc); |
| 981 | break; |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 982 | default: |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 983 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 984 | desc_name); |
| 985 | break; |
| 986 | } |
| 987 | } |
| 988 | return ret; |
| 989 | } |
| 990 | |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 991 | bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index) |
| 992 | { |
| 993 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 994 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue]; |
| 995 | u8 *entry = (u8 *)(&ring->desc[ring->idx]); |
| 996 | u8 own = (u8)rtl88ee_get_desc(entry, true, HW_DESC_OWN); |
| 997 | |
| 998 | /*beacon packet will only use the first |
| 999 | *descriptor defautly,and the own may not |
| 1000 | *be cleared by the hardware |
| 1001 | */ |
| 1002 | if (own) |
| 1003 | return false; |
| 1004 | return true; |
| 1005 | } |
| 1006 | |
Larry Finger | f0eb856 | 2013-03-24 22:06:42 -0500 | [diff] [blame] | 1007 | void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue) |
| 1008 | { |
| 1009 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1010 | if (hw_queue == BEACON_QUEUE) { |
| 1011 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4)); |
| 1012 | } else { |
| 1013 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, |
| 1014 | BIT(0) << (hw_queue)); |
| 1015 | } |
| 1016 | } |
Larry Finger | c151aed | 2014-09-22 09:39:25 -0500 | [diff] [blame^] | 1017 | |
| 1018 | u32 rtl88ee_rx_command_packet(struct ieee80211_hw *hw, |
| 1019 | struct rtl_stats status, |
| 1020 | struct sk_buff *skb) |
| 1021 | { |
| 1022 | return 0; |
| 1023 | } |