^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for USB Mass Storage devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Usual Tables File for usb-storage and libusual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2009 Alan Stern (stern@rowland.harvard.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/usb_usual.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * The table of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .driver_info = (flags) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define COMPLIANT_DEV UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define USUAL_DEV(useProto, useTrans) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Define the device is matched with Vendor ID and interface descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define UNUSUAL_VENDOR_INTF(id_vendor, cl, sc, pr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) | USB_DEVICE_ID_MATCH_VENDOR, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .idVendor = (id_vendor), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .bInterfaceClass = (cl), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .bInterfaceSubClass = (sc), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .bInterfaceProtocol = (pr), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .driver_info = (flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const struct usb_device_id usb_storage_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) # include "unusual_devs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #undef COMPLIANT_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #undef USUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #undef UNUSUAL_VENDOR_INTF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * The table of devices to ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct ignore_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u16 vid, pid, bcdmin, bcdmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .vid = id_vendor, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .pid = id_product, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .bcdmin = bcdDeviceMin, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .bcdmax = bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static const struct ignore_entry ignore_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) # include "unusual_alauda.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) # include "unusual_cypress.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) # include "unusual_datafab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) # include "unusual_ene_ub6250.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) # include "unusual_freecom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) # include "unusual_isd200.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) # include "unusual_jumpshot.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) # include "unusual_karma.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) # include "unusual_onetouch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) # include "unusual_realtek.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) # include "unusual_sddr09.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) # include "unusual_sddr55.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) # include "unusual_usbat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Return an error if a device is in the ignore_ids list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int usb_usual_ignore_device(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) unsigned vid, pid, bcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const struct ignore_entry *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) vid = le16_to_cpu(udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) pid = le16_to_cpu(udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) bcd = le16_to_cpu(udev->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) for (p = ignore_ids; p->vid; ++p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (p->vid == vid && p->pid == pid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) p->bcdmin <= bcd && p->bcdmax >= bcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }