~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/usbip/stub_rx.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * USA.
18
18
 */
19
19
 
20
 
#include <linux/slab.h>
 
20
#include <asm/byteorder.h>
 
21
#include <linux/kthread.h>
 
22
#include <linux/usb.h>
 
23
#include <linux/usb/hcd.h>
21
24
 
22
25
#include "usbip_common.h"
23
26
#include "stub.h"
24
 
#include <linux/usb/hcd.h>
25
 
 
26
27
 
27
28
static int is_clear_halt_cmd(struct urb *urb)
28
29
{
42
43
        req = (struct usb_ctrlrequest *) urb->setup_packet;
43
44
 
44
45
        return (req->bRequest == USB_REQ_SET_INTERFACE) &&
45
 
                   (req->bRequestType == USB_RECIP_INTERFACE);
 
46
                (req->bRequestType == USB_RECIP_INTERFACE);
46
47
}
47
48
 
48
49
static int is_set_configuration_cmd(struct urb *urb)
52
53
        req = (struct usb_ctrlrequest *) urb->setup_packet;
53
54
 
54
55
        return (req->bRequest == USB_REQ_SET_CONFIGURATION) &&
55
 
                   (req->bRequestType == USB_RECIP_DEVICE);
 
56
                (req->bRequestType == USB_RECIP_DEVICE);
56
57
}
57
58
 
58
59
static int is_reset_device_cmd(struct urb *urb)
66
67
        index = le16_to_cpu(req->wIndex);
67
68
 
68
69
        if ((req->bRequest == USB_REQ_SET_FEATURE) &&
69
 
                        (req->bRequestType == USB_RT_PORT) &&
70
 
                        (value == USB_PORT_FEAT_RESET)) {
 
70
            (req->bRequestType == USB_RT_PORT) &&
 
71
            (value == USB_PORT_FEAT_RESET)) {
71
72
                usbip_dbg_stub_rx("reset_device_cmd, port %u\n", index);
72
73
                return 1;
73
74
        } else
101
102
 
102
103
        ret = usb_clear_halt(urb->dev, target_pipe);
103
104
        if (ret < 0)
104
 
                usbip_uinfo("clear_halt error: devnum %d endp %d, %d\n",
105
 
                                        urb->dev->devnum, target_endp, ret);
 
105
                dev_err(&urb->dev->dev, "usb_clear_halt error: devnum %d endp "
 
106
                        "%d ret %d\n", urb->dev->devnum, target_endp, ret);
106
107
        else
107
 
                usbip_uinfo("clear_halt done: devnum %d endp %d\n",
108
 
                                        urb->dev->devnum, target_endp);
 
108
                dev_info(&urb->dev->dev, "usb_clear_halt done: devnum %d endp "
 
109
                         "%d\n", urb->dev->devnum, target_endp);
109
110
 
110
111
        return ret;
111
112
}
121
122
        alternate = le16_to_cpu(req->wValue);
122
123
        interface = le16_to_cpu(req->wIndex);
123
124
 
124
 
        usbip_dbg_stub_rx("set_interface: inf %u alt %u\n", interface,
125
 
                                                                alternate);
 
125
        usbip_dbg_stub_rx("set_interface: inf %u alt %u\n",
 
126
                          interface, alternate);
126
127
 
127
128
        ret = usb_set_interface(urb->dev, interface, alternate);
128
129
        if (ret < 0)
129
 
                usbip_uinfo("set_interface error: inf %u alt %u, %d\n",
130
 
                                        interface, alternate, ret);
 
130
                dev_err(&urb->dev->dev, "usb_set_interface error: inf %u alt "
 
131
                        "%u ret %d\n", interface, alternate, ret);
131
132
        else
132
 
                usbip_uinfo("set_interface done: inf %u alt %u\n",
133
 
                                                        interface,
134
 
                                                        alternate);
 
133
                dev_info(&urb->dev->dev, "usb_set_interface done: inf %u alt "
 
134
                         "%u\n", interface, alternate);
135
135
 
136
136
        return ret;
137
137
}
160
160
         * A user may need to set a special configuration value before
161
161
         * exporting the device.
162
162
         */
163
 
        usbip_uinfo("set_configuration (%d) to %s\n", config,
164
 
                                                dev_name(&urb->dev->dev));
165
 
        usbip_uinfo("but, skip!\n");
 
163
        dev_info(&urb->dev->dev, "usb_set_configuration %d to %s... skip!\n",
 
164
                 config, dev_name(&urb->dev->dev));
166
165
 
167
166
        return 0;
168
167
        /* return usb_driver_set_configuration(urb->dev, config); */
173
172
        struct stub_priv *priv = (struct stub_priv *) urb->context;
174
173
        struct stub_device *sdev = priv->sdev;
175
174
 
176
 
        usbip_uinfo("reset_device %s\n", dev_name(&urb->dev->dev));
 
175
        dev_info(&urb->dev->dev, "usb_queue_reset_device\n");
177
176
 
178
177
        /*
179
 
         * usb_lock_device_for_reset caused a deadlock: it causes the driver
180
 
         * to unbind. In the shutdown the rx thread is signalled to shut down
181
 
         * but this thread is pending in the usb_lock_device_for_reset.
182
 
         *
183
 
         * Instead queue the reset.
184
 
         *
185
 
         * Unfortunatly an existing usbip connection will be dropped due to
186
 
         * driver unbinding.
 
178
         * With the implementation of pre_reset and post_reset the driver no 
 
179
         * longer unbinds. This allows the use of synchronous reset.
187
180
         */
188
 
        usb_queue_reset_device(sdev->interface);
 
