trx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. u8 *psaddr;
  220. __le16 fc;
  221. u16 type;
  222. bool packet_matchbssid, packet_toself, packet_beacon;
  223. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  224. hdr = (struct ieee80211_hdr *)tmp_buf;
  225. fc = hdr->frame_control;
  226. type = WLAN_FC_GET_TYPE(fc);
  227. praddr = hdr->addr1;
  228. psaddr = ieee80211_get_SA(hdr);
  229. packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
  230. (!compare_ether_addr(mac->bssid,
  231. (le16_to_cpu(fc) & IEEE80211_FCTL_TODS) ?
  232. hdr->addr1 : (le16_to_cpu(fc) &
  233. IEEE80211_FCTL_FROMDS) ?
  234. hdr->addr2 : hdr->addr3)) && (!pstatus->hwerror) &&
  235. (!pstatus->crc) && (!pstatus->icv));
  236. packet_toself = packet_matchbssid &&
  237. (!compare_ether_addr(praddr, rtlefuse->dev_addr));
  238. if (ieee80211_is_beacon(fc))
  239. packet_beacon = true;
  240. _rtl8723ae_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  241. packet_matchbssid, packet_toself,
  242. packet_beacon);
  243. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  244. }
  245. bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw,
  246. struct rtl_stats *status,
  247. struct ieee80211_rx_status *rx_status,
  248. u8 *pdesc, struct sk_buff *skb)
  249. {
  250. struct rx_fwinfo_8723e *p_drvinfo;
  251. struct ieee80211_hdr *hdr;
  252. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  253. status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  254. status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  255. RX_DRV_INFO_SIZE_UNIT;
  256. status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  257. status->icv = (u16) GET_RX_DESC_ICV(pdesc);
  258. status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  259. status->hwerror = (status->crc | status->icv);
  260. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  261. status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
  262. status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  263. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  264. status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1)
  265. && (GET_RX_DESC_FAGGR(pdesc) == 1));
  266. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  267. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  268. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  269. status->is_cck = RTL8723E_RX_HAL_IS_CCK_RATE(status->rate);
  270. rx_status->freq = hw->conf.channel->center_freq;
  271. rx_status->band = hw->conf.channel->band;
  272. hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
  273. + status->rx_bufshift);
  274. if (status->crc)
  275. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  276. if (status->rx_is40Mhzpacket)
  277. rx_status->flag |= RX_FLAG_40MHZ;
  278. if (status->is_ht)
  279. rx_status->flag |= RX_FLAG_HT;
  280. rx_status->flag |= RX_FLAG_MACTIME_START;
  281. /* hw will set status->decrypted true, if it finds the
  282. * frame is open data frame or mgmt frame.
  283. * Thus hw will not decrypt a robust managment frame
  284. * for IEEE80211w but still set status->decrypted
  285. * true, so here we should set it back to undecrypted
  286. * for IEEE80211w frame, and mac80211 sw will help
  287. * to decrypt it
  288. */
  289. if (status->decrypted) {
  290. if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
  291. (ieee80211_has_protected(hdr->frame_control)))
  292. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  293. else
  294. rx_status->flag |= RX_FLAG_DECRYPTED;
  295. }
  296. /* rate_idx: index of data rate into band's
  297. * supported rates or MCS index if HT rates
  298. * are use (RX_FLAG_HT)
  299. */
  300. rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
  301. status->rate, false);
  302. rx_status->mactime = status->timestamp_low;
  303. if (phystatus == true) {
  304. p_drvinfo = (struct rx_fwinfo_8723e *)(skb->data +
  305. status->rx_bufshift);
  306. _rtl8723ae_translate_rx_signal_stuff(hw,
  307. skb, status, pdesc, p_drvinfo);
  308. }
  309. /*rx_status->qual = status->signal; */
  310. rx_status->signal = status->recvsignalpower + 10;
  311. /*rx_status->noise = -status->noise; */
  312. return true;
  313. }
  314. void rtl8723ae_tx_fill_desc(struct ieee80211_hw *hw,
  315. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  316. struct ieee80211_tx_info *info,
  317. struct ieee80211_sta *sta,
  318. struct sk_buff *skb, u8 hw_queue,
  319. struct rtl_tcb_desc *ptcdesc)
  320. {
  321. struct rtl_priv *rtlpriv = rtl_priv(hw);
  322. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  323. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  324. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  325. bool defaultadapter = true;
  326. u8 *pdesc = (u8 *) pdesc_tx;
  327. u16 seq_number;
  328. __le16 fc = hdr->frame_control;
  329. u8 fw_qsel = _rtl8723ae_map_hwqueue_to_fwqueue(skb, hw_queue);
  330. bool firstseg = ((hdr->seq_ctrl &
  331. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  332. bool lastseg = ((hdr->frame_control &
  333. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  334. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  335. skb->data, skb->len,
  336. PCI_DMA_TODEVICE);
  337. u8 bw_40 = 0;
  338. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  339. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  340. "DMA mapping error");
  341. return;
  342. }
  343. if (mac->opmode == NL80211_IFTYPE_STATION) {
  344. bw_40 = mac->bw_40;
  345. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  346. mac->opmode == NL80211_IFTYPE_ADHOC) {
  347. if (sta)
  348. bw_40 = sta->ht_cap.cap &
  349. IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  350. }
  351. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  352. rtl_get_tcb_desc(hw, info, sta, skb, ptcdesc);
  353. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8723e));
  354. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  355. firstseg = true;
  356. lastseg = true;
  357. }
  358. if (firstseg) {
  359. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  360. SET_TX_DESC_TX_RATE(pdesc, ptcdesc->hw_rate);
  361. if (ptcdesc->use_shortgi || ptcdesc->use_shortpreamble)
  362. SET_TX_DESC_DATA_SHORTGI(pdesc, 1);
  363. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  364. SET_TX_DESC_AGG_BREAK(pdesc, 1);
  365. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  366. }
  367. SET_TX_DESC_SEQ(pdesc, seq_number);
  368. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcdesc->rts_enable &&
  369. !ptcdesc->
  370. cts_enable) ? 1 : 0));
  371. SET_TX_DESC_HW_RTS_ENABLE(pdesc,
  372. ((ptcdesc->rts_enable
  373. || ptcdesc->cts_enable) ? 1 : 0));
  374. SET_TX_DESC_CTS2SELF(pdesc, ((ptcdesc->cts_enable) ? 1 : 0));
  375. SET_TX_DESC_RTS_STBC(pdesc, ((ptcdesc->rts_stbc) ? 1 : 0));
  376. SET_TX_DESC_RTS_RATE(pdesc, ptcdesc->rts_rate);
  377. SET_TX_DESC_RTS_BW(pdesc, 0);
  378. SET_TX_DESC_RTS_SC(pdesc, ptcdesc->rts_sc);
  379. SET_TX_DESC_RTS_SHORT(pdesc,
  380. ((ptcdesc->rts_rate <= DESC92_RATE54M) ?
  381. (ptcdesc->rts_use_shortpreamble ? 1 : 0)
  382. : (ptcdesc->rts_use_shortgi ? 1 : 0)));
  383. if (bw_40) {
  384. if (ptcdesc->packet_bw) {
  385. SET_TX_DESC_DATA_BW(pdesc, 1);
  386. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  387. } else {
  388. SET_TX_DESC_DATA_BW(pdesc, 0);
  389. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  390. mac->cur_40_prime_sc);
  391. }
  392. } else {
  393. SET_TX_DESC_DATA_BW(pdesc, 0);
  394. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  395. }
  396. SET_TX_DESC_LINIP(pdesc, 0);
  397. SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
  398. if (sta) {
  399. u8 ampdu_density = sta->ht_cap.ampdu_density;
  400. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  401. }
  402. if (info->control.hw_key) {
  403. struct ieee80211_key_conf *keyconf =
  404. info->control.hw_key;
  405. switch (keyconf->cipher) {
  406. case WLAN_CIPHER_SUITE_WEP40:
  407. case WLAN_CIPHER_SUITE_WEP104:
  408. case WLAN_CIPHER_SUITE_TKIP:
  409. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  410. break;
  411. case WLAN_CIPHER_SUITE_CCMP:
  412. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  413. break;
  414. default:
  415. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  416. break;
  417. }
  418. }
  419. SET_TX_DESC_PKT_ID(pdesc, 0);
  420. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  421. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  422. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  423. SET_TX_DESC_DISABLE_FB(pdesc, 0);
  424. SET_TX_DESC_USE_RATE(pdesc, ptcdesc->use_driver_rate ? 1 : 0);
  425. if (ieee80211_is_data_qos(fc)) {
  426. if (mac->rdg_en) {
  427. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  428. "Enable RDG function.\n");
  429. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  430. SET_TX_DESC_HTC(pdesc, 1);
  431. }
  432. }
  433. }
  434. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  435. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  436. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
  437. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  438. if (rtlpriv->dm.useramask) {
  439. SET_TX_DESC_RATE_ID(pdesc, ptcdesc->ratr_index);
  440. SET_TX_DESC_MACID(pdesc, ptcdesc->mac_id);
  441. } else {
  442. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcdesc->ratr_index);
  443. SET_TX_DESC_MACID(pdesc, ptcdesc->ratr_index);
  444. }
  445. if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) {
  446. SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1);
  447. if (!defaultadapter)
  448. SET_TX_DESC_HWSEQ_SEL_8723(pdesc, 1);
  449. }
  450. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  451. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  452. is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
  453. SET_TX_DESC_BMC(pdesc, 1);
  454. }
  455. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  456. }
  457. void rtl8723ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
  458. u8 *pdesc, bool firstseg,
  459. bool lastseg, struct sk_buff *skb)
  460. {
  461. struct rtl_priv *rtlpriv = rtl_priv(hw);
  462. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  463. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  464. u8 fw_queue = QSLT_BEACON;
  465. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  466. skb->data, skb->len,
  467. PCI_DMA_TODEVICE);
  468. __le16 fc = hdr->frame_control;
  469. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  470. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  471. "DMA mapping error");
  472. return;
  473. }
  474. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  475. if (firstseg)
  476. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  477. SET_TX_DESC_TX_RATE(pdesc, DESC92_RATE1M);
  478. SET_TX_DESC_SEQ(pdesc, 0);
  479. SET_TX_DESC_LINIP(pdesc, 0);
  480. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  481. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  482. SET_TX_DESC_LAST_SEG(pdesc, 1);
  483. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
  484. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  485. SET_TX_DESC_RATE_ID(pdesc, 7);
  486. SET_TX_DESC_MACID(pdesc, 0);
  487. SET_TX_DESC_OWN(pdesc, 1);
  488. SET_TX_DESC_PKT_SIZE((u8 *) pdesc, (u16) (skb->len));
  489. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  490. SET_TX_DESC_LAST_SEG(pdesc, 1);
  491. SET_TX_DESC_OFFSET(pdesc, 0x20);
  492. SET_TX_DESC_USE_RATE(pdesc, 1);
  493. if (!ieee80211_is_data_qos(fc)) {
  494. SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1);
  495. /* SET_TX_DESC_HWSEQ_EN(pdesc, 1); */
  496. /* SET_TX_DESC_PKT_ID(pdesc, 8); */
  497. }
  498. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  499. "H2C Tx Cmd Content\n",
  500. pdesc, TX_DESC_SIZE);
  501. }
  502. void rtl8723ae_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
  503. {
  504. if (istx == true) {
  505. switch (desc_name) {
  506. case HW_DESC_OWN:
  507. SET_TX_DESC_OWN(pdesc, 1);
  508. break;
  509. case HW_DESC_TX_NEXTDESC_ADDR:
  510. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
  511. break;
  512. default:
  513. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  514. desc_name);
  515. break;
  516. }
  517. } else {
  518. switch (desc_name) {
  519. case HW_DESC_RXOWN:
  520. SET_RX_DESC_OWN(pdesc, 1);
  521. break;
  522. case HW_DESC_RXBUFF_ADDR:
  523. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val);
  524. break;
  525. case HW_DESC_RXPKT_LEN:
  526. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val);
  527. break;
  528. case HW_DESC_RXERO:
  529. SET_RX_DESC_EOR(pdesc, 1);
  530. break;
  531. default:
  532. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  533. desc_name);
  534. break;
  535. }
  536. }
  537. }
  538. u32 rtl8723ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  539. {
  540. u32 ret = 0;
  541. if (istx == true) {
  542. switch (desc_name) {
  543. case HW_DESC_OWN:
  544. ret = GET_TX_DESC_OWN(pdesc);
  545. break;
  546. case HW_DESC_TXBUFF_ADDR:
  547. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  548. break;
  549. default:
  550. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  551. desc_name);
  552. break;
  553. }
  554. } else {
  555. switch (desc_name) {
  556. case HW_DESC_OWN:
  557. ret = GET_RX_DESC_OWN(pdesc);
  558. break;
  559. case HW_DESC_RXPKT_LEN:
  560. ret = GET_RX_DESC_PKT_LEN(pdesc);
  561. break;
  562. default:
  563. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  564. desc_name);
  565. break;
  566. }
  567. }
  568. return ret;
  569. }
  570. void rtl8723ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  571. {
  572. struct rtl_priv *rtlpriv = rtl_priv(hw);
  573. if (hw_queue == BEACON_QUEUE) {
  574. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  575. } else {
  576. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  577. BIT(0) << (hw_queue));
  578. }
  579. }