trx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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. #include "../wifi.h"
  30. #include "../pci.h"
  31. #include "../base.h"
  32. #include "../stats.h"
  33. #include "reg.h"
  34. #include "def.h"
  35. #include "phy.h"
  36. #include "trx.h"
  37. #include "led.h"
  38. static u8 _rtl8723ae_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
  39. {
  40. __le16 fc = rtl_get_fc(skb);
  41. if (unlikely(ieee80211_is_beacon(fc)))
  42. return QSLT_BEACON;
  43. if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
  44. return QSLT_MGNT;
  45. return skb->priority;
  46. }
  47. static void _rtl8723ae_query_rxphystatus(struct ieee80211_hw *hw,
  48. struct rtl_stats *pstatus, u8 *pdesc,
  49. struct rx_fwinfo_8723e *p_drvinfo,
  50. bool bpacket_match_bssid,
  51. bool bpacket_toself, bool packet_beacon)
  52. {
  53. struct rtl_priv *rtlpriv = rtl_priv(hw);
  54. struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
  55. struct phy_sts_cck_8723e_t *cck_buf;
  56. s8 rx_pwr_all, rx_pwr[4];
  57. u8 rf_rx_num = 0, evm, pwdb_all;
  58. u8 i, max_spatial_stream;
  59. u32 rssi, total_rssi = 0;
  60. bool is_cck = pstatus->is_cck;
  61. /* Record it for next packet processing */
  62. pstatus->packet_matchbssid = bpacket_match_bssid;
  63. pstatus->packet_toself = bpacket_toself;
  64. pstatus->packet_beacon = packet_beacon;
  65. pstatus->rx_mimo_sig_qual[0] = -1;
  66. pstatus->rx_mimo_sig_qual[1] = -1;
  67. if (is_cck) {
  68. u8 report, cck_highpwr;
  69. /* CCK Driver info Structure is not the same as OFDM packet. */
  70. cck_buf = (struct phy_sts_cck_8723e_t *)p_drvinfo;
  71. /* (1)Hardware does not provide RSSI for CCK
  72. * (2)PWDB, Average PWDB cacluated by
  73. * hardware (for rate adaptive)
  74. */
  75. if (ppsc->rfpwr_state == ERFON)
  76. cck_highpwr = (u8) rtl_get_bbreg(hw,
  77. RFPGA0_XA_HSSIPARAMETER2,
  78. BIT(9));
  79. else
  80. cck_highpwr = false;
  81. if (!cck_highpwr) {
  82. u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
  83. report = cck_buf->cck_agc_rpt & 0xc0;
  84. report = report >> 6;
  85. switch (report) {
  86. case 0x3:
  87. rx_pwr_all = -46 - (cck_agc_rpt & 0x3e);
  88. break;
  89. case 0x2:
  90. rx_pwr_all = -26 - (cck_agc_rpt & 0x3e);
  91. break;
  92. case 0x1:
  93. rx_pwr_all = -12 - (cck_agc_rpt & 0x3e);
  94. break;
  95. case 0x0:
  96. rx_pwr_all = 16 - (cck_agc_rpt & 0x3e);
  97. break;
  98. }
  99. } else {
  100. u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
  101. report = p_drvinfo->cfosho[0] & 0x60;
  102. report = report >> 5;
  103. switch (report) {
  104. case 0x3:
  105. rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1);
  106. break;
  107. case 0x2:
  108. rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1);
  109. break;
  110. case 0x1:
  111. rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1);
  112. break;
  113. case 0x0:
  114. rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1);
  115. break;
  116. }
  117. }
  118. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  119. /* CCK gain is smaller than OFDM/MCS gain,
  120. * so we add gain diff. From experience, the val is 6
  121. */
  122. pwdb_all += 6;
  123. if (pwdb_all > 100)
  124. pwdb_all = 100;
  125. /* modify the offset to make the same
  126. * gain index with OFDM.
  127. */
  128. if (pwdb_all > 34 && pwdb_all <= 42)
  129. pwdb_all -= 2;
  130. else if (pwdb_all > 26 && pwdb_all <= 34)
  131. pwdb_all -= 6;
  132. else if (pwdb_all > 14 && pwdb_all <= 26)
  133. pwdb_all -= 8;
  134. else if (pwdb_all > 4 && pwdb_all <= 14)
  135. pwdb_all -= 4;
  136. pstatus->rx_pwdb_all = pwdb_all;
  137. pstatus->recvsignalpower = rx_pwr_all;
  138. /* (3) Get Signal Quality (EVM) */
  139. if (bpacket_match_bssid) {
  140. u8 sq;
  141. if (pstatus->rx_pwdb_all > 40) {
  142. sq = 100;
  143. } else {
  144. sq = cck_buf->sq_rpt;
  145. if (sq > 64)
  146. sq = 0;
  147. else if (sq < 20)
  148. sq = 100;
  149. else
  150. sq = ((64 - sq) * 100) / 44;
  151. }
  152. pstatus->signalquality = sq;
  153. pstatus->rx_mimo_sig_qual[0] = sq;
  154. pstatus->rx_mimo_sig_qual[1] = -1;
  155. }
  156. } else {
  157. rtlpriv->dm.rfpath_rxenable[0] =
  158. rtlpriv->dm.rfpath_rxenable[1] = true;
  159. /* (1)Get RSSI for HT rate */
  160. for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
  161. /* we will judge RF RX path now. */
  162. if (rtlpriv->dm.rfpath_rxenable[i])
  163. rf_rx_num++;
  164. rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f)*2) - 110;
  165. /* Translate DBM to percentage. */
  166. rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
  167. total_rssi += rssi;
  168. /* Get Rx snr value in DB */
  169. rtlpriv->stats.rx_snr_db[i] = (p_drvinfo->rxsnr[i] / 2);
  170. /* Record Signal Strength for next packet */
  171. if (bpacket_match_bssid)
  172. pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
  173. }
  174. /* (2)PWDB, Average PWDB cacluated by
  175. * hardware (for rate adaptive)
  176. */
  177. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  178. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  179. pstatus->rx_pwdb_all = pwdb_all;
  180. pstatus->rxpower = rx_pwr_all;
  181. pstatus->recvsignalpower = rx_pwr_all;
  182. /* (3)EVM of HT rate */
  183. if (pstatus->is_ht && pstatus->rate >= DESC92_RATEMCS8 &&
  184. pstatus->rate <= DESC92_RATEMCS15)
  185. max_spatial_stream = 2;
  186. else
  187. max_spatial_stream = 1;
  188. for (i = 0; i < max_spatial_stream; i++) {
  189. evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
  190. if (bpacket_match_bssid) {
  191. /* Fill value in RFD, Get the first
  192. * spatial stream only
  193. */
  194. if (i == 0)
  195. pstatus->signalquality = (evm & 0xff);
  196. pstatus->rx_mimo_sig_qual[i] = (evm & 0xff);
  197. }
  198. }
  199. }
  200. /* UI BSS List signal strength(in percentage),
  201. * make it good looking, from 0~100.
  202. */
  203. if (is_cck)
  204. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  205. pwdb_all));
  206. else if (rf_rx_num != 0)
  207. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  208. total_rssi /= rf_rx_num));
  209. }
  210. static void _rtl8723ae_translate_rx_signal_stuff(struct ieee80211_hw *hw,
  211. struct sk_buff *skb, struct rtl_stats *pstatus,
  212. u8 *pdesc, struct rx_fwinfo_8723e *p_drvinfo)
  213. {
  214. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  215. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  216. struct ieee80211_hdr *hdr;
  217. u8 *tmp_buf;
  218. u8 *praddr;
  219. __le16 fc;
  220. u16 type;
  221. bool packet_matchbssid, packet_toself, packet_beacon = false;
  222. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  223. hdr = (struct ieee80211_hdr *)tmp_buf;
  224. fc = hdr->frame_control;
  225. type = WLAN_FC_GET_TYPE(fc);
  226. praddr = hdr->addr1;
  227. packet_matchbssid =
  228. ((IEEE80211_FTYPE_CTL != type) &&
  229. ether_addr_equal(mac->bssid,
  230. (le16_to_cpu(fc) & IEEE80211_FCTL_TODS) ? hdr->addr1 :
  231. (le16_to_cpu(fc) & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
  232. hdr->addr3) &&
  233. (!pstatus->hwerror) && (!pstatus->crc) && (!pstatus->icv));
  234. packet_toself = (packet_matchbssid &&
  235. ether_addr_equal(praddr, rtlefuse->dev_addr));
  236. if (ieee80211_is_beacon(fc))
  237. packet_beacon = true;
  238. _rtl8723ae_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  239. packet_matchbssid, packet_toself,
  240. packet_beacon);
  241. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  242. }
  243. bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw,
  244. struct rtl_stats *status,
  245. struct ieee80211_rx_status *rx_status,
  246. u8 *pdesc, struct sk_buff *skb)
  247. {
  248. struct rx_fwinfo_8723e *p_drvinfo;
  249. struct ieee80211_hdr *hdr;
  250. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  251. status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  252. status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  253. RX_DRV_INFO_SIZE_UNIT;
  254. status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  255. status->icv = (u16) GET_RX_DESC_ICV(pdesc);
  256. status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  257. status->hwerror = (status->crc | status->icv);
  258. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  259. status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
  260. status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  261. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  262. status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1)
  263. && (GET_RX_DESC_FAGGR(pdesc) == 1));
  264. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  265. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  266. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  267. status->is_cck = RTL8723E_RX_HAL_IS_CCK_RATE(status->rate);
  268. rx_status->freq = hw->conf.chandef.chan->center_freq;
  269. rx_status->band = hw->conf.chandef.chan->band;
  270. if (status->crc)
  271. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  272. if (status->rx_is40Mhzpacket)
  273. rx_status->flag |= RX_FLAG_40MHZ;
  274. if (status->is_ht)
  275. rx_status->flag |= RX_FLAG_HT;
  276. rx_status->flag |= RX_FLAG_MACTIME_START;
  277. /* hw will set status->decrypted true, if it finds the
  278. * frame is open data frame or mgmt frame.
  279. * Thus hw will not decrypt a robust managment frame
  280. * for IEEE80211w but still set status->decrypted
  281. * true, so here we should set it back to undecrypted
  282. * for IEEE80211w frame, and mac80211 sw will help
  283. * to decrypt it
  284. */
  285. if (status->decrypted) {
  286. hdr = (struct ieee80211_hdr *)(skb->data +
  287. status->rx_drvinfo_size + status->rx_bufshift);
  288. if (!hdr) {
  289. /* during testing, hdr could be NULL here */
  290. return false;
  291. }
  292. if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
  293. (ieee80211_has_protected(hdr->frame_control)))
  294. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  295. else
  296. rx_status->flag |= RX_FLAG_DECRYPTED;
  297. }
  298. /* rate_idx: index of data rate into band's
  299. * supported rates or MCS index if HT rates
  300. * are use (RX_FLAG_HT)
  301. */
  302. rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
  303. status->rate, false);
  304. rx_status->mactime = status->timestamp_low;
  305. if (phystatus == true) {
  306. p_drvinfo = (struct rx_fwinfo_8723e *)(skb->data +
  307. status->rx_bufshift);
  308. _rtl8723ae_translate_rx_signal_stuff(hw,
  309. skb, status, pdesc, p_drvinfo);
  310. }
  311. /*rx_status->qual = status->signal; */
  312. rx_status->signal = status->recvsignalpower + 10;
  313. /*rx_status->noise = -status->noise; */
  314. return true;
  315. }
  316. void rtl8723ae_tx_fill_desc(struct ieee80211_hw *hw,
  317. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  318. struct ieee80211_tx_info *info,
  319. struct ieee80211_sta *sta,
  320. struct sk_buff *skb, u8 hw_queue,
  321. struct rtl_tcb_desc *ptcdesc)
  322. {
  323. struct rtl_priv *rtlpriv = rtl_priv(hw);
  324. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  325. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  326. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  327. bool defaultadapter = true;
  328. u8 *pdesc = (u8 *) pdesc_tx;
  329. u16 seq_number;
  330. __le16 fc = hdr->frame_control;
  331. u8 fw_qsel = _rtl8723ae_map_hwqueue_to_fwqueue(skb, hw_queue);
  332. bool firstseg = ((hdr->seq_ctrl &
  333. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  334. bool lastseg = ((hdr->frame_control &
  335. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  336. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  337. skb->data, skb->len,
  338. PCI_DMA_TODEVICE);
  339. u8 bw_40 = 0;
  340. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  341. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  342. "DMA mapping error");
  343. return;
  344. }
  345. if (mac->opmode == NL80211_IFTYPE_STATION) {
  346. bw_40 = mac->bw_40;
  347. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  348. mac->opmode == NL80211_IFTYPE_ADHOC) {
  349. if (sta)
  350. bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
  351. }
  352. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  353. rtl_get_tcb_desc(hw, info, sta, skb, ptcdesc);
  354. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8723e));
  355. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  356. firstseg = true;
  357. lastseg = true;
  358. }
  359. if (firstseg) {
  360. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  361. SET_TX_DESC_TX_RATE(pdesc, ptcdesc->hw_rate);
  362. if (ptcdesc->use_shortgi || ptcdesc->use_shortpreamble)
  363. SET_TX_DESC_DATA_SHORTGI(pdesc, 1);
  364. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  365. SET_TX_DESC_AGG_BREAK(pdesc, 1);
  366. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  367. }
  368. SET_TX_DESC_SEQ(pdesc, seq_number);
  369. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcdesc->rts_enable &&
  370. !ptcdesc->
  371. cts_enable) ? 1 : 0));
  372. SET_TX_DESC_HW_RTS_ENABLE(pdesc,
  373. ((ptcdesc->rts_enable
  374. || ptcdesc->cts_enable) ? 1 : 0));
  375. SET_TX_DESC_CTS2SELF(pdesc, ((ptcdesc->cts_enable) ? 1 : 0));
  376. SET_TX_DESC_RTS_STBC(pdesc, ((ptcdesc->rts_stbc) ? 1 : 0));
  377. SET_TX_DESC_RTS_RATE(pdesc, ptcdesc->rts_rate);
  378. SET_TX_DESC_RTS_BW(pdesc, 0);
  379. SET_TX_DESC_RTS_SC(pdesc, ptcdesc->rts_sc);
  380. SET_TX_DESC_RTS_SHORT(pdesc,
  381. ((ptcdesc->rts_rate <= DESC92_RATE54M) ?
  382. (ptcdesc->rts_use_shortpreamble ? 1 : 0)
  383. : (ptcdesc->rts_use_shortgi ? 1 : 0)));
  384. if (bw_40) {
  385. if (ptcdesc->packet_bw) {
  386. SET_TX_DESC_DATA_BW(pdesc, 1);
  387. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  388. } else {
  389. SET_TX_DESC_DATA_BW(pdesc, 0);
  390. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  391. mac->cur_40_prime_sc);
  392. }
  393. } else {
  394. SET_TX_DESC_DATA_BW(pdesc, 0);
  395. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  396. }
  397. SET_TX_DESC_LINIP(pdesc, 0);
  398. SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
  399. if (sta) {
  400. u8 ampdu_density = sta->ht_cap.ampdu_density;
  401. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  402. }
  403. if (info->control.hw_key) {
  404. struct ieee80211_key_conf *keyconf =
  405. info->control.hw_key;
  406. switch (keyconf->cipher) {
  407. case WLAN_CIPHER_SUITE_WEP40:
  408. case WLAN_CIPHER_SUITE_WEP104:
  409. case WLAN_CIPHER_SUITE_TKIP:
  410. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  411. break;
  412. case WLAN_CIPHER_SUITE_CCMP:
  413. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  414. break;
  415. default:
  416. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  417. break;
  418. }
  419. }
  420. SET_TX_DESC_PKT_ID(pdesc, 0);
  421. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  422. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  423. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  424. SET_TX_DESC_DISABLE_FB(pdesc, 0);
  425. SET_TX_DESC_USE_RATE(pdesc, ptcdesc->use_driver_rate ? 1 : 0);
  426. if (ieee80211_is_data_qos(fc)) {
  427. if (mac->rdg_en) {
  428. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  429. "Enable RDG function.\n");
  430. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  431. SET_TX_DESC_HTC(pdesc, 1);
  432. }
  433. }
  434. }
  435. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  436. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  437. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
  438. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  439. if (rtlpriv->dm.useramask) {
  440. SET_TX_DESC_RATE_ID(pdesc, ptcdesc->ratr_index);
  441. SET_TX_DESC_MACID(pdesc, ptcdesc->mac_id);
  442. } else {
  443. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcdesc->ratr_index);
  444. SET_TX_DESC_MACID(pdesc, ptcdesc->ratr_index);
  445. }
  446. if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) {
  447. SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1);
  448. if (!defaultadapter)
  449. SET_TX_DESC_HWSEQ_SEL_8723(pdesc, 1);
  450. }
  451. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  452. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  453. is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
  454. SET_TX_DESC_BMC(pdesc, 1);
  455. }
  456. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  457. }
  458. void rtl8723ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
  459. u8 *pdesc, bool firstseg,
  460. bool lastseg, struct sk_buff *skb)
  461. {
  462. struct rtl_priv *rtlpriv = rtl_priv(hw);
  463. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  464. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  465. u8 fw_queue = QSLT_BEACON;
  466. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  467. skb->data, skb->len,
  468. PCI_DMA_TODEVICE);
  469. __le16 fc = hdr->frame_control;
  470. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  471. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  472. "DMA mapping error");
  473. return;
  474. }
  475. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  476. if (firstseg)
  477. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  478. SET_TX_DESC_TX_RATE(pdesc, DESC92_RATE1M);
  479. SET_TX_DESC_SEQ(pdesc, 0);
  480. SET_TX_DESC_LINIP(pdesc, 0);
  481. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  482. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  483. SET_TX_DESC_LAST_SEG(pdesc, 1);
  484. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
  485. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  486. SET_TX_DESC_RATE_ID(pdesc, 7);
  487. SET_TX_DESC_MACID(pdesc, 0);
  488. SET_TX_DESC_OWN(pdesc, 1);
  489. SET_TX_DESC_PKT_SIZE((u8 *) pdesc, (u16) (skb->len));
  490. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  491. SET_TX_DESC_LAST_SEG(pdesc, 1);
  492. SET_TX_DESC_OFFSET(pdesc, 0x20);
  493. SET_TX_DESC_USE_RATE(pdesc, 1);
  494. if (!ieee80211_is_data_qos(fc)) {
  495. SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1);
  496. /* SET_TX_DESC_HWSEQ_EN(pdesc, 1); */
  497. /* SET_TX_DESC_PKT_ID(pdesc, 8); */
  498. }
  499. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  500. "H2C Tx Cmd Content\n",
  501. pdesc, TX_DESC_SIZE);
  502. }
  503. void rtl8723ae_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
  504. {
  505. if (istx == true) {
  506. switch (desc_name) {
  507. case HW_DESC_OWN:
  508. SET_TX_DESC_OWN(pdesc, 1);
  509. break;
  510. case HW_DESC_TX_NEXTDESC_ADDR:
  511. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
  512. break;
  513. default:
  514. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  515. desc_name);
  516. break;
  517. }
  518. } else {
  519. switch (desc_name) {
  520. case HW_DESC_RXOWN:
  521. SET_RX_DESC_OWN(pdesc, 1);
  522. break;
  523. case HW_DESC_RXBUFF_ADDR:
  524. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val);
  525. break;
  526. case HW_DESC_RXPKT_LEN:
  527. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val);
  528. break;
  529. case HW_DESC_RXERO:
  530. SET_RX_DESC_EOR(pdesc, 1);
  531. break;
  532. default:
  533. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  534. desc_name);
  535. break;
  536. }
  537. }
  538. }
  539. u32 rtl8723ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  540. {
  541. u32 ret = 0;
  542. if (istx == true) {
  543. switch (desc_name) {
  544. case HW_DESC_OWN:
  545. ret = GET_TX_DESC_OWN(pdesc);
  546. break;
  547. case HW_DESC_TXBUFF_ADDR:
  548. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  549. break;
  550. default:
  551. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  552. desc_name);
  553. break;
  554. }
  555. } else {
  556. switch (desc_name) {
  557. case HW_DESC_OWN:
  558. ret = GET_RX_DESC_OWN(pdesc);
  559. break;
  560. case HW_DESC_RXPKT_LEN:
  561. ret = GET_RX_DESC_PKT_LEN(pdesc);
  562. break;
  563. default:
  564. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  565. desc_name);
  566. break;
  567. }
  568. }
  569. return ret;
  570. }
  571. void rtl8723ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  572. {
  573. struct rtl_priv *rtlpriv = rtl_priv(hw);
  574. if (hw_queue == BEACON_QUEUE) {
  575. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  576. } else {
  577. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  578. BIT(0) << (hw_queue));
  579. }
  580. }