trx.c 21 KB

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