usb.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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. usb_unanchor_urb(urb);
  622. usb_free_urb(urb);
  623. goto err_out;
  624. }
  625. usb_free_urb(urb);
  626. }
  627. return 0;
  628. err_out:
  629. usb_kill_anchored_urbs(&rtlusb->rx_submitted);
  630. _rtl_usb_cleanup_rx(hw);
  631. return err;
  632. }
  633. static int rtl_usb_start(struct ieee80211_hw *hw)
  634. {
  635. int err;
  636. struct rtl_priv *rtlpriv = rtl_priv(hw);
  637. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  638. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  639. err = rtlpriv->cfg->ops->hw_init(hw);
  640. if (!err) {
  641. rtl_init_rx_config(hw);
  642. /* Enable software */
  643. SET_USB_START(rtlusb);
  644. /* should after adapter start and interrupt enable. */
  645. set_hal_start(rtlhal);
  646. /* Start bulk IN */
  647. err = _rtl_usb_receive(hw);
  648. }
  649. return err;
  650. }
  651. /**
  652. *
  653. *
  654. */
  655. /*======================= tx =========================================*/
  656. static void rtl_usb_cleanup(struct ieee80211_hw *hw)
  657. {
  658. u32 i;
  659. struct sk_buff *_skb;
  660. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  661. struct ieee80211_tx_info *txinfo;
  662. /* clean up rx stuff. */
  663. _rtl_usb_cleanup_rx(hw);
  664. /* clean up tx stuff */
  665. for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
  666. while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) {
  667. rtlusb->usb_tx_cleanup(hw, _skb);
  668. txinfo = IEEE80211_SKB_CB(_skb);
  669. ieee80211_tx_info_clear_status(txinfo);
  670. txinfo->flags |= IEEE80211_TX_STAT_ACK;
  671. ieee80211_tx_status_irqsafe(hw, _skb);
  672. }
  673. usb_kill_anchored_urbs(&rtlusb->tx_pending[i]);
  674. }
  675. usb_kill_anchored_urbs(&rtlusb->tx_submitted);
  676. }
  677. /**
  678. *
  679. * We may add some struct into struct rtl_usb later. Do deinit here.
  680. *
  681. */
  682. static void rtl_usb_deinit(struct ieee80211_hw *hw)
  683. {
  684. rtl_usb_cleanup(hw);
  685. }
  686. static void rtl_usb_stop(struct ieee80211_hw *hw)
  687. {
  688. struct rtl_priv *rtlpriv = rtl_priv(hw);
  689. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  690. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  691. struct urb *urb;
  692. /* should after adapter start and interrupt enable. */
  693. set_hal_stop(rtlhal);
  694. cancel_work_sync(&rtlpriv->works.fill_h2c_cmd);
  695. /* Enable software */
  696. SET_USB_STOP(rtlusb);
  697. /* free pre-allocated URBs from rtl_usb_start() */
  698. usb_kill_anchored_urbs(&rtlusb->rx_submitted);
  699. tasklet_kill(&rtlusb->rx_work_tasklet);
  700. cancel_work_sync(&rtlpriv->works.lps_change_work);
  701. flush_workqueue(rtlpriv->works.rtl_wq);
  702. skb_queue_purge(&rtlusb->rx_queue);
  703. while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
  704. usb_free_coherent(urb->dev, urb->transfer_buffer_length,
  705. urb->transfer_buffer, urb->transfer_dma);
  706. usb_free_urb(urb);
  707. }
  708. rtlpriv->cfg->ops->hw_disable(hw);
  709. }
  710. static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb)
  711. {
  712. int err;
  713. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  714. usb_anchor_urb(_urb, &rtlusb->tx_submitted);
  715. err = usb_submit_urb(_urb, GFP_ATOMIC);
  716. if (err < 0) {
  717. struct sk_buff *skb;
  718. pr_err("Failed to submit urb\n");
  719. usb_unanchor_urb(_urb);
  720. skb = (struct sk_buff *)_urb->context;
  721. kfree_skb(skb);
  722. }
  723. usb_free_urb(_urb);
  724. }
  725. static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb,
  726. struct sk_buff *skb)
  727. {
  728. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  729. struct ieee80211_tx_info *txinfo;
  730. rtlusb->usb_tx_post_hdl(hw, urb, skb);
  731. skb_pull(skb, RTL_TX_HEADER_SIZE);
  732. txinfo = IEEE80211_SKB_CB(skb);
  733. ieee80211_tx_info_clear_status(txinfo);
  734. txinfo->flags |= IEEE80211_TX_STAT_ACK;
  735. if (urb->status) {
  736. pr_err("Urb has error status 0x%X\n", urb->status);
  737. goto out;
  738. }
  739. /* TODO: statistics */
  740. out:
  741. ieee80211_tx_status_irqsafe(hw, skb);
  742. return urb->status;
  743. }
  744. static void _rtl_tx_complete(struct urb *urb)
  745. {
  746. struct sk_buff *skb = (struct sk_buff *)urb->context;
  747. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  748. struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0];
  749. struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
  750. int err;
  751. if (unlikely(IS_USB_STOP(rtlusb)))
  752. return;
  753. err = _usb_tx_post(hw, urb, skb);
  754. if (err) {
  755. /* Ignore error and keep issuiing other urbs */
  756. return;
  757. }
  758. }
  759. static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw,
  760. struct sk_buff *skb, u32 ep_num)
  761. {
  762. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  763. struct urb *_urb;
  764. WARN_ON(NULL == skb);
  765. _urb = usb_alloc_urb(0, GFP_ATOMIC);
  766. if (!_urb)
  767. return NULL;
  768. _rtl_install_trx_info(rtlusb, skb, ep_num);
  769. usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev,
  770. ep_num), skb->data, skb->len, _rtl_tx_complete, skb);
  771. _urb->transfer_flags |= URB_ZERO_PACKET;
  772. return _urb;
  773. }
  774. static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
  775. enum rtl_txq qnum)
  776. {
  777. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  778. u32 ep_num;
  779. struct urb *_urb = 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. _urb = _rtl_usb_tx_urb_setup(hw, skb, ep_num);
  788. if (unlikely(!_urb)) {
  789. pr_err("Can't allocate urb. Drop skb!\n");
  790. kfree_skb(skb);
  791. return;
  792. }
  793. _rtl_submit_tx_urb(hw, _urb);
  794. }
  795. static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw,
  796. struct ieee80211_sta *sta,
  797. struct sk_buff *skb,
  798. u16 hw_queue)
  799. {
  800. struct rtl_priv *rtlpriv = rtl_priv(hw);
  801. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  802. struct rtl_tx_desc *pdesc = NULL;
  803. struct rtl_tcb_desc tcb_desc;
  804. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  805. __le16 fc = hdr->frame_control;
  806. u8 *pda_addr = hdr->addr1;
  807. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  808. if (ieee80211_is_auth(fc)) {
  809. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  810. }
  811. if (rtlpriv->psc.sw_ps_enabled) {
  812. if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
  813. !ieee80211_has_pm(fc))
  814. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  815. }
  816. rtl_action_proc(hw, skb, true);
  817. if (is_multicast_ether_addr(pda_addr))
  818. rtlpriv->stats.txbytesmulticast += skb->len;
  819. else if (is_broadcast_ether_addr(pda_addr))
  820. rtlpriv->stats.txbytesbroadcast += skb->len;
  821. else
  822. rtlpriv->stats.txbytesunicast += skb->len;
  823. rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, NULL, info, sta, skb,
  824. hw_queue, &tcb_desc);
  825. if (ieee80211_is_data(fc))
  826. rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
  827. }
  828. static int rtl_usb_tx(struct ieee80211_hw *hw,
  829. struct ieee80211_sta *sta,
  830. struct sk_buff *skb,
  831. struct rtl_tcb_desc *dummy)
  832. {
  833. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  834. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  835. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  836. __le16 fc = hdr->frame_control;
  837. u16 hw_queue;
  838. if (unlikely(is_hal_stop(rtlhal)))
  839. goto err_free;
  840. hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb));
  841. _rtl_usb_tx_preprocess(hw, sta, skb, hw_queue);
  842. _rtl_usb_transmit(hw, skb, hw_queue);
  843. return NETDEV_TX_OK;
  844. err_free:
  845. dev_kfree_skb_any(skb);
  846. return NETDEV_TX_OK;
  847. }
  848. static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw,
  849. struct ieee80211_sta *sta,
  850. struct sk_buff *skb)
  851. {
  852. return false;
  853. }
  854. static void rtl_fill_h2c_cmd_work_callback(struct work_struct *work)
  855. {
  856. struct rtl_works *rtlworks =
  857. container_of(work, struct rtl_works, fill_h2c_cmd);
  858. struct ieee80211_hw *hw = rtlworks->hw;
  859. struct rtl_priv *rtlpriv = rtl_priv(hw);
  860. rtlpriv->cfg->ops->fill_h2c_cmd(hw, H2C_RA_MASK, 5, rtlpriv->rate_mask);
  861. }
  862. static const struct rtl_intf_ops rtl_usb_ops = {
  863. .adapter_start = rtl_usb_start,
  864. .adapter_stop = rtl_usb_stop,
  865. .adapter_tx = rtl_usb_tx,
  866. .waitq_insert = rtl_usb_tx_chk_waitq_insert,
  867. };
  868. int rtl_usb_probe(struct usb_interface *intf,
  869. const struct usb_device_id *id,
  870. struct rtl_hal_cfg *rtl_hal_cfg)
  871. {
  872. int err;
  873. struct ieee80211_hw *hw = NULL;
  874. struct rtl_priv *rtlpriv = NULL;
  875. struct usb_device *udev;
  876. struct rtl_usb_priv *usb_priv;
  877. hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) +
  878. sizeof(struct rtl_usb_priv), &rtl_ops);
  879. if (!hw) {
  880. WARN_ONCE(true, "rtl_usb: ieee80211 alloc failed\n");
  881. return -ENOMEM;
  882. }
  883. rtlpriv = hw->priv;
  884. rtlpriv->hw = hw;
  885. rtlpriv->usb_data = kcalloc(RTL_USB_MAX_RX_COUNT, sizeof(u32),
  886. GFP_KERNEL);
  887. if (!rtlpriv->usb_data) {
  888. ieee80211_free_hw(hw);
  889. return -ENOMEM;
  890. }
  891. /* this spin lock must be initialized early */
  892. spin_lock_init(&rtlpriv->locks.usb_lock);
  893. INIT_WORK(&rtlpriv->works.fill_h2c_cmd,
  894. rtl_fill_h2c_cmd_work_callback);
  895. INIT_WORK(&rtlpriv->works.lps_change_work,
  896. rtl_lps_change_work_callback);
  897. rtlpriv->usb_data_index = 0;
  898. init_completion(&rtlpriv->firmware_loading_complete);
  899. SET_IEEE80211_DEV(hw, &intf->dev);
  900. udev = interface_to_usbdev(intf);
  901. usb_get_dev(udev);
  902. usb_priv = rtl_usbpriv(hw);
  903. memset(usb_priv, 0, sizeof(*usb_priv));
  904. usb_priv->dev.intf = intf;
  905. usb_priv->dev.udev = udev;
  906. usb_set_intfdata(intf, hw);
  907. /* init cfg & intf_ops */
  908. rtlpriv->rtlhal.interface = INTF_USB;
  909. rtlpriv->cfg = rtl_hal_cfg;
  910. rtlpriv->intf_ops = &rtl_usb_ops;
  911. /* Init IO handler */
  912. _rtl_usb_io_handler_init(&udev->dev, hw);
  913. rtlpriv->cfg->ops->read_chip_version(hw);
  914. /*like read eeprom and so on */
  915. rtlpriv->cfg->ops->read_eeprom_info(hw);
  916. err = _rtl_usb_init(hw);
  917. if (err)
  918. goto error_out2;
  919. rtl_usb_init_sw(hw);
  920. /* Init mac80211 sw */
  921. err = rtl_init_core(hw);
  922. if (err) {
  923. pr_err("Can't allocate sw for mac80211\n");
  924. goto error_out2;
  925. }
  926. if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
  927. pr_err("Can't init_sw_vars\n");
  928. goto error_out;
  929. }
  930. rtlpriv->cfg->ops->init_sw_leds(hw);
  931. err = ieee80211_register_hw(hw);
  932. if (err) {
  933. pr_err("Can't register mac80211 hw.\n");
  934. err = -ENODEV;
  935. goto error_out;
  936. }
  937. rtlpriv->mac80211.mac80211_registered = 1;
  938. set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  939. return 0;
  940. error_out:
  941. rtl_deinit_core(hw);
  942. error_out2:
  943. _rtl_usb_io_handler_release(hw);
  944. usb_put_dev(udev);
  945. complete(&rtlpriv->firmware_loading_complete);
  946. kfree(rtlpriv->usb_data);
  947. return -ENODEV;
  948. }
  949. EXPORT_SYMBOL(rtl_usb_probe);
  950. void rtl_usb_disconnect(struct usb_interface *intf)
  951. {
  952. struct ieee80211_hw *hw = usb_get_intfdata(intf);
  953. struct rtl_priv *rtlpriv = rtl_priv(hw);
  954. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  955. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  956. if (unlikely(!rtlpriv))
  957. return;
  958. /* just in case driver is removed before firmware callback */
  959. wait_for_completion(&rtlpriv->firmware_loading_complete);
  960. clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  961. /*ieee80211_unregister_hw will call ops_stop */
  962. if (rtlmac->mac80211_registered == 1) {
  963. ieee80211_unregister_hw(hw);
  964. rtlmac->mac80211_registered = 0;
  965. } else {
  966. rtl_deinit_deferred_work(hw, false);
  967. rtlpriv->intf_ops->adapter_stop(hw);
  968. }
  969. /*deinit rfkill */
  970. /* rtl_deinit_rfkill(hw); */
  971. rtl_usb_deinit(hw);
  972. rtl_deinit_core(hw);
  973. kfree(rtlpriv->usb_data);
  974. rtlpriv->cfg->ops->deinit_sw_leds(hw);
  975. rtlpriv->cfg->ops->deinit_sw_vars(hw);
  976. _rtl_usb_io_handler_release(hw);
  977. usb_put_dev(rtlusb->udev);
  978. usb_set_intfdata(intf, NULL);
  979. ieee80211_free_hw(hw);
  980. }
  981. EXPORT_SYMBOL(rtl_usb_disconnect);
  982. int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message)
  983. {
  984. return 0;
  985. }
  986. EXPORT_SYMBOL(rtl_usb_suspend);
  987. int rtl_usb_resume(struct usb_interface *pusb_intf)
  988. {
  989. return 0;
  990. }
  991. EXPORT_SYMBOL(rtl_usb_resume);