trx.c 24 KB

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