trx.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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. #include "fw.h"
  37. static u8 _rtl8821ae_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
  38. {
  39. __le16 fc = rtl_get_fc(skb);
  40. if (unlikely(ieee80211_is_beacon(fc)))
  41. return QSLT_BEACON;
  42. if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
  43. return QSLT_MGNT;
  44. return skb->priority;
  45. }
  46. /* mac80211's rate_idx is like this:
  47. *
  48. * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
  49. *
  50. * B/G rate:
  51. * (rx_status->flag & RX_FLAG_HT) = 0,
  52. * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
  53. *
  54. * N rate:
  55. * (rx_status->flag & RX_FLAG_HT) = 1,
  56. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  57. *
  58. * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
  59. * A rate:
  60. * (rx_status->flag & RX_FLAG_HT) = 0,
  61. * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
  62. *
  63. * N rate:
  64. * (rx_status->flag & RX_FLAG_HT) = 1,
  65. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  66. */
  67. static int _rtl8821ae_rate_mapping(struct ieee80211_hw *hw,
  68. bool isht, bool isvht, u8 desc_rate)
  69. {
  70. int rate_idx;
  71. if (!isht) {
  72. if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  73. switch (desc_rate) {
  74. case DESC_RATE1M:
  75. rate_idx = 0;
  76. break;
  77. case DESC_RATE2M:
  78. rate_idx = 1;
  79. break;
  80. case DESC_RATE5_5M:
  81. rate_idx = 2;
  82. break;
  83. case DESC_RATE11M:
  84. rate_idx = 3;
  85. break;
  86. case DESC_RATE6M:
  87. rate_idx = 4;
  88. break;
  89. case DESC_RATE9M:
  90. rate_idx = 5;
  91. break;
  92. case DESC_RATE12M:
  93. rate_idx = 6;
  94. break;
  95. case DESC_RATE18M:
  96. rate_idx = 7;
  97. break;
  98. case DESC_RATE24M:
  99. rate_idx = 8;
  100. break;
  101. case DESC_RATE36M:
  102. rate_idx = 9;
  103. break;
  104. case DESC_RATE48M:
  105. rate_idx = 10;
  106. break;
  107. case DESC_RATE54M:
  108. rate_idx = 11;
  109. break;
  110. default:
  111. rate_idx = 0;
  112. break;
  113. }
  114. } else {
  115. switch (desc_rate) {
  116. case DESC_RATE6M:
  117. rate_idx = 0;
  118. break;
  119. case DESC_RATE9M:
  120. rate_idx = 1;
  121. break;
  122. case DESC_RATE12M:
  123. rate_idx = 2;
  124. break;
  125. case DESC_RATE18M:
  126. rate_idx = 3;
  127. break;
  128. case DESC_RATE24M:
  129. rate_idx = 4;
  130. break;
  131. case DESC_RATE36M:
  132. rate_idx = 5;
  133. break;
  134. case DESC_RATE48M:
  135. rate_idx = 6;
  136. break;
  137. case DESC_RATE54M:
  138. rate_idx = 7;
  139. break;
  140. default:
  141. rate_idx = 0;
  142. break;
  143. }
  144. }
  145. } else {
  146. switch (desc_rate) {
  147. case DESC_RATEMCS0:
  148. rate_idx = 0;
  149. break;
  150. case DESC_RATEMCS1:
  151. rate_idx = 1;
  152. break;
  153. case DESC_RATEMCS2:
  154. rate_idx = 2;
  155. break;
  156. case DESC_RATEMCS3:
  157. rate_idx = 3;
  158. break;
  159. case DESC_RATEMCS4:
  160. rate_idx = 4;
  161. break;
  162. case DESC_RATEMCS5:
  163. rate_idx = 5;
  164. break;
  165. case DESC_RATEMCS6:
  166. rate_idx = 6;
  167. break;
  168. case DESC_RATEMCS7:
  169. rate_idx = 7;
  170. break;
  171. case DESC_RATEMCS8:
  172. rate_idx = 8;
  173. break;
  174. case DESC_RATEMCS9:
  175. rate_idx = 9;
  176. break;
  177. case DESC_RATEMCS10:
  178. rate_idx = 10;
  179. break;
  180. case DESC_RATEMCS11:
  181. rate_idx = 11;
  182. break;
  183. case DESC_RATEMCS12:
  184. rate_idx = 12;
  185. break;
  186. case DESC_RATEMCS13:
  187. rate_idx = 13;
  188. break;
  189. case DESC_RATEMCS14:
  190. rate_idx = 14;
  191. break;
  192. case DESC_RATEMCS15:
  193. rate_idx = 15;
  194. break;
  195. default:
  196. rate_idx = 0;
  197. break;
  198. }
  199. }
  200. if (isvht) {
  201. switch (desc_rate) {
  202. case DESC_RATEVHT1SS_MCS0:
  203. rate_idx = 0;
  204. break;
  205. case DESC_RATEVHT1SS_MCS1:
  206. rate_idx = 1;
  207. break;
  208. case DESC_RATEVHT1SS_MCS2:
  209. rate_idx = 2;
  210. break;
  211. case DESC_RATEVHT1SS_MCS3:
  212. rate_idx = 3;
  213. break;
  214. case DESC_RATEVHT1SS_MCS4:
  215. rate_idx = 4;
  216. break;
  217. case DESC_RATEVHT1SS_MCS5:
  218. rate_idx = 5;
  219. break;
  220. case DESC_RATEVHT1SS_MCS6:
  221. rate_idx = 6;
  222. break;
  223. case DESC_RATEVHT1SS_MCS7:
  224. rate_idx = 7;
  225. break;
  226. case DESC_RATEVHT1SS_MCS8:
  227. rate_idx = 8;
  228. break;
  229. case DESC_RATEVHT1SS_MCS9:
  230. rate_idx = 9;
  231. break;
  232. case DESC_RATEVHT2SS_MCS0:
  233. rate_idx = 0;
  234. break;
  235. case DESC_RATEVHT2SS_MCS1:
  236. rate_idx = 1;
  237. break;
  238. case DESC_RATEVHT2SS_MCS2:
  239. rate_idx = 2;
  240. break;
  241. case DESC_RATEVHT2SS_MCS3:
  242. rate_idx = 3;
  243. break;
  244. case DESC_RATEVHT2SS_MCS4:
  245. rate_idx = 4;
  246. break;
  247. case DESC_RATEVHT2SS_MCS5:
  248. rate_idx = 5;
  249. break;
  250. case DESC_RATEVHT2SS_MCS6:
  251. rate_idx = 6;
  252. break;
  253. case DESC_RATEVHT2SS_MCS7:
  254. rate_idx = 7;
  255. break;
  256. case DESC_RATEVHT2SS_MCS8:
  257. rate_idx = 8;
  258. break;
  259. case DESC_RATEVHT2SS_MCS9:
  260. rate_idx = 9;
  261. break;
  262. default:
  263. rate_idx = 0;
  264. break;
  265. }
  266. }
  267. return rate_idx;
  268. }
  269. static u16 odm_cfo(char value)
  270. {
  271. int ret_val;
  272. if (value < 0) {
  273. ret_val = 0 - value;
  274. ret_val = (ret_val << 1) + (ret_val >> 1);
  275. /* set bit12 as 1 for negative cfo */
  276. ret_val = ret_val | BIT(12);
  277. } else {
  278. ret_val = value;
  279. ret_val = (ret_val << 1) + (ret_val >> 1);
  280. }
  281. return ret_val;
  282. }
  283. static void query_rxphystatus(struct ieee80211_hw *hw,
  284. struct rtl_stats *pstatus, u8 *pdesc,
  285. struct rx_fwinfo_8821ae *p_drvinfo,
  286. bool bpacket_match_bssid,
  287. bool bpacket_toself, bool packet_beacon)
  288. {
  289. struct rtl_priv *rtlpriv = rtl_priv(hw);
  290. struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
  291. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  292. struct rtl_phy *rtlphy = &rtlpriv->phy;
  293. char rx_pwr_all = 0, rx_pwr[4];
  294. u8 rf_rx_num = 0, evm, evmdbm, pwdb_all;
  295. u8 i, max_spatial_stream;
  296. u32 rssi, total_rssi = 0;
  297. bool is_cck = pstatus->is_cck;
  298. u8 lan_idx, vga_idx;
  299. /* Record it for next packet processing */
  300. pstatus->packet_matchbssid = bpacket_match_bssid;
  301. pstatus->packet_toself = bpacket_toself;
  302. pstatus->packet_beacon = packet_beacon;
  303. pstatus->rx_mimo_signalquality[0] = -1;
  304. pstatus->rx_mimo_signalquality[1] = -1;
  305. if (is_cck) {
  306. u8 cck_highpwr;
  307. u8 cck_agc_rpt;
  308. cck_agc_rpt = p_phystrpt->cfosho[0];
  309. /* (1)Hardware does not provide RSSI for CCK
  310. * (2)PWDB, Average PWDB cacluated by
  311. * hardware (for rate adaptive)
  312. */
  313. cck_highpwr = (u8)rtlphy->cck_high_power;
  314. lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
  315. vga_idx = (cck_agc_rpt & 0x1f);
  316. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE) {
  317. switch (lan_idx) {
  318. case 7:
  319. if (vga_idx <= 27)
  320. /*VGA_idx = 27~2*/
  321. rx_pwr_all = -100 + 2*(27-vga_idx);
  322. else
  323. rx_pwr_all = -100;
  324. break;
  325. case 6:
  326. /*VGA_idx = 2~0*/
  327. rx_pwr_all = -48 + 2*(2-vga_idx);
  328. break;
  329. case 5:
  330. /*VGA_idx = 7~5*/
  331. rx_pwr_all = -42 + 2*(7-vga_idx);
  332. break;
  333. case 4:
  334. /*VGA_idx = 7~4*/
  335. rx_pwr_all = -36 + 2*(7-vga_idx);
  336. break;
  337. case 3:
  338. /*VGA_idx = 7~0*/
  339. rx_pwr_all = -24 + 2*(7-vga_idx);
  340. break;
  341. case 2:
  342. if (cck_highpwr)
  343. /*VGA_idx = 5~0*/
  344. rx_pwr_all = -12 + 2*(5-vga_idx);
  345. else
  346. rx_pwr_all = -6 + 2*(5-vga_idx);
  347. break;
  348. case 1:
  349. rx_pwr_all = 8-2*vga_idx;
  350. break;
  351. case 0:
  352. rx_pwr_all = 14-2*vga_idx;
  353. break;
  354. default:
  355. break;
  356. }
  357. rx_pwr_all += 6;
  358. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  359. if (!cck_highpwr) {
  360. if (pwdb_all >= 80)
  361. pwdb_all =
  362. ((pwdb_all - 80)<<1) +
  363. ((pwdb_all - 80)>>1) + 80;
  364. else if ((pwdb_all <= 78) && (pwdb_all >= 20))
  365. pwdb_all += 3;
  366. if (pwdb_all > 100)
  367. pwdb_all = 100;
  368. }
  369. } else { /* 8821 */
  370. char pout = -6;
  371. switch (lan_idx) {
  372. case 5:
  373. rx_pwr_all = pout - 32 - (2*vga_idx);
  374. break;
  375. case 4:
  376. rx_pwr_all = pout - 24 - (2*vga_idx);
  377. break;
  378. case 2:
  379. rx_pwr_all = pout - 11 - (2*vga_idx);
  380. break;
  381. case 1:
  382. rx_pwr_all = pout + 5 - (2*vga_idx);
  383. break;
  384. case 0:
  385. rx_pwr_all = pout + 21 - (2*vga_idx);
  386. break;
  387. }
  388. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  389. }
  390. pstatus->rx_pwdb_all = pwdb_all;
  391. pstatus->recvsignalpower = rx_pwr_all;
  392. /* (3) Get Signal Quality (EVM) */
  393. if (bpacket_match_bssid) {
  394. u8 sq;
  395. if (pstatus->rx_pwdb_all > 40) {
  396. sq = 100;
  397. } else {
  398. sq = p_phystrpt->pwdb_all;
  399. if (sq > 64)
  400. sq = 0;
  401. else if (sq < 20)
  402. sq = 100;
  403. else
  404. sq = ((64 - sq) * 100) / 44;
  405. }
  406. pstatus->signalquality = sq;
  407. pstatus->rx_mimo_signalquality[0] = sq;
  408. pstatus->rx_mimo_signalquality[1] = -1;
  409. }
  410. } else {
  411. /* (1)Get RSSI for HT rate */
  412. for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
  413. /* we will judge RF RX path now. */
  414. if (rtlpriv->dm.rfpath_rxenable[i])
  415. rf_rx_num++;
  416. rx_pwr[i] = (p_phystrpt->gain_trsw[i] & 0x7f) - 110;
  417. /* Translate DBM to percentage. */
  418. rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
  419. total_rssi += rssi;
  420. /* Get Rx snr value in DB */
  421. pstatus->rx_snr[i] = p_phystrpt->rxsnr[i] / 2;
  422. rtlpriv->stats.rx_snr_db[i] = p_phystrpt->rxsnr[i] / 2;
  423. pstatus->cfo_short[i] = odm_cfo(p_phystrpt->cfosho[i]);
  424. pstatus->cfo_tail[i] = odm_cfo(p_phystrpt->cfotail[i]);
  425. /* Record Signal Strength for next packet */
  426. pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
  427. }
  428. /* (2)PWDB, Average PWDB cacluated by
  429. * hardware (for rate adaptive)
  430. */
  431. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  432. pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
  433. pstatus->rx_pwdb_all = pwdb_all;
  434. pstatus->rxpower = rx_pwr_all;
  435. pstatus->recvsignalpower = rx_pwr_all;
  436. /* (3)EVM of HT rate */
  437. if ((pstatus->is_ht && pstatus->rate >= DESC_RATEMCS8 &&
  438. pstatus->rate <= DESC_RATEMCS15) ||
  439. (pstatus->is_vht &&
  440. pstatus->rate >= DESC_RATEVHT2SS_MCS0 &&
  441. pstatus->rate <= DESC_RATEVHT2SS_MCS9))
  442. max_spatial_stream = 2;
  443. else
  444. max_spatial_stream = 1;
  445. for (i = 0; i < max_spatial_stream; i++) {
  446. evm = rtl_evm_db_to_percentage(p_phystrpt->rxevm[i]);
  447. evmdbm = rtl_evm_dbm_jaguar(p_phystrpt->rxevm[i]);
  448. if (bpacket_match_bssid) {
  449. /* Fill value in RFD, Get the first
  450. * spatial stream only
  451. */
  452. if (i == 0)
  453. pstatus->signalquality = evm;
  454. pstatus->rx_mimo_signalquality[i] = evm;
  455. pstatus->rx_mimo_evm_dbm[i] = evmdbm;
  456. }
  457. }
  458. if (bpacket_match_bssid) {
  459. for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
  460. rtl_priv(hw)->dm.cfo_tail[i] =
  461. (char)p_phystrpt->cfotail[i];
  462. rtl_priv(hw)->dm.packet_count++;
  463. }
  464. }
  465. /* UI BSS List signal strength(in percentage),
  466. * make it good looking, from 0~100.
  467. */
  468. if (is_cck)
  469. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  470. pwdb_all));
  471. else if (rf_rx_num != 0)
  472. pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
  473. total_rssi /= rf_rx_num));
  474. /*HW antenna diversity*/
  475. rtldm->fat_table.antsel_rx_keep_0 = p_phystrpt->antidx_anta;
  476. rtldm->fat_table.antsel_rx_keep_1 = p_phystrpt->antidx_antb;
  477. }
  478. static void translate_rx_signal_stuff(struct ieee80211_hw *hw,
  479. struct sk_buff *skb,
  480. struct rtl_stats *pstatus, u8 *pdesc,
  481. struct rx_fwinfo_8821ae *p_drvinfo)
  482. {
  483. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  484. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  485. struct ieee80211_hdr *hdr;
  486. u8 *tmp_buf;
  487. u8 *praddr;
  488. u8 *psaddr;
  489. __le16 fc;
  490. u16 type;
  491. bool packet_matchbssid, packet_toself, packet_beacon;
  492. tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
  493. hdr = (struct ieee80211_hdr *)tmp_buf;
  494. fc = hdr->frame_control;
  495. type = WLAN_FC_GET_TYPE(hdr->frame_control);
  496. praddr = hdr->addr1;
  497. psaddr = ieee80211_get_SA(hdr);
  498. ether_addr_copy(pstatus->psaddr, psaddr);
  499. packet_matchbssid = (!ieee80211_is_ctl(fc) &&
  500. (ether_addr_equal(mac->bssid,
  501. ieee80211_has_tods(fc) ?
  502. hdr->addr1 :
  503. ieee80211_has_fromds(fc) ?
  504. hdr->addr2 : hdr->addr3)) &&
  505. (!pstatus->hwerror) &&
  506. (!pstatus->crc) && (!pstatus->icv));
  507. packet_toself = packet_matchbssid &&
  508. (ether_addr_equal(praddr, rtlefuse->dev_addr));
  509. if (ieee80211_is_beacon(hdr->frame_control))
  510. packet_beacon = true;
  511. else
  512. packet_beacon = false;
  513. if (packet_beacon && packet_matchbssid)
  514. rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
  515. if (packet_matchbssid &&
  516. ieee80211_is_data_qos(hdr->frame_control) &&
  517. !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
  518. struct ieee80211_qos_hdr *hdr_qos =
  519. (struct ieee80211_qos_hdr *)tmp_buf;
  520. u16 tid = le16_to_cpu(hdr_qos->qos_ctrl) & 0xf;
  521. if (tid != 0 && tid != 3)
  522. rtl_priv(hw)->dm.dbginfo.num_non_be_pkt++;
  523. }
  524. query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
  525. packet_matchbssid, packet_toself,
  526. packet_beacon);
  527. /*_rtl8821ae_smart_antenna(hw, pstatus); */
  528. rtl_process_phyinfo(hw, tmp_buf, pstatus);
  529. }
  530. static void _rtl8821ae_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
  531. u8 *virtualaddress)
  532. {
  533. u32 dwtmp = 0;
  534. memset(virtualaddress, 0, 8);
  535. SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
  536. if (ptcb_desc->empkt_num == 1) {
  537. dwtmp = ptcb_desc->empkt_len[0];
  538. } else {
  539. dwtmp = ptcb_desc->empkt_len[0];
  540. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
  541. dwtmp += ptcb_desc->empkt_len[1];
  542. }
  543. SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
  544. if (ptcb_desc->empkt_num <= 3) {
  545. dwtmp = ptcb_desc->empkt_len[2];
  546. } else {
  547. dwtmp = ptcb_desc->empkt_len[2];
  548. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
  549. dwtmp += ptcb_desc->empkt_len[3];
  550. }
  551. SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
  552. if (ptcb_desc->empkt_num <= 5) {
  553. dwtmp = ptcb_desc->empkt_len[4];
  554. } else {
  555. dwtmp = ptcb_desc->empkt_len[4];
  556. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
  557. dwtmp += ptcb_desc->empkt_len[5];
  558. }
  559. SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
  560. SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
  561. if (ptcb_desc->empkt_num <= 7) {
  562. dwtmp = ptcb_desc->empkt_len[6];
  563. } else {
  564. dwtmp = ptcb_desc->empkt_len[6];
  565. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
  566. dwtmp += ptcb_desc->empkt_len[7];
  567. }
  568. SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
  569. if (ptcb_desc->empkt_num <= 9) {
  570. dwtmp = ptcb_desc->empkt_len[8];
  571. } else {
  572. dwtmp = ptcb_desc->empkt_len[8];
  573. dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
  574. dwtmp += ptcb_desc->empkt_len[9];
  575. }
  576. SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
  577. }
  578. static bool rtl8821ae_get_rxdesc_is_ht(struct ieee80211_hw *hw, u8 *pdesc)
  579. {
  580. struct rtl_priv *rtlpriv = rtl_priv(hw);
  581. u8 rx_rate = 0;
  582. rx_rate = GET_RX_DESC_RXMCS(pdesc);
  583. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
  584. if ((rx_rate >= DESC_RATEMCS0) && (rx_rate <= DESC_RATEMCS15))
  585. return true;
  586. return false;
  587. }
  588. static bool rtl8821ae_get_rxdesc_is_vht(struct ieee80211_hw *hw, u8 *pdesc)
  589. {
  590. struct rtl_priv *rtlpriv = rtl_priv(hw);
  591. u8 rx_rate = 0;
  592. rx_rate = GET_RX_DESC_RXMCS(pdesc);
  593. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
  594. if (rx_rate >= DESC_RATEVHT1SS_MCS0)
  595. return true;
  596. return false;
  597. }
  598. static u8 rtl8821ae_get_rx_vht_nss(struct ieee80211_hw *hw, u8 *pdesc)
  599. {
  600. u8 rx_rate = 0;
  601. u8 vht_nss = 0;
  602. rx_rate = GET_RX_DESC_RXMCS(pdesc);
  603. if ((rx_rate >= DESC_RATEVHT1SS_MCS0) &&
  604. (rx_rate <= DESC_RATEVHT1SS_MCS9))
  605. vht_nss = 1;
  606. else if ((rx_rate >= DESC_RATEVHT2SS_MCS0) &&
  607. (rx_rate <= DESC_RATEVHT2SS_MCS9))
  608. vht_nss = 2;
  609. return vht_nss;
  610. }
  611. bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw,
  612. struct rtl_stats *status,
  613. struct ieee80211_rx_status *rx_status,
  614. u8 *pdesc, struct sk_buff *skb)
  615. {
  616. struct rtl_priv *rtlpriv = rtl_priv(hw);
  617. struct rx_fwinfo_8821ae *p_drvinfo;
  618. struct ieee80211_hdr *hdr;
  619. u32 phystatus = GET_RX_DESC_PHYST(pdesc);
  620. status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
  621. status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
  622. RX_DRV_INFO_SIZE_UNIT;
  623. status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
  624. status->icv = (u16)GET_RX_DESC_ICV(pdesc);
  625. status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
  626. status->hwerror = (status->crc | status->icv);
  627. status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  628. status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
  629. status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
  630. status->isampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
  631. status->isfirst_ampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
  632. status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  633. status->rx_packet_bw = GET_RX_DESC_BW(pdesc);
  634. status->macid = GET_RX_DESC_MACID(pdesc);
  635. status->is_short_gi = !(bool)GET_RX_DESC_SPLCP(pdesc);
  636. status->is_ht = rtl8821ae_get_rxdesc_is_ht(hw, pdesc);
  637. status->is_vht = rtl8821ae_get_rxdesc_is_vht(hw, pdesc);
  638. status->vht_nss = rtl8821ae_get_rx_vht_nss(hw, pdesc);
  639. status->is_cck = RTL8821AE_RX_HAL_IS_CCK_RATE(status->rate);
  640. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  641. "rx_packet_bw=%s,is_ht %d, is_vht %d, vht_nss=%d,is_short_gi %d.\n",
  642. (status->rx_packet_bw == 2) ? "80M" :
  643. (status->rx_packet_bw == 1) ? "40M" : "20M",
  644. status->is_ht, status->is_vht, status->vht_nss,
  645. status->is_short_gi);
  646. if (GET_RX_STATUS_DESC_RPT_SEL(pdesc))
  647. status->packet_report_type = C2H_PACKET;
  648. else
  649. status->packet_report_type = NORMAL_RX;
  650. if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
  651. status->wake_match = BIT(2);
  652. else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
  653. status->wake_match = BIT(1);
  654. else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
  655. status->wake_match = BIT(0);
  656. else
  657. status->wake_match = 0;
  658. if (status->wake_match)
  659. RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
  660. "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
  661. status->wake_match);
  662. rx_status->freq = hw->conf.chandef.chan->center_freq;
  663. rx_status->band = hw->conf.chandef.chan->band;
  664. hdr = (struct ieee80211_hdr *)(skb->data +
  665. status->rx_drvinfo_size + status->rx_bufshift);
  666. if (status->crc)
  667. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  668. if (status->rx_packet_bw == HT_CHANNEL_WIDTH_20_40)
  669. rx_status->flag |= RX_FLAG_40MHZ;
  670. else if (status->rx_packet_bw == HT_CHANNEL_WIDTH_80)
  671. rx_status->vht_flag |= RX_VHT_FLAG_80MHZ;
  672. if (status->is_ht)
  673. rx_status->flag |= RX_FLAG_HT;
  674. if (status->is_vht)
  675. rx_status->flag |= RX_FLAG_VHT;
  676. if (status->is_short_gi)
  677. rx_status->flag |= RX_FLAG_SHORT_GI;
  678. rx_status->vht_nss = status->vht_nss;
  679. rx_status->flag |= RX_FLAG_MACTIME_START;
  680. /* hw will set status->decrypted true, if it finds the
  681. * frame is open data frame or mgmt frame.
  682. * So hw will not decryption robust managment frame
  683. * for IEEE80211w but still set status->decrypted
  684. * true, so here we should set it back to undecrypted
  685. * for IEEE80211w frame, and mac80211 sw will help
  686. * to decrypt it
  687. */
  688. if (status->decrypted) {
  689. if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
  690. (ieee80211_has_protected(hdr->frame_control)))
  691. rx_status->flag |= RX_FLAG_DECRYPTED;
  692. else
  693. rx_status->flag &= ~RX_FLAG_DECRYPTED;
  694. }
  695. /* rate_idx: index of data rate into band's
  696. * supported rates or MCS index if HT rates
  697. * are use (RX_FLAG_HT)
  698. */
  699. rx_status->rate_idx =
  700. _rtl8821ae_rate_mapping(hw, status->is_ht,
  701. status->is_vht, status->rate);
  702. rx_status->mactime = status->timestamp_low;
  703. if (phystatus) {
  704. p_drvinfo = (struct rx_fwinfo_8821ae *)(skb->data +
  705. status->rx_bufshift);
  706. translate_rx_signal_stuff(hw, skb, status, pdesc, p_drvinfo);
  707. }
  708. rx_status->signal = status->recvsignalpower + 10;
  709. if (status->packet_report_type == TX_REPORT2) {
  710. status->macid_valid_entry[0] =
  711. GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
  712. status->macid_valid_entry[1] =
  713. GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
  714. }
  715. return true;
  716. }
  717. static u8 rtl8821ae_bw_mapping(struct ieee80211_hw *hw,
  718. struct rtl_tcb_desc *ptcb_desc)
  719. {
  720. struct rtl_priv *rtlpriv = rtl_priv(hw);
  721. struct rtl_phy *rtlphy = &rtlpriv->phy;
  722. u8 bw_setting_of_desc = 0;
  723. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  724. "rtl8821ae_bw_mapping, current_chan_bw %d, packet_bw %d\n",
  725. rtlphy->current_chan_bw, ptcb_desc->packet_bw);
  726. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
  727. if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80)
  728. bw_setting_of_desc = 2;
  729. else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40)
  730. bw_setting_of_desc = 1;
  731. else
  732. bw_setting_of_desc = 0;
  733. } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
  734. if ((ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) ||
  735. (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80))
  736. bw_setting_of_desc = 1;
  737. else
  738. bw_setting_of_desc = 0;
  739. } else {
  740. bw_setting_of_desc = 0;
  741. }
  742. return bw_setting_of_desc;
  743. }
  744. static u8 rtl8821ae_sc_mapping(struct ieee80211_hw *hw,
  745. struct rtl_tcb_desc *ptcb_desc)
  746. {
  747. struct rtl_priv *rtlpriv = rtl_priv(hw);
  748. struct rtl_phy *rtlphy = &rtlpriv->phy;
  749. struct rtl_mac *mac = rtl_mac(rtlpriv);
  750. u8 sc_setting_of_desc = 0;
  751. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
  752. if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80) {
  753. sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
  754. } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
  755. if (mac->cur_80_prime_sc ==
  756. HAL_PRIME_CHNL_OFFSET_LOWER)
  757. sc_setting_of_desc =
  758. VHT_DATA_SC_40_LOWER_OF_80MHZ;
  759. else if (mac->cur_80_prime_sc ==
  760. HAL_PRIME_CHNL_OFFSET_UPPER)
  761. sc_setting_of_desc =
  762. VHT_DATA_SC_40_UPPER_OF_80MHZ;
  763. else
  764. RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
  765. "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
  766. } else {
  767. if ((mac->cur_40_prime_sc ==
  768. HAL_PRIME_CHNL_OFFSET_LOWER) &&
  769. (mac->cur_80_prime_sc ==
  770. HAL_PRIME_CHNL_OFFSET_LOWER))
  771. sc_setting_of_desc =
  772. VHT_DATA_SC_20_LOWEST_OF_80MHZ;
  773. else if ((mac->cur_40_prime_sc ==
  774. HAL_PRIME_CHNL_OFFSET_UPPER) &&
  775. (mac->cur_80_prime_sc ==
  776. HAL_PRIME_CHNL_OFFSET_LOWER))
  777. sc_setting_of_desc =
  778. VHT_DATA_SC_20_LOWER_OF_80MHZ;
  779. else if ((mac->cur_40_prime_sc ==
  780. HAL_PRIME_CHNL_OFFSET_LOWER) &&
  781. (mac->cur_80_prime_sc ==
  782. HAL_PRIME_CHNL_OFFSET_UPPER))
  783. sc_setting_of_desc =
  784. VHT_DATA_SC_20_UPPER_OF_80MHZ;
  785. else if ((mac->cur_40_prime_sc ==
  786. HAL_PRIME_CHNL_OFFSET_UPPER) &&
  787. (mac->cur_80_prime_sc ==
  788. HAL_PRIME_CHNL_OFFSET_UPPER))
  789. sc_setting_of_desc =
  790. VHT_DATA_SC_20_UPPERST_OF_80MHZ;
  791. else
  792. RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
  793. "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
  794. }
  795. } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
  796. if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
  797. sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
  798. } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20) {
  799. if (mac->cur_40_prime_sc ==
  800. HAL_PRIME_CHNL_OFFSET_UPPER) {
  801. sc_setting_of_desc =
  802. VHT_DATA_SC_20_UPPER_OF_80MHZ;
  803. } else if (mac->cur_40_prime_sc ==
  804. HAL_PRIME_CHNL_OFFSET_LOWER){
  805. sc_setting_of_desc =
  806. VHT_DATA_SC_20_LOWER_OF_80MHZ;
  807. } else {
  808. sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
  809. }
  810. }
  811. } else {
  812. sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
  813. }
  814. return sc_setting_of_desc;
  815. }
  816. void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
  817. struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
  818. struct ieee80211_tx_info *info,
  819. struct ieee80211_sta *sta,
  820. struct sk_buff *skb,
  821. u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
  822. {
  823. struct rtl_priv *rtlpriv = rtl_priv(hw);
  824. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  825. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  826. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  827. u8 *pdesc = (u8 *)pdesc_tx;
  828. u16 seq_number;
  829. __le16 fc = hdr->frame_control;
  830. unsigned int buf_len = 0;
  831. unsigned int skb_len = skb->len;
  832. u8 fw_qsel = _rtl8821ae_map_hwqueue_to_fwqueue(skb, hw_queue);
  833. bool firstseg = ((hdr->seq_ctrl &
  834. cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
  835. bool lastseg = ((hdr->frame_control &
  836. cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
  837. dma_addr_t mapping;
  838. u8 short_gi = 0;
  839. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  840. rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
  841. /* reserve 8 byte for AMPDU early mode */
  842. if (rtlhal->earlymode_enable) {
  843. skb_push(skb, EM_HDR_LEN);
  844. memset(skb->data, 0, EM_HDR_LEN);
  845. }
  846. buf_len = skb->len;
  847. mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
  848. PCI_DMA_TODEVICE);
  849. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  850. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  851. "DMA mapping error");
  852. return;
  853. }
  854. CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8821ae));
  855. if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
  856. firstseg = true;
  857. lastseg = true;
  858. }
  859. if (firstseg) {
  860. if (rtlhal->earlymode_enable) {
  861. SET_TX_DESC_PKT_OFFSET(pdesc, 1);
  862. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
  863. EM_HDR_LEN);
  864. if (ptcb_desc->empkt_num) {
  865. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  866. "Insert 8 byte.pTcb->EMPktNum:%d\n",
  867. ptcb_desc->empkt_num);
  868. _rtl8821ae_insert_emcontent(ptcb_desc,
  869. (u8 *)(skb->data));
  870. }
  871. } else {
  872. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  873. }
  874. /* ptcb_desc->use_driver_rate = true; */
  875. SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
  876. if (ptcb_desc->hw_rate > DESC_RATEMCS0)
  877. short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
  878. else
  879. short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
  880. SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
  881. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  882. SET_TX_DESC_AGG_ENABLE(pdesc, 1);
  883. SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x1f);
  884. }
  885. SET_TX_DESC_SEQ(pdesc, seq_number);
  886. SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
  887. !ptcb_desc->cts_enable) ? 1 : 0));
  888. SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
  889. SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
  890. SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
  891. SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
  892. SET_TX_DESC_RTS_SHORT(pdesc,
  893. ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
  894. (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
  895. (ptcb_desc->rts_use_shortgi ? 1 : 0)));
  896. if (ptcb_desc->tx_enable_sw_calc_duration)
  897. SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
  898. SET_TX_DESC_DATA_BW(pdesc,
  899. rtl8821ae_bw_mapping(hw, ptcb_desc));
  900. SET_TX_DESC_TX_SUB_CARRIER(pdesc,
  901. rtl8821ae_sc_mapping(hw, ptcb_desc));
  902. SET_TX_DESC_LINIP(pdesc, 0);
  903. SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
  904. if (sta) {
  905. u8 ampdu_density = sta->ht_cap.ampdu_density;
  906. SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
  907. }
  908. if (info->control.hw_key) {
  909. struct ieee80211_key_conf *keyconf =
  910. info->control.hw_key;
  911. switch (keyconf->cipher) {
  912. case WLAN_CIPHER_SUITE_WEP40:
  913. case WLAN_CIPHER_SUITE_WEP104:
  914. case WLAN_CIPHER_SUITE_TKIP:
  915. SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
  916. break;
  917. case WLAN_CIPHER_SUITE_CCMP:
  918. SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
  919. break;
  920. default:
  921. SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
  922. break;
  923. }
  924. }
  925. SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
  926. SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
  927. SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
  928. SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
  929. 1 : 0);
  930. SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
  931. if (ieee80211_is_data_qos(fc)) {
  932. if (mac->rdg_en) {
  933. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  934. "Enable RDG function.\n");
  935. SET_TX_DESC_RDG_ENABLE(pdesc, 1);
  936. SET_TX_DESC_HTC(pdesc, 1);
  937. }
  938. }
  939. }
  940. SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
  941. SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
  942. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
  943. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  944. /* if (rtlpriv->dm.useramask) { */
  945. if (1) {
  946. SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
  947. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  948. } else {
  949. SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
  950. SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
  951. }
  952. if (!ieee80211_is_data_qos(fc)) {
  953. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  954. SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
  955. }
  956. SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
  957. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  958. is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
  959. SET_TX_DESC_BMC(pdesc, 1);
  960. }
  961. rtl8821ae_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
  962. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
  963. }
  964. void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
  965. u8 *pdesc, bool firstseg,
  966. bool lastseg, struct sk_buff *skb)
  967. {
  968. struct rtl_priv *rtlpriv = rtl_priv(hw);
  969. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  970. u8 fw_queue = QSLT_BEACON;
  971. dma_addr_t mapping = pci_map_single(rtlpci->pdev,
  972. skb->data, skb->len,
  973. PCI_DMA_TODEVICE);
  974. if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
  975. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  976. "DMA mapping error");
  977. return;
  978. }
  979. CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
  980. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  981. SET_TX_DESC_LAST_SEG(pdesc, 1);
  982. SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len));
  983. SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
  984. SET_TX_DESC_USE_RATE(pdesc, 1);
  985. SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
  986. SET_TX_DESC_DISABLE_FB(pdesc, 1);
  987. SET_TX_DESC_DATA_BW(pdesc, 0);
  988. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  989. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  990. SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
  991. SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
  992. SET_TX_DESC_MACID(pdesc, 0);
  993. SET_TX_DESC_OWN(pdesc, 1);
  994. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  995. "H2C Tx Cmd Content\n",
  996. pdesc, TX_DESC_SIZE);
  997. }
  998. void rtl8821ae_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
  999. bool istx, u8 desc_name, u8 *val)
  1000. {
  1001. if (istx) {
  1002. switch (desc_name) {
  1003. case HW_DESC_OWN:
  1004. SET_TX_DESC_OWN(pdesc, 1);
  1005. break;
  1006. case HW_DESC_TX_NEXTDESC_ADDR:
  1007. SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
  1008. break;
  1009. default:
  1010. RT_ASSERT(false,
  1011. "ERR txdesc :%d not process\n", desc_name);
  1012. break;
  1013. }
  1014. } else {
  1015. switch (desc_name) {
  1016. case HW_DESC_RXOWN:
  1017. SET_RX_DESC_OWN(pdesc, 1);
  1018. break;
  1019. case HW_DESC_RXBUFF_ADDR:
  1020. SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
  1021. break;
  1022. case HW_DESC_RXPKT_LEN:
  1023. SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
  1024. break;
  1025. case HW_DESC_RXERO:
  1026. SET_RX_DESC_EOR(pdesc, 1);
  1027. break;
  1028. default:
  1029. RT_ASSERT(false,
  1030. "ERR rxdesc :%d not process\n", desc_name);
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. u32 rtl8821ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
  1036. {
  1037. u32 ret = 0;
  1038. if (istx) {
  1039. switch (desc_name) {
  1040. case HW_DESC_OWN:
  1041. ret = GET_TX_DESC_OWN(pdesc);
  1042. break;
  1043. case HW_DESC_TXBUFF_ADDR:
  1044. ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
  1045. break;
  1046. default:
  1047. RT_ASSERT(false,
  1048. "ERR txdesc :%d not process\n", desc_name);
  1049. break;
  1050. }
  1051. } else {
  1052. switch (desc_name) {
  1053. case HW_DESC_OWN:
  1054. ret = GET_RX_DESC_OWN(pdesc);
  1055. break;
  1056. case HW_DESC_RXPKT_LEN:
  1057. ret = GET_RX_DESC_PKT_LEN(pdesc);
  1058. break;
  1059. case HW_DESC_RXBUFF_ADDR:
  1060. ret = GET_RX_DESC_BUFF_ADDR(pdesc);
  1061. break;
  1062. default:
  1063. RT_ASSERT(false,
  1064. "ERR rxdesc :%d not process\n", desc_name);
  1065. break;
  1066. }
  1067. }
  1068. return ret;
  1069. }
  1070. bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw *hw,
  1071. u8 hw_queue, u16 index)
  1072. {
  1073. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1074. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
  1075. u8 *entry = (u8 *)(&ring->desc[ring->idx]);
  1076. u8 own = (u8)rtl8821ae_get_desc(entry, true, HW_DESC_OWN);
  1077. /**
  1078. *beacon packet will only use the first
  1079. *descriptor defautly,and the own may not
  1080. *be cleared by the hardware
  1081. */
  1082. if (own)
  1083. return false;
  1084. return true;
  1085. }
  1086. void rtl8821ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
  1087. {
  1088. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1089. if (hw_queue == BEACON_QUEUE) {
  1090. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
  1091. } else {
  1092. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
  1093. BIT(0) << (hw_queue));
  1094. }
  1095. }
  1096. u32 rtl8821ae_rx_command_packet(struct ieee80211_hw *hw,
  1097. struct rtl_stats status,
  1098. struct sk_buff *skb)
  1099. {
  1100. u32 result = 0;
  1101. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1102. switch (status.packet_report_type) {
  1103. case NORMAL_RX:
  1104. result = 0;
  1105. break;
  1106. case C2H_PACKET:
  1107. rtl8821ae_c2h_packet_handler(hw, skb->data, (u8)skb->len);
  1108. result = 1;
  1109. RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
  1110. "skb->len=%d\n\n", skb->len);
  1111. break;
  1112. default:
  1113. RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
  1114. "No this packet type!!\n");
  1115. break;
  1116. }
  1117. return result;
  1118. }