181
 
 
182
        if (usb_lock_device_for_reset(sdev->udev, sdev->interface)<0)
 
183
        {
 
184
                dev_err(&urb->dev->dev, "could not obtain lock to reset device\n");
 
185
                return 0;
 
186
        }
 
187
        usb_reset_device(sdev->udev);
 
188
        usb_unlock_device(sdev->udev);
 
189
 
189
190
        return 0;
190
191
}
191
192
 
227
228
 * See also comments about unlinking strategy in vhci_hcd.c.
228
229
 */
229
230
static int stub_recv_cmd_unlink(struct stub_device *sdev,
230
 
                                                struct usbip_header *pdu)
 
231
                                struct usbip_header *pdu)
231
232
{
232
233
        unsigned long flags;
233
234
 
234
235
        struct stub_priv *priv;
235
236
 
236
 
 
237
237
        spin_lock_irqsave(&sdev->priv_lock, flags);
238
238
 
239
239
        list_for_each_entry(priv, &sdev->priv_init, list) {
288
288
        }
289
289
 
290
290
        usbip_dbg_stub_rx("seqnum %d is not pending\n",
291
 
                                                pdu->u.cmd_unlink.seqnum);
 
291
                          pdu->u.cmd_unlink.seqnum);
292
292
 
293
293
        /*
294
294
         * The urb of the unlink target is not found in priv_init queue. It was
300
300
 
301
301
        spin_unlock_irqrestore(&sdev->priv_lock, flags);
302
302
 
303
 
 
304
303
        return 0;
305
304
}
306
305
 
369
368
        }
370
369
 
371
370
        epd = &ep->desc;
372
 
 
373
 
 
374
371
#if 0
375
372
        /* epnum 0 is always control */
376
373
        if (epnum == 0) {
380
377
                        return usb_rcvctrlpipe(udev, 0);
381
378
        }
382
379
#endif
383
 
 
384
380
        if (usb_endpoint_xfer_control(epd)) {
385
381
                if (dir == USBIP_DIR_OUT)
386
382
                        return usb_sndctrlpipe(udev, epnum);
429
425
                return;
430
426
 
431
427
        ep = (usb_pipein(urb->pipe) ? dev->ep_in : dev->ep_out)
432
 
                        [usb_pipeendpoint(urb->pipe)];
 
428
                [usb_pipeendpoint(urb->pipe)];
433
429
        if (!ep)
434
430
                return;
435
431
 
436
432
        xfertype = usb_endpoint_type(&ep->desc);
437
433
        if (xfertype == USB_ENDPOINT_XFER_CONTROL) {
438
434
                struct usb_ctrlrequest *setup =
439
 
                                (struct usb_ctrlrequest *) urb->setup_packet;
 
435
                        (struct usb_ctrlrequest *) urb->setup_packet;
440
436
 
441
437
                if (!setup)
442
438
                        return;
443
439
                is_out = !(setup->bRequestType & USB_DIR_IN) ||
444
 
                                !setup->wLength;
 
440
                        !setup->wLength;
445
441
        } else {
446
442
                is_out = usb_endpoint_dir_out(&ep->desc);
447
443
        }
477
473
        struct usb_device *udev = sdev->udev;
478
474
        int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction);
479
475
 
480
 
 
481
476
        priv = stub_priv_alloc(sdev, pdu);
482
477
        if (!priv)
483
478
                return;
485
480
        /* setup a urb */
486
481
        if (usb_pipeisoc(pipe))
487
482
                priv->urb = usb_alloc_urb(pdu->u.cmd_submit.number_of_packets,
488
 
                                                                GFP_KERNEL);
 
483
                                          GFP_KERNEL);
489
484
        else
490
485
                priv->urb = usb_alloc_urb(0, GFP_KERNEL);
491
486
 
499
494
        if (pdu->u.cmd_submit.transfer_buffer_length > 0) {
500
495
                priv->urb->transfer_buffer =
501
496
                        kzalloc(pdu->u.cmd_submit.transfer_buffer_length,
502
 
                                                                GFP_KERNEL);
 
497
                                GFP_KERNEL);
503
498
                if (!priv->urb->transfer_buffer) {
504
499
                        dev_err(&sdev->interface->dev, "malloc x_buff\n");
505
500
                        usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
540
535
 
541
536
        if (ret == 0)
542
537
                usbip_dbg_stub_rx("submit urb ok, seqnum %u\n",
543
 
                                                        pdu->base.seqnum);
 
538
                                  pdu->base.seqnum);
544
539
        else {
545
540
                dev_err(&sdev->interface->dev, "submit_urb error, %d\n", ret);
546
541
                usbip_dump_header(pdu);
601
596
                /* NOTREACHED */
602
597
                dev_err(dev, "unknown pdu\n");
603
598
                usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
604
 
                return;
 
599
                break;
605
600
        }
606
 
 
607
601
}
608
602
 
609
 
void stub_rx_loop(struct usbip_task *ut)
 
603
int stub_rx_loop(void *data)
610
604
{
611
 
        struct usbip_device *ud = container_of(ut, struct usbip_device, tcp_rx);
612
 
 
613
 
        while (1) {
614
 
                if (signal_pending(current)) {
615
 
                        usbip_dbg_stub_rx("signal caught!\n");
616
 
                        break;
617
 
                }
618
 
 
 
605
        struct usbip_device *ud = data;
 
606
 
 
607
        while (!kthread_should_stop()) {
619
608
                if (usbip_event_happened(ud))
620
609
                        break;
621
610
 
622
611
                stub_rx_pdu(ud);
623
612
        }
 
613
 
 
614
        return 0;
624
615
}