Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | 9003a4a | 2012-01-07 20:46:44 -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 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * wlanfae <wlanfae@realtek.com> |
| 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 24 | * Hsinchu 300, Taiwan. |
| 25 | * |
| 26 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include "../wifi.h" |
| 31 | #include "../pci.h" |
| 32 | #include "../base.h" |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 33 | #include "../stats.h" |
John W. Linville | 5c405b5 | 2010-12-16 15:43:36 -0500 | [diff] [blame] | 34 | #include "reg.h" |
| 35 | #include "def.h" |
| 36 | #include "phy.h" |
| 37 | #include "trx.h" |
| 38 | #include "led.h" |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 39 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 40 | static u8 _rtl92ce_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 41 | { |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 42 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 43 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 44 | if (unlikely(ieee80211_is_beacon(fc))) |
| 45 | return QSLT_BEACON; |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 46 | if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 47 | return QSLT_MGNT; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 48 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 49 | return skb->priority; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 50 | } |
| 51 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 52 | static u8 _rtl92c_query_rxpwrpercentage(char antpower) |
| 53 | { |
| 54 | if ((antpower <= -100) || (antpower >= 20)) |
| 55 | return 0; |
| 56 | else if (antpower >= 0) |
| 57 | return 100; |
| 58 | else |
| 59 | return 100 + antpower; |
| 60 | } |
| 61 | |
| 62 | static u8 _rtl92c_evm_db_to_percentage(char value) |
| 63 | { |
| 64 | char ret_val; |
| 65 | ret_val = value; |
| 66 | |
| 67 | if (ret_val >= 0) |
| 68 | ret_val = 0; |
| 69 | |
| 70 | if (ret_val <= -33) |
| 71 | ret_val = -33; |
| 72 | |
| 73 | ret_val = 0 - ret_val; |
| 74 | ret_val *= 3; |
| 75 | |
| 76 | if (ret_val == 99) |
| 77 | ret_val = 100; |
| 78 | |
| 79 | return ret_val; |
| 80 | } |
| 81 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 82 | static long _rtl92ce_signal_scale_mapping(struct ieee80211_hw *hw, |
| 83 | long currsig) |
| 84 | { |
| 85 | long retsig; |
| 86 | |
| 87 | if (currsig >= 61 && currsig <= 100) |
| 88 | retsig = 90 + ((currsig - 60) / 4); |
| 89 | else if (currsig >= 41 && currsig <= 60) |
| 90 | retsig = 78 + ((currsig - 40) / 2); |
| 91 | else if (currsig >= 31 && currsig <= 40) |
| 92 | retsig = 66 + (currsig - 30); |
| 93 | else if (currsig >= 21 && currsig <= 30) |
| 94 | retsig = 54 + (currsig - 20); |
| 95 | else if (currsig >= 5 && currsig <= 20) |
| 96 | retsig = 42 + (((currsig - 5) * 2) / 3); |
| 97 | else if (currsig == 4) |
| 98 | retsig = 36; |
| 99 | else if (currsig == 3) |
| 100 | retsig = 27; |
| 101 | else if (currsig == 2) |
| 102 | retsig = 18; |
| 103 | else if (currsig == 1) |
| 104 | retsig = 9; |
| 105 | else |
| 106 | retsig = currsig; |
| 107 | |
| 108 | return retsig; |
| 109 | } |
| 110 | |
| 111 | static void _rtl92ce_query_rxphystatus(struct ieee80211_hw *hw, |
| 112 | struct rtl_stats *pstats, |
| 113 | struct rx_desc_92c *pdesc, |
| 114 | struct rx_fwinfo_92c *p_drvinfo, |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 115 | bool packet_match_bssid, |
| 116 | bool packet_toself, |
| 117 | bool packet_beacon) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 118 | { |
| 119 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 120 | struct phy_sts_cck_8192s_t *cck_buf; |
Larry Finger | 0bd899e | 2012-10-25 13:46:30 -0500 | [diff] [blame] | 121 | struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); |
Larry Finger | 7101f40 | 2011-06-10 11:05:23 -0500 | [diff] [blame] | 122 | s8 rx_pwr_all = 0, rx_pwr[4]; |
Alessio Igor Bogani | c2a7dca0 | 2011-02-28 09:11:55 +0100 | [diff] [blame] | 123 | u8 evm, pwdb_all, rf_rx_num = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 124 | u8 i, max_spatial_stream; |
Alessio Igor Bogani | c2a7dca0 | 2011-02-28 09:11:55 +0100 | [diff] [blame] | 125 | u32 rssi, total_rssi = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 126 | bool is_cck_rate; |
| 127 | |
| 128 | is_cck_rate = RX_HAL_IS_CCK_RATE(pdesc); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 129 | pstats->packet_matchbssid = packet_match_bssid; |
| 130 | pstats->packet_toself = packet_toself; |
| 131 | pstats->is_cck = is_cck_rate; |
| 132 | pstats->packet_beacon = packet_beacon; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 133 | pstats->rx_mimo_sig_qual[0] = -1; |
| 134 | pstats->rx_mimo_sig_qual[1] = -1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 135 | |
| 136 | if (is_cck_rate) { |
| 137 | u8 report, cck_highpwr; |
| 138 | cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo; |
| 139 | |
Larry Finger | 0bd899e | 2012-10-25 13:46:30 -0500 | [diff] [blame] | 140 | if (ppsc->rfpwr_state == ERFON) |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 141 | cck_highpwr = (u8) rtl_get_bbreg(hw, |
| 142 | RFPGA0_XA_HSSIPARAMETER2, |
| 143 | BIT(9)); |
| 144 | else |
| 145 | cck_highpwr = false; |
| 146 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 147 | if (!cck_highpwr) { |
| 148 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; |
| 149 | report = cck_buf->cck_agc_rpt & 0xc0; |
| 150 | report = report >> 6; |
| 151 | switch (report) { |
| 152 | case 0x3: |
| 153 | rx_pwr_all = -46 - (cck_agc_rpt & 0x3e); |
| 154 | break; |
| 155 | case 0x2: |
| 156 | rx_pwr_all = -26 - (cck_agc_rpt & 0x3e); |
| 157 | break; |
| 158 | case 0x1: |
| 159 | rx_pwr_all = -12 - (cck_agc_rpt & 0x3e); |
| 160 | break; |
| 161 | case 0x0: |
| 162 | rx_pwr_all = 16 - (cck_agc_rpt & 0x3e); |
| 163 | break; |
| 164 | } |
| 165 | } else { |
| 166 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; |
| 167 | report = p_drvinfo->cfosho[0] & 0x60; |
| 168 | report = report >> 5; |
| 169 | switch (report) { |
| 170 | case 0x3: |
| 171 | rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1); |
| 172 | break; |
| 173 | case 0x2: |
| 174 | rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1); |
| 175 | break; |
| 176 | case 0x1: |
| 177 | rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1); |
| 178 | break; |
| 179 | case 0x0: |
| 180 | rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1); |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 185 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); |
| 186 | /* CCK gain is smaller than OFDM/MCS gain, |
| 187 | * so we add gain diff by experiences, |
| 188 | * the val is 6 |
| 189 | */ |
| 190 | pwdb_all += 6; |
| 191 | if (pwdb_all > 100) |
| 192 | pwdb_all = 100; |
| 193 | /* modify the offset to make the same |
| 194 | * gain index with OFDM. |
| 195 | */ |
| 196 | if (pwdb_all > 34 && pwdb_all <= 42) |
| 197 | pwdb_all -= 2; |
| 198 | else if (pwdb_all > 26 && pwdb_all <= 34) |
| 199 | pwdb_all -= 6; |
| 200 | else if (pwdb_all > 14 && pwdb_all <= 26) |
| 201 | pwdb_all -= 8; |
| 202 | else if (pwdb_all > 4 && pwdb_all <= 14) |
| 203 | pwdb_all -= 4; |
| 204 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 205 | pstats->rx_pwdb_all = pwdb_all; |
| 206 | pstats->recvsignalpower = rx_pwr_all; |
| 207 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 208 | /* (3) Get Signal Quality (EVM) */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 209 | if (packet_match_bssid) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 210 | u8 sq; |
| 211 | if (pstats->rx_pwdb_all > 40) |
| 212 | sq = 100; |
| 213 | else { |
| 214 | sq = cck_buf->sq_rpt; |
| 215 | if (sq > 64) |
| 216 | sq = 0; |
| 217 | else if (sq < 20) |
| 218 | sq = 100; |
| 219 | else |
| 220 | sq = ((64 - sq) * 100) / 44; |
| 221 | } |
| 222 | |
| 223 | pstats->signalquality = sq; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 224 | pstats->rx_mimo_sig_qual[0] = sq; |
| 225 | pstats->rx_mimo_sig_qual[1] = -1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 226 | } |
| 227 | } else { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 228 | rtlpriv->dm.rfpath_rxenable[0] = |
| 229 | rtlpriv->dm.rfpath_rxenable[1] = true; |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 230 | /* (1)Get RSSI for HT rate */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 231 | for (i = RF90_PATH_A; i < RF90_PATH_MAX; i++) { |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 232 | /* we will judge RF RX path now. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 233 | if (rtlpriv->dm.rfpath_rxenable[i]) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 234 | rf_rx_num++; |
| 235 | |
| 236 | rx_pwr[i] = |
| 237 | ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110; |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 238 | /* Translate DBM to percentage. */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 239 | rssi = _rtl92c_query_rxpwrpercentage(rx_pwr[i]); |
| 240 | total_rssi += rssi; |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 241 | /* Get Rx snr value in DB */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 242 | rtlpriv->stats.rx_snr_db[i] = |
| 243 | (long)(p_drvinfo->rxsnr[i] / 2); |
| 244 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 245 | /* Record Signal Strength for next packet */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 246 | if (packet_match_bssid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 247 | pstats->rx_mimo_signalstrength[i] = (u8) rssi; |
| 248 | } |
| 249 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 250 | /* (2)PWDB, Average PWDB cacluated by |
| 251 | * hardware (for rate adaptive) |
| 252 | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 253 | rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110; |
| 254 | pwdb_all = _rtl92c_query_rxpwrpercentage(rx_pwr_all); |
| 255 | pstats->rx_pwdb_all = pwdb_all; |
| 256 | pstats->rxpower = rx_pwr_all; |
| 257 | pstats->recvsignalpower = rx_pwr_all; |
| 258 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 259 | /* (3)EVM of HT rate */ |
| 260 | if (pstats->is_ht && pstats->rate >= DESC92_RATEMCS8 && |
| 261 | pstats->rate <= DESC92_RATEMCS15) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 262 | max_spatial_stream = 2; |
| 263 | else |
| 264 | max_spatial_stream = 1; |
| 265 | |
| 266 | for (i = 0; i < max_spatial_stream; i++) { |
| 267 | evm = _rtl92c_evm_db_to_percentage(p_drvinfo->rxevm[i]); |
| 268 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 269 | if (packet_match_bssid) { |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 270 | /* Fill value in RFD, Get the first |
| 271 | * spatial stream only |
| 272 | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 273 | if (i == 0) |
| 274 | pstats->signalquality = |
| 275 | (u8) (evm & 0xff); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 276 | pstats->rx_mimo_sig_qual[i] = (u8) (evm & 0xff); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 281 | /* UI BSS List signal strength(in percentage), |
| 282 | * make it good looking, from 0~100. |
| 283 | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 284 | if (is_cck_rate) |
| 285 | pstats->signalstrength = |
| 286 | (u8) (_rtl92ce_signal_scale_mapping(hw, pwdb_all)); |
| 287 | else if (rf_rx_num != 0) |
| 288 | pstats->signalstrength = |
| 289 | (u8) (_rtl92ce_signal_scale_mapping |
| 290 | (hw, total_rssi /= rf_rx_num)); |
| 291 | } |
| 292 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 293 | static void _rtl92ce_translate_rx_signal_stuff(struct ieee80211_hw *hw, |
| 294 | struct sk_buff *skb, |
| 295 | struct rtl_stats *pstats, |
| 296 | struct rx_desc_92c *pdesc, |
| 297 | struct rx_fwinfo_92c *p_drvinfo) |
| 298 | { |
| 299 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 300 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 301 | |
| 302 | struct ieee80211_hdr *hdr; |
| 303 | u8 *tmp_buf; |
| 304 | u8 *praddr; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 305 | __le16 fc; |
| 306 | u16 type, c_fc; |
Cong Ding | e48caab | 2013-02-04 22:43:22 +0100 | [diff] [blame] | 307 | bool packet_matchbssid, packet_toself, packet_beacon = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 308 | |
| 309 | tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift; |
| 310 | |
| 311 | hdr = (struct ieee80211_hdr *)tmp_buf; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 312 | fc = hdr->frame_control; |
| 313 | c_fc = le16_to_cpu(fc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 314 | type = WLAN_FC_GET_TYPE(fc); |
| 315 | praddr = hdr->addr1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 316 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 317 | packet_matchbssid = |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 318 | ((IEEE80211_FTYPE_CTL != type) && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 319 | ether_addr_equal(mac->bssid, |
| 320 | (c_fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : |
| 321 | (c_fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : |
| 322 | hdr->addr3) && |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 323 | (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 324 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 325 | packet_toself = packet_matchbssid && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 326 | ether_addr_equal(praddr, rtlefuse->dev_addr); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 327 | |
| 328 | if (ieee80211_is_beacon(fc)) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 329 | packet_beacon = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 330 | |
| 331 | _rtl92ce_query_rxphystatus(hw, pstats, pdesc, p_drvinfo, |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 332 | packet_matchbssid, packet_toself, |
| 333 | packet_beacon); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 334 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 335 | rtl_process_phyinfo(hw, tmp_buf, pstats); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw, |
| 339 | struct rtl_stats *stats, |
| 340 | struct ieee80211_rx_status *rx_status, |
| 341 | u8 *p_desc, struct sk_buff *skb) |
| 342 | { |
| 343 | struct rx_fwinfo_92c *p_drvinfo; |
| 344 | struct rx_desc_92c *pdesc = (struct rx_desc_92c *)p_desc; |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 345 | struct ieee80211_hdr *hdr; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 | u32 phystatus = GET_RX_DESC_PHYST(pdesc); |
| 347 | stats->length = (u16) GET_RX_DESC_PKT_LEN(pdesc); |
| 348 | stats->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) * |
| 349 | RX_DRV_INFO_SIZE_UNIT; |
| 350 | stats->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 351 | stats->icv = (u16) GET_RX_DESC_ICV(pdesc); |
| 352 | stats->crc = (u16) GET_RX_DESC_CRC32(pdesc); |
| 353 | stats->hwerror = (stats->crc | stats->icv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 354 | stats->decrypted = !GET_RX_DESC_SWDEC(pdesc); |
| 355 | stats->rate = (u8) GET_RX_DESC_RXMCS(pdesc); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 356 | stats->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc); |
| 357 | stats->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1); |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 358 | stats->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 359 | && (GET_RX_DESC_FAGGR(pdesc) == 1)); |
| 360 | stats->timestamp_low = GET_RX_DESC_TSFL(pdesc); |
| 361 | stats->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc); |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 362 | stats->is_ht = (bool)GET_RX_DESC_RXHT(pdesc); |
| 363 | |
| 364 | stats->is_cck = RX_HAL_IS_CCK_RATE(pdesc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 365 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 366 | rx_status->freq = hw->conf.chandef.chan->center_freq; |
| 367 | rx_status->band = hw->conf.chandef.chan->band; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 368 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 369 | hdr = (struct ieee80211_hdr *)(skb->data + stats->rx_drvinfo_size |
| 370 | + stats->rx_bufshift); |
| 371 | |
| 372 | if (stats->crc) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 373 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 374 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 375 | if (stats->rx_is40Mhzpacket) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 376 | rx_status->flag |= RX_FLAG_40MHZ; |
| 377 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 378 | if (stats->is_ht) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 379 | rx_status->flag |= RX_FLAG_HT; |
| 380 | |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 381 | rx_status->flag |= RX_FLAG_MACTIME_START; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 382 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 383 | /* hw will set stats->decrypted true, if it finds the |
| 384 | * frame is open data frame or mgmt frame. |
| 385 | * So hw will not decryption robust managment frame |
| 386 | * for IEEE80211w but still set status->decrypted |
| 387 | * true, so here we should set it back to undecrypted |
| 388 | * for IEEE80211w frame, and mac80211 sw will help |
| 389 | * to decrypt it |
| 390 | */ |
| 391 | if (stats->decrypted) { |
| 392 | if (!hdr) { |
| 393 | /* In testing, hdr was NULL here */ |
| 394 | return false; |
| 395 | } |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 396 | if ((_ieee80211_is_robust_mgmt_frame(hdr)) && |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 397 | (ieee80211_has_protected(hdr->frame_control))) |
| 398 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 399 | else |
| 400 | rx_status->flag |= RX_FLAG_DECRYPTED; |
| 401 | } |
| 402 | /* rate_idx: index of data rate into band's |
| 403 | * supported rates or MCS index if HT rates |
| 404 | * are use (RX_FLAG_HT) |
| 405 | * Notice: this is diff with windows define |
| 406 | */ |
Larry Finger | 78851b6 | 2011-08-22 16:50:15 -0500 | [diff] [blame] | 407 | rx_status->rate_idx = rtlwifi_rate_mapping(hw, |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 408 | stats->is_ht, stats->rate, |
| 409 | stats->isfirst_ampdu); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 410 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 411 | rx_status->mactime = stats->timestamp_low; |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 412 | if (phystatus) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 413 | p_drvinfo = (struct rx_fwinfo_92c *)(skb->data + |
| 414 | stats->rx_bufshift); |
| 415 | |
| 416 | _rtl92ce_translate_rx_signal_stuff(hw, |
| 417 | skb, stats, pdesc, |
| 418 | p_drvinfo); |
| 419 | } |
| 420 | |
| 421 | /*rx_status->qual = stats->signal; */ |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 422 | rx_status->signal = stats->recvsignalpower + 10; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 423 | |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw, |
| 428 | struct ieee80211_hdr *hdr, u8 *pdesc_tx, |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame^] | 429 | u8 *pbd_desc_tx, struct ieee80211_tx_info *info, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 430 | struct ieee80211_sta *sta, |
| 431 | struct sk_buff *skb, |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 432 | u8 hw_queue, struct rtl_tcb_desc *tcb_desc) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 433 | { |
| 434 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 435 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 436 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 437 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 438 | bool defaultadapter = true; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 439 | u8 *pdesc = pdesc_tx; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 440 | u16 seq_number; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 441 | __le16 fc = hdr->frame_control; |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 442 | u8 fw_qsel = _rtl92ce_map_hwqueue_to_fwqueue(skb, hw_queue); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 443 | bool firstseg = ((hdr->seq_ctrl & |
| 444 | cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 445 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 446 | bool lastseg = ((hdr->frame_control & |
| 447 | cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 448 | |
| 449 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, |
| 450 | skb->data, skb->len, |
| 451 | PCI_DMA_TODEVICE); |
Larry Finger | 9145910 | 2012-12-27 10:37:29 -0600 | [diff] [blame] | 452 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 453 | u8 bw_40 = 0; |
| 454 | |
Larry Finger | 9145910 | 2012-12-27 10:37:29 -0600 | [diff] [blame] | 455 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 456 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 457 | "DMA mapping error"); |
| 458 | return; |
| 459 | } |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 460 | rcu_read_lock(); |
| 461 | sta = get_sta(hw, mac->vif, mac->bssid); |
| 462 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 463 | bw_40 = mac->bw_40; |
| 464 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 465 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 466 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 467 | if (sta) |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 468 | bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40; |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 469 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 470 | |
| 471 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; |
| 472 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 473 | rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 474 | |
| 475 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_92c)); |
| 476 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 477 | if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) { |
| 478 | firstseg = true; |
| 479 | lastseg = true; |
| 480 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 481 | if (firstseg) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 482 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); |
| 483 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 484 | SET_TX_DESC_TX_RATE(pdesc, tcb_desc->hw_rate); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 485 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 486 | if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 487 | SET_TX_DESC_DATA_SHORTGI(pdesc, 1); |
| 488 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 489 | if (info->flags & IEEE80211_TX_CTL_AMPDU) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 490 | SET_TX_DESC_AGG_BREAK(pdesc, 1); |
| 491 | SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14); |
| 492 | } |
| 493 | SET_TX_DESC_SEQ(pdesc, seq_number); |
| 494 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 495 | SET_TX_DESC_RTS_ENABLE(pdesc, ((tcb_desc->rts_enable && |
| 496 | !tcb_desc-> |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 497 | cts_enable) ? 1 : 0)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 498 | SET_TX_DESC_HW_RTS_ENABLE(pdesc, |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 499 | ((tcb_desc->rts_enable |
| 500 | || tcb_desc->cts_enable) ? 1 : 0)); |
| 501 | SET_TX_DESC_CTS2SELF(pdesc, ((tcb_desc->cts_enable) ? 1 : 0)); |
| 502 | SET_TX_DESC_RTS_STBC(pdesc, ((tcb_desc->rts_stbc) ? 1 : 0)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 503 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 504 | SET_TX_DESC_RTS_RATE(pdesc, tcb_desc->rts_rate); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 505 | SET_TX_DESC_RTS_BW(pdesc, 0); |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 506 | SET_TX_DESC_RTS_SC(pdesc, tcb_desc->rts_sc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 507 | SET_TX_DESC_RTS_SHORT(pdesc, |
Larry Finger | 78851b6 | 2011-08-22 16:50:15 -0500 | [diff] [blame] | 508 | ((tcb_desc->rts_rate <= DESC92_RATE54M) ? |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 509 | (tcb_desc->rts_use_shortpreamble ? 1 : 0) |
| 510 | : (tcb_desc->rts_use_shortgi ? 1 : 0))); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 511 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 512 | if (bw_40) { |
| 513 | if (tcb_desc->packet_bw) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 514 | SET_TX_DESC_DATA_BW(pdesc, 1); |
| 515 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3); |
| 516 | } else { |
| 517 | SET_TX_DESC_DATA_BW(pdesc, 0); |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 518 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, |
| 519 | mac->cur_40_prime_sc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 520 | } |
| 521 | } else { |
| 522 | SET_TX_DESC_DATA_BW(pdesc, 0); |
| 523 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); |
| 524 | } |
| 525 | |
| 526 | SET_TX_DESC_LINIP(pdesc, 0); |
| 527 | SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len); |
| 528 | |
| 529 | if (sta) { |
| 530 | u8 ampdu_density = sta->ht_cap.ampdu_density; |
| 531 | SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density); |
| 532 | } |
| 533 | |
| 534 | if (info->control.hw_key) { |
| 535 | struct ieee80211_key_conf *keyconf = |
| 536 | info->control.hw_key; |
| 537 | |
| 538 | switch (keyconf->cipher) { |
| 539 | case WLAN_CIPHER_SUITE_WEP40: |
| 540 | case WLAN_CIPHER_SUITE_WEP104: |
| 541 | case WLAN_CIPHER_SUITE_TKIP: |
| 542 | SET_TX_DESC_SEC_TYPE(pdesc, 0x1); |
| 543 | break; |
| 544 | case WLAN_CIPHER_SUITE_CCMP: |
| 545 | SET_TX_DESC_SEC_TYPE(pdesc, 0x3); |
| 546 | break; |
| 547 | default: |
| 548 | SET_TX_DESC_SEC_TYPE(pdesc, 0x0); |
| 549 | break; |
| 550 | |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | SET_TX_DESC_PKT_ID(pdesc, 0); |
| 555 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel); |
| 556 | |
| 557 | SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); |
| 558 | SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF); |
| 559 | SET_TX_DESC_DISABLE_FB(pdesc, 0); |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 560 | SET_TX_DESC_USE_RATE(pdesc, tcb_desc->use_driver_rate ? 1 : 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 561 | |
| 562 | if (ieee80211_is_data_qos(fc)) { |
| 563 | if (mac->rdg_en) { |
| 564 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 565 | "Enable RDG function\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 566 | SET_TX_DESC_RDG_ENABLE(pdesc, 1); |
| 567 | SET_TX_DESC_HTC(pdesc, 1); |
| 568 | } |
| 569 | } |
| 570 | } |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 571 | rcu_read_unlock(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 572 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 573 | SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); |
| 574 | SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 575 | |
| 576 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len); |
| 577 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 578 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 579 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 580 | if (rtlpriv->dm.useramask) { |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 581 | SET_TX_DESC_RATE_ID(pdesc, tcb_desc->ratr_index); |
| 582 | SET_TX_DESC_MACID(pdesc, tcb_desc->mac_id); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 583 | } else { |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 584 | SET_TX_DESC_RATE_ID(pdesc, 0xC + tcb_desc->ratr_index); |
| 585 | SET_TX_DESC_MACID(pdesc, tcb_desc->ratr_index); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 586 | } |
| 587 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 588 | if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 589 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); |
| 590 | SET_TX_DESC_PKT_ID(pdesc, 8); |
| 591 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 592 | if (!defaultadapter) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 593 | SET_TX_DESC_QOS(pdesc, 1); |
| 594 | } |
| 595 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 596 | SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 597 | |
| 598 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || |
| 599 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) { |
| 600 | SET_TX_DESC_BMC(pdesc, 1); |
| 601 | } |
| 602 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 603 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw *hw, |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 607 | u8 *pdesc, bool firstseg, |
| 608 | bool lastseg, struct sk_buff *skb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 609 | { |
| 610 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 611 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 612 | u8 fw_queue = QSLT_BEACON; |
| 613 | |
| 614 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, |
| 615 | skb->data, skb->len, |
| 616 | PCI_DMA_TODEVICE); |
| 617 | |
| 618 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 619 | __le16 fc = hdr->frame_control; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 620 | |
Larry Finger | 9145910 | 2012-12-27 10:37:29 -0600 | [diff] [blame] | 621 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 622 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 623 | "DMA mapping error"); |
| 624 | return; |
| 625 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 626 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE); |
| 627 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 628 | if (firstseg) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 629 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); |
| 630 | |
Larry Finger | 78851b6 | 2011-08-22 16:50:15 -0500 | [diff] [blame] | 631 | SET_TX_DESC_TX_RATE(pdesc, DESC92_RATE1M); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 632 | |
| 633 | SET_TX_DESC_SEQ(pdesc, 0); |
| 634 | |
| 635 | SET_TX_DESC_LINIP(pdesc, 0); |
| 636 | |
| 637 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue); |
| 638 | |
| 639 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 640 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 641 | |
| 642 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len)); |
| 643 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 644 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 645 | |
| 646 | SET_TX_DESC_RATE_ID(pdesc, 7); |
| 647 | SET_TX_DESC_MACID(pdesc, 0); |
| 648 | |
| 649 | SET_TX_DESC_OWN(pdesc, 1); |
| 650 | |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 651 | SET_TX_DESC_PKT_SIZE(pdesc, (u16) (skb->len)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 652 | |
| 653 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 654 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 655 | |
| 656 | SET_TX_DESC_OFFSET(pdesc, 0x20); |
| 657 | |
| 658 | SET_TX_DESC_USE_RATE(pdesc, 1); |
| 659 | |
| 660 | if (!ieee80211_is_data_qos(fc)) { |
| 661 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); |
| 662 | SET_TX_DESC_PKT_ID(pdesc, 8); |
| 663 | } |
| 664 | |
| 665 | RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, |
Joe Perches | af08687 | 2012-01-04 19:40:40 -0800 | [diff] [blame] | 666 | "H2C Tx Cmd Content", pdesc, TX_DESC_SIZE); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 667 | } |
| 668 | |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame^] | 669 | void rtl92ce_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx, |
| 670 | u8 desc_name, u8 *val) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 671 | { |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 672 | if (istx) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 673 | switch (desc_name) { |
| 674 | case HW_DESC_OWN: |
Mike McCormack | 71352b2 | 2011-05-31 08:50:07 +0900 | [diff] [blame] | 675 | wmb(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 676 | SET_TX_DESC_OWN(pdesc, 1); |
| 677 | break; |
| 678 | case HW_DESC_TX_NEXTDESC_ADDR: |
| 679 | SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val); |
| 680 | break; |
| 681 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 682 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
| 683 | desc_name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 684 | break; |
| 685 | } |
| 686 | } else { |
| 687 | switch (desc_name) { |
| 688 | case HW_DESC_RXOWN: |
Mike McCormack | 71352b2 | 2011-05-31 08:50:07 +0900 | [diff] [blame] | 689 | wmb(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 690 | SET_RX_DESC_OWN(pdesc, 1); |
| 691 | break; |
| 692 | case HW_DESC_RXBUFF_ADDR: |
| 693 | SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val); |
| 694 | break; |
| 695 | case HW_DESC_RXPKT_LEN: |
| 696 | SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val); |
| 697 | break; |
| 698 | case HW_DESC_RXERO: |
| 699 | SET_RX_DESC_EOR(pdesc, 1); |
| 700 | break; |
| 701 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 702 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
| 703 | desc_name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | u32 rtl92ce_get_desc(u8 *p_desc, bool istx, u8 desc_name) |
| 710 | { |
| 711 | u32 ret = 0; |
| 712 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 713 | if (istx) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 714 | switch (desc_name) { |
| 715 | case HW_DESC_OWN: |
| 716 | ret = GET_TX_DESC_OWN(p_desc); |
| 717 | break; |
| 718 | case HW_DESC_TXBUFF_ADDR: |
| 719 | ret = GET_TX_DESC_TX_BUFFER_ADDRESS(p_desc); |
| 720 | break; |
| 721 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 722 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
| 723 | desc_name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 724 | break; |
| 725 | } |
| 726 | } else { |
| 727 | struct rx_desc_92c *pdesc = (struct rx_desc_92c *)p_desc; |
| 728 | switch (desc_name) { |
| 729 | case HW_DESC_OWN: |
| 730 | ret = GET_RX_DESC_OWN(pdesc); |
| 731 | break; |
| 732 | case HW_DESC_RXPKT_LEN: |
| 733 | ret = GET_RX_DESC_PKT_LEN(pdesc); |
| 734 | break; |
| 735 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 736 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
| 737 | desc_name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 738 | break; |
| 739 | } |
| 740 | } |
| 741 | return ret; |
| 742 | } |
| 743 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 744 | void rtl92ce_tx_polling(struct ieee80211_hw *hw, u8 hw_queue) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 745 | { |
| 746 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 747 | if (hw_queue == BEACON_QUEUE) { |
| 748 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4)); |
| 749 | } else { |
| 750 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, |
| 751 | BIT(0) << (hw_queue)); |
| 752 | } |
| 753 | } |
Larry Finger | 25b2bc3 | 2011-02-11 14:34:03 -0600 | [diff] [blame] | 754 | |