trx.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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 = ether_addr_equal(mac->bssid,
  279. (ufc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
  280. (ufc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
  281. hdr->addr3);
  282. match_bssid = ((IEEE80211_FTYPE_CTL != type) && (!pstatus->hwerror) &&
  283. (!pstatus->crc) && (!pstatus->icv)) && addr;
  284. addr = ether_addr_equal(praddr, rtlefuse->dev_addr);
  285. packet_toself = match_bssid && addr;
  286. if (ieee80211_is_beacon(fc))
  287. packet_beacon = true;
  288. _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  289. match_bssid, packet_toself, packet_beacon);
  290. _rtl88ee_smart_antenna(hw, pstatus);
  291. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  292. }
  293. static void insert_em(struct rtl_tcb_desc *ptcb_desc, u8 *virtualaddress)
  294. {
  295. u32 dwtmp = 0;
  296. memset(virtualaddress, 0, 8);
  297. SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
  298. if (ptcb_desc->empkt_num == 1) {
  299. dwtmp = ptcb_desc->empkt_len[0];
  300. } else {
  301. dwtmp = ptcb_desc->empkt_len[0];
  302. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  303. dwtmp += ptcb_desc->empkt_len[1];
  304. }
  305. SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
  306. if (ptcb_desc->empkt_num <= 3) {
  307. dwtmp = ptcb_desc->empkt_len[2];
  308. } else {
  309. dwtmp = ptcb_desc->empkt_len[2];
  310. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  311. dwtmp += ptcb_desc->empkt_len[3];
  312. }
  313. SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
  314. if (ptcb_desc->empkt_num <= 5) {
  315. dwtmp = ptcb_desc->empkt_len[4];
  316. } else {
  317. dwtmp = ptcb_desc->empkt_len[4];
  318. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  319. dwtmp += ptcb_desc->empkt_len[5];
  320. }
  321. SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
  322. SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
  323. if (ptcb_desc->empkt_num <= 7) {
  324. dwtmp = ptcb_desc->empkt_len[6];
  325. } else {
  326. dwtmp = ptcb_desc->empkt_len[6];
  327. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  328. dwtmp += ptcb_desc->empkt_len[7];
  329. }
  330. SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
  331. if (ptcb_desc->empkt_num <= 9) {
  332. dwtmp = ptcb_desc->empkt_len[8];
  333. } else {
  334. dwtmp = ptcb_desc->empkt_len[8];
  335. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
  336. dwtmp += ptcb_desc->empkt_len[9];
  337. }
  338. SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
  339. }
  340. bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
  341. struct rtl_stats *status,
  342. struct ieee80211_rx_status *rx_status,
  343. u8 *pdesc, struct sk_buff *skb)
  344. {
  345. struct rtl_priv *rtlpriv = rtl_priv(hw);
  346. struct rx_fwinfo_88e *p_drvinfo;
  347. struct ieee80211_hdr *hdr;
  348. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  349. status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
  350. if (status->packet_report_type == TX_REPORT2)
  351. status->length = (u16) GET_RX_RPT2_DESC_PKT_LEN(pdesc);
  352. else
  353. status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  354. status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  355. RX_DRV_INFO_SIZE_UNIT;
  356. status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  357. status->icv = (u16) GET_RX_DESC_ICV(pdesc);
  358. status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  359. status->hwerror = (status->crc | status->icv);
  360. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  361. status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
  362. status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  363. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  364. status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1) &&
  365. (GET_RX_DESC_FAGGR(pdesc) == 1));
  366. if (status->packet_report_type == NORMAL_RX)
  367. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  368. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  369. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  370. status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate);
  371. status->macid = GET_RX_DESC_MACID(pdesc);
  372. if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  373. status->wake_match = BIT(2);
  374. else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  375. status->wake_match = BIT(1);
  376. else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
  377. status->wake_match = BIT(0);
  378. else
  379. status->wake_match = 0;
  380. if (status->wake_match)
  381. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  382. "Get Wakeup Packet!! WakeMatch =%d\n",
  383. status->wake_match);
  384. rx_status->freq = hw->conf.chandef.chan->center_freq;
  385. rx_status->band = hw->conf.chandef.chan->band;
  386. if (status->crc)
  387. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  388. if (status->rx_is40Mhzpacket)
  389. rx_status->flag |= RX_FLAG_40MHZ;
  390. if (status->is_ht)
  391. rx_status->flag |= RX_FLAG_HT;
  392. rx_status->flag |= RX_FLAG_MACTIME_START;
  393. /* hw will set status->decrypted true, if it finds the
  394. * frame is open data frame or mgmt frame.
  395. * So hw will not decryption robust managment frame
  396. * for IEEE80211w but still set status->decrypted
  397. * true, so here we should set it back to undecrypted
  398. * for IEEE80211w frame, and mac80211 sw will help
  399. * to decrypt it
  400. */
  401. if (status->decrypted) {
  402. hdr = (struct ieee80211_hdr *)(skb->data +
  403. status->rx_drvinfo_size + status->rx_bufshift);
  404. if (!hdr) {
  405. /* During testing, hdr was NULL */
  406. return false;
  407. }
  408. if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
  409. (ieee80211_has_protected(hdr->frame_control)))
  410. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  411. else
  412. rx_status->flag |= RX_FLAG_DECRYPTED;
  413. }
  414. /* rate_idx: index of data rate into band's
  415. * supported rates or MCS index if HT rates
  416. * are use (RX_FLAG_HT)
  417. * Notice: this is diff with windows define
  418. */
  419. rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
  420. status->rate, false);
  421. rx_status->mactime = status->timestamp_low;
  422. if (phystatus == true) {
  423. p_drvinfo = (struct rx_fwinfo_88e *)(skb->data +
  424. status->rx_bufshift);
  425. _rtl88ee_translate_rx_signal_stuff(hw, skb, status, pdesc,
  426. p_drvinfo);
  427. }
  428. /*rx_status->qual = status->signal; */
  429. rx_status->signal = status->recvsignalpower + 10;
  430. /*rx_status->noise = -status->noise; */
  431. if (status->packet_report_type == TX_REPORT2) {
  432. status->macid_valid_entry[0] =
  433. GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
  434. status->macid_valid_entry[1] =
  435. GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
  436. }
  437. return true;
  438. }
  439. void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw,
  440. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  441. struct ieee80211_tx_info *info,
  442. struct ieee80211_sta *sta,
  443. struct sk_buff *skb,
  444. u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
  445. {
  446. struct rtl_priv *rtlpriv = rtl_priv(hw);
  447. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  448. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  449. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  450. u8 *pdesc = (u8 *)pdesc_tx;
  451. u16 seq_number;
  452. __le16 fc = hdr->frame_control;
  453. unsigned int buf_len = 0;
  454. unsigned int skb_len = skb->len;
  455. u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue);
  456. bool firstseg = ((hdr->seq_ctrl &
  457. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  458. bool lastseg = ((hdr->frame_control &
  459. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  460. dma_addr_t mapping;
  461. u8 bw_40 = 0;
  462. u8 short_gi = 0;
  463. if (mac->opmode == NL80211_IFTYPE_STATION) {
  464. bw_40 = mac->bw_40;
  465. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  466. mac->opmode == NL80211_IFTYPE_ADHOC) {
  467. if (sta)
  468. bw_40 = sta->ht_cap.cap &
  469. IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  470. }
  471. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  472. rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
  473. /* reserve 8 byte for AMPDU early mode */
  474. if (rtlhal->earlymode_enable) {
  475. skb_push(skb, EM_HDR_LEN);
  476. memset(skb->data, 0, EM_HDR_LEN);
  477. }
  478. buf_len = skb->len;
  479. mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
  480. PCI_DMA_TODEVICE);
  481. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  482. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  483. "DMA mapping error");
  484. return;
  485. }
  486. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e));
  487. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  488. firstseg = true;
  489. lastseg = true;
  490. }
  491. if (firstseg) {
  492. if (rtlhal->earlymode_enable) {
  493. SET_TX_DESC_PKT_OFFSET(pdesc, 1);
  494. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
  495. EM_HDR_LEN);
  496. if (ptcb_desc->empkt_num) {
  497. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  498. "Insert 8 byte.pTcb->EMPktNum:%d\n",
  499. ptcb_desc->empkt_num);
  500. insert_em(ptcb_desc, (u8 *)(skb->data));
  501. }
  502. } else {
  503. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  504. }
  505. ptcb_desc->use_driver_rate = true;
  506. SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
  507. if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
  508. short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
  509. else
  510. short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
  511. SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
  512. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  513. SET_TX_DESC_AGG_ENABLE(pdesc, 1);
  514. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  515. }
  516. SET_TX_DESC_SEQ(pdesc, seq_number);
  517. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
  518. !ptcb_desc->cts_enable) ? 1 : 0));
  519. SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
  520. SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
  521. SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
  522. SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
  523. SET_TX_DESC_RTS_BW(pdesc, 0);
  524. SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
  525. SET_TX_DESC_RTS_SHORT(pdesc,
  526. ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
  527. (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
  528. (ptcb_desc->rts_use_shortgi ? 1 : 0)));
  529. if (ptcb_desc->btx_enable_sw_calc_duration)
  530. SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
  531. if (bw_40) {
  532. if (ptcb_desc->packet_bw) {
  533. SET_TX_DESC_DATA_BW(pdesc, 1);
  534. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  535. } else {
  536. SET_TX_DESC_DATA_BW(pdesc, 0);
  537. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  538. mac->cur_40_prime_sc);
  539. }
  540. } else {
  541. SET_TX_DESC_DATA_BW(pdesc, 0);
  542. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  543. }
  544. SET_TX_DESC_LINIP(pdesc, 0);
  545. SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
  546. if (sta) {
  547. u8 ampdu_density = sta->ht_cap.ampdu_density;
  548. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  549. }
  550. if (info->control.hw_key) {
  551. struct ieee80211_key_conf *keyconf;
  552. keyconf = info->control.hw_key;
  553. switch (keyconf->cipher) {
  554. case WLAN_CIPHER_SUITE_WEP40:
  555. case WLAN_CIPHER_SUITE_WEP104:
  556. case WLAN_CIPHER_SUITE_TKIP:
  557. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  558. break;
  559. case WLAN_CIPHER_SUITE_CCMP:
  560. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  561. break;
  562. default:
  563. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  564. break;
  565. }
  566. }
  567. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  568. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  569. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  570. SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
  571. 1 : 0);
  572. SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
  573. /* Set TxRate and RTSRate in TxDesc */
  574. /* This prevent Tx initial rate of new-coming packets */
  575. /* from being overwritten by retried packet rate.*/
  576. if (!ptcb_desc->use_driver_rate) {
  577. /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
  578. /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
  579. }
  580. if (ieee80211_is_data_qos(fc)) {
  581. if (mac->rdg_en) {
  582. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  583. "Enable RDG function.\n");
  584. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  585. SET_TX_DESC_HTC(pdesc, 1);
  586. }
  587. }
  588. }
  589. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  590. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  591. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
  592. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  593. if (rtlpriv->dm.useramask) {
  594. SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
  595. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  596. } else {
  597. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
  598. SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index);
  599. }
  600. if (ieee80211_is_data_qos(fc))
  601. SET_TX_DESC_QOS(pdesc, 1);
  602. if (!ieee80211_is_data_qos(fc))
  603. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  604. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  605. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  606. is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
  607. SET_TX_DESC_BMC(pdesc, 1);
  608. rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
  609. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  610. }
  611. void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
  612. u8 *pdesc, bool firstseg,
  613. bool lastseg, struct sk_buff *skb)
  614. {
  615. struct rtl_priv *rtlpriv = rtl_priv(hw);
  616. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  617. u8 fw_queue = QSLT_BEACON;
  618. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  619. skb->data, skb->len,
  620. PCI_DMA_TODEVICE);
  621. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  622. __le16 fc = hdr->frame_control;
  623. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  624. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  625. "DMA mapping error");
  626. return;
  627. }
  628. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  629. if (firstseg)
  630. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  631. SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
  632. SET_TX_DESC_SEQ(pdesc, 0);
  633. SET_TX_DESC_LINIP(pdesc, 0);
  634. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  635. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  636. SET_TX_DESC_LAST_SEG(pdesc, 1);
  637. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
  638. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  639. SET_TX_DESC_RATE_ID(pdesc, 7);
  640. SET_TX_DESC_MACID(pdesc, 0);
  641. SET_TX_DESC_OWN(pdesc, 1);
  642. SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len));
  643. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  644. SET_TX_DESC_LAST_SEG(pdesc, 1);
  645. SET_TX_DESC_OFFSET(pdesc, 0x20);
  646. SET_TX_DESC_USE_RATE(pdesc, 1);
  647. if (!ieee80211_is_data_qos(fc))
  648. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  649. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  650. "H2C Tx Cmd Content\n",
  651. pdesc, TX_DESC_SIZE);
  652. }
  653. void rtl88ee_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
  654. {
  655. if (istx == true) {
  656. switch (desc_name) {
  657. case HW_DESC_OWN:
  658. SET_TX_DESC_OWN(pdesc, 1);
  659. break;
  660. case HW_DESC_TX_NEXTDESC_ADDR:
  661. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
  662. break;
  663. default:
  664. RT_ASSERT(false, "ERR txdesc :%d not processed\n",
  665. desc_name);
  666. break;
  667. }
  668. } else {
  669. switch (desc_name) {
  670. case HW_DESC_RXOWN:
  671. SET_RX_DESC_OWN(pdesc, 1);
  672. break;
  673. case HW_DESC_RXBUFF_ADDR:
  674. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
  675. break;
  676. case HW_DESC_RXPKT_LEN:
  677. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
  678. break;
  679. case HW_DESC_RXERO:
  680. SET_RX_DESC_EOR(pdesc, 1);
  681. break;
  682. default:
  683. RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
  684. desc_name);
  685. break;
  686. }
  687. }
  688. }
  689. u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  690. {
  691. u32 ret = 0;
  692. if (istx == true) {
  693. switch (desc_name) {
  694. case HW_DESC_OWN:
  695. ret = GET_TX_DESC_OWN(pdesc);
  696. break;
  697. case HW_DESC_TXBUFF_ADDR:
  698. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  699. break;
  700. default:
  701. RT_ASSERT(false, "ERR txdesc :%d not processed\n",
  702. desc_name);
  703. break;
  704. }
  705. } else {
  706. switch (desc_name) {
  707. case HW_DESC_OWN:
  708. ret = GET_RX_DESC_OWN(pdesc);
  709. break;
  710. case HW_DESC_RXPKT_LEN:
  711. ret = GET_RX_DESC_PKT_LEN(pdesc);
  712. break;
  713. default:
  714. RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
  715. desc_name);
  716. break;
  717. }
  718. }
  719. return ret;
  720. }
  721. void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  722. {
  723. struct rtl_priv *rtlpriv = rtl_priv(hw);
  724. if (hw_queue == BEACON_QUEUE) {
  725. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  726. } else {
  727. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  728. BIT(0) << (hw_queue));
  729. }
  730. }