usb.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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. *****************************************************************************/
  23. #include "wifi.h"
  24. #include "core.h"
  25. #include "usb.h"
  26. #include "base.h"
  27. #include "ps.h"
  28. #include "rtl8192c/fw_common.h"
  29. #include <linux/export.h>
  30. #include <linux/module.h>
  31. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  32. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  33. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  34. MODULE_LICENSE("GPL");
  35. MODULE_DESCRIPTION("USB basic driver for rtlwifi");
  36. #define REALTEK_USB_VENQT_READ 0xC0
  37. #define REALTEK_USB_VENQT_WRITE 0x40
  38. #define REALTEK_USB_VENQT_CMD_REQ 0x05
  39. #define REALTEK_USB_VENQT_CMD_IDX 0x00
  40. #define MAX_USBCTRL_VENDORREQ_TIMES 10
  41. static void usbctrl_async_callback(struct urb *urb)
  42. {
  43. if (urb) {
  44. /* free dr */
  45. kfree(urb->setup_packet);
  46. /* free databuf */
  47. kfree(urb->transfer_buffer);
  48. }
  49. }
  50. static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
  51. u16 value, u16 index, void *pdata,
  52. u16 len)
  53. {
  54. int rc;
  55. unsigned int pipe;
  56. u8 reqtype;
  57. struct usb_ctrlrequest *dr;
  58. struct urb *urb;
  59. const u16 databuf_maxlen = REALTEK_USB_VENQT_MAX_BUF_SIZE;
  60. u8 *databuf;
  61. if (WARN_ON_ONCE(len > databuf_maxlen))
  62. len = databuf_maxlen;
  63. pipe = usb_sndctrlpipe(udev, 0); /* write_out */
  64. reqtype = REALTEK_USB_VENQT_WRITE;
  65. dr = kzalloc(sizeof(*dr), GFP_ATOMIC);
  66. if (!dr)
  67. return -ENOMEM;
  68. databuf = kzalloc(databuf_maxlen, GFP_ATOMIC);
  69. if (!databuf) {
  70. kfree(dr);
  71. return -ENOMEM;
  72. }
  73. urb = usb_alloc_urb(0, GFP_ATOMIC);
  74. if (!urb) {
  75. kfree(databuf);
  76. kfree(dr);
  77. return -ENOMEM;
  78. }
  79. dr->bRequestType = reqtype;
  80. dr->bRequest = request;
  81. dr->wValue = cpu_to_le16(value);
  82. dr->wIndex = cpu_to_le16(index);
  83. dr->wLength = cpu_to_le16(len);
  84. /* data are already in little-endian order */
  85. memcpy(databuf, pdata, len);
  86. usb_fill_control_urb(urb, udev, pipe,
  87. (unsigned char *)dr, databuf, len,
  88. usbctrl_async_callback, NULL);
  89. rc = usb_submit_urb(urb, GFP_ATOMIC);
  90. if (rc < 0) {
  91. kfree(databuf);
  92. kfree(dr);
  93. }
  94. usb_free_urb(urb);
  95. return rc;
  96. }
  97. static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request,
  98. u16 value, u16 index, void *pdata,
  99. u16 len)
  100. {
  101. unsigned int pipe;
  102. int status;
  103. u8 reqtype;
  104. int vendorreq_times = 0;
  105. static int count;
  106. pipe = usb_rcvctrlpipe(udev, 0); /* read_in */
  107. reqtype = REALTEK_USB_VENQT_READ;
  108. do {
  109. status = usb_control_msg(udev, pipe, request, reqtype, value,
  110. index, pdata, len, 1000);
  111. if (status < 0) {
  112. /* firmware download is checksumed, don't retry */
  113. if ((value >= FW_8192C_START_ADDRESS &&
  114. value <= FW_8192C_END_ADDRESS))
  115. break;
  116. } else {
  117. break;
  118. }
  119. } while (++vendorreq_times < MAX_USBCTRL_VENDORREQ_TIMES);
  120. if (status < 0 && count++ < 4)
  121. pr_err("reg 0x%x, usbctrl_vendorreq TimeOut! status:0x%x value=0x%x\n",
  122. value, status, *(u32 *)pdata);
  123. return status;
  124. }
  125. static u32 _usb_read_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len)
  126. {
  127. struct device *dev = rtlpriv->io.dev;
  128. struct usb_device *udev = to_usb_device(dev);
  129. u8 request;
  130. u16 wvalue;
  131. u16 index;
  132. __le32 *data;
  133. unsigned long flags;
  134. spin_lock_irqsave(&rtlpriv->locks.usb_lock, flags);
  135. if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT)
  136. rtlpriv->usb_data_index = 0;
  137. data = &rtlpriv->usb_data[rtlpriv->usb_data_index];
  138. spin_unlock_irqrestore(&rtlpriv->locks.usb_lock, flags);
  139. request = REALTEK_USB_VENQT_CMD_REQ;
  140. index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
  141. wvalue = (u16)addr;
  142. _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len);
  143. return le32_to_cpu(*data);
  144. }
  145. static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
  146. {
  147. return (u8)_usb_read_sync(rtlpriv, addr, 1);
  148. }
  149. static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
  150. {
  151. return (u16)_usb_read_sync(rtlpriv, addr, 2);
  152. }
  153. static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
  154. {
  155. return _usb_read_sync(rtlpriv, addr, 4);
  156. }
  157. static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val,
  158. u16 len)
  159. {
  160. u8 request;
  161. u16 wvalue;
  162. u16 index;
  163. __le32 data;
  164. request = REALTEK_USB_VENQT_CMD_REQ;
  165. index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
  166. wvalue = (u16)(addr&0x0000ffff);
  167. data = cpu_to_le32(val);
  168. _usbctrl_vendorreq_async_write(udev, request, wvalue, index, &data,
  169. len);
  170. }
  171. static void _usb_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
  172. {
  173. struct device *dev = rtlpriv->io.dev;
  174. _usb_write_async(to_usb_device(dev), addr, val, 1);
  175. }
  176. static void _usb_write16_async(struct rtl_priv *rtlpriv, u32 addr, u16 val)
  177. {
  178. struct device *dev = rtlpriv->io.dev;
  179. _usb_write_async(to_usb_device(dev), addr, val, 2);
  180. }
  181. static void _usb_write32_async(struct rtl_priv *rtlpriv, u32 addr, u32 val)
  182. {
  183. struct device *dev = rtlpriv->io.dev;
  184. _usb_write_async(to_usb_device(dev), addr, val, 4);
  185. }
  186. static void _usb_writeN_sync(struct rtl_priv *rtlpriv, u32 addr, void *data,
  187. u16 len)
  188. {
  189. struct device *dev = rtlpriv->io.dev;
  190. struct usb_device *udev = to_usb_device(dev);
  191. u8 request = REALTEK_USB_VENQT_CMD_REQ;
  192. u8 reqtype = REALTEK_USB_VENQT_WRITE;
  193. u16 wvalue;
  194. u16 index = REALTEK_USB_VENQT_CMD_IDX;
  195. int pipe = usb_sndctrlpipe(udev, 0); /* write_out */
  196. u8 *buffer;
  197. wvalue = (u16)(addr & 0x0000ffff);
  198. buffer = kmemdup(data, len, GFP_ATOMIC);
  199. if (!buffer)
  200. return;
  201. usb_control_msg(udev, pipe, request, reqtype, wvalue,
  202. index, buffer, len, 50);
  203. kfree(buffer);
  204. }
  205. static void _rtl_usb_io_handler_init(struct device *dev,
  206. struct ieee80211_hw *hw)
  207. {
  208. struct rtl_priv *rtlpriv = rtl_priv(hw);
  209. rtlpriv->io.dev = dev;
  210. mutex_init(&rtlpriv->io.bb_mutex);
  211. rtlpriv->io.write8_async = _usb_write8_async;
  212. rtlpriv->io.write16_async = _usb_write16_async;
  213. rtlpriv->io.write32_async = _usb_write32_async;
  214. rtlpriv->io.read8_sync = _usb_read8_sync;
  215. rtlpriv->io.read16_sync = _usb_read16_sync;
  216. rtlpriv->io.read32_sync = _usb_read32_sync;
  217. rtlpriv->io.writeN_sync = _usb_writeN_sync;
  218. }
  219. static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw)
  220. {
  221. struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw);
  222. mutex_destroy(&rtlpriv->io.bb_mutex);
  223. }
  224. /**
  225. *
  226. * Default aggregation handler. Do nothing and just return the oldest skb.
  227. */
  228. static struct sk_buff *_none_usb_tx_aggregate_hdl(struct ieee80211_hw *hw,
  229. struct sk_buff_head *list)
  230. {
  231. return skb_dequeue(list);
  232. }
  233. #define IS_HIGH_SPEED_USB(udev) \
  234. ((USB_SPEED_HIGH == (udev)->speed) ? true : false)
  235. static int _rtl_usb_init_tx(struct ieee80211_hw *hw)
  236. {
  237. u32 i;
  238. struct rtl_priv *rtlpriv = rtl_priv(hw);
  239. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  240. rtlusb->max_bulk_out_size = IS_HIGH_SPEED_USB(rtlusb->udev)
  241. ? USB_HIGH_SPEED_BULK_SIZE
  242. : USB_FULL_SPEED_BULK_SIZE;
  243. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "USB Max Bulk-out Size=%d\n",
  244. rtlusb->max_bulk_out_size);
  245. for (i = 0; i < __RTL_TXQ_NUM; i++) {
  246. u32 ep_num = rtlusb->ep_map.ep_mapping[i];
  247. if (!ep_num) {
  248. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  249. "Invalid endpoint map setting!\n");
  250. return -EINVAL;
  251. }
  252. }
  253. rtlusb->usb_tx_post_hdl =
  254. rtlpriv->cfg->usb_interface_cfg->usb_tx_post_hdl;
  255. rtlusb->usb_tx_cleanup =
  256. rtlpriv->cfg->usb_interface_cfg->usb_tx_cleanup;
  257. rtlusb->usb_tx_aggregate_hdl =
  258. (rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl)
  259. ? rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl
  260. : &_none_usb_tx_aggregate_hdl;
  261. init_usb_anchor(&rtlusb->tx_submitted);
  262. for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
  263. skb_queue_head_init(&rtlusb->tx_skb_queue[i]);
  264. init_usb_anchor(&rtlusb->tx_pending[i]);
  265. }
  266. return 0;
  267. }
  268. static void _rtl_rx_work(unsigned long param);
  269. static int _rtl_usb_init_rx(struct ieee80211_hw *hw)
  270. {
  271. struct rtl_priv *rtlpriv = rtl_priv(hw);
  272. struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
  273. struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
  274. rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size;
  275. rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num;
  276. rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num;
  277. rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl;
  278. rtlusb->usb_rx_segregate_hdl =
  279. rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl;
  280. pr_info("rx_max_size %d, rx_urb_num %d, in_ep %d\n",
  281. rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep);
  282. init_usb_anchor(&rtlusb->rx_submitted);
  283. init_usb_anchor(&rtlusb->rx_cleanup_urbs);
  284. skb_queue_head_init(&rtlusb->rx_queue);
  285. rtlusb->rx_work_tasklet.func = _rtl_rx_work;
  286. rtlusb->rx_work_tasklet.data = (unsigned long)rtlusb;
  287. return 0;
  288. }
  289. static int _rtl_usb_init(struct ieee80211_hw *hw)
  290. {
  291. struct rtl_priv *rtlpriv = rtl_priv(hw);
  292. struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
  293. struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
  294. int err;
  295. u8 epidx;
  296. struct usb_interface *usb_intf = rtlusb->intf;
  297. u8 epnums = usb_intf->cur_altsetting->desc.bNumEndpoints;
  298. rtlusb->out_ep_nums = rtlusb->in_ep_nums = 0;
  299. for (epidx = 0; epidx < epnums; epidx++) {
  300. struct usb_endpoint_descriptor *pep_desc;
  301. pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc;
  302. if (usb_endpoint_dir_in(pep_desc))
  303. rtlusb->in_ep_nums++;
  304. else if (usb_endpoint_dir_out(pep_desc))
  305. rtlusb->out_ep_nums++;
  306. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  307. "USB EP(0x%02x), MaxPacketSize=%d, Interval=%d\n",
  308. pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize,
  309. pep_desc->bInterval);
  310. }
  311. if (rtlusb->in_ep_nums < rtlpriv->cfg->usb_interface_cfg->in_ep_num) {
  312. pr_err("Too few input end points found\n");
  313. return -EINVAL;
  314. }
  315. if (rtlusb->out_ep_nums == 0) {
  316. pr_err("No output end points found\n");
  317. return -EINVAL;
  318. }
  319. /* usb endpoint mapping */
  320. err = rtlpriv->cfg->usb_interface_cfg->usb_endpoint_mapping(hw);
  321. rtlusb->usb_mq_to_hwq = rtlpriv->cfg->usb_interface_cfg->usb_mq_to_hwq;
  322. _rtl_usb_init_tx(hw);
  323. _rtl_usb_init_rx(hw);
  324. return err;
  325. }
  326. static void rtl_usb_init_sw(struct ieee80211_hw *hw)
  327. {
  328. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  329. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  330. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  331. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  332. rtlhal->hw = hw;
  333. ppsc->inactiveps = false;
  334. ppsc->leisure_ps = false;
  335. ppsc->fwctrl_lps = false;
  336. ppsc->reg_fwctrl_lps = 3;
  337. ppsc->reg_max_lps_awakeintvl = 5;
  338. ppsc->fwctrl_psmode = FW_PS_DTIM_MODE;
  339. /* IBSS */
  340. mac->beacon_interval = 100;
  341. /* AMPDU */
  342. mac->min_space_cfg = 0;
  343. mac->max_mss_density = 0;
  344. /* set sane AMPDU defaults */
  345. mac->current_ampdu_density = 7;
  346. mac->current_ampdu_factor = 3;
  347. /* QOS */
  348. rtlusb->acm_method = EACMWAY2_SW;
  349. /* IRQ */
  350. /* HIMR - turn all on */
  351. rtlusb->irq_mask[0] = 0xFFFFFFFF;
  352. /* HIMR_EX - turn all on */
  353. rtlusb->irq_mask[1] = 0xFFFFFFFF;
  354. rtlusb->disableHWSM = true;
  355. }
  356. static void _rtl_rx_completed(struct urb *urb);
  357. static int _rtl_prep_rx_urb(struct ieee80211_hw *hw, struct rtl_usb *rtlusb,
  358. struct urb *urb, gfp_t gfp_mask)
  359. {
  360. void *buf;
  361. buf = usb_alloc_coherent(rtlusb->udev, rtlusb->rx_max_size, gfp_mask,
  362. &urb->transfer_dma);
  363. if (!buf) {
  364. pr_err("Failed to usb_alloc_coherent!!\n");
  365. return -ENOMEM;
  366. }
  367. usb_fill_bulk_urb(urb, rtlusb->udev,
  368. usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep),
  369. buf, rtlusb->rx_max_size, _rtl_rx_completed, rtlusb);
  370. urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  371. return 0;
  372. }
  373. static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw,
  374. struct sk_buff *skb)
  375. {
  376. struct rtl_priv *rtlpriv = rtl_priv(hw);
  377. u8 *rxdesc = skb->data;
  378. struct ieee80211_hdr *hdr;
  379. bool unicast = false;
  380. __le16 fc;
  381. struct ieee80211_rx_status rx_status = {0};
  382. struct rtl_stats stats = {
  383. .signal = 0,
  384. .rate = 0,
  385. };
  386. skb_pull(skb, RTL_RX_DESC_SIZE);
  387. rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
  388. skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
  389. hdr = (struct ieee80211_hdr *)(skb->data);
  390. fc = hdr->frame_control;
  391. if (!stats.crc) {
  392. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  393. if (is_broadcast_ether_addr(hdr->addr1)) {
  394. /*TODO*/;
  395. } else if (is_multicast_ether_addr(hdr->addr1)) {
  396. /*TODO*/
  397. } else {
  398. unicast = true;
  399. rtlpriv->stats.rxbytesunicast += skb->len;
  400. }
  401. if (ieee80211_is_data(fc)) {
  402. rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
  403. if (unicast)
  404. rtlpriv->link_info.num_rx_inperiod++;
  405. }
  406. /* static bcn for roaming */
  407. rtl_beacon_statistic(hw, skb);
  408. }
  409. }
  410. static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw,
  411. struct sk_buff *skb)
  412. {
  413. struct rtl_priv *rtlpriv = rtl_priv(hw);
  414. u8 *rxdesc = skb->data;
  415. struct ieee80211_hdr *hdr;
  416. bool unicast = false;
  417. __le16 fc;
  418. struct ieee80211_rx_status rx_status = {0};
  419. struct rtl_stats stats = {
  420. .signal = 0,
  421. .rate = 0,
  422. };
  423. skb_pull(skb, RTL_RX_DESC_SIZE);
  424. rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
  425. skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
  426. hdr = (struct ieee80211_hdr *)(skb->data);
  427. fc = hdr->frame_control;
  428. if (!stats.crc) {
  429. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  430. if (is_broadcast_ether_addr(hdr->addr1)) {
  431. /*TODO*/;
  432. } else if (is_multicast_ether_addr(hdr->addr1)) {
  433. /*TODO*/
  434. } else {
  435. unicast = true;
  436. rtlpriv->stats.rxbytesunicast += skb->len;
  437. }
  438. if (ieee80211_is_data(fc)) {
  439. rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
  440. if (unicast)
  441. rtlpriv->link_info.num_rx_inperiod++;
  442. }
  443. /* static bcn for roaming */
  444. rtl_beacon_statistic(hw, skb);
  445. if (likely(rtl_action_proc(hw, skb, false)))
  446. ieee80211_rx(hw, skb);
  447. else
  448. dev_kfree_skb_any(skb);
  449. } else {
  450. dev_kfree_skb_any(skb);
  451. }
  452. }
  453. static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb)
  454. {
  455. struct sk_buff *_skb;
  456. struct sk_buff_head rx_queue;
  457. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  458. skb_queue_head_init(&rx_queue);
  459. if (rtlusb->usb_rx_segregate_hdl)
  460. rtlusb->usb_rx_segregate_hdl(hw, skb, &rx_queue);
  461. WARN_ON(skb_queue_empty(&rx_queue));
  462. while (!skb_queue_empty(&rx_queue)) {
  463. _skb = skb_dequeue(&rx_queue);
  464. _rtl_usb_rx_process_agg(hw, _skb);
  465. ieee80211_rx(hw, _skb);
  466. }
  467. }
  468. #define __RX_SKB_MAX_QUEUED 64
  469. static void _rtl_rx_work(unsigned long param)
  470. {
  471. struct rtl_usb *rtlusb = (struct rtl_usb *)param;
  472. struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
  473. struct sk_buff *skb;
  474. while ((skb = skb_dequeue(&rtlusb->rx_queue))) {
  475. if (unlikely(IS_USB_STOP(rtlusb))) {
  476. dev_kfree_skb_any(skb);
  477. continue;
  478. }
  479. if (likely(!rtlusb->usb_rx_segregate_hdl)) {
  480. _rtl_usb_rx_process_noagg(hw, skb);
  481. } else {
  482. /* TO DO */
  483. _rtl_rx_pre_process(hw, skb);
  484. pr_err("rx agg not supported\n");
  485. }
  486. }
  487. }
  488. static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr,
  489. unsigned int len)
  490. {
  491. #if NET_IP_ALIGN != 0
  492. unsigned int padding = 0;
  493. #endif
  494. /* make function no-op when possible */
  495. if (NET_IP_ALIGN == 0 || len < sizeof(*hdr))
  496. return 0;
  497. #if NET_IP_ALIGN != 0
  498. /* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */
  499. /* TODO: deduplicate common code, define helper function instead? */
  500. if (ieee80211_is_data_qos(hdr->frame_control)) {
  501. u8 *qc = ieee80211_get_qos_ctl(hdr);
  502. padding ^= NET_IP_ALIGN;
  503. /* Input might be invalid, avoid accessing memory outside
  504. * the buffer.
  505. */
  506. if ((unsigned long)qc - (unsigned long)hdr < len &&
  507. *qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  508. padding ^= NET_IP_ALIGN;
  509. }
  510. if (ieee80211_has_a4(hdr->frame_control))
  511. padding ^= NET_IP_ALIGN;
  512. return padding;
  513. #endif
  514. }
  515. #define __RADIO_TAP_SIZE_RSV 32
  516. static void _rtl_rx_completed(struct urb *_urb)
  517. {
  518. struct rtl_usb *rtlusb = (struct rtl_usb *)_urb->context;
  519. int err = 0;
  520. if (unlikely(IS_USB_STOP(rtlusb)))
  521. goto free;
  522. if (likely(0 == _urb->status)) {
  523. unsigned int padding;
  524. struct sk_buff *skb;
  525. unsigned int qlen;
  526. unsigned int size = _urb->actual_length;
  527. struct ieee80211_hdr *hdr;
  528. if (size < RTL_RX_DESC_SIZE + sizeof(struct ieee80211_hdr)) {
  529. pr_err("Too short packet from bulk IN! (len: %d)\n",
  530. size);
  531. goto resubmit;
  532. }
  533. qlen = skb_queue_len(&rtlusb->rx_queue);
  534. if (qlen >= __RX_SKB_MAX_QUEUED) {
  535. pr_err("Pending RX skbuff queue full! (qlen: %d)\n",
  536. qlen);
  537. goto resubmit;
  538. }
  539. hdr = (void *)(_urb->transfer_buffer + RTL_RX_DESC_SIZE);
  540. padding = _rtl_rx_get_padding(hdr, size - RTL_RX_DESC_SIZE);
  541. skb = dev_alloc_skb(size + __RADIO_TAP_SIZE_RSV + padding);
  542. if (!skb) {
  543. pr_err("Can't allocate skb for bulk IN!\n");
  544. goto resubmit;
  545. }
  546. _rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep);
  547. /* Make sure the payload data is 4 byte aligned. */
  548. skb_reserve(skb, padding);
  549. /* reserve some space for mac80211's radiotap */
  550. skb_reserve(skb, __RADIO_TAP_SIZE_RSV);
  551. skb_put_data(skb, _urb->transfer_buffer, size);
  552. skb_queue_tail(&rtlusb->rx_queue, skb);
  553. tasklet_schedule(&rtlusb->rx_work_tasklet);
  554. goto resubmit;
  555. }
  556. switch (_urb->status) {
  557. /* disconnect */
  558. case -ENOENT:
  559. case -ECONNRESET:
  560. case -ENODEV:
  561. case -ESHUTDOWN:
  562. goto free;
  563. default:
  564. break;
  565. }
  566. resubmit:
  567. usb_anchor_urb(_urb, &rtlusb->rx_submitted);
  568. err = usb_submit_urb(_urb, GFP_ATOMIC);
  569. if (unlikely(err)) {
  570. usb_unanchor_urb(_urb);
  571. goto free;
  572. }
  573. return;
  574. free:
  575. /* On some architectures, usb_free_coherent must not be called from
  576. * hardirq context. Queue urb to cleanup list.
  577. */
  578. usb_anchor_urb(_urb, &rtlusb->rx_cleanup_urbs);
  579. }
  580. #undef __RADIO_TAP_SIZE_RSV
  581. static void _rtl_usb_cleanup_rx(struct ieee80211_hw *hw)
  582. {
  583. struct rtl_priv *rtlpriv = rtl_priv(hw);
  584. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  585. struct urb *urb;
  586. usb_kill_anchored_urbs(&rtlusb->rx_submitted);
  587. tasklet_kill(&rtlusb->rx_work_tasklet);
  588. cancel_work_sync(&rtlpriv->works.lps_change_work);
  589. flush_workqueue(rtlpriv->works.rtl_wq);
  590. destroy_workqueue(rtlpriv->works.rtl_wq);
  591. skb_queue_purge(&rtlusb->rx_queue);
  592. while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
  593. usb_free_coherent(urb->dev, urb->transfer_buffer_length,
  594. urb->transfer_buffer, urb->transfer_dma);
  595. usb_free_urb(urb);
  596. }
  597. }
  598. static int _rtl_usb_receive(struct ieee80211_hw *hw)
  599. {
  600. struct urb *urb;
  601. int err;
  602. int i;
  603. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  604. WARN_ON(0 == rtlusb->rx_urb_num);
  605. /* 1600 == 1514 + max WLAN header + rtk info */
  606. WARN_ON(rtlusb->rx_max_size < 1600);
  607. for (i = 0; i < rtlusb->rx_urb_num; i++) {
  608. err = -ENOMEM;
  609. urb = usb_alloc_urb(0, GFP_KERNEL);
  610. if (!urb)
  611. goto err_out;
  612. err = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL);
  613. if (err < 0) {
  614. pr_err("Failed to prep_rx_urb!!\n");
  615. usb_free_urb(urb);
  616. goto err_out;
  617. }
  618. usb_anchor_urb(urb, &rtlusb->rx_submitted);
  619. err = usb_submit_urb(urb, GFP_KERNEL);
  620. if (err)
  621. goto err_out;
  622. usb_free_urb(urb);
  623. }
  624. return 0;
  625. err_out:
  626. usb_kill_anchored_urbs(&rtlusb->rx_submitted);
  627. _rtl_usb_cleanup_rx(hw);
  628. return err;
  629. }
  630. static int rtl_usb_start(struct ieee80211_hw *hw)
  631. {
  632. int err;
  633. struct rtl_priv *rtlpriv = rtl_priv(hw);
  634. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  635. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  636. err = rtlpriv->cfg->ops->hw_init(hw);
  637. if (!err) {
  638. rtl_init_rx_config(hw);
  639. /* Enable software */
  640. SET_USB_START(rtlusb);
  641. /* should after adapter start and interrupt enable. */
  642. set_hal_start(rtlhal);
  643. /* Start bulk IN */
  644. err = _rtl_usb_receive(hw);
  645. }
  646. return err;
  647. }
  648. /**
  649. *
  650. *
  651. */
  652. /*======================= tx =========================================*/
  653. static void rtl_usb_cleanup(struct ieee80211_hw *hw)
  654. {
  655. u32 i;
  656. struct sk_buff *_skb;
  657. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  658. struct ieee80211_tx_info *txinfo;
  659. /* clean up rx stuff. */
  660. _rtl_usb_cleanup_rx(hw);
  661. /* clean up tx stuff */
  662. for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
  663. while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) {
  664. rtlusb->usb_tx_cleanup(hw, _skb);
  665. txinfo = IEEE80211_SKB_CB(_skb);
  666. ieee80211_tx_info_clear_status(txinfo);
  667. txinfo->flags |= IEEE80211_TX_STAT_ACK;
  668. ieee80211_tx_status_irqsafe(hw, _skb);
  669. }
  670. usb_kill_anchored_urbs(&rtlusb->tx_pending[i]);
  671. }
  672. usb_kill_anchored_urbs(&rtlusb->tx_submitted);
  673. }
  674. /**
  675. *
  676. * We may add some struct into struct rtl_usb later. Do deinit here.
  677. *
  678. */
  679. static void rtl_usb_deinit(struct ieee80211_hw *hw)
  680. {
  681. rtl_usb_cleanup(hw);
  682. }
  683. static void rtl_usb_stop(struct ieee80211_hw *hw)
  684. {
  685. struct rtl_priv *rtlpriv = rtl_priv(hw);
  686. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  687. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  688. struct urb *urb;
  689. /* should after adapter start and interrupt enable. */
  690. set_hal_stop(rtlhal);
  691. cancel_work_sync(&rtlpriv->works.fill_h2c_cmd);
  692. /* Enable software */
  693. SET_USB_STOP(rtlusb);
  694. /* free pre-allocated URBs from rtl_usb_start() */
  695. usb_kill_anchored_urbs(&rtlusb->rx_submitted);
  696. tasklet_kill(&rtlusb->rx_work_tasklet);
  697. cancel_work_sync(&rtlpriv->works.lps_change_work);
  698. flush_workqueue(rtlpriv->works.rtl_wq);
  699. skb_queue_purge(&rtlusb->rx_queue);
  700. while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
  701. usb_free_coherent(urb->dev, urb->transfer_buffer_length,
  702. urb->transfer_buffer, urb->transfer_dma);
  703. usb_free_urb(urb);
  704. }
  705. rtlpriv->cfg->ops->hw_disable(hw);
  706. }
  707. static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb)
  708. {
  709. int err;
  710. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  711. usb_anchor_urb(_urb, &rtlusb->tx_submitted);
  712. err = usb_submit_urb(_urb, GFP_ATOMIC);
  713. if (err < 0) {
  714. struct sk_buff *skb;
  715. pr_err("Failed to submit urb\n");
  716. usb_unanchor_urb(_urb);
  717. skb = (struct sk_buff *)_urb->context;
  718. kfree_skb(skb);
  719. }
  720. usb_free_urb(_urb);
  721. }
  722. static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb,
  723. struct sk_buff *skb)
  724. {
  725. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  726. struct ieee80211_tx_info *txinfo;
  727. rtlusb->usb_tx_post_hdl(hw, urb, skb);
  728. skb_pull(skb, RTL_TX_HEADER_SIZE);
  729. txinfo = IEEE80211_SKB_CB(skb);
  730. ieee80211_tx_info_clear_status(txinfo);
  731. txinfo->flags |= IEEE80211_TX_STAT_ACK;
  732. if (urb->status) {
  733. pr_err("Urb has error status 0x%X\n", urb->status);
  734. goto out;
  735. }
  736. /* TODO: statistics */
  737. out:
  738. ieee80211_tx_status_irqsafe(hw, skb);
  739. return urb->status;
  740. }
  741. static void _rtl_tx_complete(struct urb *urb)
  742. {
  743. struct sk_buff *skb = (struct sk_buff *)urb->context;
  744. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  745. struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0];
  746. struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
  747. int err;
  748. if (unlikely(IS_USB_STOP(rtlusb)))
  749. return;
  750. err = _usb_tx_post(hw, urb, skb);
  751. if (err) {
  752. /* Ignore error and keep issuiing other urbs */
  753. return;
  754. }
  755. }
  756. static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw,
  757. struct sk_buff *skb, u32 ep_num)
  758. {
  759. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  760. struct urb *_urb;
  761. WARN_ON(NULL == skb);
  762. _urb = usb_alloc_urb(0, GFP_ATOMIC);
  763. if (!_urb) {
  764. kfree_skb(skb);
  765. return NULL;
  766. }
  767. _rtl_install_trx_info(rtlusb, skb, ep_num);
  768. usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev,
  769. ep_num), skb->data, skb->len, _rtl_tx_complete, skb);
  770. _urb->transfer_flags |= URB_ZERO_PACKET;
  771. return _urb;
  772. }
  773. static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
  774. enum rtl_txq qnum)
  775. {
  776. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  777. u32 ep_num;
  778. struct urb *_urb = NULL;
  779. struct sk_buff *_skb = NULL;
  780. WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl);
  781. if (unlikely(IS_USB_STOP(rtlusb))) {
  782. pr_err("USB device is stopping...\n");
  783. kfree_skb(skb);
  784. return;
  785. }
  786. ep_num = rtlusb->ep_map.ep_mapping[qnum];
  787. _skb = skb;
  788. _urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num);
  789. if (unlikely(!_urb)) {
  790. pr_err("Can't allocate urb. Drop skb!\n");
  791. kfree_skb(skb);
  792. return;
  793. }
  794. _rtl_submit_tx_urb(hw, _urb);
  795. }
  796. static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw,
  797. struct ieee80211_sta *sta,
  798. struct sk_buff *skb,
  799. u16 hw_queue)
  800. {
  801. struct rtl_priv *rtlpriv = rtl_priv(hw);
  802. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  803. struct rtl_tx_desc *pdesc = NULL;
  804. struct rtl_tcb_desc tcb_desc;
  805. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  806. __le16 fc = hdr->frame_control;
  807. u8 *pda_addr = hdr->addr1;
  808. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  809. if (ieee80211_is_auth(fc)) {
  810. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  811. }
  812. if (rtlpriv->psc.sw_ps_enabled) {
  813. if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
  814. !ieee80211_has_pm(fc))
  815. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  816. }
  817. rtl_action_proc(hw, skb, true);
  818. if (is_multicast_ether_addr(pda_addr))
  819. rtlpriv->stats.txbytesmulticast += skb->len;
  820. else if (is_broadcast_ether_addr(pda_addr))
  821. rtlpriv->stats.txbytesbroadcast += skb->len;
  822. else
  823. rtlpriv->stats.txbytesunicast += skb->len;
  824. rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, NULL, info, sta, skb,
  825. hw_queue, &tcb_desc);
  826. if (ieee80211_is_data(fc))
  827. rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
  828. }
  829. static int rtl_usb_tx(struct ieee80211_hw *hw,
  830. struct ieee80211_sta *sta,
  831. struct sk_buff *skb,
  832. struct rtl_tcb_desc *dummy)
  833. {
  834. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  835. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  836. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  837. __le16 fc = hdr->frame_control;
  838. u16 hw_queue;
  839. if (unlikely(is_hal_stop(rtlhal)))
  840. goto err_free;
  841. hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb));
  842. _rtl_usb_tx_preprocess(hw, sta, skb, hw_queue);
  843. _rtl_usb_transmit(hw, skb, hw_queue);
  844. return NETDEV_TX_OK;
  845. err_free:
  846. dev_kfree_skb_any(skb);
  847. return NETDEV_TX_OK;
  848. }
  849. static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw,
  850. struct ieee80211_sta *sta,
  851. struct sk_buff *skb)
  852. {
  853. return false;
  854. }
  855. static void rtl_fill_h2c_cmd_work_callback(struct work_struct *work)
  856. {
  857. struct rtl_works *rtlworks =
  858. container_of(work, struct rtl_works, fill_h2c_cmd);
  859. struct ieee80211_hw *hw = rtlworks->hw;
  860. struct rtl_priv *rtlpriv = rtl_priv(hw);
  861. rtlpriv->cfg->ops->fill_h2c_cmd(hw, H2C_RA_MASK, 5, rtlpriv->rate_mask);
  862. }
  863. static const struct rtl_intf_ops rtl_usb_ops = {
  864. .adapter_start = rtl_usb_start,
  865. .adapter_stop = rtl_usb_stop,
  866. .adapter_tx = rtl_usb_tx,
  867. .waitq_insert = rtl_usb_tx_chk_waitq_insert,
  868. };
  869. int rtl_usb_probe(struct usb_interface *intf,
  870. const struct usb_device_id *id,
  871. struct rtl_hal_cfg *rtl_hal_cfg)
  872. {
  873. int err;
  874. struct ieee80211_hw *hw = NULL;
  875. struct rtl_priv *rtlpriv = NULL;
  876. struct usb_device *udev;
  877. struct rtl_usb_priv *usb_priv;
  878. hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) +
  879. sizeof(struct rtl_usb_priv), &rtl_ops);
  880. if (!hw) {
  881. WARN_ONCE(true, "rtl_usb: ieee80211 alloc failed\n");
  882. return -ENOMEM;
  883. }
  884. rtlpriv = hw->priv;
  885. rtlpriv->hw = hw;
  886. rtlpriv->usb_data = kcalloc(RTL_USB_MAX_RX_COUNT, sizeof(u32),
  887. GFP_KERNEL);
  888. if (!rtlpriv->usb_data) {
  889. ieee80211_free_hw(hw);
  890. return -ENOMEM;
  891. }
  892. /* this spin lock must be initialized early */
  893. spin_lock_init(&rtlpriv->locks.usb_lock);
  894. INIT_WORK(&rtlpriv->works.fill_h2c_cmd,
  895. rtl_fill_h2c_cmd_work_callback);
  896. INIT_WORK(&rtlpriv->works.lps_change_work,
  897. rtl_lps_change_work_callback);
  898. rtlpriv->usb_data_index = 0;
  899. init_completion(&rtlpriv->firmware_loading_complete);
  900. SET_IEEE80211_DEV(hw, &intf->dev);
  901. udev = interface_to_usbdev(intf);
  902. usb_get_dev(udev);
  903. usb_priv = rtl_usbpriv(hw);
  904. memset(usb_priv, 0, sizeof(*usb_priv));
  905. usb_priv->dev.intf = intf;
  906. usb_priv->dev.udev = udev;
  907. usb_set_intfdata(intf, hw);
  908. /* init cfg & intf_ops */
  909. rtlpriv->rtlhal.interface = INTF_USB;
  910. rtlpriv->cfg = rtl_hal_cfg;
  911. rtlpriv->intf_ops = &rtl_usb_ops;
  912. /* Init IO handler */
  913. _rtl_usb_io_handler_init(&udev->dev, hw);
  914. rtlpriv->cfg->ops->read_chip_version(hw);
  915. /*like read eeprom and so on */
  916. rtlpriv->cfg->ops->read_eeprom_info(hw);
  917. err = _rtl_usb_init(hw);
  918. if (err)
  919. goto error_out2;
  920. rtl_usb_init_sw(hw);
  921. /* Init mac80211 sw */
  922. err = rtl_init_core(hw);
  923. if (err) {
  924. pr_err("Can't allocate sw for mac80211\n");
  925. goto error_out2;
  926. }
  927. if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
  928. pr_err("Can't init_sw_vars\n");
  929. goto error_out;
  930. }
  931. rtlpriv->cfg->ops->init_sw_leds(hw);
  932. err = ieee80211_register_hw(hw);
  933. if (err) {
  934. pr_err("Can't register mac80211 hw.\n");
  935. err = -ENODEV;
  936. goto error_out;
  937. }
  938. rtlpriv->mac80211.mac80211_registered = 1;
  939. set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  940. return 0;
  941. error_out:
  942. rtl_deinit_core(hw);
  943. error_out2:
  944. _rtl_usb_io_handler_release(hw);
  945. usb_put_dev(udev);
  946. complete(&rtlpriv->firmware_loading_complete);
  947. kfree(rtlpriv->usb_data);
  948. return -ENODEV;
  949. }
  950. EXPORT_SYMBOL(rtl_usb_probe);
  951. void rtl_usb_disconnect(struct usb_interface *intf)
  952. {
  953. struct ieee80211_hw *hw = usb_get_intfdata(intf);
  954. struct rtl_priv *rtlpriv = rtl_priv(hw);
  955. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  956. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  957. if (unlikely(!rtlpriv))
  958. return;
  959. /* just in case driver is removed before firmware callback */
  960. wait_for_completion(&rtlpriv->firmware_loading_complete);
  961. clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  962. /*ieee80211_unregister_hw will call ops_stop */
  963. if (rtlmac->mac80211_registered == 1) {
  964. ieee80211_unregister_hw(hw);
  965. rtlmac->mac80211_registered = 0;
  966. } else {
  967. rtl_deinit_deferred_work(hw, false);
  968. rtlpriv->intf_ops->adapter_stop(hw);
  969. }
  970. /*deinit rfkill */
  971. /* rtl_deinit_rfkill(hw); */
  972. rtl_usb_deinit(hw);
  973. rtl_deinit_core(hw);
  974. kfree(rtlpriv->usb_data);
  975. rtlpriv->cfg->ops->deinit_sw_leds(hw);
  976. rtlpriv->cfg->ops->deinit_sw_vars(hw);
  977. _rtl_usb_io_handler_release(hw);
  978. usb_put_dev(rtlusb->udev);
  979. usb_set_intfdata(intf, NULL);
  980. ieee80211_free_hw(hw);
  981. }
  982. EXPORT_SYMBOL(rtl_usb_disconnect);
  983. int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message)
  984. {
  985. return 0;
  986. }
  987. EXPORT_SYMBOL(rtl_usb_suspend);
  988. int rtl_usb_resume(struct usb_interface *pusb_intf)
  989. {
  990. return 0;
  991. }
  992. EXPORT_SYMBOL(rtl_usb_resume);