trx.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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. * 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 "phy.h"
  36. static u8 _rtl88ee_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 _rtl88ee_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 _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw,
  202. struct rtl_stats *pstatus, u8 *pdesc,
  203. struct rx_fwinfo_88e *p_drvinfo,
  204. bool bpacket_match_bssid,
  205. bool bpacket_toself, 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_8192s_t *cck_buf;
  210. struct phy_status_rpt *phystrpt =
  211. (struct phy_status_rpt *)p_drvinfo;
  212. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  213. char rx_pwr_all = 0, rx_pwr[4];
  214. u8 rf_rx_num = 0, evm, pwdb_all;
  215. u8 i, max_spatial_stream;
  216. u32 rssi, total_rssi = 0;
  217. bool is_cck = pstatus->is_cck;
  218. u8 lan_idx, vga_idx;
  219. /* Record it for next packet processing */
  220. pstatus->packet_matchbssid = bpacket_match_bssid;
  221. pstatus->packet_toself = bpacket_toself;
  222. pstatus->packet_beacon = packet_beacon;
  223. pstatus->rx_mimo_signalquality[0] = -1;
  224. pstatus->rx_mimo_signalquality[1] = -1;
  225. if (is_cck) {
  226. u8 cck_highpwr;
  227. u8 cck_agc_rpt;
  228. /* CCK Driver info Structure is not the same as OFDM packet. */
  229. cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
  230. cck_agc_rpt = cck_buf->cck_agc_rpt;
  231. /* (1)Hardware does not provide RSSI for CCK
  232. * (2)PWDB, Average PWDB cacluated by
  233. * hardware (for rate adaptive)
  234. */
  235. if (ppsc->rfpwr_state == ERFON)
  236. cck_highpwr =
  237. (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
  238. BIT(9));
  239. else
  240. cck_highpwr = false;
  241. lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
  242. vga_idx = (cck_agc_rpt & 0x1f);
  243. switch (lan_idx) {
  244. case 7:
  245. if (vga_idx <= 27)
  246. /*VGA_idx = 27~2*/
  247. rx_pwr_all = -100 + 2*(27-vga_idx);
  248. else
  249. rx_pwr_all = -100;
  250. break;
  251. case 6:
  252. /*VGA_idx = 2~0*/
  253. rx_pwr_all = -48 + 2*(2-vga_idx);
  254. break;
  255. case 5:
  256. /*VGA_idx = 7~5*/
  257. rx_pwr_all = -42 + 2*(7-vga_idx);
  258. break;
  259. case 4:
  260. /*VGA_idx = 7~4*/
  261. rx_pwr_all = -36 + 2*(7-vga_idx);
  262. break;
  263. case 3:
  264. /*VGA_idx = 7~0*/
  265. rx_pwr_all = -24 + 2*(7-vga_idx);
  266. break;
  267. case 2:
  268. if (cck_highpwr)
  269. /*VGA_idx = 5~0*/
  270. rx_pwr_all = -12 + 2*(5-vga_idx);
  271. else
  272. rx_pwr_all = -6 + 2*(5-vga_idx);
  273. break;
  274. case 1:
  275. rx_pwr_all = 8-2*vga_idx;
  276. break;
  277. case 0:
  278. rx_pwr_all = 14-2*vga_idx;
  279. break;
  280. default:
  281. break;
  282. }
  283. rx_pwr_all += 6;
  284. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  285. /* CCK gain is smaller than OFDM/MCS gain, */
  286. /* so we add gain diff by experiences, the val is 6 */
  287. pwdb_all += 6;
  288. if (pwdb_all > 100)
  289. pwdb_all = 100;
  290. /* modify the offset to make the same
  291. * gain index with OFDM.
  292. */
  293. if (pwdb_all > 34 && pwdb_all <= 42)
  294. pwdb_all -= 2;
  295. else if (pwdb_all > 26 && pwdb_all <= 34)
  296. pwdb_all -= 6;
  297. else if (pwdb_all > 14 && pwdb_all <= 26)
  298. pwdb_all -= 8;
  299. else if (pwdb_all > 4 && pwdb_all <= 14)
  300. pwdb_all -= 4;
  301. if (!cck_highpwr) {
  302. if (pwdb_all >= 80)
  303. pwdb_all = ((pwdb_all-80)<<1) +
  304. ((pwdb_all-80)>>1) + 80;
  305. else if ((pwdb_all <= 78) && (pwdb_all >= 20))
  306. pwdb_all += 3;
  307. if (pwdb_all > 100)
  308. pwdb_all = 100;
  309. }
  310. pstatus->rx_pwdb_all = pwdb_all;
  311. pstatus->recvsignalpower = rx_pwr_all;
  312. /* (3) Get Signal Quality (EVM) */
  313. if (bpacket_match_bssid) {
  314. u8 sq;
  315. if (pstatus->rx_pwdb_all > 40)
  316. sq = 100;
  317. else {
  318. sq = cck_buf->sq_rpt;
  319. if (sq > 64)
  320. sq = 0;
  321. else if (sq < 20)
  322. sq = 100;
  323. else
  324. sq = ((64 - sq) * 100) / 44;
  325. }
  326. pstatus->signalquality = sq;
  327. pstatus->rx_mimo_signalquality[0] = sq;
  328. pstatus->rx_mimo_signalquality[1] = -1;
  329. }
  330. } else {
  331. rtlpriv->dm.rfpath_rxenable[0] =
  332. rtlpriv->dm.rfpath_rxenable[1] = true;
  333. /* (1)Get RSSI for HT rate */
  334. for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
  335. /* we will judge RF RX path now. */
  336. if (rtlpriv->dm.rfpath_rxenable[i])
  337. rf_rx_num++;
  338. rx_pwr[i] = ((p_drvinfo->gain_trsw[i] &
  339. 0x3f) * 2) - 110;
  340. /* Translate DBM to percentage. */
  341. rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
  342. total_rssi += rssi;
  343. /* Get Rx snr value in DB */
  344. rtlpriv->stats.rx_snr_db[i] =
  345. (long)(p_drvinfo->rxsnr[i] / 2);
  346. /* Record Signal Strength for next packet */
  347. if (bpacket_match_bssid)
  348. pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
  349. }
  350. /* (2)PWDB, Average PWDB cacluated by
  351. * hardware (for rate adaptive)
  352. */
  353. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  354. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  355. pstatus->rx_pwdb_all = pwdb_all;
  356. pstatus->rxpower = rx_pwr_all;
  357. pstatus->recvsignalpower = rx_pwr_all;
  358. /* (3)EVM of HT rate */
  359. if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
  360. pstatus->rate <= DESC92C_RATEMCS15)
  361. max_spatial_stream = 2;
  362. else
  363. max_spatial_stream = 1;
  364. for (i = 0; i < max_spatial_stream; i++) {
  365. evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
  366. if (bpacket_match_bssid) {
  367. /* Fill value in RFD, Get the first
  368. * spatial stream onlyi
  369. */
  370. if (i == 0)
  371. pstatus->signalquality =
  372. (u8)(evm & 0xff);
  373. pstatus->rx_mimo_signalquality[i] =
  374. (u8)(evm & 0xff);
  375. }
  376. }
  377. }
  378. /* UI BSS List signal strength(in percentage),
  379. * make it good looking, from 0~100.
  380. */
  381. if (is_cck)
  382. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  383. pwdb_all));
  384. else if (rf_rx_num != 0)
  385. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  386. total_rssi /= rf_rx_num));
  387. /*HW antenna diversity*/
  388. rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel;
  389. rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b;
  390. rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2;
  391. }
  392. static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw,
  393. struct rtl_stats *pstatus)
  394. {
  395. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  396. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  397. u8 antsel_tr_mux;
  398. struct fast_ant_training *pfat_table = &rtldm->fat_table;
  399. if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
  400. if (pfat_table->fat_state == FAT_TRAINING_STATE) {
  401. if (pstatus->packet_toself) {
  402. antsel_tr_mux =
  403. (pfat_table->antsel_rx_keep_2 << 2) |
  404. (pfat_table->antsel_rx_keep_1 << 1) |
  405. pfat_table->antsel_rx_keep_0;
  406. pfat_table->ant_sum[antsel_tr_mux] +=
  407. pstatus->rx_pwdb_all;
  408. pfat_table->ant_cnt[antsel_tr_mux]++;
  409. }
  410. }
  411. } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
  412. (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
  413. if (pstatus->packet_toself || pstatus->packet_matchbssid) {
  414. antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
  415. (pfat_table->antsel_rx_keep_1 << 1) |
  416. pfat_table->antsel_rx_keep_0;
  417. rtl88e_dm_ant_sel_statistics(hw, antsel_tr_mux, 0,
  418. pstatus->rx_pwdb_all);
  419. }
  420. }
  421. }
  422. static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw,
  423. struct sk_buff *skb,
  424. struct rtl_stats *pstatus,
  425. u8 *pdesc,
  426. struct rx_fwinfo_88e *p_drvinfo)
  427. {
  428. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  429. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  430. struct ieee80211_hdr *hdr;
  431. u8 *tmp_buf;
  432. u8 *praddr;
  433. u8 *psaddr;
  434. __le16 fc;
  435. bool packet_matchbssid, packet_toself, packet_beacon;
  436. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  437. hdr = (struct ieee80211_hdr *)tmp_buf;
  438. fc = hdr->frame_control;
  439. praddr = hdr->addr1;
  440. psaddr = ieee80211_get_SA(hdr);
  441. memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
  442. packet_matchbssid = ((!ieee80211_is_ctl(fc)) &&
  443. (ether_addr_equal(mac->bssid, ieee80211_has_tods(fc) ?
  444. hdr->addr1 : ieee80211_has_fromds(fc) ?
  445. hdr->addr2 : hdr->addr3)) &&
  446. (!pstatus->hwerror) &&
  447. (!pstatus->crc) && (!pstatus->icv));
  448. packet_toself = packet_matchbssid &&
  449. (ether_addr_equal(praddr, rtlefuse->dev_addr));
  450. if (ieee80211_is_beacon(hdr->frame_control))
  451. packet_beacon = true;
  452. else
  453. packet_beacon = false;
  454. _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  455. packet_matchbssid, packet_toself,
  456. packet_beacon);
  457. _rtl88ee_smart_antenna(hw, pstatus);
  458. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  459. }
  460. static void _rtl88ee_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
  461. u8 *virtualaddress)
  462. {
  463. u32 dwtmp = 0;
  464. memset(virtualaddress, 0, 8);
  465. SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
  466. if (ptcb_desc->empkt_num == 1) {
  467. dwtmp = ptcb_desc->empkt_len[0];
  468. } else {
  469. dwtmp = ptcb_desc->empkt_len[0];
  470. dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
  471. dwtmp += ptcb_desc->empkt_len[1];
  472. }
  473. SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
  474. if (ptcb_desc->empkt_num <= 3) {
  475. dwtmp = ptcb_desc->empkt_len[2];
  476. } else {
  477. dwtmp = ptcb_desc->empkt_len[2];
  478. dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
  479. dwtmp += ptcb_desc->empkt_len[3];
  480. }
  481. SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
  482. if (ptcb_desc->empkt_num <= 5) {
  483. dwtmp = ptcb_desc->empkt_len[4];
  484. } else {
  485. dwtmp = ptcb_desc->empkt_len[4];
  486. dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
  487. dwtmp += ptcb_desc->empkt_len[5];
  488. }
  489. SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
  490. SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
  491. if (ptcb_desc->empkt_num <= 7) {
  492. dwtmp = ptcb_desc->empkt_len[6];
  493. } else {
  494. dwtmp = ptcb_desc->empkt_len[6];
  495. dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
  496. dwtmp += ptcb_desc->empkt_len[7];
  497. }
  498. SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
  499. if (ptcb_desc->empkt_num <= 9) {
  500. dwtmp = ptcb_desc->empkt_len[8];
  501. } else {
  502. dwtmp = ptcb_desc->empkt_len[8];
  503. dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
  504. dwtmp += ptcb_desc->empkt_len[9];
  505. }
  506. SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
  507. }
  508. bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
  509. struct rtl_stats *status,
  510. struct ieee80211_rx_status *rx_status,
  511. u8 *pdesc, struct sk_buff *skb)
  512. {
  513. struct rtl_priv *rtlpriv = rtl_priv(hw);
  514. struct rx_fwinfo_88e *p_drvinfo;
  515. struct ieee80211_hdr *hdr;
  516. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  517. status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
  518. if (status->packet_report_type == TX_REPORT2)
  519. status->length = (u16)GET_RX_RPT2_DESC_PKT_LEN(pdesc);
  520. else
  521. status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
  522. status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  523. RX_DRV_INFO_SIZE_UNIT;
  524. status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
  525. status->icv = (u16)GET_RX_DESC_ICV(pdesc);
  526. status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
  527. status->hwerror = (status->crc | status->icv);
  528. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  529. status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
  530. status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
  531. status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  532. status->isfirst_ampdu = (bool)((GET_RX_DESC_PAGGR(pdesc) == 1) &&
  533. (GET_RX_DESC_FAGGR(pdesc) == 1));
  534. if (status->packet_report_type == NORMAL_RX)
  535. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  536. status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  537. status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
  538. status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate);
  539. status->macid = GET_RX_DESC_MACID(pdesc);
  540. if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  541. status->wake_match = BIT(2);
  542. else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  543. status->wake_match = BIT(1);
  544. else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
  545. status->wake_match = BIT(0);
  546. else
  547. status->wake_match = 0;
  548. if (status->wake_match)
  549. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  550. "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
  551. status->wake_match);
  552. rx_status->freq = hw->conf.chandef.chan->center_freq;
  553. rx_status->band = hw->conf.chandef.chan->band;
  554. hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
  555. + status->rx_bufshift);
  556. if (status->crc)
  557. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  558. if (status->rx_is40Mhzpacket)
  559. rx_status->flag |= RX_FLAG_40MHZ;
  560. if (status->is_ht)
  561. rx_status->flag |= RX_FLAG_HT;
  562. rx_status->flag |= RX_FLAG_MACTIME_START;
  563. /* hw will set status->decrypted true, if it finds the
  564. * frame is open data frame or mgmt frame.
  565. * So hw will not decryption robust managment frame
  566. * for IEEE80211w but still set status->decrypted
  567. * true, so here we should set it back to undecrypted
  568. * for IEEE80211w frame, and mac80211 sw will help
  569. * to decrypt it
  570. */
  571. if (status->decrypted) {
  572. if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
  573. (ieee80211_has_protected(hdr->frame_control)))
  574. rx_status->flag |= RX_FLAG_DECRYPTED;
  575. else
  576. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  577. }
  578. /* rate_idx: index of data rate into band's
  579. * supported rates or MCS index if HT rates
  580. * are use (RX_FLAG_HT)
  581. * Notice: this is diff with windows define
  582. */
  583. rx_status->rate_idx = _rtl88ee_rate_mapping(hw,
  584. status->is_ht, status->rate);
  585. rx_status->mactime = status->timestamp_low;
  586. if (phystatus == true) {
  587. p_drvinfo = (struct rx_fwinfo_88e *)(skb->data +
  588. status->rx_bufshift);
  589. _rtl88ee_translate_rx_signal_stuff(hw,
  590. skb, status, pdesc,
  591. p_drvinfo);
  592. }
  593. rx_status->signal = status->recvsignalpower + 10;
  594. if (status->packet_report_type == TX_REPORT2) {
  595. status->macid_valid_entry[0] =
  596. GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
  597. status->macid_valid_entry[1] =
  598. GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
  599. }
  600. return true;
  601. }
  602. void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw,
  603. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  604. u8 *txbd, struct ieee80211_tx_info *info,
  605. struct ieee80211_sta *sta,
  606. struct sk_buff *skb,
  607. u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
  608. {
  609. struct rtl_priv *rtlpriv = rtl_priv(hw);
  610. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  611. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  612. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  613. u8 *pdesc = (u8 *)pdesc_tx;
  614. u16 seq_number;
  615. __le16 fc = hdr->frame_control;
  616. unsigned int buf_len = 0;
  617. unsigned int skb_len = skb->len;
  618. u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue);
  619. bool firstseg = ((hdr->seq_ctrl &
  620. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  621. bool lastseg = ((hdr->frame_control &
  622. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  623. dma_addr_t mapping;
  624. u8 bw_40 = 0;
  625. u8 short_gi = 0;
  626. if (mac->opmode == NL80211_IFTYPE_STATION) {
  627. bw_40 = mac->bw_40;
  628. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  629. mac->opmode == NL80211_IFTYPE_ADHOC) {
  630. if (sta)
  631. bw_40 = sta->ht_cap.cap &
  632. IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  633. }
  634. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  635. rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
  636. /* reserve 8 byte for AMPDU early mode */
  637. if (rtlhal->earlymode_enable) {
  638. skb_push(skb, EM_HDR_LEN);
  639. memset(skb->data, 0, EM_HDR_LEN);
  640. }
  641. buf_len = skb->len;
  642. mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
  643. PCI_DMA_TODEVICE);
  644. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  645. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  646. "DMA mapping error");
  647. return;
  648. }
  649. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e));
  650. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  651. firstseg = true;
  652. lastseg = true;
  653. }
  654. if (firstseg) {
  655. if (rtlhal->earlymode_enable) {
  656. SET_TX_DESC_PKT_OFFSET(pdesc, 1);
  657. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
  658. EM_HDR_LEN);
  659. if (ptcb_desc->empkt_num) {
  660. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  661. "Insert 8 byte.pTcb->EMPktNum:%d\n",
  662. ptcb_desc->empkt_num);
  663. _rtl88ee_insert_emcontent(ptcb_desc,
  664. (u8 *)(skb->data));
  665. }
  666. } else {
  667. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  668. }
  669. ptcb_desc->use_driver_rate = true;
  670. SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
  671. if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
  672. short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
  673. else
  674. short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
  675. SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
  676. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  677. SET_TX_DESC_AGG_ENABLE(pdesc, 1);
  678. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
  679. }
  680. SET_TX_DESC_SEQ(pdesc, seq_number);
  681. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
  682. !ptcb_desc->cts_enable) ? 1 : 0));
  683. SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
  684. SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
  685. SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
  686. SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
  687. SET_TX_DESC_RTS_BW(pdesc, 0);
  688. SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
  689. SET_TX_DESC_RTS_SHORT(pdesc,
  690. ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
  691. (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
  692. (ptcb_desc->rts_use_shortgi ? 1 : 0)));
  693. if (ptcb_desc->tx_enable_sw_calc_duration)
  694. SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
  695. if (bw_40) {
  696. if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
  697. SET_TX_DESC_DATA_BW(pdesc, 1);
  698. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
  699. } else {
  700. SET_TX_DESC_DATA_BW(pdesc, 0);
  701. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  702. mac->cur_40_prime_sc);
  703. }
  704. } else {
  705. SET_TX_DESC_DATA_BW(pdesc, 0);
  706. SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
  707. }
  708. SET_TX_DESC_LINIP(pdesc, 0);
  709. SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
  710. if (sta) {
  711. u8 ampdu_density = sta->ht_cap.ampdu_density;
  712. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  713. }
  714. if (info->control.hw_key) {
  715. struct ieee80211_key_conf *keyconf;
  716. keyconf = info->control.hw_key;
  717. switch (keyconf->cipher) {
  718. case WLAN_CIPHER_SUITE_WEP40:
  719. case WLAN_CIPHER_SUITE_WEP104:
  720. case WLAN_CIPHER_SUITE_TKIP:
  721. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  722. break;
  723. case WLAN_CIPHER_SUITE_CCMP:
  724. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  725. break;
  726. default:
  727. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  728. break;
  729. }
  730. }
  731. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  732. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  733. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  734. SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
  735. 1 : 0);
  736. SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
  737. /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
  738. /* Set TxRate and RTSRate in TxDesc */
  739. /* This prevent Tx initial rate of new-coming packets */
  740. /* from being overwritten by retried packet rate.*/
  741. if (!ptcb_desc->use_driver_rate) {
  742. /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
  743. /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
  744. }
  745. if (ieee80211_is_data_qos(fc)) {
  746. if (mac->rdg_en) {
  747. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  748. "Enable RDG function.\n");
  749. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  750. SET_TX_DESC_HTC(pdesc, 1);
  751. }
  752. }
  753. }
  754. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  755. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  756. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
  757. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  758. if (rtlpriv->dm.useramask) {
  759. SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
  760. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  761. } else {
  762. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
  763. SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index);
  764. }
  765. if (ieee80211_is_data_qos(fc))
  766. SET_TX_DESC_QOS(pdesc, 1);
  767. if (!ieee80211_is_data_qos(fc))
  768. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  769. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  770. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  771. is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
  772. SET_TX_DESC_BMC(pdesc, 1);
  773. }
  774. rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
  775. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  776. }
  777. void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
  778. u8 *pdesc, bool firstseg,
  779. bool lastseg, struct sk_buff *skb)
  780. {
  781. struct rtl_priv *rtlpriv = rtl_priv(hw);
  782. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  783. u8 fw_queue = QSLT_BEACON;
  784. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  785. skb->data, skb->len,
  786. PCI_DMA_TODEVICE);
  787. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  788. __le16 fc = hdr->frame_control;
  789. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  790. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  791. "DMA mapping error");
  792. return;
  793. }
  794. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  795. if (firstseg)
  796. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  797. SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
  798. SET_TX_DESC_SEQ(pdesc, 0);
  799. SET_TX_DESC_LINIP(pdesc, 0);
  800. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  801. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  802. SET_TX_DESC_LAST_SEG(pdesc, 1);
  803. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
  804. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  805. SET_TX_DESC_RATE_ID(pdesc, 7);
  806. SET_TX_DESC_MACID(pdesc, 0);
  807. SET_TX_DESC_OWN(pdesc, 1);
  808. SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
  809. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  810. SET_TX_DESC_LAST_SEG(pdesc, 1);
  811. SET_TX_DESC_OFFSET(pdesc, 0x20);
  812. SET_TX_DESC_USE_RATE(pdesc, 1);
  813. if (!ieee80211_is_data_qos(fc))
  814. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  815. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  816. "H2C Tx Cmd Content\n",
  817. pdesc, TX_DESC_SIZE);
  818. }
  819. void rtl88ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
  820. bool istx, u8 desc_name, u8 *val)
  821. {
  822. if (istx == true) {
  823. switch (desc_name) {
  824. case HW_DESC_OWN:
  825. SET_TX_DESC_OWN(pdesc, 1);
  826. break;
  827. case HW_DESC_TX_NEXTDESC_ADDR:
  828. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
  829. break;
  830. default:
  831. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  832. desc_name);
  833. break;
  834. }
  835. } else {
  836. switch (desc_name) {
  837. case HW_DESC_RXOWN:
  838. SET_RX_DESC_OWN(pdesc, 1);
  839. break;
  840. case HW_DESC_RXBUFF_ADDR:
  841. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
  842. break;
  843. case HW_DESC_RXPKT_LEN:
  844. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
  845. break;
  846. case HW_DESC_RXERO:
  847. SET_RX_DESC_EOR(pdesc, 1);
  848. break;
  849. default:
  850. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  851. desc_name);
  852. break;
  853. }
  854. }
  855. }
  856. u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  857. {
  858. u32 ret = 0;
  859. if (istx == true) {
  860. switch (desc_name) {
  861. case HW_DESC_OWN:
  862. ret = GET_TX_DESC_OWN(pdesc);
  863. break;
  864. case HW_DESC_TXBUFF_ADDR:
  865. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  866. break;
  867. default:
  868. RT_ASSERT(false, "ERR txdesc :%d not process\n",
  869. desc_name);
  870. break;
  871. }
  872. } else {
  873. switch (desc_name) {
  874. case HW_DESC_OWN:
  875. ret = GET_RX_DESC_OWN(pdesc);
  876. break;
  877. case HW_DESC_RXPKT_LEN:
  878. ret = GET_RX_DESC_PKT_LEN(pdesc);
  879. break;
  880. case HW_DESC_RXBUFF_ADDR:
  881. ret = GET_RX_DESC_BUFF_ADDR(pdesc);
  882. break;
  883. default:
  884. RT_ASSERT(false, "ERR rxdesc :%d not process\n",
  885. desc_name);
  886. break;
  887. }
  888. }
  889. return ret;
  890. }
  891. bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index)
  892. {
  893. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  894. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
  895. u8 *entry = (u8 *)(&ring->desc[ring->idx]);
  896. u8 own = (u8)rtl88ee_get_desc(entry, true, HW_DESC_OWN);
  897. /*beacon packet will only use the first
  898. *descriptor defautly,and the own may not
  899. *be cleared by the hardware
  900. */
  901. if (own)
  902. return false;
  903. return true;
  904. }
  905. void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  906. {
  907. struct rtl_priv *rtlpriv = rtl_priv(hw);
  908. if (hw_queue == BEACON_QUEUE) {
  909. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  910. } else {
  911. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  912. BIT(0) << (hw_queue));
  913. }
  914. }
  915. u32 rtl88ee_rx_command_packet(struct ieee80211_hw *hw,
  916. struct rtl_stats status,
  917. struct sk_buff *skb)
  918. {
  919. return 0;
  920. }