rt2x00usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00usb
  19. Abstract: rt2x00 generic usb device routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/usb.h>
  24. #include <linux/bug.h>
  25. #include "rt2x00.h"
  26. #include "rt2x00usb.h"
  27. /*
  28. * Interfacing with the HW.
  29. */
  30. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  31. const u8 request, const u8 requesttype,
  32. const u16 offset, const u16 value,
  33. void *buffer, const u16 buffer_length,
  34. const int timeout)
  35. {
  36. struct usb_device *usb_dev =
  37. interface_to_usbdev(to_usb_interface(rt2x00dev->dev));
  38. int status;
  39. unsigned int i;
  40. unsigned int pipe =
  41. (requesttype == USB_VENDOR_REQUEST_IN) ?
  42. usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0);
  43. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  44. status = usb_control_msg(usb_dev, pipe, request, requesttype,
  45. value, offset, buffer, buffer_length,
  46. timeout);
  47. if (status >= 0)
  48. return 0;
  49. /*
  50. * Check for errors
  51. * -ENODEV: Device has disappeared, no point continuing.
  52. * All other errors: Try again.
  53. */
  54. else if (status == -ENODEV)
  55. break;
  56. }
  57. ERROR(rt2x00dev,
  58. "Vendor Request 0x%02x failed for offset 0x%04x with error %d.\n",
  59. request, offset, status);
  60. return status;
  61. }
  62. EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request);
  63. int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
  64. const u8 request, const u8 requesttype,
  65. const u16 offset, void *buffer,
  66. const u16 buffer_length, const int timeout)
  67. {
  68. int status;
  69. BUG_ON(!mutex_is_locked(&rt2x00dev->usb_cache_mutex));
  70. /*
  71. * Check for Cache availability.
  72. */
  73. if (unlikely(!rt2x00dev->csr.cache || buffer_length > CSR_CACHE_SIZE)) {
  74. ERROR(rt2x00dev, "CSR cache not available.\n");
  75. return -ENOMEM;
  76. }
  77. if (requesttype == USB_VENDOR_REQUEST_OUT)
  78. memcpy(rt2x00dev->csr.cache, buffer, buffer_length);
  79. status = rt2x00usb_vendor_request(rt2x00dev, request, requesttype,
  80. offset, 0, rt2x00dev->csr.cache,
  81. buffer_length, timeout);
  82. if (!status && requesttype == USB_VENDOR_REQUEST_IN)
  83. memcpy(buffer, rt2x00dev->csr.cache, buffer_length);
  84. return status;
  85. }
  86. EXPORT_SYMBOL_GPL(rt2x00usb_vendor_req_buff_lock);
  87. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  88. const u8 request, const u8 requesttype,
  89. const u16 offset, void *buffer,
  90. const u16 buffer_length, const int timeout)
  91. {
  92. int status;
  93. mutex_lock(&rt2x00dev->usb_cache_mutex);
  94. status = rt2x00usb_vendor_req_buff_lock(rt2x00dev, request,
  95. requesttype, offset, buffer,
  96. buffer_length, timeout);
  97. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  98. return status;
  99. }
  100. EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request_buff);
  101. /*
  102. * TX data handlers.
  103. */
  104. static void rt2x00usb_interrupt_txdone(struct urb *urb)
  105. {
  106. struct queue_entry *entry = (struct queue_entry *)urb->context;
  107. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  108. struct txdone_entry_desc txdesc;
  109. enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
  110. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
  111. !__test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
  112. return;
  113. /*
  114. * Remove the descriptor data from the buffer.
  115. */
  116. skb_pull(entry->skb, entry->queue->desc_size);
  117. /*
  118. * Obtain the status about this packet.
  119. * Note that when the status is 0 it does not mean the
  120. * frame was send out correctly. It only means the frame
  121. * was succesfully pushed to the hardware, we have no
  122. * way to determine the transmission status right now.
  123. * (Only indirectly by looking at the failed TX counters
  124. * in the register).
  125. */
  126. if (!urb->status)
  127. __set_bit(TXDONE_UNKNOWN, &txdesc.flags);
  128. else
  129. __set_bit(TXDONE_FAILURE, &txdesc.flags);
  130. txdesc.retry = 0;
  131. rt2x00lib_txdone(entry, &txdesc);
  132. /*
  133. * Make this entry available for reuse.
  134. */
  135. entry->flags = 0;
  136. rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
  137. /*
  138. * If the data queue was below the threshold before the txdone
  139. * handler we must make sure the packet queue in the mac80211 stack
  140. * is reenabled when the txdone handler has finished.
  141. */
  142. if (!rt2x00queue_threshold(entry->queue))
  143. ieee80211_wake_queue(rt2x00dev->hw, qid);
  144. }
  145. int rt2x00usb_write_tx_data(struct queue_entry *entry)
  146. {
  147. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  148. struct usb_device *usb_dev =
  149. interface_to_usbdev(to_usb_interface(rt2x00dev->dev));
  150. struct queue_entry_priv_usb *entry_priv = entry->priv_data;
  151. struct skb_frame_desc *skbdesc;
  152. u32 length;
  153. /*
  154. * Add the descriptor in front of the skb.
  155. */
  156. skb_push(entry->skb, entry->queue->desc_size);
  157. memset(entry->skb->data, 0, entry->queue->desc_size);
  158. /*
  159. * Fill in skb descriptor
  160. */
  161. skbdesc = get_skb_frame_desc(entry->skb);
  162. memset(skbdesc, 0, sizeof(*skbdesc));
  163. skbdesc->desc = entry->skb->data;
  164. skbdesc->desc_len = entry->queue->desc_size;
  165. skbdesc->entry = entry;
  166. /*
  167. * USB devices cannot blindly pass the skb->len as the
  168. * length of the data to usb_fill_bulk_urb. Pass the skb
  169. * to the driver to determine what the length should be.
  170. */
  171. length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, entry->skb);
  172. usb_fill_bulk_urb(entry_priv->urb, usb_dev,
  173. usb_sndbulkpipe(usb_dev, 1),
  174. entry->skb->data, length,
  175. rt2x00usb_interrupt_txdone, entry);
  176. return 0;
  177. }
  178. EXPORT_SYMBOL_GPL(rt2x00usb_write_tx_data);
  179. static inline void rt2x00usb_kick_tx_entry(struct queue_entry *entry)
  180. {
  181. struct queue_entry_priv_usb *entry_priv = entry->priv_data;
  182. if (__test_and_clear_bit(ENTRY_DATA_PENDING, &entry->flags))
  183. usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
  184. }
  185. void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  186. const enum data_queue_qid qid)
  187. {
  188. struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, qid);
  189. unsigned long irqflags;
  190. unsigned int index;
  191. unsigned int index_done;
  192. unsigned int i;
  193. /*
  194. * Only protect the range we are going to loop over,
  195. * if during our loop a extra entry is set to pending
  196. * it should not be kicked during this run, since it
  197. * is part of another TX operation.
  198. */
  199. spin_lock_irqsave(&queue->lock, irqflags);
  200. index = queue->index[Q_INDEX];
  201. index_done = queue->index[Q_INDEX_DONE];
  202. spin_unlock_irqrestore(&queue->lock, irqflags);
  203. /*
  204. * Start from the TX done pointer, this guarentees that we will
  205. * send out all frames in the correct order.
  206. */
  207. if (index_done < index) {
  208. for (i = index_done; i < index; i++)
  209. rt2x00usb_kick_tx_entry(&queue->entries[i]);
  210. } else {
  211. for (i = index_done; i < queue->limit; i++)
  212. rt2x00usb_kick_tx_entry(&queue->entries[i]);
  213. for (i = 0; i < index; i++)
  214. rt2x00usb_kick_tx_entry(&queue->entries[i]);
  215. }
  216. }
  217. EXPORT_SYMBOL_GPL(rt2x00usb_kick_tx_queue);
  218. /*
  219. * RX data handlers.
  220. */
  221. static void rt2x00usb_interrupt_rxdone(struct urb *urb)
  222. {
  223. struct queue_entry *entry = (struct queue_entry *)urb->context;
  224. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  225. struct sk_buff *skb;
  226. struct skb_frame_desc *skbdesc;
  227. struct rxdone_entry_desc rxdesc;
  228. u8 rxd[32];
  229. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
  230. !test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
  231. return;
  232. /*
  233. * Check if the received data is simply too small
  234. * to be actually valid, or if the urb is signaling
  235. * a problem.
  236. */
  237. if (urb->actual_length < entry->queue->desc_size || urb->status)
  238. goto skip_entry;
  239. /*
  240. * Fill in skb descriptor
  241. */
  242. skbdesc = get_skb_frame_desc(entry->skb);
  243. memset(skbdesc, 0, sizeof(*skbdesc));
  244. skbdesc->entry = entry;
  245. skbdesc->desc = rxd;
  246. skbdesc->desc_len = entry->queue->desc_size;
  247. memset(&rxdesc, 0, sizeof(rxdesc));
  248. rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
  249. /*
  250. * Allocate a new sk buffer to replace the current one.
  251. * If allocation fails, we should drop the current frame
  252. * so we can recycle the existing sk buffer for the new frame.
  253. */
  254. skb = rt2x00queue_alloc_rxskb(entry->queue);
  255. if (!skb)
  256. goto skip_entry;
  257. /*
  258. * Send the frame to rt2x00lib for further processing.
  259. */
  260. rt2x00lib_rxdone(entry, &rxdesc);
  261. /*
  262. * Replace current entry's skb with the newly allocated one,
  263. * and reinitialize the urb.
  264. */
  265. entry->skb = skb;
  266. urb->transfer_buffer = entry->skb->data;
  267. urb->transfer_buffer_length = entry->skb->len;
  268. skip_entry:
  269. if (test_bit(DEVICE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags)) {
  270. __set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
  271. usb_submit_urb(urb, GFP_ATOMIC);
  272. }
  273. rt2x00queue_index_inc(entry->queue, Q_INDEX);
  274. }
  275. /*
  276. * Radio handlers
  277. */
  278. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  279. {
  280. struct queue_entry_priv_usb *entry_priv;
  281. struct queue_entry_priv_usb_bcn *bcn_priv;
  282. unsigned int i;
  283. rt2x00usb_vendor_request_sw(rt2x00dev, USB_RX_CONTROL, 0, 0,
  284. REGISTER_TIMEOUT);
  285. /*
  286. * Cancel all queues.
  287. */
  288. for (i = 0; i < rt2x00dev->rx->limit; i++) {
  289. entry_priv = rt2x00dev->rx->entries[i].priv_data;
  290. usb_kill_urb(entry_priv->urb);
  291. }
  292. /*
  293. * Kill guardian urb (if required by driver).
  294. */
  295. if (!test_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags))
  296. return;
  297. for (i = 0; i < rt2x00dev->bcn->limit; i++) {
  298. bcn_priv = rt2x00dev->bcn->entries[i].priv_data;
  299. if (bcn_priv->guardian_urb)
  300. usb_kill_urb(bcn_priv->guardian_urb);
  301. }
  302. }
  303. EXPORT_SYMBOL_GPL(rt2x00usb_disable_radio);
  304. /*
  305. * Device initialization handlers.
  306. */
  307. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  308. struct queue_entry *entry)
  309. {
  310. struct usb_device *usb_dev =
  311. interface_to_usbdev(to_usb_interface(rt2x00dev->dev));
  312. struct queue_entry_priv_usb *entry_priv = entry->priv_data;
  313. usb_fill_bulk_urb(entry_priv->urb, usb_dev,
  314. usb_rcvbulkpipe(usb_dev, 1),
  315. entry->skb->data, entry->skb->len,
  316. rt2x00usb_interrupt_rxdone, entry);
  317. __set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
  318. usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
  319. }
  320. EXPORT_SYMBOL_GPL(rt2x00usb_init_rxentry);
  321. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  322. struct queue_entry *entry)
  323. {
  324. entry->flags = 0;
  325. }
  326. EXPORT_SYMBOL_GPL(rt2x00usb_init_txentry);
  327. static int rt2x00usb_alloc_urb(struct rt2x00_dev *rt2x00dev,
  328. struct data_queue *queue)
  329. {
  330. struct queue_entry_priv_usb *entry_priv;
  331. struct queue_entry_priv_usb_bcn *bcn_priv;
  332. unsigned int i;
  333. for (i = 0; i < queue->limit; i++) {
  334. entry_priv = queue->entries[i].priv_data;
  335. entry_priv->urb = usb_alloc_urb(0, GFP_KERNEL);
  336. if (!entry_priv->urb)
  337. return -ENOMEM;
  338. }
  339. /*
  340. * If this is not the beacon queue or
  341. * no guardian byte was required for the beacon,
  342. * then we are done.
  343. */
  344. if (rt2x00dev->bcn != queue ||
  345. !test_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags))
  346. return 0;
  347. for (i = 0; i < queue->limit; i++) {
  348. bcn_priv = queue->entries[i].priv_data;
  349. bcn_priv->guardian_urb = usb_alloc_urb(0, GFP_KERNEL);
  350. if (!bcn_priv->guardian_urb)
  351. return -ENOMEM;
  352. }
  353. return 0;
  354. }
  355. static void rt2x00usb_free_urb(struct rt2x00_dev *rt2x00dev,
  356. struct data_queue *queue)
  357. {
  358. struct queue_entry_priv_usb *entry_priv;
  359. struct queue_entry_priv_usb_bcn *bcn_priv;
  360. unsigned int i;
  361. if (!queue->entries)
  362. return;
  363. for (i = 0; i < queue->limit; i++) {
  364. entry_priv = queue->entries[i].priv_data;
  365. usb_kill_urb(entry_priv->urb);
  366. usb_free_urb(entry_priv->urb);
  367. if (queue->entries[i].skb)
  368. kfree_skb(queue->entries[i].skb);
  369. }
  370. /*
  371. * If this is not the beacon queue or
  372. * no guardian byte was required for the beacon,
  373. * then we are done.
  374. */
  375. if (rt2x00dev->bcn != queue ||
  376. !test_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags))
  377. return;
  378. for (i = 0; i < queue->limit; i++) {
  379. bcn_priv = queue->entries[i].priv_data;
  380. usb_kill_urb(bcn_priv->guardian_urb);
  381. usb_free_urb(bcn_priv->guardian_urb);
  382. }
  383. }
  384. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev)
  385. {
  386. struct data_queue *queue;
  387. struct sk_buff *skb;
  388. unsigned int entry_size;
  389. unsigned int i;
  390. int uninitialized_var(status);
  391. /*
  392. * Allocate DMA
  393. */
  394. queue_for_each(rt2x00dev, queue) {
  395. status = rt2x00usb_alloc_urb(rt2x00dev, queue);
  396. if (status)
  397. goto exit;
  398. }
  399. /*
  400. * For the RX queue, skb's should be allocated.
  401. */
  402. entry_size = rt2x00dev->rx->data_size + rt2x00dev->rx->desc_size;
  403. for (i = 0; i < rt2x00dev->rx->limit; i++) {
  404. skb = rt2x00queue_alloc_rxskb(rt2x00dev->rx);
  405. if (!skb)
  406. goto exit;
  407. rt2x00dev->rx->entries[i].skb = skb;
  408. }
  409. return 0;
  410. exit:
  411. rt2x00usb_uninitialize(rt2x00dev);
  412. return status;
  413. }
  414. EXPORT_SYMBOL_GPL(rt2x00usb_initialize);
  415. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
  416. {
  417. struct data_queue *queue;
  418. queue_for_each(rt2x00dev, queue)
  419. rt2x00usb_free_urb(rt2x00dev, queue);
  420. }
  421. EXPORT_SYMBOL_GPL(rt2x00usb_uninitialize);
  422. /*
  423. * USB driver handlers.
  424. */
  425. static void rt2x00usb_free_reg(struct rt2x00_dev *rt2x00dev)
  426. {
  427. kfree(rt2x00dev->rf);
  428. rt2x00dev->rf = NULL;
  429. kfree(rt2x00dev->eeprom);
  430. rt2x00dev->eeprom = NULL;
  431. kfree(rt2x00dev->csr.cache);
  432. rt2x00dev->csr.cache = NULL;
  433. }
  434. static int rt2x00usb_alloc_reg(struct rt2x00_dev *rt2x00dev)
  435. {
  436. rt2x00dev->csr.cache = kzalloc(CSR_CACHE_SIZE, GFP_KERNEL);
  437. if (!rt2x00dev->csr.cache)
  438. goto exit;
  439. rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
  440. if (!rt2x00dev->eeprom)
  441. goto exit;
  442. rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
  443. if (!rt2x00dev->rf)
  444. goto exit;
  445. return 0;
  446. exit:
  447. ERROR_PROBE("Failed to allocate registers.\n");
  448. rt2x00usb_free_reg(rt2x00dev);
  449. return -ENOMEM;
  450. }
  451. int rt2x00usb_probe(struct usb_interface *usb_intf,
  452. const struct usb_device_id *id)
  453. {
  454. struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
  455. struct rt2x00_ops *ops = (struct rt2x00_ops *)id->driver_info;
  456. struct ieee80211_hw *hw;
  457. struct rt2x00_dev *rt2x00dev;
  458. int retval;
  459. usb_dev = usb_get_dev(usb_dev);
  460. hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
  461. if (!hw) {
  462. ERROR_PROBE("Failed to allocate hardware.\n");
  463. retval = -ENOMEM;
  464. goto exit_put_device;
  465. }
  466. usb_set_intfdata(usb_intf, hw);
  467. rt2x00dev = hw->priv;
  468. rt2x00dev->dev = &usb_intf->dev;
  469. rt2x00dev->ops = ops;
  470. rt2x00dev->hw = hw;
  471. mutex_init(&rt2x00dev->usb_cache_mutex);
  472. rt2x00dev->usb_maxpacket =
  473. usb_maxpacket(usb_dev, usb_sndbulkpipe(usb_dev, 1), 1);
  474. if (!rt2x00dev->usb_maxpacket)
  475. rt2x00dev->usb_maxpacket = 1;
  476. retval = rt2x00usb_alloc_reg(rt2x00dev);
  477. if (retval)
  478. goto exit_free_device;
  479. retval = rt2x00lib_probe_dev(rt2x00dev);
  480. if (retval)
  481. goto exit_free_reg;
  482. return 0;
  483. exit_free_reg:
  484. rt2x00usb_free_reg(rt2x00dev);
  485. exit_free_device:
  486. ieee80211_free_hw(hw);
  487. exit_put_device:
  488. usb_put_dev(usb_dev);
  489. usb_set_intfdata(usb_intf, NULL);
  490. return retval;
  491. }
  492. EXPORT_SYMBOL_GPL(rt2x00usb_probe);
  493. void rt2x00usb_disconnect(struct usb_interface *usb_intf)
  494. {
  495. struct ieee80211_hw *hw = usb_get_intfdata(usb_intf);
  496. struct rt2x00_dev *rt2x00dev = hw->priv;
  497. /*
  498. * Free all allocated data.
  499. */
  500. rt2x00lib_remove_dev(rt2x00dev);
  501. rt2x00usb_free_reg(rt2x00dev);
  502. ieee80211_free_hw(hw);
  503. /*
  504. * Free the USB device data.
  505. */
  506. usb_set_intfdata(usb_intf, NULL);
  507. usb_put_dev(interface_to_usbdev(usb_intf));
  508. }
  509. EXPORT_SYMBOL_GPL(rt2x00usb_disconnect);
  510. #ifdef CONFIG_PM
  511. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state)
  512. {
  513. struct ieee80211_hw *hw = usb_get_intfdata(usb_intf);
  514. struct rt2x00_dev *rt2x00dev = hw->priv;
  515. int retval;
  516. retval = rt2x00lib_suspend(rt2x00dev, state);
  517. if (retval)
  518. return retval;
  519. rt2x00usb_free_reg(rt2x00dev);
  520. /*
  521. * Decrease usbdev refcount.
  522. */
  523. usb_put_dev(interface_to_usbdev(usb_intf));
  524. return 0;
  525. }
  526. EXPORT_SYMBOL_GPL(rt2x00usb_suspend);
  527. int rt2x00usb_resume(struct usb_interface *usb_intf)
  528. {
  529. struct ieee80211_hw *hw = usb_get_intfdata(usb_intf);
  530. struct rt2x00_dev *rt2x00dev = hw->priv;
  531. int retval;
  532. usb_get_dev(interface_to_usbdev(usb_intf));
  533. retval = rt2x00usb_alloc_reg(rt2x00dev);
  534. if (retval)
  535. return retval;
  536. retval = rt2x00lib_resume(rt2x00dev);
  537. if (retval)
  538. goto exit_free_reg;
  539. return 0;
  540. exit_free_reg:
  541. rt2x00usb_free_reg(rt2x00dev);
  542. return retval;
  543. }
  544. EXPORT_SYMBOL_GPL(rt2x00usb_resume);
  545. #endif /* CONFIG_PM */
  546. /*
  547. * rt2x00usb module information.
  548. */
  549. MODULE_AUTHOR(DRV_PROJECT);
  550. MODULE_VERSION(DRV_VERSION);
  551. MODULE_DESCRIPTION("rt2x00 usb library");
  552. MODULE_LICENSE("GPL");