blob: 28101c7e6a9f10acb9919df540ce07cb43ba5f2a [file] [log] [blame]
Hans de Goede82aa0382013-10-21 08:53:31 +01001#include <linux/usb.h>
2#include <linux/usb/hcd.h>
3
4static int uas_is_interface(struct usb_host_interface *intf)
5{
6 return (intf->desc.bInterfaceClass == USB_CLASS_MASS_STORAGE &&
7 intf->desc.bInterfaceSubClass == USB_SC_SCSI &&
8 intf->desc.bInterfaceProtocol == USB_PR_UAS);
9}
10
11static int uas_isnt_supported(struct usb_device *udev)
12{
13 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
14
15 dev_warn(&udev->dev, "The driver for the USB controller %s does not "
16 "support scatter-gather which is\n",
17 hcd->driver->description);
18 dev_warn(&udev->dev, "required by the UAS driver. Please try an"
19 "alternative USB controller if you wish to use UAS.\n");
20 return -ENODEV;
21}
22
23static int uas_find_uas_alt_setting(struct usb_interface *intf)
24{
25 int i;
26 struct usb_device *udev = interface_to_usbdev(intf);
27 int sg_supported = udev->bus->sg_tablesize != 0;
28
29 for (i = 0; i < intf->num_altsetting; i++) {
30 struct usb_host_interface *alt = &intf->altsetting[i];
31
32 if (uas_is_interface(alt)) {
33 if (!sg_supported)
34 return uas_isnt_supported(udev);
35 return alt->desc.bAlternateSetting;
36 }
37 }
38
39 return -ENODEV;
40}