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