Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | ca742cd | 2012-01-07 20:46:47 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [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 | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 33 | #include "../stats.h" |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 34 | #include "reg.h" |
| 35 | #include "def.h" |
| 36 | #include "phy.h" |
| 37 | #include "fw.h" |
| 38 | #include "trx.h" |
| 39 | #include "led.h" |
| 40 | |
| 41 | static u8 _rtl92se_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 skb_queue) |
| 42 | { |
| 43 | __le16 fc = rtl_get_fc(skb); |
| 44 | |
| 45 | if (unlikely(ieee80211_is_beacon(fc))) |
| 46 | return QSLT_BEACON; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 47 | if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 48 | return QSLT_MGNT; |
| 49 | if (ieee80211_is_nullfunc(fc)) |
| 50 | return QSLT_HIGH; |
| 51 | |
| 52 | return skb->priority; |
| 53 | } |
| 54 | |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 55 | static void _rtl92se_query_rxphystatus(struct ieee80211_hw *hw, |
| 56 | struct rtl_stats *pstats, u8 *pdesc, |
| 57 | struct rx_fwinfo *p_drvinfo, |
| 58 | bool packet_match_bssid, |
| 59 | bool packet_toself, |
| 60 | bool packet_beacon) |
| 61 | { |
| 62 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 63 | struct phy_sts_cck_8192s_t *cck_buf; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 64 | struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 65 | s8 rx_pwr_all = 0, rx_pwr[4]; |
| 66 | u8 rf_rx_num = 0, evm, pwdb_all; |
| 67 | u8 i, max_spatial_stream; |
| 68 | u32 rssi, total_rssi = 0; |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 69 | bool is_cck = pstats->is_cck; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 70 | |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 71 | pstats->packet_matchbssid = packet_match_bssid; |
| 72 | pstats->packet_toself = packet_toself; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 73 | pstats->packet_beacon = packet_beacon; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 74 | pstats->rx_mimo_sig_qual[0] = -1; |
| 75 | pstats->rx_mimo_sig_qual[1] = -1; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 76 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 77 | if (is_cck) { |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 78 | u8 report, cck_highpwr; |
| 79 | cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo; |
| 80 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 81 | if (ppsc->rfpwr_state == ERFON) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 82 | cck_highpwr = (u8) rtl_get_bbreg(hw, |
| 83 | RFPGA0_XA_HSSIPARAMETER2, |
| 84 | 0x200); |
| 85 | else |
| 86 | cck_highpwr = false; |
| 87 | |
| 88 | if (!cck_highpwr) { |
| 89 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; |
| 90 | report = cck_buf->cck_agc_rpt & 0xc0; |
| 91 | report = report >> 6; |
| 92 | switch (report) { |
| 93 | case 0x3: |
| 94 | rx_pwr_all = -40 - (cck_agc_rpt & 0x3e); |
| 95 | break; |
| 96 | case 0x2: |
| 97 | rx_pwr_all = -20 - (cck_agc_rpt & 0x3e); |
| 98 | break; |
| 99 | case 0x1: |
| 100 | rx_pwr_all = -2 - (cck_agc_rpt & 0x3e); |
| 101 | break; |
| 102 | case 0x0: |
| 103 | rx_pwr_all = 14 - (cck_agc_rpt & 0x3e); |
| 104 | break; |
| 105 | } |
| 106 | } else { |
| 107 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; |
| 108 | report = p_drvinfo->cfosho[0] & 0x60; |
| 109 | report = report >> 5; |
| 110 | switch (report) { |
| 111 | case 0x3: |
| 112 | rx_pwr_all = -40 - ((cck_agc_rpt & 0x1f) << 1); |
| 113 | break; |
| 114 | case 0x2: |
| 115 | rx_pwr_all = -20 - ((cck_agc_rpt & 0x1f) << 1); |
| 116 | break; |
| 117 | case 0x1: |
| 118 | rx_pwr_all = -2 - ((cck_agc_rpt & 0x1f) << 1); |
| 119 | break; |
| 120 | case 0x0: |
| 121 | rx_pwr_all = 14 - ((cck_agc_rpt & 0x1f) << 1); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 126 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 127 | |
| 128 | /* CCK gain is smaller than OFDM/MCS gain, */ |
| 129 | /* so we add gain diff by experiences, the val is 6 */ |
| 130 | pwdb_all += 6; |
| 131 | if (pwdb_all > 100) |
| 132 | pwdb_all = 100; |
| 133 | /* modify the offset to make the same gain index with OFDM. */ |
| 134 | if (pwdb_all > 34 && pwdb_all <= 42) |
| 135 | pwdb_all -= 2; |
| 136 | else if (pwdb_all > 26 && pwdb_all <= 34) |
| 137 | pwdb_all -= 6; |
| 138 | else if (pwdb_all > 14 && pwdb_all <= 26) |
| 139 | pwdb_all -= 8; |
| 140 | else if (pwdb_all > 4 && pwdb_all <= 14) |
| 141 | pwdb_all -= 4; |
| 142 | |
| 143 | pstats->rx_pwdb_all = pwdb_all; |
| 144 | pstats->recvsignalpower = rx_pwr_all; |
| 145 | |
| 146 | if (packet_match_bssid) { |
| 147 | u8 sq; |
| 148 | if (pstats->rx_pwdb_all > 40) { |
| 149 | sq = 100; |
| 150 | } else { |
| 151 | sq = cck_buf->sq_rpt; |
| 152 | if (sq > 64) |
| 153 | sq = 0; |
| 154 | else if (sq < 20) |
| 155 | sq = 100; |
| 156 | else |
| 157 | sq = ((64 - sq) * 100) / 44; |
| 158 | } |
| 159 | |
| 160 | pstats->signalquality = sq; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 161 | pstats->rx_mimo_sig_qual[0] = sq; |
| 162 | pstats->rx_mimo_sig_qual[1] = -1; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 163 | } |
| 164 | } else { |
| 165 | rtlpriv->dm.rfpath_rxenable[0] = |
| 166 | rtlpriv->dm.rfpath_rxenable[1] = true; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 167 | for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) { |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 168 | if (rtlpriv->dm.rfpath_rxenable[i]) |
| 169 | rf_rx_num++; |
| 170 | |
| 171 | rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & |
| 172 | 0x3f) * 2) - 110; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 173 | rssi = rtl_query_rxpwrpercentage(rx_pwr[i]); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 174 | total_rssi += rssi; |
| 175 | rtlpriv->stats.rx_snr_db[i] = |
| 176 | (long)(p_drvinfo->rxsnr[i] / 2); |
| 177 | |
| 178 | if (packet_match_bssid) |
| 179 | pstats->rx_mimo_signalstrength[i] = (u8) rssi; |
| 180 | } |
| 181 | |
| 182 | rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 183 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 184 | pstats->rx_pwdb_all = pwdb_all; |
| 185 | pstats->rxpower = rx_pwr_all; |
| 186 | pstats->recvsignalpower = rx_pwr_all; |
| 187 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 188 | if (pstats->is_ht && pstats->rate >= DESC92_RATEMCS8 && |
| 189 | pstats->rate <= DESC92_RATEMCS15) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 190 | max_spatial_stream = 2; |
| 191 | else |
| 192 | max_spatial_stream = 1; |
| 193 | |
| 194 | for (i = 0; i < max_spatial_stream; i++) { |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 195 | evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 196 | |
| 197 | if (packet_match_bssid) { |
| 198 | if (i == 0) |
| 199 | pstats->signalquality = (u8)(evm & |
| 200 | 0xff); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 201 | pstats->rx_mimo_sig_qual[i] = (u8) (evm & 0xff); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 206 | if (is_cck) |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 207 | pstats->signalstrength = (u8)(rtl_signal_scale_mapping(hw, |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 208 | pwdb_all)); |
| 209 | else if (rf_rx_num != 0) |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 210 | pstats->signalstrength = (u8) (rtl_signal_scale_mapping(hw, |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 211 | total_rssi /= rf_rx_num)); |
| 212 | } |
| 213 | |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 214 | static void _rtl92se_translate_rx_signal_stuff(struct ieee80211_hw *hw, |
| 215 | struct sk_buff *skb, struct rtl_stats *pstats, |
| 216 | u8 *pdesc, struct rx_fwinfo *p_drvinfo) |
| 217 | { |
| 218 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 219 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 220 | |
| 221 | struct ieee80211_hdr *hdr; |
| 222 | u8 *tmp_buf; |
| 223 | u8 *praddr; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 224 | __le16 fc; |
| 225 | u16 type, cfc; |
Cong Ding | eee569e | 2013-01-19 13:56:36 +0100 | [diff] [blame] | 226 | bool packet_matchbssid, packet_toself, packet_beacon = false; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 227 | |
| 228 | tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift; |
| 229 | |
| 230 | hdr = (struct ieee80211_hdr *)tmp_buf; |
| 231 | fc = hdr->frame_control; |
| 232 | cfc = le16_to_cpu(fc); |
| 233 | type = WLAN_FC_GET_TYPE(fc); |
| 234 | praddr = hdr->addr1; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 235 | |
| 236 | packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 237 | ether_addr_equal(mac->bssid, |
| 238 | (cfc & IEEE80211_FCTL_TODS) ? hdr->addr1 : |
| 239 | (cfc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : |
| 240 | hdr->addr3) && |
| 241 | (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv)); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 242 | |
| 243 | packet_toself = packet_matchbssid && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 244 | ether_addr_equal(praddr, rtlefuse->dev_addr); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 245 | |
| 246 | if (ieee80211_is_beacon(fc)) |
| 247 | packet_beacon = true; |
| 248 | |
| 249 | _rtl92se_query_rxphystatus(hw, pstats, pdesc, p_drvinfo, |
| 250 | packet_matchbssid, packet_toself, packet_beacon); |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 251 | rtl_process_phyinfo(hw, tmp_buf, pstats); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats, |
| 255 | struct ieee80211_rx_status *rx_status, u8 *pdesc, |
| 256 | struct sk_buff *skb) |
| 257 | { |
| 258 | struct rx_fwinfo *p_drvinfo; |
| 259 | u32 phystatus = (u32)GET_RX_STATUS_DESC_PHY_STATUS(pdesc); |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 260 | struct ieee80211_hdr *hdr; |
| 261 | bool first_ampdu = false; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 262 | |
| 263 | stats->length = (u16)GET_RX_STATUS_DESC_PKT_LEN(pdesc); |
| 264 | stats->rx_drvinfo_size = (u8)GET_RX_STATUS_DESC_DRVINFO_SIZE(pdesc) * 8; |
| 265 | stats->rx_bufshift = (u8)(GET_RX_STATUS_DESC_SHIFT(pdesc) & 0x03); |
| 266 | stats->icv = (u16)GET_RX_STATUS_DESC_ICV(pdesc); |
| 267 | stats->crc = (u16)GET_RX_STATUS_DESC_CRC32(pdesc); |
| 268 | stats->hwerror = (u16)(stats->crc | stats->icv); |
| 269 | stats->decrypted = !GET_RX_STATUS_DESC_SWDEC(pdesc); |
| 270 | |
| 271 | stats->rate = (u8)GET_RX_STATUS_DESC_RX_MCS(pdesc); |
| 272 | stats->shortpreamble = (u16)GET_RX_STATUS_DESC_SPLCP(pdesc); |
| 273 | stats->isampdu = (bool)(GET_RX_STATUS_DESC_PAGGR(pdesc) == 1); |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 274 | stats->isfirst_ampdu = (bool) ((GET_RX_STATUS_DESC_PAGGR(pdesc) == 1) |
| 275 | && (GET_RX_STATUS_DESC_FAGGR(pdesc) == 1)); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 276 | stats->timestamp_low = GET_RX_STATUS_DESC_TSFL(pdesc); |
| 277 | stats->rx_is40Mhzpacket = (bool)GET_RX_STATUS_DESC_BW(pdesc); |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 278 | stats->is_ht = (bool)GET_RX_STATUS_DESC_RX_HT(pdesc); |
| 279 | stats->is_cck = SE_RX_HAL_IS_CCK_RATE(pdesc); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 280 | |
| 281 | if (stats->hwerror) |
| 282 | return false; |
| 283 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 284 | rx_status->freq = hw->conf.chandef.chan->center_freq; |
| 285 | rx_status->band = hw->conf.chandef.chan->band; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 286 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 287 | if (stats->crc) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 288 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 289 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 290 | if (stats->rx_is40Mhzpacket) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 291 | rx_status->flag |= RX_FLAG_40MHZ; |
| 292 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 293 | if (stats->is_ht) |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 294 | rx_status->flag |= RX_FLAG_HT; |
| 295 | |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 296 | rx_status->flag |= RX_FLAG_MACTIME_START; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 297 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 298 | /* hw will set stats->decrypted true, if it finds the |
| 299 | * frame is open data frame or mgmt frame, |
| 300 | * hw will not decrypt robust managment frame |
| 301 | * for IEEE80211w but still set stats->decrypted |
| 302 | * true, so here we should set it back to undecrypted |
| 303 | * for IEEE80211w frame, and mac80211 sw will help |
| 304 | * to decrypt it */ |
| 305 | if (stats->decrypted) { |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 306 | hdr = (struct ieee80211_hdr *)(skb->data + |
| 307 | stats->rx_drvinfo_size + stats->rx_bufshift); |
| 308 | |
| 309 | if (!hdr) { |
| 310 | /* during testing, hdr was NULL here */ |
| 311 | return false; |
| 312 | } |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 313 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && |
| 314 | (ieee80211_has_protected(hdr->frame_control))) |
| 315 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 316 | else |
| 317 | rx_status->flag |= RX_FLAG_DECRYPTED; |
| 318 | } |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 319 | |
Larry Finger | 8e35337 | 2011-08-22 16:50:17 -0500 | [diff] [blame] | 320 | rx_status->rate_idx = rtlwifi_rate_mapping(hw, |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 321 | stats->is_ht, stats->rate, first_ampdu); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 322 | |
Chaoming Li | 5c079d8 | 2011-10-12 15:59:09 -0500 | [diff] [blame] | 323 | rx_status->mactime = stats->timestamp_low; |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 324 | if (phystatus) { |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 325 | p_drvinfo = (struct rx_fwinfo *)(skb->data + |
| 326 | stats->rx_bufshift); |
| 327 | _rtl92se_translate_rx_signal_stuff(hw, skb, stats, pdesc, |
| 328 | p_drvinfo); |
| 329 | } |
| 330 | |
| 331 | /*rx_status->qual = stats->signal; */ |
| 332 | rx_status->signal = stats->rssi + 10; |
| 333 | /*rx_status->noise = -stats->noise; */ |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | void rtl92se_tx_fill_desc(struct ieee80211_hw *hw, |
| 339 | struct ieee80211_hdr *hdr, u8 *pdesc_tx, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 340 | struct ieee80211_tx_info *info, |
| 341 | struct ieee80211_sta *sta, |
| 342 | struct sk_buff *skb, |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 343 | u8 hw_queue, struct rtl_tcb_desc *ptcb_desc) |
| 344 | { |
| 345 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 346 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 347 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 348 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 349 | u8 *pdesc = pdesc_tx; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 350 | u16 seq_number; |
| 351 | __le16 fc = hdr->frame_control; |
| 352 | u8 reserved_macid = 0; |
| 353 | u8 fw_qsel = _rtl92se_map_hwqueue_to_fwqueue(skb, hw_queue); |
| 354 | bool firstseg = (!(hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG))); |
| 355 | bool lastseg = (!(hdr->frame_control & |
| 356 | cpu_to_le16(IEEE80211_FCTL_MOREFRAGS))); |
| 357 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len, |
| 358 | PCI_DMA_TODEVICE); |
| 359 | u8 bw_40 = 0; |
| 360 | |
Larry Finger | f6aa93a | 2012-12-27 10:37:31 -0600 | [diff] [blame] | 361 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 362 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 363 | "DMA mapping error"); |
| 364 | return; |
| 365 | } |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 366 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 367 | bw_40 = mac->bw_40; |
| 368 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
| 369 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
| 370 | if (sta) |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 371 | bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; |
| 375 | |
| 376 | rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc); |
| 377 | |
| 378 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE_RTL8192S); |
| 379 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 380 | if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) { |
| 381 | firstseg = true; |
| 382 | lastseg = true; |
| 383 | } |
| 384 | |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 385 | if (firstseg) { |
| 386 | if (rtlpriv->dm.useramask) { |
| 387 | /* set txdesc macId */ |
| 388 | if (ptcb_desc->mac_id < 32) { |
| 389 | SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id); |
| 390 | reserved_macid |= ptcb_desc->mac_id; |
| 391 | } |
| 392 | } |
| 393 | SET_TX_DESC_RSVD_MACID(pdesc, reserved_macid); |
| 394 | |
| 395 | SET_TX_DESC_TXHT(pdesc, ((ptcb_desc->hw_rate >= |
Larry Finger | 8e35337 | 2011-08-22 16:50:17 -0500 | [diff] [blame] | 396 | DESC92_RATEMCS0) ? 1 : 0)); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 397 | |
| 398 | if (rtlhal->version == VERSION_8192S_ACUT) { |
Larry Finger | 8e35337 | 2011-08-22 16:50:17 -0500 | [diff] [blame] | 399 | if (ptcb_desc->hw_rate == DESC92_RATE1M || |
| 400 | ptcb_desc->hw_rate == DESC92_RATE2M || |
| 401 | ptcb_desc->hw_rate == DESC92_RATE5_5M || |
| 402 | ptcb_desc->hw_rate == DESC92_RATE11M) { |
| 403 | ptcb_desc->hw_rate = DESC92_RATE12M; |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate); |
| 408 | |
| 409 | if (ptcb_desc->use_shortgi || ptcb_desc->use_shortpreamble) |
| 410 | SET_TX_DESC_TX_SHORT(pdesc, 0); |
| 411 | |
| 412 | /* Aggregation related */ |
| 413 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 414 | SET_TX_DESC_AGG_ENABLE(pdesc, 1); |
| 415 | |
| 416 | /* For AMPDU, we must insert SSN into TX_DESC */ |
| 417 | SET_TX_DESC_SEQ(pdesc, seq_number); |
| 418 | |
| 419 | /* Protection mode related */ |
| 420 | /* For 92S, if RTS/CTS are set, HW will execute RTS. */ |
| 421 | /* We choose only one protection mode to execute */ |
| 422 | SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable && |
| 423 | !ptcb_desc->cts_enable) ? 1 : 0)); |
| 424 | SET_TX_DESC_CTS_ENABLE(pdesc, ((ptcb_desc->cts_enable) ? |
| 425 | 1 : 0)); |
| 426 | SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0)); |
| 427 | |
| 428 | SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate); |
| 429 | SET_TX_DESC_RTS_BANDWIDTH(pdesc, 0); |
| 430 | SET_TX_DESC_RTS_SUB_CARRIER(pdesc, ptcb_desc->rts_sc); |
| 431 | SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <= |
Larry Finger | 8e35337 | 2011-08-22 16:50:17 -0500 | [diff] [blame] | 432 | DESC92_RATE54M) ? |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 433 | (ptcb_desc->rts_use_shortpreamble ? 1 : 0) |
| 434 | : (ptcb_desc->rts_use_shortgi ? 1 : 0))); |
| 435 | |
| 436 | |
| 437 | /* Set Bandwidth and sub-channel settings. */ |
| 438 | if (bw_40) { |
| 439 | if (ptcb_desc->packet_bw) { |
| 440 | SET_TX_DESC_TX_BANDWIDTH(pdesc, 1); |
| 441 | /* use duplicated mode */ |
| 442 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); |
| 443 | } else { |
| 444 | SET_TX_DESC_TX_BANDWIDTH(pdesc, 0); |
| 445 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, |
| 446 | mac->cur_40_prime_sc); |
| 447 | } |
| 448 | } else { |
| 449 | SET_TX_DESC_TX_BANDWIDTH(pdesc, 0); |
| 450 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); |
| 451 | } |
| 452 | |
| 453 | /* 3 Fill necessary field in First Descriptor */ |
| 454 | /*DWORD 0*/ |
| 455 | SET_TX_DESC_LINIP(pdesc, 0); |
| 456 | SET_TX_DESC_OFFSET(pdesc, 32); |
| 457 | SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len); |
| 458 | |
| 459 | /*DWORD 1*/ |
| 460 | SET_TX_DESC_RA_BRSR_ID(pdesc, ptcb_desc->ratr_index); |
| 461 | |
| 462 | /* Fill security related */ |
| 463 | if (info->control.hw_key) { |
| 464 | struct ieee80211_key_conf *keyconf; |
| 465 | |
| 466 | keyconf = info->control.hw_key; |
| 467 | switch (keyconf->cipher) { |
| 468 | case WLAN_CIPHER_SUITE_WEP40: |
| 469 | case WLAN_CIPHER_SUITE_WEP104: |
| 470 | SET_TX_DESC_SEC_TYPE(pdesc, 0x1); |
| 471 | break; |
| 472 | case WLAN_CIPHER_SUITE_TKIP: |
| 473 | SET_TX_DESC_SEC_TYPE(pdesc, 0x2); |
| 474 | break; |
| 475 | case WLAN_CIPHER_SUITE_CCMP: |
| 476 | SET_TX_DESC_SEC_TYPE(pdesc, 0x3); |
| 477 | break; |
| 478 | default: |
| 479 | SET_TX_DESC_SEC_TYPE(pdesc, 0x0); |
| 480 | break; |
| 481 | |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /* Set Packet ID */ |
| 486 | SET_TX_DESC_PACKET_ID(pdesc, 0); |
| 487 | |
| 488 | /* We will assign magement queue to BK. */ |
| 489 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel); |
| 490 | |
| 491 | /* Alwasy enable all rate fallback range */ |
| 492 | SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); |
| 493 | |
| 494 | /* Fix: I don't kown why hw use 6.5M to tx when set it */ |
| 495 | SET_TX_DESC_USER_RATE(pdesc, |
| 496 | ptcb_desc->use_driver_rate ? 1 : 0); |
| 497 | |
| 498 | /* Set NON_QOS bit. */ |
| 499 | if (!ieee80211_is_data_qos(fc)) |
| 500 | SET_TX_DESC_NON_QOS(pdesc, 1); |
| 501 | |
| 502 | } |
| 503 | |
| 504 | /* Fill fields that are required to be initialized |
| 505 | * in all of the descriptors */ |
| 506 | /*DWORD 0 */ |
| 507 | SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); |
| 508 | SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); |
| 509 | |
| 510 | /* DWORD 7 */ |
| 511 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len); |
| 512 | |
| 513 | /* DOWRD 8 */ |
Larry Finger | 8e2c406 | 2012-08-31 15:39:00 -0500 | [diff] [blame] | 514 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 515 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 516 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n"); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void rtl92se_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc, |
| 520 | bool firstseg, bool lastseg, struct sk_buff *skb) |
| 521 | { |
Larry Finger | f6aa93a | 2012-12-27 10:37:31 -0600 | [diff] [blame] | 522 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 523 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 524 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 525 | struct rtl_tcb_desc *tcb_desc = (struct rtl_tcb_desc *)(skb->cb); |
| 526 | |
| 527 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len, |
| 528 | PCI_DMA_TODEVICE); |
| 529 | |
Larry Finger | f6aa93a | 2012-12-27 10:37:31 -0600 | [diff] [blame] | 530 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
| 531 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, |
| 532 | "DMA mapping error"); |
| 533 | return; |
| 534 | } |
| 535 | /* Clear all status */ |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 536 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_CMDDESC_SIZE_RTL8192S); |
| 537 | |
| 538 | /* This bit indicate this packet is used for FW download. */ |
| 539 | if (tcb_desc->cmd_or_init == DESC_PACKET_TYPE_INIT) { |
| 540 | /* For firmware downlaod we only need to set LINIP */ |
| 541 | SET_TX_DESC_LINIP(pdesc, tcb_desc->last_inipkt); |
| 542 | |
| 543 | /* 92SE must set as 1 for firmware download HW DMA error */ |
| 544 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 545 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 546 | |
| 547 | /* 92SE need not to set TX packet size when firmware download */ |
| 548 | SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len)); |
| 549 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len)); |
Larry Finger | 8e2c406 | 2012-08-31 15:39:00 -0500 | [diff] [blame] | 550 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 551 | |
Larry Finger | 5111dd3 | 2011-05-23 20:37:31 -0500 | [diff] [blame] | 552 | wmb(); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 553 | SET_TX_DESC_OWN(pdesc, 1); |
| 554 | } else { /* H2C Command Desc format (Host TXCMD) */ |
| 555 | /* 92SE must set as 1 for firmware download HW DMA error */ |
| 556 | SET_TX_DESC_FIRST_SEG(pdesc, 1); |
| 557 | SET_TX_DESC_LAST_SEG(pdesc, 1); |
| 558 | |
| 559 | SET_TX_DESC_OFFSET(pdesc, 0x20); |
| 560 | |
| 561 | /* Buffer size + command header */ |
| 562 | SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len)); |
| 563 | /* Fixed queue of H2C command */ |
| 564 | SET_TX_DESC_QUEUE_SEL(pdesc, 0x13); |
| 565 | |
| 566 | SET_BITS_TO_LE_4BYTE(skb->data, 24, 7, rtlhal->h2c_txcmd_seq); |
| 567 | |
| 568 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len)); |
Larry Finger | 8e2c406 | 2012-08-31 15:39:00 -0500 | [diff] [blame] | 569 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 570 | |
Larry Finger | 5111dd3 | 2011-05-23 20:37:31 -0500 | [diff] [blame] | 571 | wmb(); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 572 | SET_TX_DESC_OWN(pdesc, 1); |
| 573 | |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | void rtl92se_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val) |
| 578 | { |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 579 | if (istx) { |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 580 | switch (desc_name) { |
| 581 | case HW_DESC_OWN: |
Larry Finger | 5111dd3 | 2011-05-23 20:37:31 -0500 | [diff] [blame] | 582 | wmb(); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 583 | SET_TX_DESC_OWN(pdesc, 1); |
| 584 | break; |
| 585 | case HW_DESC_TX_NEXTDESC_ADDR: |
| 586 | SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val); |
| 587 | break; |
| 588 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 589 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
| 590 | desc_name); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 591 | break; |
| 592 | } |
| 593 | } else { |
| 594 | switch (desc_name) { |
| 595 | case HW_DESC_RXOWN: |
Larry Finger | 5111dd3 | 2011-05-23 20:37:31 -0500 | [diff] [blame] | 596 | wmb(); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 597 | SET_RX_STATUS_DESC_OWN(pdesc, 1); |
| 598 | break; |
| 599 | case HW_DESC_RXBUFF_ADDR: |
| 600 | SET_RX_STATUS__DESC_BUFF_ADDR(pdesc, *(u32 *) val); |
| 601 | break; |
| 602 | case HW_DESC_RXPKT_LEN: |
| 603 | SET_RX_STATUS_DESC_PKT_LEN(pdesc, *(u32 *) val); |
| 604 | break; |
| 605 | case HW_DESC_RXERO: |
| 606 | SET_RX_STATUS_DESC_EOR(pdesc, 1); |
| 607 | break; |
| 608 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 609 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
| 610 | desc_name); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | u32 rtl92se_get_desc(u8 *desc, bool istx, u8 desc_name) |
| 617 | { |
| 618 | u32 ret = 0; |
| 619 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 620 | if (istx) { |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 621 | switch (desc_name) { |
| 622 | case HW_DESC_OWN: |
| 623 | ret = GET_TX_DESC_OWN(desc); |
| 624 | break; |
| 625 | case HW_DESC_TXBUFF_ADDR: |
| 626 | ret = GET_TX_DESC_TX_BUFFER_ADDRESS(desc); |
| 627 | break; |
| 628 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 629 | RT_ASSERT(false, "ERR txdesc :%d not process\n", |
| 630 | desc_name); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 631 | break; |
| 632 | } |
| 633 | } else { |
| 634 | switch (desc_name) { |
| 635 | case HW_DESC_OWN: |
| 636 | ret = GET_RX_STATUS_DESC_OWN(desc); |
| 637 | break; |
| 638 | case HW_DESC_RXPKT_LEN: |
| 639 | ret = GET_RX_STATUS_DESC_PKT_LEN(desc); |
| 640 | break; |
| 641 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 642 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", |
| 643 | desc_name); |
Chaoming Li | 84f494c | 2011-05-03 09:49:26 -0500 | [diff] [blame] | 644 | break; |
| 645 | } |
| 646 | } |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | void rtl92se_tx_polling(struct ieee80211_hw *hw, u8 hw_queue) |
| 651 | { |
| 652 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 653 | rtl_write_word(rtlpriv, TP_POLL, BIT(0) << (hw_queue)); |
| 654 | } |