trx.c 18 KB

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