blob: 02bf5ec957f5130e861c6d30ba5fc4dd85ba0e5e [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}
Hans de Goede79b4c062013-10-25 17:04:33 +010041
42static int uas_use_uas_driver(struct usb_interface *intf,
43 const struct usb_device_id *id)
44{
45 unsigned long flags = id->driver_info;
46
47 if (flags & US_FL_IGNORE_UAS)
48 return 0;
49
50 return uas_find_uas_alt_setting(intf) >= 0;
51}