trx.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2013 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. #include "dm.h"
  39. static u8 _rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
  40. {
  41. __le16 fc = rtl_get_fc(skb);
  42. if (unlikely(ieee80211_is_beacon(fc)))
  43. return QSLT_BEACON;
  44. if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
  45. return QSLT_MGNT;
  46. return skb->priority;
  47. }
  48. static void _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw,
  49. struct rtl_stats *pstatus, u8 *pdesc,
  50. struct rx_fwinfo_88e *p_drvinfo,
  51. bool bpacket_match_bssid,
  52. bool bpacket_toself, bool packet_beacon)
  53. {
  54. struct rtl_priv *rtlpriv = rtl_priv(hw);
  55. struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
  56. struct phy_sts_cck_8192s_t *cck_buf;
  57. struct phy_status_rpt *phystrpt = (struct phy_status_rpt *)p_drvinfo;
  58. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  59. char rx_pwr_all = 0, rx_pwr[4];
  60. u8 rf_rx_num = 0, evm, pwdb_all;
  61. u8 i, max_spatial_stream;
  62. u32 rssi, total_rssi = 0;
  63. bool is_cck = pstatus->is_cck;
  64. u8 lan_idx, vga_idx;
  65. /* Record it for next packet processing */
  66. pstatus->packet_matchbssid = bpacket_match_bssid;
  67. pstatus->packet_toself = bpacket_toself;
  68. pstatus->packet_beacon = packet_beacon;
  69. pstatus->rx_mimo_sig_qual[0] = -1;
  70. pstatus->rx_mimo_sig_qual[1] = -1;
  71. if (is_cck) {
  72. u8 cck_hipwr;
  73. u8 cck_agc_rpt;
  74. /* CCK Driver info Structure is not the same as OFDM packet. */
  75. cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
  76. cck_agc_rpt = cck_buf->cck_agc_rpt;
  77. /* (1)Hardware does not provide RSSI for CCK
  78. * (2)PWDB, Average PWDB cacluated by
  79. * hardware (for rate adaptive)
  80. */
  81. if (ppsc->rfpwr_state == ERFON)
  82. cck_hipwr = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
  83. BIT(9));
  84. else
  85. cck_hipwr = false;
  86. lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
  87. vga_idx = (cck_agc_rpt & 0x1f);
  88. switch (lan_idx) {
  89. case 7:
  90. if (vga_idx <= 27)
  91. rx_pwr_all = -100 + 2 * (27 - vga_idx);
  92. else
  93. rx_pwr_all = -100;
  94. break;
  95. case 6:
  96. rx_pwr_all = -48 + 2 * (2 - vga_idx); /*VGA_idx = 2~0*/
  97. break;
  98. case 5:
  99. rx_pwr_all = -42 + 2 * (7 - vga_idx); /*VGA_idx = 7~5*/
  100. break;
  101. case 4:
  102. rx_pwr_all = -36 + 2 * (7 - vga_idx); /*VGA_idx = 7~4*/
  103. break;
  104. case 3:
  105. rx_pwr_all = -24 + 2 * (7 - vga_idx); /*VGA_idx = 7~0*/
  106. break;
  107. case 2:
  108. if (cck_hipwr)
  109. rx_pwr_all = -12 + 2 * (5 - vga_idx);
  110. else
  111. rx_pwr_all = -6 + 2 * (5 - vga_idx);
  112. break;
  113. case 1:
  114. rx_pwr_all = 8 - 2 * vga_idx;
  115. break;
  116. case 0:
  117. rx_pwr_all = 14 - 2 * vga_idx;
  118. break;
  119. default:
  120. break;
  121. }
  122. rx_pwr_all += 6;
  123. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  124. /* CCK gain is smaller than OFDM/MCS gain,
  125. * so we add gain diff by experiences,
  126. * the val is 6
  127. */
  128. pwdb_all += 6;
  129. if (pwdb_all > 100)
  130. pwdb_all = 100;
  131. /* modify the offset to make the same
  132. * gain index with OFDM.
  133. */
  134. if (pwdb_all > 34 && pwdb_all <= 42)
  135. pwdb_all -= 2;
  136. else if (pwdb_all > 26 && pwdb_all <= 34)
  137. pwdb_all -= 6;
  138. else if (pwdb_all > 14 && pwdb_all <= 26)
  139. pwdb_all -= 8;
  140. else if (pwdb_all > 4 && pwdb_all <= 14)
  141. pwdb_all -= 4;
  142. if (cck_hipwr == false) {
  143. if (pwdb_all >= 80)
  144. pwdb_all = ((pwdb_all - 80)<<1) +
  145. ((pwdb_all - 80)>>1) + 80;
  146. else if ((pwdb_all <= 78) && (pwdb_all >= 20))
  147. pwdb_all += 3;
  148. if (pwdb_all > 100)
  149. pwdb_all = 100;
  150. }
  151. pstatus->rx_pwdb_all = pwdb_all;
  152. pstatus->recvsignalpower = rx_pwr_all;
  153. /* (3) Get Signal Quality (EVM) */
  154. if (bpacket_match_bssid) {
  155. u8 sq;
  156. if (pstatus->rx_pwdb_all > 40) {
  157. sq = 100;
  158. } else {
  159. sq = cck_buf->sq_rpt;
  160. if (sq > 64)
  161. sq = 0;
  162. else if (sq < 20)
  163. sq = 100;
  164. else
  165. sq = ((64 - sq) * 100) / 44;
  166. }
  167. pstatus->signalquality = sq;
  168. pstatus->rx_mimo_sig_qual[0] = sq;
  169. pstatus->rx_mimo_sig_qual[1] = -1;
  170. }
  171. } else {
  172. rtlpriv->dm.rfpath_rxenable[0] =
  173. rtlpriv->dm.rfpath_rxenable[1] = true;
  174. /* (1)Get RSSI for HT rate */
  175. for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
  176. /* we will judge RF RX path now. */
  177. if (rtlpriv->dm.rfpath_rxenable[i])
  178. rf_rx_num++;
  179. rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f) * 2)-110;
  180. /* Translate DBM to percentage. */
  181. rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
  182. total_rssi += rssi;
  183. /* Get Rx snr value in DB */
  184. rtlpriv->stats.rx_snr_db[i] = p_drvinfo->rxsnr[i] / 2;
  185. /* Record Signal Strength for next packet */
  186. if (bpacket_match_bssid)
  187. pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
  188. }
  189. /* (2)PWDB, Average PWDB cacluated by
  190. * hardware (for rate adaptive)
  191. */
  192. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  193. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  194. pstatus->rx_pwdb_all = pwdb_all;
  195. pstatus->rxpower = rx_pwr_all;
  196. pstatus->recvsignalpower = rx_pwr_all;
  197. /* (3)EVM of HT rate */
  198. if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
  199. pstatus->rate <= DESC92C_RATEMCS15)
  200. max_spatial_stream = 2;
  201. else
  202. max_spatial_stream = 1;
  203. for (i = 0; i < max_spatial_stream; i++) {
  204. evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
  205. if (bpacket_match_bssid) {
  206. /* Fill value in RFD, Get the first
  207. * spatial stream only
  208. */
  209. if (i == 0)
  210. pstatus->signalquality = evm & 0xff;
  211. pstatus->rx_mimo_sig_qual[i] = evm & 0xff;
  212. }
  213. }
  214. }
  215. /* UI BSS List signal strength(in percentage),
  216. * make it good looking, from 0~100.
  217. */
  218. if (is_cck)
  219. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  220. pwdb_all));
  221. else if (rf_rx_num != 0)
  222. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  223. total_rssi /= rf_rx_num));
  224. /*HW antenna diversity*/
  225. rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel;
  226. rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b;
  227. rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2;
  228. }
  229. static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw,
  230. struct rtl_stats *pstatus)
  231. {
  232. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  233. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  234. u8 ant_mux;
  235. struct fast_ant_training *pfat = &(rtldm->fat_table);
  236. if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
  237. if (pfat->fat_state == FAT_TRAINING_STATE) {
  238. if (pstatus->packet_toself) {
  239. ant_mux = (pfat->antsel_rx_keep_2 << 2) |
  240. (pfat->antsel_rx_keep_1 << 1) |
  241. pfat->antsel_rx_keep_0;
  242. pfat->ant_sum[ant_mux] += pstatus->rx_pwdb_all;
  243. pfat->ant_cnt[ant_mux]++;
  244. }
  245. }
  246. } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
  247. (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
  248. if (pstatus->packet_toself || pstatus->packet_matchbssid) {
  249. ant_mux = (pfat->antsel_rx_keep_2 << 2) |
  250. (pfat->antsel_rx_keep_1 << 1) |
  251. pfat->antsel_rx_keep_0;
  252. rtl88e_dm_ant_sel_statistics(hw, ant_mux, 0,
  253. pstatus->rx_pwdb_all);
  254. }
  255. }
  256. }
  257. static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw,
  258. struct sk_buff *skb, struct rtl_stats *pstatus,
  259. u8 *pdesc, struct rx_fwinfo_88e *p_drvinfo)
  260. {
  261. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  262. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  263. struct ieee80211_hdr *hdr;
  264. u8 *tmp_buf;
  265. u8 *praddr;
  266. u8 *psaddr;
  267. __le16 fc;
  268. u16 type, ufc;
  269. bool match_bssid, packet_toself, packet_beacon, addr;
  270. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  271. hdr = (struct ieee80211_hdr *)tmp_buf;
  272. fc = hdr->frame_control;
  273. ufc = le16_to_cpu(fc);
  274. type = WLAN_FC_GET_TYPE(fc);
  275. praddr = hdr->addr1;
  276. psaddr = ieee80211_get_SA(hdr);
  277. memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
  278. addr = (!compare_ether_addr(mac->bssid, (ufc & IEEE80211_FCTL_TODS) ?
  279. hdr->addr1 : (ufc & IEEE80211_FCTL_FROMDS) ?
  280. hdr->addr2 : hdr->addr3));
  281. match_bssid = ((IEEE80211_FTYPE_CTL != type) && (!pstatus->hwerror) &&
  282. (!pstatus->crc) && (!pstatus->icv)) && addr;
  283. addr = (!compare_ether_addr(praddr, rtlefuse->dev_addr));
  284. packet_toself = match_bssid && addr;
  285. if (ieee80211_is_beacon(fc))
  286. packet_beacon = true;
  287. _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  288. match_bssid, packet_toself, packet_beacon);
  289. _rtl88ee_smart_antenna(hw, pstatus);
  290. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  291. }
  292. static void insert_em(struct rtl_tcb_desc *ptcb_desc, u8 *virtualaddress)
  293. {
  294. u32 dwtmp = 0;
  295. memset(virtualaddress, 0, 8);
  296. SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
  297. if (ptcb_desc->empkt_num == 1) {
  298. dwtmp = ptcb_desc->empkt_len[0];
  299. } else {
  300. dwtmp = ptcb_desc->empkt_len[0];
  301. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  302. dwtmp += ptcb_desc->empkt_len[1];
  303. }
  304. SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
  305. if (ptcb_desc->empkt_num <= 3) {
  306. dwtmp = ptcb_desc->empkt_len[2];
  307. } else {
  308. dwtmp = ptcb_desc->empkt_len[2];
  309. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  310. dwtmp += ptcb_desc->empkt_len[3];
  311. }
  312. SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
  313. if (ptcb_desc->empkt_num <= 5) {
  314. dwtmp = ptcb_desc->empkt_len[4];
  315. } else {
  316. dwtmp = ptcb_desc->empkt_len[4];
  317. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  318. dwtmp += ptcb_desc->empkt_len[5];
  319. }
  320. SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
  321. SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
  322. if (ptcb_desc->empkt_num <= 7) {
  323. dwtmp = ptcb_desc->empkt_len[6];
  324. } else {
  325. dwtmp = ptcb_desc->empkt_len[6];
  326. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  327. dwtmp += ptcb_desc->empkt_len[7];
  328. }
  329. SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
  330. if (ptcb_desc->empkt_num <= 9) {
  331. dwtmp = ptcb_desc->empkt_len[8];
  332. } else {
  333. dwtmp = ptcb_desc->empkt_len[8];
  334. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  335. dwtmp += ptcb_desc->empkt_len[9];
  336. }
  337. SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
  338. }
  339. bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
  340. struct rtl_stats *status,
  341. struct ieee80211_rx_status *rx_status,
  342. u8 *pdesc, struct sk_buff *skb)
  343. {
  344. struct rtl_priv *rtlpriv = rtl_priv(hw);
  345. struct rx_fwinfo_88e *p_drvinfo;
  346. struct ieee80211_hdr *hdr;
  347. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  348. status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
  349. if (status->packet_report_type == TX_REPORT2)
  350. status->length = (u16) GET_RX_RPT2_DESC_PKT_LEN(pdesc);
  351. else
  352. status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  353. status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  354. RX_DRV_INFO_SIZE_UNIT;
  355. status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  356. status->icv = (u16) GET_RX_DESC_ICV(pdesc);
  357. status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  358. status->hwerror = (status->crc | status->icv);
  359. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  360. status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
  361. status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  362. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  363. status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1) &&
  364. (GET_RX_DESC_FAGGR(pdesc) == 1));
  365. if (status->packet_report_type == NORMAL_RX)
  366. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  367. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  368. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  369. status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate);
  370. status->macid = GET_RX_DESC_MACID(pdesc);
  371. if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  372. status->wake_match = BIT(2);
  373. else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  374. status->wake_match = BIT(1);
  375. else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
  376. status->wake_match = BIT(0);
  377. else
  378. status->wake_match = 0;
  379. if (status->wake_match)
  380. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  381. "Get Wakeup Packet!! WakeMatch =%d\n",
  382. status->wake_match);
  383. rx_status->freq = hw->conf.chandef.chan->center_freq;
  384. rx_status->band = hw->conf.chandef.chan->band;
  385. if (status->crc)
  386. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  387. if (status->rx_is40Mhzpacket)
  388. rx_status->flag |= RX_FLAG_40MHZ;
  389. if (status->is_ht)
  390. rx_status->flag |= RX_FLAG_HT;
  391. rx_status->flag |= RX_FLAG_MACTIME_START;
  392. /* hw will set status->decrypted true, if it finds the
  393. * frame is open data frame or mgmt frame.
  394. * So hw will not decryption robust managment frame
  395. * for IEEE80211w but still set status->decrypted
  396. * true, so here we should set it back to undecrypted
  397. * for IEEE80211w frame, and mac80211 sw will help
  398. * to decrypt it
  399. */
  400. if (status->decrypted) {
  401. hdr = (struct ieee80211_hdr *)(skb->data +
  402. status->rx_drvinfo_size + status->rx_bufshift);
  403. if (!hdr) {
  404. /* During testing, hdr was NULL */
  405. return false;
  406. }
  407. if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
  408. (ieee80211_has_protected(hdr->frame_control)))
  409. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  410. else
  411. rx_status->flag |= RX_FLAG_DECRYPTED;
  412. }
  413. /* rate_idx: index of data rate into band's
  414. * supported rates or MCS index if HT rates
  415. * are use (RX_FLAG_HT)
  416. * Notice: this is diff with windows define
  417. */
  418. rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
  419. status->rate, false);
  420. rx_status->mactime = status->timestamp_low;
  421. if (phystatus == true) {
  422. p_drvinfo = (struct rx_fwinfo_88e *)(skb->data +
  423. status->rx_bufshift);
  424. _rtl88ee_translate_rx_signal_stuff(hw, skb, status, pdesc,
  425. p_drvinfo);
  426. }
  427. /*rx_status->qual = status->signal; */
  428. rx_status->signal = status->recvsignalpower + 10;
  429. /*rx_status->noise = -status->noise; */
  430. if (status->packet_report_type == TX_REPORT2) {
  431. status->macid_valid_entry[0] =
  432. GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
  433. status->macid_valid_entry[1] =
  434. GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
  435. }
  436. return true;
  437. }
  438. void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw,
  439. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  440. struct ieee80211_tx_info *info,
  441. struct ieee80211_sta *sta,
  442. struct sk_buff *skb,
  443. u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
  444. {
  445. struct rtl_priv *rtlpriv = rtl_priv(hw);
  446. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  447. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  448. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  449. u8 *pdesc = (u8 *)pdesc_tx;
  450. u16 seq_number;
  451. __le16 fc = hdr->frame_control;
  452. unsigned int buf_len = 0;
  453. unsigned int skb_len = skb->len;
  454. u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue);
  455. bool firstseg = ((hdr->seq_ctrl &
  456. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  457. bool lastseg = ((hdr->frame_control &
  458. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  459. dma_addr_t mapping;
  460. u8 bw_40 = 0;
  461. u8 short_gi = 0;
  462. if (mac->opmode == NL80211_IFTYPE_STATION) {
  463. bw_40 = mac->bw_40;
  464. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  465. mac->opmode == NL80211_IFTYPE_ADHOC) {
  466. if (sta)
  467. bw_40 = sta->ht_cap.cap &
  468. IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  469. }
  470. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  471. rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
  472. /* reserve 8 byte for AMPDU early mode */
  473. if (rtlhal->earlymode_enable) {
  474. skb_push(skb, EM_HDR_LEN);
  475. memset(skb->data, 0, EM_HDR_LEN);
  476. }
  477. buf_len = skb->len;
  478. mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
  479. PCI_DMA_TODEVICE);
  480. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  481. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  482. "DMA mapping error");
  483. return;
  484. }
  485. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e));
  486. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  487. firstseg = true;
  488. lastseg = true;
  489. }
  490. if (firstseg) {
  491. if (rtlhal->earlymode_enable) {
  492. SET_TX_DESC_PKT_OFFSET(pdesc, 1);
  493. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
  494. EM_HDR_LEN);
  495. if (ptcb_desc->empkt_num) {
  496. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  497. "Insert 8 byte.pTcb->EMPktNum:%d\n",
  498. ptcb_desc->empkt_num);
  499. insert_em(ptcb_desc, (u8 *)(skb->data));
  500. }
  501. } else {
  502. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  503. }
  504. ptcb_desc->use_driver_rate = true;
  505. SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
  506. if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
  507. short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
  508. else
  509. short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
  510. SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
  511. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  512. SET_TX_DESC_AGG_ENABLE(pdesc, 1);
  513. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  514. }
  515. SET_TX_DESC_SEQ(pdesc, seq_number);
  516. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
  517. !ptcb_desc->cts_enable) ? 1 : 0));
  518. SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
  519. SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
  520. SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
  521. SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
  522. SET_TX_DESC_RTS_BW(pdesc, 0);
  523. SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
  524. SET_TX_DESC_RTS_SHORT(pdesc,
  525. ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
  526. (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
  527. (ptcb_desc->rts_use_shortgi ? 1 : 0)));
  528. if (ptcb_desc->btx_enable_sw_calc_duration)
  529. SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
  530. if (bw_40) {
  531. if (ptcb_desc->packet_bw) {
  532. SET_TX_DESC_DATA_BW(pdesc, 1);
  533. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  534. } else {
  535. SET_TX_DESC_DATA_BW(pdesc, 0);
  536. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  537. mac->cur_40_prime_sc);
  538. }
  539. } else {
  540. SET_TX_DESC_DATA_BW(pdesc, 0);
  541. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  542. }
  543. SET_TX_DESC_LINIP(pdesc, 0);
  544. SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
  545. if (sta) {
  546. u8 ampdu_density = sta->ht_cap.ampdu_density;
  547. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  548. }
  549. if (info->control.hw_key) {
  550. struct ieee80211_key_conf *keyconf;
  551. keyconf = info->control.hw_key;
  552. switch (keyconf->cipher) {
  553. case WLAN_CIPHER_SUITE_WEP40:
  554. case WLAN_CIPHER_SUITE_WEP104:
  555. case WLAN_CIPHER_SUITE_TKIP:
  556. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  557. break;
  558. case WLAN_CIPHER_SUITE_CCMP:
  559. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  560. break;
  561. default:
  562. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  563. break;
  564. }
  565. }
  566. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  567. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  568. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  569. SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
  570. 1 : 0);
  571. SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
  572. /* Set TxRate and RTSRate in TxDesc */
  573. /* This prevent Tx initial rate of new-coming packets */
  574. /* from being overwritten by retried packet rate.*/
  575. if (!ptcb_desc->use_driver_rate) {
  576. /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
  577. /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
  578. }
  579. if (ieee80211_is_data_qos(fc)) {
  580. if (mac->rdg_en) {
  581. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  582. "Enable RDG function.\n");
  583. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  584. SET_TX_DESC_HTC(pdesc, 1);
  585. }
  586. }
  587. }
  588. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  589. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  590. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
  591. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  592. if (rtlpriv->dm.useramask) {
  593. SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
  594. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  595. } else {
  596. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
  597. SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index);
  598. }
  599. if (ieee80211_is_data_qos(fc))
  600. SET_TX_DESC_QOS(pdesc, 1);
  601. if (!ieee80211_is_data_qos(fc))
  602. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  603. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  604. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  605. is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
  606. SET_TX_DESC_BMC(pdesc, 1);
  607. rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
  608. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  609. }
  610. void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
  611. u8 *pdesc, bool firstseg,
  612. bool lastseg, struct sk_buff *skb)
  613. {
  614. struct rtl_priv *rtlpriv = rtl_priv(hw);
  615. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  616. u8 fw_queue = QSLT_BEACON;
  617. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  618. skb->data, skb->len,
  619. PCI_DMA_TODEVICE);
  620. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  621. __le16 fc = hdr->frame_control;
  622. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  623. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  624. "DMA mapping error");
  625. return;
  626. }
  627. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  628. if (firstseg)
  629. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  630. SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
  631. SET_TX_DESC_SEQ(pdesc, 0);
  632. SET_TX_DESC_LINIP(pdesc, 0);
  633. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  634. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  635. SET_TX_DESC_LAST_SEG(pdesc, 1);
  636. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
  637. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  638. SET_TX_DESC_RATE_ID(pdesc, 7);
  639. SET_TX_DESC_MACID(pdesc, 0);
  640. SET_TX_DESC_OWN(pdesc, 1);
  641. SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len));
  642. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  643. SET_TX_DESC_LAST_SEG(pdesc, 1);
  644. SET_TX_DESC_OFFSET(pdesc, 0x20);
  645. SET_TX_DESC_USE_RATE(pdesc, 1);
  646. if (!ieee80211_is_data_qos(fc))
  647. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  648. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  649. "H2C Tx Cmd Content\n",
  650. pdesc, TX_DESC_SIZE);
  651. }
  652. void rtl88ee_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
  653. {
  654. if (istx == true) {
  655. switch (desc_name) {
  656. case HW_DESC_OWN:
  657. SET_TX_DESC_OWN(pdesc, 1);
  658. break;
  659. case HW_DESC_TX_NEXTDESC_ADDR:
  660. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
  661. break;
  662. default:
  663. RT_ASSERT(false, "ERR txdesc :%d not processed\n",
  664. desc_name);
  665. break;
  666. }
  667. } else {
  668. switch (desc_name) {
  669. case HW_DESC_RXOWN:
  670. SET_RX_DESC_OWN(pdesc, 1);
  671. break;
  672. case HW_DESC_RXBUFF_ADDR:
  673. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
  674. break;
  675. case HW_DESC_RXPKT_LEN:
  676. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
  677. break;
  678. case HW_DESC_RXERO:
  679. SET_RX_DESC_EOR(pdesc, 1);
  680. break;
  681. default:
  682. RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
  683. desc_name);
  684. break;
  685. }
  686. }
  687. }
  688. u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  689. {
  690. u32 ret = 0;
  691. if (istx == true) {
  692. switch (desc_name) {
  693. case HW_DESC_OWN:
  694. ret = GET_TX_DESC_OWN(pdesc);
  695. break;
  696. case HW_DESC_TXBUFF_ADDR:
  697. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  698. break;
  699. default:
  700. RT_ASSERT(false, "ERR txdesc :%d not processed\n",
  701. desc_name);
  702. break;
  703. }
  704. } else {
  705. switch (desc_name) {
  706. case HW_DESC_OWN:
  707. ret = GET_RX_DESC_OWN(pdesc);
  708. break;
  709. case HW_DESC_RXPKT_LEN:
  710. ret = GET_RX_DESC_PKT_LEN(pdesc);
  711. break;
  712. default:
  713. RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
  714. desc_name);
  715. break;
  716. }
  717. }
  718. return ret;
  719. }
  720. void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  721. {
  722. struct rtl_priv *rtlpriv = rtl_priv(hw);
  723. if (hw_queue == BEACON_QUEUE) {
  724. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  725. } else {
  726. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  727. BIT(0) << (hw_queue));
  728. }
  729. }