uas: Log a warning when we cannot use uas because the hcd lacks streams
[linux-2.6/btrfs-unstable.git] / drivers / usb / storage / uas-detect.h
blob503ac5c8d80f7bb7bcb87832df78a71d8c14587f
1 #include <linux/usb.h>
2 #include <linux/usb/hcd.h>
3 #include "usb.h"
5 static int uas_is_interface(struct usb_host_interface *intf)
7 return (intf->desc.bInterfaceClass == USB_CLASS_MASS_STORAGE &&
8 intf->desc.bInterfaceSubClass == USB_SC_SCSI &&
9 intf->desc.bInterfaceProtocol == USB_PR_UAS);
12 static int uas_find_uas_alt_setting(struct usb_interface *intf)
14 int i;
16 for (i = 0; i < intf->num_altsetting; i++) {
17 struct usb_host_interface *alt = &intf->altsetting[i];
19 if (uas_is_interface(alt))
20 return alt->desc.bAlternateSetting;
23 return -ENODEV;
26 static int uas_find_endpoints(struct usb_host_interface *alt,
27 struct usb_host_endpoint *eps[])
29 struct usb_host_endpoint *endpoint = alt->endpoint;
30 unsigned i, n_endpoints = alt->desc.bNumEndpoints;
32 for (i = 0; i < n_endpoints; i++) {
33 unsigned char *extra = endpoint[i].extra;
34 int len = endpoint[i].extralen;
35 while (len >= 3) {
36 if (extra[1] == USB_DT_PIPE_USAGE) {
37 unsigned pipe_id = extra[2];
38 if (pipe_id > 0 && pipe_id < 5)
39 eps[pipe_id - 1] = &endpoint[i];
40 break;
42 len -= extra[0];
43 extra += extra[0];
47 if (!eps[0] || !eps[1] || !eps[2] || !eps[3])
48 return -ENODEV;
50 return 0;
53 static int uas_use_uas_driver(struct usb_interface *intf,
54 const struct usb_device_id *id)
56 struct usb_host_endpoint *eps[4] = { };
57 struct usb_device *udev = interface_to_usbdev(intf);
58 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
59 unsigned long flags = id->driver_info;
60 int r, alt;
62 usb_stor_adjust_quirks(udev, &flags);
64 if (flags & US_FL_IGNORE_UAS)
65 return 0;
67 alt = uas_find_uas_alt_setting(intf);
68 if (alt < 0)
69 return 0;
71 r = uas_find_endpoints(&intf->altsetting[alt], eps);
72 if (r < 0)
73 return 0;
75 if (udev->bus->sg_tablesize == 0) {
76 dev_warn(&udev->dev,
77 "The driver for the USB controller %s does not support scatter-gather which is\n",
78 hcd->driver->description);
79 dev_warn(&udev->dev,
80 "required by the UAS driver. Please try an other USB controller if you wish to use UAS.\n");
81 return 0;
84 if (udev->speed >= USB_SPEED_SUPER && !hcd->can_do_streams) {
85 dev_warn(&udev->dev,
86 "USB controller %s does not support streams, which are required by the UAS driver.\n",
87 hcd_to_bus(hcd)->bus_name);
88 dev_warn(&udev->dev,
89 "Please try an other USB controller if you wish to use UAS.\n");
90 return 0;
93 return 1;