trx.c 21 KB

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