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