trx.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2014 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. #include "dm.h"
  35. static u8 _rtl8723be_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
  36. {
  37. __le16 fc = rtl_get_fc(skb);
  38. if (unlikely(ieee80211_is_beacon(fc)))
  39. return QSLT_BEACON;
  40. if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
  41. return QSLT_MGNT;
  42. return skb->priority;
  43. }
  44. /* mac80211's rate_idx is like this:
  45. *
  46. * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
  47. *
  48. * B/G rate:
  49. * (rx_status->flag & RX_FLAG_HT) = 0,
  50. * DESC92C_RATE1M-->DESC92C_RATE54M ==> idx is 0-->11,
  51. *
  52. * N rate:
  53. * (rx_status->flag & RX_FLAG_HT) = 1,
  54. * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
  55. *
  56. * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
  57. * A rate:
  58. * (rx_status->flag & RX_FLAG_HT) = 0,
  59. * DESC92C_RATE6M-->DESC92C_RATE54M ==> idx is 0-->7,
  60. *
  61. * N rate:
  62. * (rx_status->flag & RX_FLAG_HT) = 1,
  63. * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
  64. */
  65. static int _rtl8723be_rate_mapping(struct ieee80211_hw *hw,
  66. bool isht, u8 desc_rate)
  67. {
  68. int rate_idx;
  69. if (!isht) {
  70. if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  71. switch (desc_rate) {
  72. case DESC92C_RATE1M:
  73. rate_idx = 0;
  74. break;
  75. case DESC92C_RATE2M:
  76. rate_idx = 1;
  77. break;
  78. case DESC92C_RATE5_5M:
  79. rate_idx = 2;
  80. break;
  81. case DESC92C_RATE11M:
  82. rate_idx = 3;
  83. break;
  84. case DESC92C_RATE6M:
  85. rate_idx = 4;
  86. break;
  87. case DESC92C_RATE9M:
  88. rate_idx = 5;
  89. break;
  90. case DESC92C_RATE12M:
  91. rate_idx = 6;
  92. break;
  93. case DESC92C_RATE18M:
  94. rate_idx = 7;
  95. break;
  96. case DESC92C_RATE24M:
  97. rate_idx = 8;
  98. break;
  99. case DESC92C_RATE36M:
  100. rate_idx = 9;
  101. break;
  102. case DESC92C_RATE48M:
  103. rate_idx = 10;
  104. break;
  105. case DESC92C_RATE54M:
  106. rate_idx = 11;
  107. break;
  108. default:
  109. rate_idx = 0;
  110. break;
  111. }
  112. } else {
  113. switch (desc_rate) {
  114. case DESC92C_RATE6M:
  115. rate_idx = 0;
  116. break;
  117. case DESC92C_RATE9M:
  118. rate_idx = 1;
  119. break;
  120. case DESC92C_RATE12M:
  121. rate_idx = 2;
  122. break;
  123. case DESC92C_RATE18M:
  124. rate_idx = 3;
  125. break;
  126. case DESC92C_RATE24M:
  127. rate_idx = 4;
  128. break;
  129. case DESC92C_RATE36M:
  130. rate_idx = 5;
  131. break;
  132. case DESC92C_RATE48M:
  133. rate_idx = 6;
  134. break;
  135. case DESC92C_RATE54M:
  136. rate_idx = 7;
  137. break;
  138. default:
  139. rate_idx = 0;
  140. break;
  141. }
  142. }
  143. } else {
  144. switch (desc_rate) {
  145. case DESC92C_RATEMCS0:
  146. rate_idx = 0;
  147. break;
  148. case DESC92C_RATEMCS1:
  149. rate_idx = 1;
  150. break;
  151. case DESC92C_RATEMCS2:
  152. rate_idx = 2;
  153. break;
  154. case DESC92C_RATEMCS3:
  155. rate_idx = 3;
  156. break;
  157. case DESC92C_RATEMCS4:
  158. rate_idx = 4;
  159. break;
  160. case DESC92C_RATEMCS5:
  161. rate_idx = 5;
  162. break;
  163. case DESC92C_RATEMCS6:
  164. rate_idx = 6;
  165. break;
  166. case DESC92C_RATEMCS7:
  167. rate_idx = 7;
  168. break;
  169. case DESC92C_RATEMCS8:
  170. rate_idx = 8;
  171. break;
  172. case DESC92C_RATEMCS9:
  173. rate_idx = 9;
  174. break;
  175. case DESC92C_RATEMCS10:
  176. rate_idx = 10;
  177. break;
  178. case DESC92C_RATEMCS11:
  179. rate_idx = 11;
  180. break;
  181. case DESC92C_RATEMCS12:
  182. rate_idx = 12;
  183. break;
  184. case DESC92C_RATEMCS13:
  185. rate_idx = 13;
  186. break;
  187. case DESC92C_RATEMCS14:
  188. rate_idx = 14;
  189. break;
  190. case DESC92C_RATEMCS15:
  191. rate_idx = 15;
  192. break;
  193. default:
  194. rate_idx = 0;
  195. break;
  196. }
  197. }
  198. return rate_idx;
  199. }
  200. static void _rtl8723be_query_rxphystatus(struct ieee80211_hw *hw,
  201. struct rtl_stats *pstatus, u8 *pdesc,
  202. struct rx_fwinfo_8723be *p_drvinfo,
  203. bool packet_match_bssid,
  204. bool packet_toself,
  205. bool packet_beacon)
  206. {
  207. struct rtl_priv *rtlpriv = rtl_priv(hw);
  208. struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
  209. struct phy_sts_cck_8723e_t *cck_buf;
  210. struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
  211. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  212. char rx_pwr_all = 0, rx_pwr[4];
  213. u8 rf_rx_num = 0, evm, pwdb_all;
  214. u8 i, max_spatial_stream;
  215. u32 rssi, total_rssi = 0;
  216. bool is_cck = pstatus->is_cck;
  217. u8 lan_idx, vga_idx;
  218. /* Record it for next packet processing */
  219. pstatus->packet_matchbssid = packet_match_bssid;
  220. pstatus->packet_toself = packet_toself;
  221. pstatus->packet_beacon = packet_beacon;
  222. pstatus->rx_mimo_sig_qual[0] = -1;
  223. pstatus->rx_mimo_sig_qual[1] = -1;
  224. if (is_cck) {
  225. u8 cck_highpwr;
  226. u8 cck_agc_rpt;
  227. /* CCK Driver info Structure is not the same as OFDM packet. */
  228. cck_buf = (struct phy_sts_cck_8723e_t *)p_drvinfo;
  229. cck_agc_rpt = cck_buf->cck_agc_rpt;
  230. /* (1)Hardware does not provide RSSI for CCK
  231. * (2)PWDB, Average PWDB cacluated by
  232. * hardware (for rate adaptive)
  233. */
  234. if (ppsc->rfpwr_state == ERFON)
  235. cck_highpwr = (u8) rtl_get_bbreg(hw,
  236. RFPGA0_XA_HSSIPARAMETER2,
  237. BIT(9));
  238. else
  239. cck_highpwr = false;
  240. lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
  241. vga_idx = (cck_agc_rpt & 0x1f);
  242. switch (lan_idx) {
  243. case 7:
  244. if (vga_idx <= 27)/*VGA_idx = 27~2*/
  245. rx_pwr_all = -100 + 2 * (27 - vga_idx);
  246. else
  247. rx_pwr_all = -100;
  248. break;
  249. case 6:/*VGA_idx = 2~0*/
  250. rx_pwr_all = -48 + 2 * (2 - vga_idx);
  251. break;
  252. case 5:/*VGA_idx = 7~5*/
  253. rx_pwr_all = -42 + 2 * (7 - vga_idx);
  254. break;
  255. case 4:/*VGA_idx = 7~4*/
  256. rx_pwr_all = -36 + 2 * (7 - vga_idx);
  257. break;
  258. case 3:/*VGA_idx = 7~0*/
  259. rx_pwr_all = -24 + 2 * (7 - vga_idx);
  260. break;
  261. case 2:
  262. if (cck_highpwr)/*VGA_idx = 5~0*/
  263. rx_pwr_all = -12 + 2 * (5 - vga_idx);
  264. else
  265. rx_pwr_all = -6 + 2 * (5 - vga_idx);
  266. break;
  267. case 1:
  268. rx_pwr_all = 8 - 2 * vga_idx;
  269. break;
  270. case 0:
  271. rx_pwr_all = 14 - 2 * vga_idx;
  272. break;
  273. default:
  274. break;
  275. }
  276. rx_pwr_all += 6;
  277. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  278. /* CCK gain is smaller than OFDM/MCS gain, */
  279. /* so we add gain diff by experiences,
  280. * the val is 6
  281. */
  282. pwdb_all += 6;
  283. if (pwdb_all > 100)
  284. pwdb_all = 100;
  285. /* modify the offset to make the same gain index with OFDM. */
  286. if (pwdb_all > 34 && pwdb_all <= 42)
  287. pwdb_all -= 2;
  288. else if (pwdb_all > 26 && pwdb_all <= 34)
  289. pwdb_all -= 6;
  290. else if (pwdb_all > 14 && pwdb_all <= 26)
  291. pwdb_all -= 8;
  292. else if (pwdb_all > 4 && pwdb_all <= 14)
  293. pwdb_all -= 4;
  294. if (!cck_highpwr) {
  295. if (pwdb_all >= 80)
  296. pwdb_all = ((pwdb_all - 80) << 1) +
  297. ((pwdb_all - 80) >> 1) + 80;
  298. else if ((pwdb_all <= 78) && (pwdb_all >= 20))
  299. pwdb_all += 3;
  300. if (pwdb_all > 100)
  301. pwdb_all = 100;
  302. }
  303. pstatus->rx_pwdb_all = pwdb_all;
  304. pstatus->recvsignalpower = rx_pwr_all;
  305. /* (3) Get Signal Quality (EVM) */
  306. if (packet_match_bssid) {
  307. u8 sq;
  308. if (pstatus->rx_pwdb_all > 40) {
  309. sq = 100;
  310. } else {
  311. sq = cck_buf->sq_rpt;
  312. if (sq > 64)
  313. sq = 0;
  314. else if (sq < 20)
  315. sq = 100;
  316. else
  317. sq = ((64 - sq) * 100) / 44;
  318. }
  319. pstatus->signalquality = sq;
  320. pstatus->rx_mimo_sig_qual[0] = sq;
  321. pstatus->rx_mimo_sig_qual[1] = -1;
  322. }
  323. } else {
  324. rtlpriv->dm.rfpath_rxenable[0] = true;
  325. rtlpriv->dm.rfpath_rxenable[1] = true;
  326. /* (1)Get RSSI for HT rate */
  327. for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
  328. /* we will judge RF RX path now. */
  329. if (rtlpriv->dm.rfpath_rxenable[i])
  330. rf_rx_num++;
  331. rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f)*2) - 110;
  332. /* Translate DBM to percentage. */
  333. rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
  334. total_rssi += rssi;
  335. /* Get Rx snr value in DB */
  336. rtlpriv->stats.rx_snr_db[i] =
  337. (long)(p_drvinfo->rxsnr[i] / 2);
  338. /* Record Signal Strength for next packet */
  339. if (packet_match_bssid)
  340. pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
  341. }
  342. /* (2)PWDB, Avg cacluated by hardware (for rate adaptive) */
  343. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  344. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  345. pstatus->rx_pwdb_all = pwdb_all;
  346. pstatus->rxpower = rx_pwr_all;
  347. pstatus->recvsignalpower = rx_pwr_all;
  348. /* (3)EVM of HT rate */
  349. if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
  350. pstatus->rate <= DESC92C_RATEMCS15)
  351. max_spatial_stream = 2;
  352. else
  353. max_spatial_stream = 1;
  354. for (i = 0; i < max_spatial_stream; i++) {
  355. evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
  356. if (packet_match_bssid) {
  357. /* Fill value in RFD, Get the first
  358. * spatial stream only
  359. */
  360. if (i == 0)
  361. pstatus->signalquality =
  362. (u8) (evm & 0xff);
  363. pstatus->rx_mimo_sig_qual[i] =
  364. (u8) (evm & 0xff);
  365. }
  366. }
  367. if (packet_match_bssid) {
  368. for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
  369. rtl_priv(hw)->dm.cfo_tail[i] =
  370. (char)p_phystrpt->path_cfotail[i];
  371. rtl_priv(hw)->dm.packet_count++;
  372. if (rtl_priv(hw)->dm.packet_count == 0xffffffff)
  373. rtl_priv(hw)->dm.packet_count = 0;
  374. }
  375. }
  376. /* UI BSS List signal strength(in percentage),
  377. * make it good looking, from 0~100.
  378. */
  379. if (is_cck)
  380. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  381. pwdb_all));
  382. else if (rf_rx_num != 0)
  383. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  384. total_rssi /= rf_rx_num));
  385. /*HW antenna diversity*/
  386. rtldm->fat_table.antsel_rx_keep_0 = p_phystrpt->ant_sel;
  387. rtldm->fat_table.antsel_rx_keep_1 = p_phystrpt->ant_sel_b;
  388. rtldm->fat_table.antsel_rx_keep_2 = p_phystrpt->antsel_rx_keep_2;
  389. }
  390. static void _rtl8723be_translate_rx_signal_stuff(struct ieee80211_hw *hw,
  391. struct sk_buff *skb,
  392. struct rtl_stats *pstatus,
  393. u8 *pdesc,
  394. struct rx_fwinfo_8723be *p_drvinfo)
  395. {
  396. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  397. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  398. struct ieee80211_hdr *hdr;
  399. u8 *tmp_buf;
  400. u8 *praddr;
  401. u8 *psaddr;
  402. u16 fc, type;
  403. bool packet_matchbssid, packet_toself, packet_beacon;
  404. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  405. hdr = (struct ieee80211_hdr *)tmp_buf;
  406. fc = le16_to_cpu(hdr->frame_control);
  407. type = WLAN_FC_GET_TYPE(hdr->frame_control);
  408. praddr = hdr->addr1;
  409. psaddr = ieee80211_get_SA(hdr);
  410. memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
  411. packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
  412. (!ether_addr_equal(mac->bssid, (fc & IEEE80211_FCTL_TODS) ?
  413. hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ?
  414. hdr->addr2 : hdr->addr3)) &&
  415. (!pstatus->hwerror) &&
  416. (!pstatus->crc) && (!pstatus->icv));
  417. packet_toself = packet_matchbssid &&
  418. (!ether_addr_equal(praddr, rtlefuse->dev_addr));
  419. /* YP: packet_beacon is not initialized,
  420. * this assignment is neccesary,
  421. * otherwise it counld be true in this case
  422. * the situation is much worse in Kernel 3.10
  423. */
  424. if (ieee80211_is_beacon(hdr->frame_control))
  425. packet_beacon = true;
  426. else
  427. packet_beacon = false;
  428. if (packet_beacon && packet_matchbssid)
  429. rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
  430. _rtl8723be_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  431. packet_matchbssid,
  432. packet_toself,
  433. packet_beacon);
  434. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  435. }
  436. static void _rtl8723be_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
  437. u8 *virtualaddress)
  438. {
  439. u32 dwtmp = 0;
  440. memset(virtualaddress, 0, 8);
  441. SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
  442. if (ptcb_desc->empkt_num == 1) {
  443. dwtmp = ptcb_desc->empkt_len[0];
  444. } else {
  445. dwtmp = ptcb_desc->empkt_len[0];
  446. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  447. dwtmp += ptcb_desc->empkt_len[1];
  448. }
  449. SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
  450. if (ptcb_desc->empkt_num <= 3) {
  451. dwtmp = ptcb_desc->empkt_len[2];
  452. } else {
  453. dwtmp = ptcb_desc->empkt_len[2];
  454. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  455. dwtmp += ptcb_desc->empkt_len[3];
  456. }
  457. SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
  458. if (ptcb_desc->empkt_num <= 5) {
  459. dwtmp = ptcb_desc->empkt_len[4];
  460. } else {
  461. dwtmp = ptcb_desc->empkt_len[4];
  462. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  463. dwtmp += ptcb_desc->empkt_len[5];
  464. }
  465. SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
  466. SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
  467. if (ptcb_desc->empkt_num <= 7) {
  468. dwtmp = ptcb_desc->empkt_len[6];
  469. } else {
  470. dwtmp = ptcb_desc->empkt_len[6];
  471. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  472. dwtmp += ptcb_desc->empkt_len[7];
  473. }
  474. SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
  475. if (ptcb_desc->empkt_num <= 9) {
  476. dwtmp = ptcb_desc->empkt_len[8];
  477. } else {
  478. dwtmp = ptcb_desc->empkt_len[8];
  479. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  480. dwtmp += ptcb_desc->empkt_len[9];
  481. }
  482. SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
  483. }
  484. bool rtl8723be_rx_query_desc(struct ieee80211_hw *hw,
  485. struct rtl_stats *status,
  486. struct ieee80211_rx_status *rx_status,
  487. u8 *pdesc, struct sk_buff *skb)
  488. {
  489. struct rtl_priv *rtlpriv = rtl_priv(hw);
  490. struct rx_fwinfo_8723be *p_drvinfo;
  491. struct ieee80211_hdr *hdr;
  492. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  493. status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
  494. if (status->packet_report_type == TX_REPORT2)
  495. status->length = (u16) GET_RX_RPT2_DESC_PKT_LEN(pdesc);
  496. else
  497. status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  498. status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  499. RX_DRV_INFO_SIZE_UNIT;
  500. status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  501. status->icv = (u16) GET_RX_DESC_ICV(pdesc);
  502. status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  503. status->hwerror = (status->crc | status->icv);
  504. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  505. status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
  506. status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  507. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  508. status->isfirst_ampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  509. if (status->packet_report_type == NORMAL_RX)
  510. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  511. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  512. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  513. status->is_cck = RTL8723E_RX_HAL_IS_CCK_RATE(status->rate);
  514. status->macid = GET_RX_DESC_MACID(pdesc);
  515. if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  516. status->wake_match = BIT(2);
  517. else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  518. status->wake_match = BIT(1);
  519. else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
  520. status->wake_match = BIT(0);
  521. else
  522. status->wake_match = 0;
  523. if (status->wake_match)
  524. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  525. "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
  526. status->wake_match);
  527. rx_status->freq = hw->conf.chandef.chan->center_freq;
  528. rx_status->band = hw->conf.chandef.chan->band;
  529. hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size +
  530. status->rx_bufshift);
  531. if (status->crc)
  532. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  533. if (status->rx_is40Mhzpacket)
  534. rx_status->flag |= RX_FLAG_40MHZ;
  535. if (status->is_ht)
  536. rx_status->flag |= RX_FLAG_HT;
  537. rx_status->flag |= RX_FLAG_MACTIME_START;
  538. /* hw will set status->decrypted true, if it finds the
  539. * frame is open data frame or mgmt frame.
  540. * So hw will not decryption robust managment frame
  541. * for IEEE80211w but still set status->decrypted
  542. * true, so here we should set it back to undecrypted
  543. * for IEEE80211w frame, and mac80211 sw will help
  544. * to decrypt it
  545. */
  546. if (status->decrypted) {
  547. if (!hdr) {
  548. WARN_ON_ONCE(true);
  549. pr_err("decrypted is true but hdr NULL in skb %p\n",
  550. rtl_get_hdr(skb));
  551. return false;
  552. }
  553. if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
  554. (ieee80211_has_protected(hdr->frame_control)))
  555. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  556. else
  557. rx_status->flag |= RX_FLAG_DECRYPTED;
  558. }
  559. /* rate_idx: index of data rate into band's
  560. * supported rates or MCS index if HT rates
  561. * are use (RX_FLAG_HT)
  562. * Notice: this is diff with windows define
  563. */
  564. rx_status->rate_idx = _rtl8723be_rate_mapping(hw, status->is_ht,
  565. status->rate);
  566. rx_status->mactime = status->timestamp_low;
  567. if (phystatus) {
  568. p_drvinfo = (struct rx_fwinfo_8723be *)(skb->data +
  569. status->rx_bufshift);
  570. _rtl8723be_translate_rx_signal_stuff(hw, skb, status,
  571. pdesc, p_drvinfo);
  572. }
  573. /*rx_status->qual = status->signal; */
  574. rx_status->signal = status->recvsignalpower + 10;
  575. if (status->packet_report_type == TX_REPORT2) {
  576. status->macid_valid_entry[0] =
  577. GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
  578. status->macid_valid_entry[1] =
  579. GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
  580. }
  581. return true;
  582. }
  583. void rtl8723be_tx_fill_desc(struct ieee80211_hw *hw,
  584. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  585. u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
  586. struct ieee80211_sta *sta, struct sk_buff *skb,
  587. u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
  588. {
  589. struct rtl_priv *rtlpriv = rtl_priv(hw);
  590. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  591. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  592. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  593. u8 *pdesc = pdesc_tx;
  594. u16 seq_number;
  595. __le16 fc = hdr->frame_control;
  596. unsigned int buf_len = 0;
  597. unsigned int skb_len = skb->len;
  598. u8 fw_qsel = _rtl8723be_map_hwqueue_to_fwqueue(skb, hw_queue);
  599. bool firstseg = ((hdr->seq_ctrl &
  600. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  601. bool lastseg = ((hdr->frame_control &
  602. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  603. dma_addr_t mapping;
  604. u8 bw_40 = 0;
  605. u8 short_gi = 0;
  606. if (mac->opmode == NL80211_IFTYPE_STATION) {
  607. bw_40 = mac->bw_40;
  608. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  609. mac->opmode == NL80211_IFTYPE_ADHOC) {
  610. if (sta)
  611. bw_40 = sta->ht_cap.cap &
  612. IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  613. }
  614. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  615. rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
  616. /* reserve 8 byte for AMPDU early mode */
  617. if (rtlhal->earlymode_enable) {
  618. skb_push(skb, EM_HDR_LEN);
  619. memset(skb->data, 0, EM_HDR_LEN);
  620. }
  621. buf_len = skb->len;
  622. mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
  623. PCI_DMA_TODEVICE);
  624. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  625. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "DMA mapping error");
  626. return;
  627. }
  628. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8723be));
  629. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  630. firstseg = true;
  631. lastseg = true;
  632. }
  633. if (firstseg) {
  634. if (rtlhal->earlymode_enable) {
  635. SET_TX_DESC_PKT_OFFSET(pdesc, 1);
  636. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
  637. EM_HDR_LEN);
  638. if (ptcb_desc->empkt_num) {
  639. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  640. "Insert 8 byte.pTcb->EMPktNum:%d\n",
  641. ptcb_desc->empkt_num);
  642. _rtl8723be_insert_emcontent(ptcb_desc,
  643. (u8 *)(skb->data));
  644. }
  645. } else {
  646. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  647. }
  648. /* ptcb_desc->use_driver_rate = true; */
  649. SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
  650. if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
  651. short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
  652. else
  653. short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
  654. SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
  655. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  656. SET_TX_DESC_AGG_ENABLE(pdesc, 1);
  657. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  658. }
  659. SET_TX_DESC_SEQ(pdesc, seq_number);
  660. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
  661. !ptcb_desc->cts_enable) ?
  662. 1 : 0));
  663. SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
  664. SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ?
  665. 1 : 0));
  666. SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
  667. SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
  668. SET_TX_DESC_RTS_SHORT(pdesc,
  669. ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
  670. (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
  671. (ptcb_desc->rts_use_shortgi ? 1 : 0)));
  672. if (ptcb_desc->btx_enable_sw_calc_duration)
  673. SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
  674. if (bw_40) {
  675. if (ptcb_desc->packet_bw) {
  676. SET_TX_DESC_DATA_BW(pdesc, 1);
  677. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  678. } else {
  679. SET_TX_DESC_DATA_BW(pdesc, 0);
  680. SET_TX_DESC_TX_SUB_CARRIER(pdesc, mac->cur_40_prime_sc);
  681. }
  682. } else {
  683. SET_TX_DESC_DATA_BW(pdesc, 0);
  684. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  685. }
  686. SET_TX_DESC_LINIP(pdesc, 0);
  687. SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
  688. if (sta) {
  689. u8 ampdu_density = sta->ht_cap.ampdu_density;
  690. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  691. }
  692. if (info->control.hw_key) {
  693. struct ieee80211_key_conf *keyconf =
  694. info->control.hw_key;
  695. switch (keyconf->cipher) {
  696. case WLAN_CIPHER_SUITE_WEP40:
  697. case WLAN_CIPHER_SUITE_WEP104:
  698. case WLAN_CIPHER_SUITE_TKIP:
  699. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  700. break;
  701. case WLAN_CIPHER_SUITE_CCMP:
  702. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  703. break;
  704. default:
  705. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  706. break;
  707. }
  708. }
  709. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  710. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  711. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  712. SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
  713. 1 : 0);
  714. SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
  715. if (ieee80211_is_data_qos(fc)) {
  716. if (mac->rdg_en) {
  717. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  718. "Enable RDG function.\n");
  719. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  720. SET_TX_DESC_HTC(pdesc, 1);
  721. }
  722. }
  723. }
  724. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  725. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  726. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
  727. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  728. SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
  729. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  730. if (!ieee80211_is_data_qos(fc)) {
  731. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  732. SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
  733. }
  734. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  735. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  736. is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
  737. SET_TX_DESC_BMC(pdesc, 1);
  738. }
  739. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  740. }
  741. void rtl8723be_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
  742. bool b_firstseg, bool b_lastseg,
  743. struct sk_buff *skb)
  744. {
  745. struct rtl_priv *rtlpriv = rtl_priv(hw);
  746. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  747. u8 fw_queue = QSLT_BEACON;
  748. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  749. skb->data, skb->len,
  750. PCI_DMA_TODEVICE);
  751. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  752. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  753. "DMA mapping error");
  754. return;
  755. }
  756. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  757. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  758. SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
  759. SET_TX_DESC_SEQ(pdesc, 0);
  760. SET_TX_DESC_LINIP(pdesc, 0);
  761. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  762. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  763. SET_TX_DESC_LAST_SEG(pdesc, 1);
  764. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
  765. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  766. SET_TX_DESC_RATE_ID(pdesc, 0);
  767. SET_TX_DESC_MACID(pdesc, 0);
  768. SET_TX_DESC_OWN(pdesc, 1);
  769. SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
  770. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  771. SET_TX_DESC_LAST_SEG(pdesc, 1);
  772. SET_TX_DESC_USE_RATE(pdesc, 1);
  773. }
  774. void rtl8723be_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
  775. u8 desc_name, u8 *val)
  776. {
  777. if (istx) {
  778. switch (desc_name) {
  779. case HW_DESC_OWN:
  780. SET_TX_DESC_OWN(pdesc, 1);
  781. break;
  782. case HW_DESC_TX_NEXTDESC_ADDR:
  783. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
  784. break;
  785. default:
  786. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  787. desc_name);
  788. break;
  789. }
  790. } else {
  791. switch (desc_name) {
  792. case HW_DESC_RXOWN:
  793. SET_RX_DESC_OWN(pdesc, 1);
  794. break;
  795. case HW_DESC_RXBUFF_ADDR:
  796. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
  797. break;
  798. case HW_DESC_RXPKT_LEN:
  799. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
  800. break;
  801. case HW_DESC_RXERO:
  802. SET_RX_DESC_EOR(pdesc, 1);
  803. break;
  804. default:
  805. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  806. desc_name);
  807. break;
  808. }
  809. }
  810. }
  811. u32 rtl8723be_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  812. {
  813. u32 ret = 0;
  814. if (istx) {
  815. switch (desc_name) {
  816. case HW_DESC_OWN:
  817. ret = GET_TX_DESC_OWN(pdesc);
  818. break;
  819. case HW_DESC_TXBUFF_ADDR:
  820. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  821. break;
  822. default:
  823. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  824. desc_name);
  825. break;
  826. }
  827. } else {
  828. switch (desc_name) {
  829. case HW_DESC_OWN:
  830. ret = GET_RX_DESC_OWN(pdesc);
  831. break;
  832. case HW_DESC_RXPKT_LEN:
  833. ret = GET_RX_DESC_PKT_LEN(pdesc);
  834. break;
  835. default:
  836. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  837. desc_name);
  838. break;
  839. }
  840. }
  841. return ret;
  842. }
  843. bool rtl8723be_is_tx_desc_closed(struct ieee80211_hw *hw,
  844. u8 hw_queue, u16 index)
  845. {
  846. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  847. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
  848. u8 *entry = (u8 *)(&ring->desc[ring->idx]);
  849. u8 own = (u8) rtl8723be_get_desc(entry, true, HW_DESC_OWN);
  850. /*beacon packet will only use the first
  851. *descriptor by default, and the own may not
  852. *be cleared by the hardware
  853. */
  854. if (own)
  855. return false;
  856. else
  857. return true;
  858. }
  859. void rtl8723be_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  860. {
  861. struct rtl_priv *rtlpriv = rtl_priv(hw);
  862. if (hw_queue == BEACON_QUEUE) {
  863. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  864. } else {
  865. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  866. BIT(0) << (hw_queue));
  867. }
  868. }