2 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
3 Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
4 <http://rt2x00.serialmonkey.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 Abstract: rt2x00 generic usb device routines.
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/usb.h>
29 #include <linux/bug.h>
32 #include "rt2x00usb.h"
35 * Interfacing with the HW.
37 int rt2x00usb_vendor_request(struct rt2x00_dev
*rt2x00dev
,
38 const u8 request
, const u8 requesttype
,
39 const u16 offset
, const u16 value
,
40 void *buffer
, const u16 buffer_length
,
43 struct usb_device
*usb_dev
= to_usb_device_intf(rt2x00dev
->dev
);
46 (requesttype
== USB_VENDOR_REQUEST_IN
) ?
47 usb_rcvctrlpipe(usb_dev
, 0) : usb_sndctrlpipe(usb_dev
, 0);
48 unsigned long expire
= jiffies
+ msecs_to_jiffies(timeout
);
50 if (!test_bit(DEVICE_STATE_PRESENT
, &rt2x00dev
->flags
))
54 status
= usb_control_msg(usb_dev
, pipe
, request
, requesttype
,
55 value
, offset
, buffer
, buffer_length
,
60 if (status
== -ENODEV
) {
61 /* Device has disappeared. */
62 clear_bit(DEVICE_STATE_PRESENT
, &rt2x00dev
->flags
);
65 } while (time_before(jiffies
, expire
));
68 "Vendor Request 0x%02x failed for offset 0x%04x with error %d\n",
69 request
, offset
, status
);
73 EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request
);
75 int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev
*rt2x00dev
,
76 const u8 request
, const u8 requesttype
,
77 const u16 offset
, void *buffer
,
78 const u16 buffer_length
, const int timeout
)
82 BUG_ON(!mutex_is_locked(&rt2x00dev
->csr_mutex
));
85 * Check for Cache availability.
87 if (unlikely(!rt2x00dev
->csr
.cache
|| buffer_length
> CSR_CACHE_SIZE
)) {
88 rt2x00_err(rt2x00dev
, "CSR cache not available\n");
92 if (requesttype
== USB_VENDOR_REQUEST_OUT
)
93 memcpy(rt2x00dev
->csr
.cache
, buffer
, buffer_length
);
95 status
= rt2x00usb_vendor_request(rt2x00dev
, request
, requesttype
,
96 offset
, 0, rt2x00dev
->csr
.cache
,
97 buffer_length
, timeout
);
99 if (!status
&& requesttype
== USB_VENDOR_REQUEST_IN
)
100 memcpy(buffer
, rt2x00dev
->csr
.cache
, buffer_length
);
104 EXPORT_SYMBOL_GPL(rt2x00usb_vendor_req_buff_lock
);
106 int rt2x00usb_vendor_request_buff(struct rt2x00_dev
*rt2x00dev
,
107 const u8 request
, const u8 requesttype
,
108 const u16 offset
, void *buffer
,
109 const u16 buffer_length
)
115 mutex_lock(&rt2x00dev
->csr_mutex
);
120 while (len
&& !status
) {
121 bsize
= min_t(u16
, CSR_CACHE_SIZE
, len
);
122 status
= rt2x00usb_vendor_req_buff_lock(rt2x00dev
, request
,
123 requesttype
, off
, tb
,
124 bsize
, REGISTER_TIMEOUT
);
131 mutex_unlock(&rt2x00dev
->csr_mutex
);
135 EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request_buff
);
137 int rt2x00usb_regbusy_read(struct rt2x00_dev
*rt2x00dev
,
138 const unsigned int offset
,
139 const struct rt2x00_field32 field
,
144 if (!test_bit(DEVICE_STATE_PRESENT
, &rt2x00dev
->flags
))
147 for (i
= 0; i
< REGISTER_USB_BUSY_COUNT
; i
++) {
148 rt2x00usb_register_read_lock(rt2x00dev
, offset
, reg
);
149 if (!rt2x00_get_field32(*reg
, field
))
151 udelay(REGISTER_BUSY_DELAY
);
154 rt2x00_err(rt2x00dev
, "Indirect register access failed: offset=0x%.08x, value=0x%.08x\n",
160 EXPORT_SYMBOL_GPL(rt2x00usb_regbusy_read
);
163 struct rt2x00_async_read_data
{
165 struct usb_ctrlrequest cr
;
166 struct rt2x00_dev
*rt2x00dev
;
167 bool (*callback
)(struct rt2x00_dev
*, int, u32
);
170 static void rt2x00usb_register_read_async_cb(struct urb
*urb
)
172 struct rt2x00_async_read_data
*rd
= urb
->context
;
173 if (rd
->callback(rd
->rt2x00dev
, urb
->status
, le32_to_cpu(rd
->reg
))) {
174 if (usb_submit_urb(urb
, GFP_ATOMIC
) < 0)
180 void rt2x00usb_register_read_async(struct rt2x00_dev
*rt2x00dev
,
181 const unsigned int offset
,
182 bool (*callback
)(struct rt2x00_dev
*, int, u32
))
184 struct usb_device
*usb_dev
= to_usb_device_intf(rt2x00dev
->dev
);
186 struct rt2x00_async_read_data
*rd
;
188 rd
= kmalloc(sizeof(*rd
), GFP_ATOMIC
);
192 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
198 rd
->rt2x00dev
= rt2x00dev
;
199 rd
->callback
= callback
;
200 rd
->cr
.bRequestType
= USB_VENDOR_REQUEST_IN
;
201 rd
->cr
.bRequest
= USB_MULTI_READ
;
203 rd
->cr
.wIndex
= cpu_to_le16(offset
);
204 rd
->cr
.wLength
= cpu_to_le16(sizeof(u32
));
206 usb_fill_control_urb(urb
, usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
207 (unsigned char *)(&rd
->cr
), &rd
->reg
, sizeof(rd
->reg
),
208 rt2x00usb_register_read_async_cb
, rd
);
209 if (usb_submit_urb(urb
, GFP_ATOMIC
) < 0)
213 EXPORT_SYMBOL_GPL(rt2x00usb_register_read_async
);
218 static void rt2x00usb_work_txdone_entry(struct queue_entry
*entry
)
221 * If the transfer to hardware succeeded, it does not mean the
222 * frame was send out correctly. It only means the frame
223 * was successfully pushed to the hardware, we have no
224 * way to determine the transmission status right now.
225 * (Only indirectly by looking at the failed TX counters
228 if (test_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
))
229 rt2x00lib_txdone_noinfo(entry
, TXDONE_FAILURE
);
231 rt2x00lib_txdone_noinfo(entry
, TXDONE_UNKNOWN
);
234 static void rt2x00usb_work_txdone(struct work_struct
*work
)
236 struct rt2x00_dev
*rt2x00dev
=
237 container_of(work
, struct rt2x00_dev
, txdone_work
);
238 struct data_queue
*queue
;
239 struct queue_entry
*entry
;
241 tx_queue_for_each(rt2x00dev
, queue
) {
242 while (!rt2x00queue_empty(queue
)) {
243 entry
= rt2x00queue_get_entry(queue
, Q_INDEX_DONE
);
245 if (test_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
) ||
246 !test_bit(ENTRY_DATA_STATUS_PENDING
, &entry
->flags
))
249 rt2x00usb_work_txdone_entry(entry
);
254 static void rt2x00usb_interrupt_txdone(struct urb
*urb
)
256 struct queue_entry
*entry
= (struct queue_entry
*)urb
->context
;
257 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
259 if (!test_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
))
262 * Check if the frame was correctly uploaded
265 set_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
);
267 * Report the frame as DMA done
269 rt2x00lib_dmadone(entry
);
271 if (rt2x00dev
->ops
->lib
->tx_dma_done
)
272 rt2x00dev
->ops
->lib
->tx_dma_done(entry
);
274 * Schedule the delayed work for reading the TX status
277 if (!rt2x00_has_cap_flag(rt2x00dev
, REQUIRE_TXSTATUS_FIFO
) ||
278 !kfifo_is_empty(&rt2x00dev
->txstatus_fifo
))
279 queue_work(rt2x00dev
->workqueue
, &rt2x00dev
->txdone_work
);
282 static bool rt2x00usb_kick_tx_entry(struct queue_entry
*entry
, void *data
)
284 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
285 struct usb_device
*usb_dev
= to_usb_device_intf(rt2x00dev
->dev
);
286 struct queue_entry_priv_usb
*entry_priv
= entry
->priv_data
;
290 if (!test_and_clear_bit(ENTRY_DATA_PENDING
, &entry
->flags
) ||
291 test_bit(ENTRY_DATA_STATUS_PENDING
, &entry
->flags
))
295 * USB devices require certain padding at the end of each frame
296 * and urb. Those paddings are not included in skbs. Pass entry
297 * to the driver to determine what the overall length should be.
299 length
= rt2x00dev
->ops
->lib
->get_tx_data_len(entry
);
301 status
= skb_padto(entry
->skb
, length
);
302 if (unlikely(status
)) {
303 /* TODO: report something more appropriate than IO_FAILED. */
304 rt2x00_warn(rt2x00dev
, "TX SKB padding error, out of memory\n");
305 set_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
);
306 rt2x00lib_dmadone(entry
);
311 usb_fill_bulk_urb(entry_priv
->urb
, usb_dev
,
312 usb_sndbulkpipe(usb_dev
, entry
->queue
->usb_endpoint
),
313 entry
->skb
->data
, length
,
314 rt2x00usb_interrupt_txdone
, entry
);
316 status
= usb_submit_urb(entry_priv
->urb
, GFP_ATOMIC
);
318 if (status
== -ENODEV
)
319 clear_bit(DEVICE_STATE_PRESENT
, &rt2x00dev
->flags
);
320 set_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
);
321 rt2x00lib_dmadone(entry
);
330 static void rt2x00usb_work_rxdone(struct work_struct
*work
)
332 struct rt2x00_dev
*rt2x00dev
=
333 container_of(work
, struct rt2x00_dev
, rxdone_work
);
334 struct queue_entry
*entry
;
335 struct skb_frame_desc
*skbdesc
;
338 while (!rt2x00queue_empty(rt2x00dev
->rx
)) {
339 entry
= rt2x00queue_get_entry(rt2x00dev
->rx
, Q_INDEX_DONE
);
341 if (test_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
) ||
342 !test_bit(ENTRY_DATA_STATUS_PENDING
, &entry
->flags
))
346 * Fill in desc fields of the skb descriptor
348 skbdesc
= get_skb_frame_desc(entry
->skb
);
350 skbdesc
->desc_len
= entry
->queue
->desc_size
;
353 * Send the frame to rt2x00lib for further processing.
355 rt2x00lib_rxdone(entry
, GFP_KERNEL
);
359 static void rt2x00usb_interrupt_rxdone(struct urb
*urb
)
361 struct queue_entry
*entry
= (struct queue_entry
*)urb
->context
;
362 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
364 if (!test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
))
368 * Report the frame as DMA done
370 rt2x00lib_dmadone(entry
);
373 * Check if the received data is simply too small
374 * to be actually valid, or if the urb is signaling
377 if (urb
->actual_length
< entry
->queue
->desc_size
|| urb
->status
)
378 set_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
);
381 * Schedule the delayed work for reading the RX status
384 queue_work(rt2x00dev
->workqueue
, &rt2x00dev
->rxdone_work
);
387 static bool rt2x00usb_kick_rx_entry(struct queue_entry
*entry
, void *data
)
389 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
390 struct usb_device
*usb_dev
= to_usb_device_intf(rt2x00dev
->dev
);
391 struct queue_entry_priv_usb
*entry_priv
= entry
->priv_data
;
394 if (test_and_set_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
) ||
395 test_bit(ENTRY_DATA_STATUS_PENDING
, &entry
->flags
))
398 rt2x00lib_dmastart(entry
);
400 usb_fill_bulk_urb(entry_priv
->urb
, usb_dev
,
401 usb_rcvbulkpipe(usb_dev
, entry
->queue
->usb_endpoint
),
402 entry
->skb
->data
, entry
->skb
->len
,
403 rt2x00usb_interrupt_rxdone
, entry
);
405 status
= usb_submit_urb(entry_priv
->urb
, GFP_ATOMIC
);
407 if (status
== -ENODEV
)
408 clear_bit(DEVICE_STATE_PRESENT
, &rt2x00dev
->flags
);
409 set_bit(ENTRY_DATA_IO_FAILED
, &entry
->flags
);
410 rt2x00lib_dmadone(entry
);
416 void rt2x00usb_kick_queue(struct data_queue
*queue
)
418 switch (queue
->qid
) {
423 if (!rt2x00queue_empty(queue
))
424 rt2x00queue_for_each_entry(queue
,
428 rt2x00usb_kick_tx_entry
);
431 if (!rt2x00queue_full(queue
))
432 rt2x00queue_for_each_entry(queue
,
436 rt2x00usb_kick_rx_entry
);
442 EXPORT_SYMBOL_GPL(rt2x00usb_kick_queue
);
444 static bool rt2x00usb_flush_entry(struct queue_entry
*entry
, void *data
)
446 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
447 struct queue_entry_priv_usb
*entry_priv
= entry
->priv_data
;
448 struct queue_entry_priv_usb_bcn
*bcn_priv
= entry
->priv_data
;
450 if (!test_bit(ENTRY_OWNER_DEVICE_DATA
, &entry
->flags
))
453 usb_kill_urb(entry_priv
->urb
);
456 * Kill guardian urb (if required by driver).
458 if ((entry
->queue
->qid
== QID_BEACON
) &&
459 (rt2x00_has_cap_flag(rt2x00dev
, REQUIRE_BEACON_GUARD
)))
460 usb_kill_urb(bcn_priv
->guardian_urb
);
465 void rt2x00usb_flush_queue(struct data_queue
*queue
, bool drop
)
467 struct work_struct
*completion
;
471 rt2x00queue_for_each_entry(queue
, Q_INDEX_DONE
, Q_INDEX
, NULL
,
472 rt2x00usb_flush_entry
);
475 * Obtain the queue completion handler
477 switch (queue
->qid
) {
482 completion
= &queue
->rt2x00dev
->txdone_work
;
485 completion
= &queue
->rt2x00dev
->rxdone_work
;
491 for (i
= 0; i
< 10; i
++) {
493 * Check if the driver is already done, otherwise we
494 * have to sleep a little while to give the driver/hw
495 * the oppurtunity to complete interrupt process itself.
497 if (rt2x00queue_empty(queue
))
501 * Schedule the completion handler manually, when this
502 * worker function runs, it should cleanup the queue.
504 queue_work(queue
->rt2x00dev
->workqueue
, completion
);
507 * Wait for a little while to give the driver
508 * the oppurtunity to recover itself.
513 EXPORT_SYMBOL_GPL(rt2x00usb_flush_queue
);
515 static void rt2x00usb_watchdog_tx_dma(struct data_queue
*queue
)
517 rt2x00_warn(queue
->rt2x00dev
, "TX queue %d DMA timed out, invoke forced forced reset\n",
520 rt2x00queue_stop_queue(queue
);
521 rt2x00queue_flush_queue(queue
, true);
522 rt2x00queue_start_queue(queue
);
525 static int rt2x00usb_dma_timeout(struct data_queue
*queue
)
527 struct queue_entry
*entry
;
529 entry
= rt2x00queue_get_entry(queue
, Q_INDEX_DMA_DONE
);
530 return rt2x00queue_dma_timeout(entry
);
533 void rt2x00usb_watchdog(struct rt2x00_dev
*rt2x00dev
)
535 struct data_queue
*queue
;
537 tx_queue_for_each(rt2x00dev
, queue
) {
538 if (!rt2x00queue_empty(queue
)) {
539 if (rt2x00usb_dma_timeout(queue
))
540 rt2x00usb_watchdog_tx_dma(queue
);
544 EXPORT_SYMBOL_GPL(rt2x00usb_watchdog
);
549 void rt2x00usb_disable_radio(struct rt2x00_dev
*rt2x00dev
)
551 rt2x00usb_vendor_request_sw(rt2x00dev
, USB_RX_CONTROL
, 0, 0,
554 EXPORT_SYMBOL_GPL(rt2x00usb_disable_radio
);
557 * Device initialization handlers.
559 void rt2x00usb_clear_entry(struct queue_entry
*entry
)
563 if (entry
->queue
->qid
== QID_RX
)
564 rt2x00usb_kick_rx_entry(entry
, NULL
);
566 EXPORT_SYMBOL_GPL(rt2x00usb_clear_entry
);
568 static void rt2x00usb_assign_endpoint(struct data_queue
*queue
,
569 struct usb_endpoint_descriptor
*ep_desc
)
571 struct usb_device
*usb_dev
= to_usb_device_intf(queue
->rt2x00dev
->dev
);
574 queue
->usb_endpoint
= usb_endpoint_num(ep_desc
);
576 if (queue
->qid
== QID_RX
) {
577 pipe
= usb_rcvbulkpipe(usb_dev
, queue
->usb_endpoint
);
578 queue
->usb_maxpacket
= usb_maxpacket(usb_dev
, pipe
, 0);
580 pipe
= usb_sndbulkpipe(usb_dev
, queue
->usb_endpoint
);
581 queue
->usb_maxpacket
= usb_maxpacket(usb_dev
, pipe
, 1);
584 if (!queue
->usb_maxpacket
)
585 queue
->usb_maxpacket
= 1;
588 static int rt2x00usb_find_endpoints(struct rt2x00_dev
*rt2x00dev
)
590 struct usb_interface
*intf
= to_usb_interface(rt2x00dev
->dev
);
591 struct usb_host_interface
*intf_desc
= intf
->cur_altsetting
;
592 struct usb_endpoint_descriptor
*ep_desc
;
593 struct data_queue
*queue
= rt2x00dev
->tx
;
594 struct usb_endpoint_descriptor
*tx_ep_desc
= NULL
;
598 * Walk through all available endpoints to search for "bulk in"
599 * and "bulk out" endpoints. When we find such endpoints collect
600 * the information we need from the descriptor and assign it
603 for (i
= 0; i
< intf_desc
->desc
.bNumEndpoints
; i
++) {
604 ep_desc
= &intf_desc
->endpoint
[i
].desc
;
606 if (usb_endpoint_is_bulk_in(ep_desc
)) {
607 rt2x00usb_assign_endpoint(rt2x00dev
->rx
, ep_desc
);
608 } else if (usb_endpoint_is_bulk_out(ep_desc
) &&
609 (queue
!= queue_end(rt2x00dev
))) {
610 rt2x00usb_assign_endpoint(queue
, ep_desc
);
611 queue
= queue_next(queue
);
613 tx_ep_desc
= ep_desc
;
618 * At least 1 endpoint for RX and 1 endpoint for TX must be available.
620 if (!rt2x00dev
->rx
->usb_endpoint
|| !rt2x00dev
->tx
->usb_endpoint
) {
621 rt2x00_err(rt2x00dev
, "Bulk-in/Bulk-out endpoints not found\n");
626 * It might be possible not all queues have a dedicated endpoint.
627 * Loop through all TX queues and copy the endpoint information
628 * which we have gathered from already assigned endpoints.
630 txall_queue_for_each(rt2x00dev
, queue
) {
631 if (!queue
->usb_endpoint
)
632 rt2x00usb_assign_endpoint(queue
, tx_ep_desc
);
638 static int rt2x00usb_alloc_entries(struct data_queue
*queue
)
640 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
641 struct queue_entry_priv_usb
*entry_priv
;
642 struct queue_entry_priv_usb_bcn
*bcn_priv
;
645 for (i
= 0; i
< queue
->limit
; i
++) {
646 entry_priv
= queue
->entries
[i
].priv_data
;
647 entry_priv
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
648 if (!entry_priv
->urb
)
653 * If this is not the beacon queue or
654 * no guardian byte was required for the beacon,
657 if (queue
->qid
!= QID_BEACON
||
658 !rt2x00_has_cap_flag(rt2x00dev
, REQUIRE_BEACON_GUARD
))
661 for (i
= 0; i
< queue
->limit
; i
++) {
662 bcn_priv
= queue
->entries
[i
].priv_data
;
663 bcn_priv
->guardian_urb
= usb_alloc_urb(0, GFP_KERNEL
);
664 if (!bcn_priv
->guardian_urb
)
671 static void rt2x00usb_free_entries(struct data_queue
*queue
)
673 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
674 struct queue_entry_priv_usb
*entry_priv
;
675 struct queue_entry_priv_usb_bcn
*bcn_priv
;
681 for (i
= 0; i
< queue
->limit
; i
++) {
682 entry_priv
= queue
->entries
[i
].priv_data
;
683 usb_kill_urb(entry_priv
->urb
);
684 usb_free_urb(entry_priv
->urb
);
688 * If this is not the beacon queue or
689 * no guardian byte was required for the beacon,
692 if (queue
->qid
!= QID_BEACON
||
693 !rt2x00_has_cap_flag(rt2x00dev
, REQUIRE_BEACON_GUARD
))
696 for (i
= 0; i
< queue
->limit
; i
++) {
697 bcn_priv
= queue
->entries
[i
].priv_data
;
698 usb_kill_urb(bcn_priv
->guardian_urb
);
699 usb_free_urb(bcn_priv
->guardian_urb
);
703 int rt2x00usb_initialize(struct rt2x00_dev
*rt2x00dev
)
705 struct data_queue
*queue
;
709 * Find endpoints for each queue
711 status
= rt2x00usb_find_endpoints(rt2x00dev
);
718 queue_for_each(rt2x00dev
, queue
) {
719 status
= rt2x00usb_alloc_entries(queue
);
727 rt2x00usb_uninitialize(rt2x00dev
);
731 EXPORT_SYMBOL_GPL(rt2x00usb_initialize
);
733 void rt2x00usb_uninitialize(struct rt2x00_dev
*rt2x00dev
)
735 struct data_queue
*queue
;
737 queue_for_each(rt2x00dev
, queue
)
738 rt2x00usb_free_entries(queue
);
740 EXPORT_SYMBOL_GPL(rt2x00usb_uninitialize
);
743 * USB driver handlers.
745 static void rt2x00usb_free_reg(struct rt2x00_dev
*rt2x00dev
)
747 kfree(rt2x00dev
->rf
);
748 rt2x00dev
->rf
= NULL
;
750 kfree(rt2x00dev
->eeprom
);
751 rt2x00dev
->eeprom
= NULL
;
753 kfree(rt2x00dev
->csr
.cache
);
754 rt2x00dev
->csr
.cache
= NULL
;
757 static int rt2x00usb_alloc_reg(struct rt2x00_dev
*rt2x00dev
)
759 rt2x00dev
->csr
.cache
= kzalloc(CSR_CACHE_SIZE
, GFP_KERNEL
);
760 if (!rt2x00dev
->csr
.cache
)
763 rt2x00dev
->eeprom
= kzalloc(rt2x00dev
->ops
->eeprom_size
, GFP_KERNEL
);
764 if (!rt2x00dev
->eeprom
)
767 rt2x00dev
->rf
= kzalloc(rt2x00dev
->ops
->rf_size
, GFP_KERNEL
);
774 rt2x00_probe_err("Failed to allocate registers\n");
776 rt2x00usb_free_reg(rt2x00dev
);
781 int rt2x00usb_probe(struct usb_interface
*usb_intf
,
782 const struct rt2x00_ops
*ops
)
784 struct usb_device
*usb_dev
= interface_to_usbdev(usb_intf
);
785 struct ieee80211_hw
*hw
;
786 struct rt2x00_dev
*rt2x00dev
;
789 usb_dev
= usb_get_dev(usb_dev
);
790 usb_reset_device(usb_dev
);
792 hw
= ieee80211_alloc_hw(sizeof(struct rt2x00_dev
), ops
->hw
);
794 rt2x00_probe_err("Failed to allocate hardware\n");
796 goto exit_put_device
;
799 usb_set_intfdata(usb_intf
, hw
);
801 rt2x00dev
= hw
->priv
;
802 rt2x00dev
->dev
= &usb_intf
->dev
;
803 rt2x00dev
->ops
= ops
;
806 rt2x00_set_chip_intf(rt2x00dev
, RT2X00_CHIP_INTF_USB
);
808 INIT_WORK(&rt2x00dev
->rxdone_work
, rt2x00usb_work_rxdone
);
809 INIT_WORK(&rt2x00dev
->txdone_work
, rt2x00usb_work_txdone
);
810 hrtimer_init(&rt2x00dev
->txstatus_timer
, CLOCK_MONOTONIC
,
813 retval
= rt2x00usb_alloc_reg(rt2x00dev
);
815 goto exit_free_device
;
817 retval
= rt2x00lib_probe_dev(rt2x00dev
);
824 rt2x00usb_free_reg(rt2x00dev
);
827 ieee80211_free_hw(hw
);
830 usb_put_dev(usb_dev
);
832 usb_set_intfdata(usb_intf
, NULL
);
836 EXPORT_SYMBOL_GPL(rt2x00usb_probe
);
838 void rt2x00usb_disconnect(struct usb_interface
*usb_intf
)
840 struct ieee80211_hw
*hw
= usb_get_intfdata(usb_intf
);
841 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
844 * Free all allocated data.
846 rt2x00lib_remove_dev(rt2x00dev
);
847 rt2x00usb_free_reg(rt2x00dev
);
848 ieee80211_free_hw(hw
);
851 * Free the USB device data.
853 usb_set_intfdata(usb_intf
, NULL
);
854 usb_put_dev(interface_to_usbdev(usb_intf
));
856 EXPORT_SYMBOL_GPL(rt2x00usb_disconnect
);
859 int rt2x00usb_suspend(struct usb_interface
*usb_intf
, pm_message_t state
)
861 struct ieee80211_hw
*hw
= usb_get_intfdata(usb_intf
);
862 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
864 return rt2x00lib_suspend(rt2x00dev
, state
);
866 EXPORT_SYMBOL_GPL(rt2x00usb_suspend
);
868 int rt2x00usb_resume(struct usb_interface
*usb_intf
)
870 struct ieee80211_hw
*hw
= usb_get_intfdata(usb_intf
);
871 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
873 return rt2x00lib_resume(rt2x00dev
);
875 EXPORT_SYMBOL_GPL(rt2x00usb_resume
);
876 #endif /* CONFIG_PM */
879 * rt2x00usb module information.
881 MODULE_AUTHOR(DRV_PROJECT
);
882 MODULE_VERSION(DRV_VERSION
);
883 MODULE_DESCRIPTION("rt2x00 usb library");
884 MODULE_LICENSE("GPL");