27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
50 usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0);
57 value, offset, buffer, buffer_length,
67 else if (status == -
ENODEV) {
74 "Vendor Request 0x%02x failed for offset 0x%04x with error %d.\n",
75 request, offset, status);
94 ERROR(rt2x00dev,
"CSR cache not available.\n");
103 buffer_length, timeout);
126 while (len && !status) {
129 requesttype, off, tb,
144 const unsigned int offset,
154 rt2x00usb_register_read_lock(rt2x00dev, offset, reg);
160 ERROR(rt2x00dev,
"Indirect register access failed: "
161 "offset=0x%.08x, value=0x%.08x\n", offset, *reg);
176 static void rt2x00usb_register_read_async_cb(
struct urb *
urb)
187 const unsigned int offset,
212 usb_fill_control_urb(urb, usb_dev, usb_rcvctrlpipe(usb_dev, 0),
213 (
unsigned char *)(&rd->
cr), &rd->
reg,
sizeof(rd->
reg),
214 rt2x00usb_register_read_async_cb, rd);
224 static void rt2x00usb_work_txdone_entry(
struct queue_entry *
entry)
245 struct queue_entry *
entry;
248 while (!rt2x00queue_empty(queue)) {
255 rt2x00usb_work_txdone_entry(entry);
260 static void rt2x00usb_interrupt_txdone(
struct urb *
urb)
262 struct queue_entry *entry = (
struct queue_entry *)urb->context;
263 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
277 if (rt2x00dev->
ops->lib->tx_dma_done)
278 rt2x00dev->
ops->lib->tx_dma_done(entry);
288 static bool rt2x00usb_kick_tx_entry(
struct queue_entry *entry)
290 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
305 length = rt2x00dev->
ops->lib->get_tx_data_len(entry);
307 status = skb_padto(entry->skb, length);
310 WARNING(rt2x00dev,
"TX SKB padding error, out of memory\n");
317 usb_fill_bulk_urb(entry_priv->
urb, usb_dev,
318 usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint),
319 entry->skb->data, length,
320 rt2x00usb_interrupt_txdone, entry);
336 static void rt2x00usb_work_rxdone(
struct work_struct *work)
340 struct queue_entry *
entry;
344 while (!rt2x00queue_empty(rt2x00dev->
rx)) {
354 skbdesc = get_skb_frame_desc(entry->skb);
356 skbdesc->
desc_len = entry->queue->desc_size;
365 static void rt2x00usb_interrupt_rxdone(
struct urb *urb)
367 struct queue_entry *entry = (
struct queue_entry *)urb->context;
368 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
383 if (urb->actual_length < entry->queue->desc_size || urb->status)
393 static bool rt2x00usb_kick_rx_entry(
struct queue_entry *entry)
395 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
406 usb_fill_bulk_urb(entry_priv->
urb, usb_dev,
407 usb_rcvbulkpipe(usb_dev, entry->queue->usb_endpoint),
408 entry->skb->data, entry->skb->len,
409 rt2x00usb_interrupt_rxdone, entry);
424 switch (queue->
qid) {
429 if (!rt2x00queue_empty(queue))
431 rt2x00usb_kick_tx_entry);
434 if (!rt2x00queue_full(queue))
436 rt2x00usb_kick_rx_entry);
444 static bool rt2x00usb_flush_entry(
struct queue_entry *entry)
446 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
472 rt2x00usb_flush_entry);
477 switch (queue->
qid) {
482 completion = &queue->
rt2x00dev->txdone_work;
485 completion = &queue->
rt2x00dev->rxdone_work;
491 for (i = 0; i < 10; i++) {
497 if (rt2x00queue_empty(queue))
515 static void rt2x00usb_watchdog_tx_dma(
struct data_queue *queue)
518 " invoke forced forced reset\n", queue->
qid);
523 static int rt2x00usb_dma_timeout(
struct data_queue *queue)
525 struct queue_entry *
entry;
528 return rt2x00queue_dma_timeout(entry);
536 if (!rt2x00queue_empty(queue)) {
537 if (rt2x00usb_dma_timeout(queue))
538 rt2x00usb_watchdog_tx_dma(queue);
561 if (entry->queue->qid ==
QID_RX)
562 rt2x00usb_kick_rx_entry(entry);
566 static void rt2x00usb_assign_endpoint(
struct data_queue *queue,
586 static int rt2x00usb_find_endpoints(
struct rt2x00_dev *rt2x00dev)
589 struct usb_host_interface *intf_desc = intf->cur_altsetting;
601 for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) {
602 ep_desc = &intf_desc->endpoint[
i].desc;
604 if (usb_endpoint_is_bulk_in(ep_desc)) {
605 rt2x00usb_assign_endpoint(rt2x00dev->
rx, ep_desc);
606 }
else if (usb_endpoint_is_bulk_out(ep_desc) &&
608 rt2x00usb_assign_endpoint(queue, ep_desc);
618 if (!rt2x00dev->
rx->usb_endpoint || !rt2x00dev->
tx->usb_endpoint) {
619 ERROR(rt2x00dev,
"Bulk-in/Bulk-out endpoints not found\n");
630 rt2x00usb_assign_endpoint(queue, tx_ep_desc);
636 static int rt2x00usb_alloc_entries(
struct data_queue *queue)
643 for (i = 0; i < queue->
limit; i++) {
644 entry_priv = queue->
entries[
i].priv_data;
646 if (!entry_priv->
urb)
659 for (i = 0; i < queue->
limit; i++) {
660 bcn_priv = queue->
entries[
i].priv_data;
669 static void rt2x00usb_free_entries(
struct data_queue *queue)
679 for (i = 0; i < queue->
limit; i++) {
680 entry_priv = queue->
entries[
i].priv_data;
694 for (i = 0; i < queue->
limit; i++) {
695 bcn_priv = queue->
entries[
i].priv_data;
709 status = rt2x00usb_find_endpoints(rt2x00dev);
717 status = rt2x00usb_alloc_entries(queue);
736 rt2x00usb_free_entries(queue);
743 static void rt2x00usb_free_reg(
struct rt2x00_dev *rt2x00dev)
755 static int rt2x00usb_alloc_reg(
struct rt2x00_dev *rt2x00dev)
774 rt2x00usb_free_reg(rt2x00dev);
782 struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
794 goto exit_put_device;
797 usb_set_intfdata(usb_intf, hw);
799 rt2x00dev = hw->
priv;
800 rt2x00dev->
dev = &usb_intf->dev;
811 retval = rt2x00usb_alloc_reg(rt2x00dev);
813 goto exit_free_device;
822 rt2x00usb_free_reg(rt2x00dev);
830 usb_set_intfdata(usb_intf,
NULL);
845 rt2x00usb_free_reg(rt2x00dev);
851 usb_set_intfdata(usb_intf,
NULL);
862 return rt2x00lib_suspend(rt2x00dev, state);
871 return rt2x00lib_resume(rt2x00dev);