trx.c 22 KB

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