trx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation. All rights reserved.
  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 "../usb.h"
  27. #include "../ps.h"
  28. #include "../base.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "phy.h"
  32. #include "rf.h"
  33. #include "dm.h"
  34. #include "mac.h"
  35. #include "trx.h"
  36. #include "../rtl8192c/fw_common.h"
  37. static int _ConfigVerTOutEP(struct ieee80211_hw *hw)
  38. {
  39. u8 ep_cfg, txqsele;
  40. u8 ep_nums = 0;
  41. struct rtl_priv *rtlpriv = rtl_priv(hw);
  42. struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
  43. struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
  44. rtlusb->out_queue_sel = 0;
  45. ep_cfg = rtl_read_byte(rtlpriv, REG_TEST_SIE_OPTIONAL);
  46. ep_cfg = (ep_cfg & USB_TEST_EP_MASK) >> USB_TEST_EP_SHIFT;
  47. switch (ep_cfg) {
  48. case 0: /* 2 bulk OUT, 1 bulk IN */
  49. case 3:
  50. rtlusb->out_queue_sel = TX_SELE_HQ | TX_SELE_LQ;
  51. ep_nums = 2;
  52. break;
  53. case 1: /* 1 bulk IN/OUT => map all endpoint to Low queue */
  54. case 2: /* 1 bulk IN, 1 bulk OUT => map all endpoint to High queue */
  55. txqsele = rtl_read_byte(rtlpriv, REG_TEST_USB_TXQS);
  56. if (txqsele & 0x0F) /* /map all endpoint to High queue */
  57. rtlusb->out_queue_sel = TX_SELE_HQ;
  58. else if (txqsele&0xF0) /* map all endpoint to Low queue */
  59. rtlusb->out_queue_sel = TX_SELE_LQ;
  60. ep_nums = 1;
  61. break;
  62. default:
  63. break;
  64. }
  65. return (rtlusb->out_ep_nums == ep_nums) ? 0 : -EINVAL;
  66. }
  67. static int _ConfigVerNOutEP(struct ieee80211_hw *hw)
  68. {
  69. u8 ep_cfg;
  70. u8 ep_nums = 0;
  71. struct rtl_priv *rtlpriv = rtl_priv(hw);
  72. struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
  73. struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
  74. rtlusb->out_queue_sel = 0;
  75. /* Normal and High queue */
  76. ep_cfg = rtl_read_byte(rtlpriv, (REG_NORMAL_SIE_EP + 1));
  77. if (ep_cfg & USB_NORMAL_SIE_EP_MASK) {
  78. rtlusb->out_queue_sel |= TX_SELE_HQ;
  79. ep_nums++;
  80. }
  81. if ((ep_cfg >> USB_NORMAL_SIE_EP_SHIFT) & USB_NORMAL_SIE_EP_MASK) {
  82. rtlusb->out_queue_sel |= TX_SELE_NQ;
  83. ep_nums++;
  84. }
  85. /* Low queue */
  86. ep_cfg = rtl_read_byte(rtlpriv, (REG_NORMAL_SIE_EP + 2));
  87. if (ep_cfg & USB_NORMAL_SIE_EP_MASK) {
  88. rtlusb->out_queue_sel |= TX_SELE_LQ;
  89. ep_nums++;
  90. }
  91. return (rtlusb->out_ep_nums == ep_nums) ? 0 : -EINVAL;
  92. }
  93. static void _TwoOutEpMapping(struct ieee80211_hw *hw, bool bIsChipB,
  94. bool bwificfg, struct rtl_ep_map *ep_map)
  95. {
  96. struct rtl_priv *rtlpriv = rtl_priv(hw);
  97. if (bwificfg) { /* for WMM */
  98. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  99. "USB Chip-B & WMM Setting.....\n");
  100. ep_map->ep_mapping[RTL_TXQ_BE] = 2;
  101. ep_map->ep_mapping[RTL_TXQ_BK] = 3;
  102. ep_map->ep_mapping[RTL_TXQ_VI] = 3;
  103. ep_map->ep_mapping[RTL_TXQ_VO] = 2;
  104. ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
  105. ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
  106. ep_map->ep_mapping[RTL_TXQ_HI] = 2;
  107. } else { /* typical setting */
  108. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  109. "USB typical Setting.....\n");
  110. ep_map->ep_mapping[RTL_TXQ_BE] = 3;
  111. ep_map->ep_mapping[RTL_TXQ_BK] = 3;
  112. ep_map->ep_mapping[RTL_TXQ_VI] = 2;
  113. ep_map->ep_mapping[RTL_TXQ_VO] = 2;
  114. ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
  115. ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
  116. ep_map->ep_mapping[RTL_TXQ_HI] = 2;
  117. }
  118. }
  119. static void _ThreeOutEpMapping(struct ieee80211_hw *hw, bool bwificfg,
  120. struct rtl_ep_map *ep_map)
  121. {
  122. struct rtl_priv *rtlpriv = rtl_priv(hw);
  123. if (bwificfg) { /* for WMM */
  124. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  125. "USB 3EP Setting for WMM.....\n");
  126. ep_map->ep_mapping[RTL_TXQ_BE] = 5;
  127. ep_map->ep_mapping[RTL_TXQ_BK] = 3;
  128. ep_map->ep_mapping[RTL_TXQ_VI] = 3;
  129. ep_map->ep_mapping[RTL_TXQ_VO] = 2;
  130. ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
  131. ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
  132. ep_map->ep_mapping[RTL_TXQ_HI] = 2;
  133. } else { /* typical setting */
  134. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  135. "USB 3EP Setting for typical.....\n");
  136. ep_map->ep_mapping[RTL_TXQ_BE] = 5;
  137. ep_map->ep_mapping[RTL_TXQ_BK] = 5;
  138. ep_map->ep_mapping[RTL_TXQ_VI] = 3;
  139. ep_map->ep_mapping[RTL_TXQ_VO] = 2;
  140. ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
  141. ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
  142. ep_map->ep_mapping[RTL_TXQ_HI] = 2;
  143. }
  144. }
  145. static void _OneOutEpMapping(struct ieee80211_hw *hw, struct rtl_ep_map *ep_map)
  146. {
  147. ep_map->ep_mapping[RTL_TXQ_BE] = 2;
  148. ep_map->ep_mapping[RTL_TXQ_BK] = 2;
  149. ep_map->ep_mapping[RTL_TXQ_VI] = 2;
  150. ep_map->ep_mapping[RTL_TXQ_VO] = 2;
  151. ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
  152. ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
  153. ep_map->ep_mapping[RTL_TXQ_HI] = 2;
  154. }
  155. static int _out_ep_mapping(struct ieee80211_hw *hw)
  156. {
  157. int err = 0;
  158. bool bIsChipN, bwificfg = false;
  159. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  160. struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
  161. struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
  162. struct rtl_ep_map *ep_map = &(rtlusb->ep_map);
  163. bIsChipN = IS_NORMAL_CHIP(rtlhal->version);
  164. switch (rtlusb->out_ep_nums) {
  165. case 2:
  166. _TwoOutEpMapping(hw, bIsChipN, bwificfg, ep_map);
  167. break;
  168. case 3:
  169. /* Test chip doesn't support three out EPs. */
  170. if (!bIsChipN) {
  171. err = -EINVAL;
  172. goto err_out;
  173. }
  174. _ThreeOutEpMapping(hw, bIsChipN, ep_map);
  175. break;
  176. case 1:
  177. _OneOutEpMapping(hw, ep_map);
  178. break;
  179. default:
  180. err = -EINVAL;
  181. break;
  182. }
  183. err_out:
  184. return err;
  185. }
  186. /* endpoint mapping */
  187. int rtl8192cu_endpoint_mapping(struct ieee80211_hw *hw)
  188. {
  189. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  190. int error = 0;
  191. if (likely(IS_NORMAL_CHIP(rtlhal->version)))
  192. error = _ConfigVerNOutEP(hw);
  193. else
  194. error = _ConfigVerTOutEP(hw);
  195. if (error)
  196. goto err_out;
  197. error = _out_ep_mapping(hw);
  198. if (error)
  199. goto err_out;
  200. err_out:
  201. return error;
  202. }
  203. u16 rtl8192cu_mq_to_hwq(__le16 fc, u16 mac80211_queue_index)
  204. {
  205. u16 hw_queue_index;
  206. if (unlikely(ieee80211_is_beacon(fc))) {
  207. hw_queue_index = RTL_TXQ_BCN;
  208. goto out;
  209. }
  210. if (ieee80211_is_mgmt(fc)) {
  211. hw_queue_index = RTL_TXQ_MGT;
  212. goto out;
  213. }
  214. switch (mac80211_queue_index) {
  215. case 0:
  216. hw_queue_index = RTL_TXQ_VO;
  217. break;
  218. case 1:
  219. hw_queue_index = RTL_TXQ_VI;
  220. break;
  221. case 2:
  222. hw_queue_index = RTL_TXQ_BE;
  223. break;
  224. case 3:
  225. hw_queue_index = RTL_TXQ_BK;
  226. break;
  227. default:
  228. hw_queue_index = RTL_TXQ_BE;
  229. WARN_ONCE(true, "rtl8192cu: QSLT_BE queue, skb_queue:%d\n",
  230. mac80211_queue_index);
  231. break;
  232. }
  233. out:
  234. return hw_queue_index;
  235. }
  236. static enum rtl_desc_qsel _rtl8192cu_mq_to_descq(struct ieee80211_hw *hw,
  237. __le16 fc, u16 mac80211_queue_index)
  238. {
  239. enum rtl_desc_qsel qsel;
  240. struct rtl_priv *rtlpriv = rtl_priv(hw);
  241. if (unlikely(ieee80211_is_beacon(fc))) {
  242. qsel = QSLT_BEACON;
  243. goto out;
  244. }
  245. if (ieee80211_is_mgmt(fc)) {
  246. qsel = QSLT_MGNT;
  247. goto out;
  248. }
  249. switch (mac80211_queue_index) {
  250. case 0: /* VO */
  251. qsel = QSLT_VO;
  252. RT_TRACE(rtlpriv, COMP_USB, DBG_DMESG,
  253. "VO queue, set qsel = 0x%x\n", QSLT_VO);
  254. break;
  255. case 1: /* VI */
  256. qsel = QSLT_VI;
  257. RT_TRACE(rtlpriv, COMP_USB, DBG_DMESG,
  258. "VI queue, set qsel = 0x%x\n", QSLT_VI);
  259. break;
  260. case 3: /* BK */
  261. qsel = QSLT_BK;
  262. RT_TRACE(rtlpriv, COMP_USB, DBG_DMESG,
  263. "BK queue, set qsel = 0x%x\n", QSLT_BK);
  264. break;
  265. case 2: /* BE */
  266. default:
  267. qsel = QSLT_BE;
  268. RT_TRACE(rtlpriv, COMP_USB, DBG_DMESG,
  269. "BE queue, set qsel = 0x%x\n", QSLT_BE);
  270. break;
  271. }
  272. out:
  273. return qsel;
  274. }
  275. /* =============================================================== */
  276. /*----------------------------------------------------------------------
  277. *
  278. * Rx handler
  279. *
  280. *---------------------------------------------------------------------- */
  281. bool rtl92cu_rx_query_desc(struct ieee80211_hw *hw,
  282. struct rtl_stats *stats,
  283. struct ieee80211_rx_status *rx_status,
  284. u8 *pdesc, struct sk_buff *skb)
  285. {
  286. struct rx_fwinfo_92c *p_drvinfo;
  287. struct rx_desc_92c *p_desc = (struct rx_desc_92c *)pdesc;
  288. u32 phystatus = GET_RX_DESC_PHY_STATUS(pdesc);
  289. stats->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
  290. stats->rx_drvinfo_size = (u8)GET_RX_DESC_DRVINFO_SIZE(pdesc) *
  291. RX_DRV_INFO_SIZE_UNIT;
  292. stats->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
  293. stats->icv = (u16) GET_RX_DESC_ICV(pdesc);
  294. stats->crc = (u16) GET_RX_DESC_CRC32(pdesc);
  295. stats->hwerror = (stats->crc | stats->icv);
  296. stats->decrypted = !GET_RX_DESC_SWDEC(pdesc);
  297. stats->rate = (u8) GET_RX_DESC_RX_MCS(pdesc);
  298. stats->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
  299. stats->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
  300. stats->isfirst_ampdu = (bool)((GET_RX_DESC_PAGGR(pdesc) == 1)
  301. && (GET_RX_DESC_FAGGR(pdesc) == 1));
  302. stats->timestamp_low = GET_RX_DESC_TSFL(pdesc);
  303. stats->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
  304. stats->is_ht = (bool)GET_RX_DESC_RX_HT(pdesc);
  305. rx_status->freq = hw->conf.chandef.chan->center_freq;
  306. rx_status->band = hw->conf.chandef.chan->band;
  307. if (GET_RX_DESC_CRC32(pdesc))
  308. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  309. if (!GET_RX_DESC_SWDEC(pdesc))
  310. rx_status->flag |= RX_FLAG_DECRYPTED;
  311. if (GET_RX_DESC_BW(pdesc))
  312. rx_status->bw = RATE_INFO_BW_40;
  313. if (GET_RX_DESC_RX_HT(pdesc))
  314. rx_status->encoding = RX_ENC_HT;
  315. rx_status->flag |= RX_FLAG_MACTIME_START;
  316. if (stats->decrypted)
  317. rx_status->flag |= RX_FLAG_DECRYPTED;
  318. rx_status->rate_idx = rtlwifi_rate_mapping(hw, stats->is_ht,
  319. false, stats->rate);
  320. rx_status->mactime = GET_RX_DESC_TSFL(pdesc);
  321. if (phystatus) {
  322. p_drvinfo = (struct rx_fwinfo_92c *)(skb->data +
  323. stats->rx_bufshift);
  324. rtl92c_translate_rx_signal_stuff(hw, skb, stats, p_desc,
  325. p_drvinfo);
  326. }
  327. /*rx_status->qual = stats->signal; */
  328. rx_status->signal = stats->recvsignalpower + 10;
  329. return true;
  330. }
  331. #define RTL_RX_DRV_INFO_UNIT 8
  332. static void _rtl_rx_process(struct ieee80211_hw *hw, struct sk_buff *skb)
  333. {
  334. struct ieee80211_rx_status *rx_status =
  335. (struct ieee80211_rx_status *)IEEE80211_SKB_RXCB(skb);
  336. u32 skb_len, pkt_len, drvinfo_len;
  337. struct rtl_priv *rtlpriv = rtl_priv(hw);
  338. u8 *rxdesc;
  339. struct rtl_stats stats = {
  340. .signal = 0,
  341. .rate = 0,
  342. };
  343. struct rx_fwinfo_92c *p_drvinfo;
  344. bool bv;
  345. __le16 fc;
  346. struct ieee80211_hdr *hdr;
  347. memset(rx_status, 0, sizeof(*rx_status));
  348. rxdesc = skb->data;
  349. skb_len = skb->len;
  350. drvinfo_len = (GET_RX_DESC_DRVINFO_SIZE(rxdesc) * RTL_RX_DRV_INFO_UNIT);
  351. pkt_len = GET_RX_DESC_PKT_LEN(rxdesc);
  352. /* TODO: Error recovery. drop this skb or something. */
  353. WARN_ON(skb_len < (pkt_len + RTL_RX_DESC_SIZE + drvinfo_len));
  354. stats.length = (u16) GET_RX_DESC_PKT_LEN(rxdesc);
  355. stats.rx_drvinfo_size = (u8)GET_RX_DESC_DRVINFO_SIZE(rxdesc) *
  356. RX_DRV_INFO_SIZE_UNIT;
  357. stats.rx_bufshift = (u8) (GET_RX_DESC_SHIFT(rxdesc) & 0x03);
  358. stats.icv = (u16) GET_RX_DESC_ICV(rxdesc);
  359. stats.crc = (u16) GET_RX_DESC_CRC32(rxdesc);
  360. stats.hwerror = (stats.crc | stats.icv);
  361. stats.decrypted = !GET_RX_DESC_SWDEC(rxdesc);
  362. stats.rate = (u8) GET_RX_DESC_RX_MCS(rxdesc);
  363. stats.shortpreamble = (u16) GET_RX_DESC_SPLCP(rxdesc);
  364. stats.isampdu = (bool) ((GET_RX_DESC_PAGGR(rxdesc) == 1)
  365. && (GET_RX_DESC_FAGGR(rxdesc) == 1));
  366. stats.timestamp_low = GET_RX_DESC_TSFL(rxdesc);
  367. stats.rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(rxdesc);
  368. stats.is_ht = (bool)GET_RX_DESC_RX_HT(rxdesc);
  369. /* TODO: is center_freq changed when doing scan? */
  370. /* TODO: Shall we add protection or just skip those two step? */
  371. rx_status->freq = hw->conf.chandef.chan->center_freq;
  372. rx_status->band = hw->conf.chandef.chan->band;
  373. if (GET_RX_DESC_CRC32(rxdesc))
  374. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  375. if (!GET_RX_DESC_SWDEC(rxdesc))
  376. rx_status->flag |= RX_FLAG_DECRYPTED;
  377. if (GET_RX_DESC_BW(rxdesc))
  378. rx_status->bw = RATE_INFO_BW_40;
  379. if (GET_RX_DESC_RX_HT(rxdesc))
  380. rx_status->encoding = RX_ENC_HT;
  381. /* Data rate */
  382. rx_status->rate_idx = rtlwifi_rate_mapping(hw, stats.is_ht,
  383. false, stats.rate);
  384. /* There is a phy status after this rx descriptor. */
  385. if (GET_RX_DESC_PHY_STATUS(rxdesc)) {
  386. p_drvinfo = (struct rx_fwinfo_92c *)(rxdesc + RTL_RX_DESC_SIZE);
  387. rtl92c_translate_rx_signal_stuff(hw, skb, &stats,
  388. (struct rx_desc_92c *)rxdesc, p_drvinfo);
  389. }
  390. skb_pull(skb, (drvinfo_len + RTL_RX_DESC_SIZE));
  391. hdr = (struct ieee80211_hdr *)(skb->data);
  392. fc = hdr->frame_control;
  393. bv = ieee80211_is_probe_resp(fc);
  394. if (bv)
  395. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  396. "Got probe response frame\n");
  397. if (ieee80211_is_beacon(fc))
  398. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Got beacon frame\n");
  399. if (ieee80211_is_data(fc))
  400. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Got data frame\n");
  401. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  402. "Fram: fc = 0x%X addr1 = 0x%02X:0x%02X:0x%02X:0x%02X:0x%02X:0x%02X\n",
  403. fc,
  404. (u32)hdr->addr1[0], (u32)hdr->addr1[1],
  405. (u32)hdr->addr1[2], (u32)hdr->addr1[3],
  406. (u32)hdr->addr1[4], (u32)hdr->addr1[5]);
  407. ieee80211_rx(hw, skb);
  408. }
  409. void rtl8192cu_rx_hdl(struct ieee80211_hw *hw, struct sk_buff * skb)
  410. {
  411. _rtl_rx_process(hw, skb);
  412. }
  413. /*----------------------------------------------------------------------
  414. *
  415. * Tx handler
  416. *
  417. *---------------------------------------------------------------------- */
  418. void rtl8192c_tx_cleanup(struct ieee80211_hw *hw, struct sk_buff *skb)
  419. {
  420. }
  421. int rtl8192c_tx_post_hdl(struct ieee80211_hw *hw, struct urb *urb,
  422. struct sk_buff *skb)
  423. {
  424. return 0;
  425. }
  426. struct sk_buff *rtl8192c_tx_aggregate_hdl(struct ieee80211_hw *hw,
  427. struct sk_buff_head *list)
  428. {
  429. return skb_dequeue(list);
  430. }
  431. /*======================================== trx ===============================*/
  432. static void _rtl_fill_usb_tx_desc(u8 *txdesc)
  433. {
  434. SET_TX_DESC_OWN(txdesc, 1);
  435. SET_TX_DESC_LAST_SEG(txdesc, 1);
  436. SET_TX_DESC_FIRST_SEG(txdesc, 1);
  437. }
  438. /**
  439. * For HW recovery information
  440. */
  441. static void _rtl_tx_desc_checksum(u8 *txdesc)
  442. {
  443. __le16 *ptr = (__le16 *)txdesc;
  444. u16 checksum = 0;
  445. u32 index;
  446. /* Clear first */
  447. SET_TX_DESC_TX_DESC_CHECKSUM(txdesc, 0);
  448. for (index = 0; index < 16; index++)
  449. checksum = checksum ^ le16_to_cpu(*(ptr + index));
  450. SET_TX_DESC_TX_DESC_CHECKSUM(txdesc, checksum);
  451. }
  452. void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
  453. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  454. u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
  455. struct ieee80211_sta *sta,
  456. struct sk_buff *skb,
  457. u8 queue_index,
  458. struct rtl_tcb_desc *tcb_desc)
  459. {
  460. struct rtl_priv *rtlpriv = rtl_priv(hw);
  461. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  462. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  463. bool defaultadapter = true;
  464. u8 *qc = ieee80211_get_qos_ctl(hdr);
  465. u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  466. u16 seq_number;
  467. __le16 fc = hdr->frame_control;
  468. u8 rate_flag = info->control.rates[0].flags;
  469. u16 pktlen = skb->len;
  470. enum rtl_desc_qsel fw_qsel = _rtl8192cu_mq_to_descq(hw, fc,
  471. skb_get_queue_mapping(skb));
  472. u8 *txdesc;
  473. seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
  474. rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc);
  475. txdesc = skb_push(skb, RTL_TX_HEADER_SIZE);
  476. memset(txdesc, 0, RTL_TX_HEADER_SIZE);
  477. SET_TX_DESC_PKT_SIZE(txdesc, pktlen);
  478. SET_TX_DESC_LINIP(txdesc, 0);
  479. SET_TX_DESC_PKT_OFFSET(txdesc, RTL_DUMMY_OFFSET);
  480. SET_TX_DESC_OFFSET(txdesc, RTL_TX_HEADER_SIZE);
  481. SET_TX_DESC_TX_RATE(txdesc, tcb_desc->hw_rate);
  482. if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble)
  483. SET_TX_DESC_DATA_SHORTGI(txdesc, 1);
  484. if (mac->tids[tid].agg.agg_state == RTL_AGG_ON &&
  485. info->flags & IEEE80211_TX_CTL_AMPDU) {
  486. SET_TX_DESC_AGG_ENABLE(txdesc, 1);
  487. SET_TX_DESC_MAX_AGG_NUM(txdesc, 0x14);
  488. } else {
  489. SET_TX_DESC_AGG_BREAK(txdesc, 1);
  490. }
  491. SET_TX_DESC_SEQ(txdesc, seq_number);
  492. SET_TX_DESC_RTS_ENABLE(txdesc, ((tcb_desc->rts_enable &&
  493. !tcb_desc->cts_enable) ? 1 : 0));
  494. SET_TX_DESC_HW_RTS_ENABLE(txdesc, ((tcb_desc->rts_enable ||
  495. tcb_desc->cts_enable) ? 1 : 0));
  496. SET_TX_DESC_CTS2SELF(txdesc, ((tcb_desc->cts_enable) ? 1 : 0));
  497. SET_TX_DESC_RTS_STBC(txdesc, ((tcb_desc->rts_stbc) ? 1 : 0));
  498. SET_TX_DESC_RTS_RATE(txdesc, tcb_desc->rts_rate);
  499. SET_TX_DESC_RTS_BW(txdesc, 0);
  500. SET_TX_DESC_RTS_SC(txdesc, tcb_desc->rts_sc);
  501. SET_TX_DESC_RTS_SHORT(txdesc,
  502. ((tcb_desc->rts_rate <= DESC_RATE54M) ?
  503. (tcb_desc->rts_use_shortpreamble ? 1 : 0)
  504. : (tcb_desc->rts_use_shortgi ? 1 : 0)));
  505. if (mac->bw_40) {
  506. if (rate_flag & IEEE80211_TX_RC_DUP_DATA) {
  507. SET_TX_DESC_DATA_BW(txdesc, 1);
  508. SET_TX_DESC_DATA_SC(txdesc, 3);
  509. } else if(rate_flag & IEEE80211_TX_RC_40_MHZ_WIDTH){
  510. SET_TX_DESC_DATA_BW(txdesc, 1);
  511. SET_TX_DESC_DATA_SC(txdesc, mac->cur_40_prime_sc);
  512. } else {
  513. SET_TX_DESC_DATA_BW(txdesc, 0);
  514. SET_TX_DESC_DATA_SC(txdesc, 0);
  515. }
  516. } else {
  517. SET_TX_DESC_DATA_BW(txdesc, 0);
  518. SET_TX_DESC_DATA_SC(txdesc, 0);
  519. }
  520. rcu_read_lock();
  521. sta = ieee80211_find_sta(mac->vif, mac->bssid);
  522. if (sta) {
  523. u8 ampdu_density = sta->ht_cap.ampdu_density;
  524. SET_TX_DESC_AMPDU_DENSITY(txdesc, ampdu_density);
  525. }
  526. rcu_read_unlock();
  527. if (info->control.hw_key) {
  528. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  529. switch (keyconf->cipher) {
  530. case WLAN_CIPHER_SUITE_WEP40:
  531. case WLAN_CIPHER_SUITE_WEP104:
  532. case WLAN_CIPHER_SUITE_TKIP:
  533. SET_TX_DESC_SEC_TYPE(txdesc, 0x1);
  534. break;
  535. case WLAN_CIPHER_SUITE_CCMP:
  536. SET_TX_DESC_SEC_TYPE(txdesc, 0x3);
  537. break;
  538. default:
  539. SET_TX_DESC_SEC_TYPE(txdesc, 0x0);
  540. break;
  541. }
  542. }
  543. SET_TX_DESC_PKT_ID(txdesc, 0);
  544. SET_TX_DESC_QUEUE_SEL(txdesc, fw_qsel);
  545. SET_TX_DESC_DATA_RATE_FB_LIMIT(txdesc, 0x1F);
  546. SET_TX_DESC_RTS_RATE_FB_LIMIT(txdesc, 0xF);
  547. SET_TX_DESC_DISABLE_FB(txdesc, 0);
  548. SET_TX_DESC_USE_RATE(txdesc, tcb_desc->use_driver_rate ? 1 : 0);
  549. if (ieee80211_is_data_qos(fc)) {
  550. if (mac->rdg_en) {
  551. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  552. "Enable RDG function\n");
  553. SET_TX_DESC_RDG_ENABLE(txdesc, 1);
  554. SET_TX_DESC_HTC(txdesc, 1);
  555. }
  556. }
  557. if (rtlpriv->dm.useramask) {
  558. SET_TX_DESC_RATE_ID(txdesc, tcb_desc->ratr_index);
  559. SET_TX_DESC_MACID(txdesc, tcb_desc->mac_id);
  560. } else {
  561. SET_TX_DESC_RATE_ID(txdesc, 0xC + tcb_desc->ratr_index);
  562. SET_TX_DESC_MACID(txdesc, tcb_desc->ratr_index);
  563. }
  564. if ((!ieee80211_is_data_qos(fc)) && ppsc->leisure_ps &&
  565. ppsc->fwctrl_lps) {
  566. SET_TX_DESC_HWSEQ_EN(txdesc, 1);
  567. SET_TX_DESC_PKT_ID(txdesc, 8);
  568. if (!defaultadapter)
  569. SET_TX_DESC_QOS(txdesc, 1);
  570. }
  571. if (ieee80211_has_morefrags(fc))
  572. SET_TX_DESC_MORE_FRAG(txdesc, 1);
  573. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
  574. is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
  575. SET_TX_DESC_BMC(txdesc, 1);
  576. _rtl_fill_usb_tx_desc(txdesc);
  577. _rtl_tx_desc_checksum(txdesc);
  578. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "==>\n");
  579. }
  580. void rtl92cu_fill_fake_txdesc(struct ieee80211_hw *hw, u8 * pDesc,
  581. u32 buffer_len, bool bIsPsPoll)
  582. {
  583. /* Clear all status */
  584. memset(pDesc, 0, RTL_TX_HEADER_SIZE);
  585. SET_TX_DESC_FIRST_SEG(pDesc, 1); /* bFirstSeg; */
  586. SET_TX_DESC_LAST_SEG(pDesc, 1); /* bLastSeg; */
  587. SET_TX_DESC_OFFSET(pDesc, RTL_TX_HEADER_SIZE); /* Offset = 32 */
  588. SET_TX_DESC_PKT_SIZE(pDesc, buffer_len); /* Buffer size + command hdr */
  589. SET_TX_DESC_QUEUE_SEL(pDesc, QSLT_MGNT); /* Fixed queue of Mgnt queue */
  590. /* Set NAVUSEHDR to prevent Ps-poll AId filed to be changed to error
  591. * vlaue by Hw. */
  592. if (bIsPsPoll) {
  593. SET_TX_DESC_NAV_USE_HDR(pDesc, 1);
  594. } else {
  595. SET_TX_DESC_HWSEQ_EN(pDesc, 1); /* Hw set sequence number */
  596. SET_TX_DESC_PKT_ID(pDesc, 0x100); /* set bit3 to 1. */
  597. }
  598. SET_TX_DESC_USE_RATE(pDesc, 1); /* use data rate which is set by Sw */
  599. SET_TX_DESC_OWN(pDesc, 1);
  600. SET_TX_DESC_TX_RATE(pDesc, DESC_RATE1M);
  601. _rtl_tx_desc_checksum(pDesc);
  602. }
  603. void rtl92cu_tx_fill_cmddesc(struct ieee80211_hw *hw,
  604. u8 *pdesc, bool firstseg,
  605. bool lastseg, struct sk_buff *skb)
  606. {
  607. struct rtl_priv *rtlpriv = rtl_priv(hw);
  608. u8 fw_queue = QSLT_BEACON;
  609. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  610. __le16 fc = hdr->frame_control;
  611. memset((void *)pdesc, 0, RTL_TX_HEADER_SIZE);
  612. if (firstseg)
  613. SET_TX_DESC_OFFSET(pdesc, RTL_TX_HEADER_SIZE);
  614. SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
  615. SET_TX_DESC_SEQ(pdesc, 0);
  616. SET_TX_DESC_LINIP(pdesc, 0);
  617. SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
  618. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  619. SET_TX_DESC_LAST_SEG(pdesc, 1);
  620. SET_TX_DESC_RATE_ID(pdesc, 7);
  621. SET_TX_DESC_MACID(pdesc, 0);
  622. SET_TX_DESC_OWN(pdesc, 1);
  623. SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb->len);
  624. SET_TX_DESC_FIRST_SEG(pdesc, 1);
  625. SET_TX_DESC_LAST_SEG(pdesc, 1);
  626. SET_TX_DESC_OFFSET(pdesc, 0x20);
  627. SET_TX_DESC_USE_RATE(pdesc, 1);
  628. if (!ieee80211_is_data_qos(fc)) {
  629. SET_TX_DESC_HWSEQ_EN(pdesc, 1);
  630. SET_TX_DESC_PKT_ID(pdesc, 8);
  631. }
  632. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, "H2C Tx Cmd Content",
  633. pdesc, RTL_TX_DESC_SIZE);
  634. }