usb.c (3d5271f9883cba7b54762bc4fe027d4172f06db7) usb.c (a00828e9ac62caed7b830d631914d7748817ccd1)
1/* Driver for USB Mass Storage compliant devices
2 *
3 * $Id: usb.c,v 1.75 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by:
6 * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 *
8 * Developed with the assistance of:

--- 98 unchanged lines hidden (view full) ---

107
108/* These are used to make sure the module doesn't unload before all the
109 * threads have exited.
110 */
111static atomic_t total_threads = ATOMIC_INIT(0);
112static DECLARE_COMPLETION(threads_gone);
113
114
1/* Driver for USB Mass Storage compliant devices
2 *
3 * $Id: usb.c,v 1.75 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by:
6 * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 *
8 * Developed with the assistance of:

--- 98 unchanged lines hidden (view full) ---

107
108/* These are used to make sure the module doesn't unload before all the
109 * threads have exited.
110 */
111static atomic_t total_threads = ATOMIC_INIT(0);
112static DECLARE_COMPLETION(threads_gone);
113
114
115/* The entries in this table, except for final ones here
116 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond,
117 * line for line with the entries of us_unsuaul_dev_list[].
115/*
116 * The entries in this table correspond, line for line,
117 * with the entries of us_unusual_dev_list[].
118 */
118 */
119#ifndef CONFIG_USB_LIBUSUAL
119
120#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
121 vendorName, productName,useProtocol, useTransport, \
122 initFunction, flags) \
120
121#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
122 vendorName, productName,useProtocol, useTransport, \
123 initFunction, flags) \
123{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax) }
124{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
125 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
124
126
127#define USUAL_DEV(useProto, useTrans, useType) \
128{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
129 .driver_info = (USB_US_TYPE_STOR<<24) }
130
125static struct usb_device_id storage_usb_ids [] = {
126
127# include "unusual_devs.h"
128#undef UNUSUAL_DEV
131static struct usb_device_id storage_usb_ids [] = {
132
133# include "unusual_devs.h"
134#undef UNUSUAL_DEV
129 /* Control/Bulk transport for all SubClass values */
130 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_RBC, US_PR_CB) },
131 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8020, US_PR_CB) },
132 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_QIC, US_PR_CB) },
133 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_UFI, US_PR_CB) },
134 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8070, US_PR_CB) },
135 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_SCSI, US_PR_CB) },
136
137 /* Control/Bulk/Interrupt transport for all SubClass values */
138 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_RBC, US_PR_CBI) },
139 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8020, US_PR_CBI) },
140 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_QIC, US_PR_CBI) },
141 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_UFI, US_PR_CBI) },
142 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8070, US_PR_CBI) },
143 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_SCSI, US_PR_CBI) },
144
145 /* Bulk-only transport for all SubClass values */
146 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_RBC, US_PR_BULK) },
147 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8020, US_PR_BULK) },
148 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_QIC, US_PR_BULK) },
149 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_UFI, US_PR_BULK) },
150 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8070, US_PR_BULK) },
151 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_SCSI, US_PR_BULK) },
152
135#undef USUAL_DEV
153 /* Terminating entry */
154 { }
155};
156
157MODULE_DEVICE_TABLE (usb, storage_usb_ids);
136 /* Terminating entry */
137 { }
138};
139
140MODULE_DEVICE_TABLE (usb, storage_usb_ids);
141#endif /* CONFIG_USB_LIBUSUAL */
158
159/* This is the list of devices we recognize, along with their flag data */
160
161/* The vendor name should be kept at eight characters or less, and
162 * the product name should be kept at 16 characters or less. If a device
163 * has the US_FL_FIX_INQUIRY flag, then the vendor and product names
164 * normally generated by a device thorugh the INQUIRY response will be
165 * taken from this list, and this is the reason for the above size
166 * restriction. However, if the flag is not present, then you
167 * are free to use as many characters as you like.
168 */
169
142
143/* This is the list of devices we recognize, along with their flag data */
144
145/* The vendor name should be kept at eight characters or less, and
146 * the product name should be kept at 16 characters or less. If a device
147 * has the US_FL_FIX_INQUIRY flag, then the vendor and product names
148 * normally generated by a device thorugh the INQUIRY response will be
149 * taken from this list, and this is the reason for the above size
150 * restriction. However, if the flag is not present, then you
151 * are free to use as many characters as you like.
152 */
153
170#undef UNUSUAL_DEV
171#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
172 vendor_name, product_name, use_protocol, use_transport, \
173 init_function, Flags) \
174{ \
175 .vendorName = vendor_name, \
176 .productName = product_name, \
177 .useProtocol = use_protocol, \
178 .useTransport = use_transport, \
179 .initFunction = init_function, \
154#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
155 vendor_name, product_name, use_protocol, use_transport, \
156 init_function, Flags) \
157{ \
158 .vendorName = vendor_name, \
159 .productName = product_name, \
160 .useProtocol = use_protocol, \
161 .useTransport = use_transport, \
162 .initFunction = init_function, \
180 .flags = Flags, \
181}
182
163}
164
165#define USUAL_DEV(use_protocol, use_transport, use_type) \
166{ \
167 .useProtocol = use_protocol, \
168 .useTransport = use_transport, \
169}
170
183static struct us_unusual_dev us_unusual_dev_list[] = {
184# include "unusual_devs.h"
185# undef UNUSUAL_DEV
171static struct us_unusual_dev us_unusual_dev_list[] = {
172# include "unusual_devs.h"
173# undef UNUSUAL_DEV
186 /* Control/Bulk transport for all SubClass values */
187 { .useProtocol = US_SC_RBC,
188 .useTransport = US_PR_CB},
189 { .useProtocol = US_SC_8020,
190 .useTransport = US_PR_CB},
191 { .useProtocol = US_SC_QIC,
192 .useTransport = US_PR_CB},
193 { .useProtocol = US_SC_UFI,
194 .useTransport = US_PR_CB},
195 { .useProtocol = US_SC_8070,
196 .useTransport = US_PR_CB},
197 { .useProtocol = US_SC_SCSI,
198 .useTransport = US_PR_CB},
174# undef USUAL_DEV
199
175
200 /* Control/Bulk/Interrupt transport for all SubClass values */
201 { .useProtocol = US_SC_RBC,
202 .useTransport = US_PR_CBI},
203 { .useProtocol = US_SC_8020,
204 .useTransport = US_PR_CBI},
205 { .useProtocol = US_SC_QIC,
206 .useTransport = US_PR_CBI},
207 { .useProtocol = US_SC_UFI,
208 .useTransport = US_PR_CBI},
209 { .useProtocol = US_SC_8070,
210 .useTransport = US_PR_CBI},
211 { .useProtocol = US_SC_SCSI,
212 .useTransport = US_PR_CBI},
213
214 /* Bulk-only transport for all SubClass values */
215 { .useProtocol = US_SC_RBC,
216 .useTransport = US_PR_BULK},
217 { .useProtocol = US_SC_8020,
218 .useTransport = US_PR_BULK},
219 { .useProtocol = US_SC_QIC,
220 .useTransport = US_PR_BULK},
221 { .useProtocol = US_SC_UFI,
222 .useTransport = US_PR_BULK},
223 { .useProtocol = US_SC_8070,
224 .useTransport = US_PR_BULK},
225 { .useProtocol = US_SC_SCSI,
226 .useTransport = US_PR_BULK},
227
228 /* Terminating entry */
229 { NULL }
230};
231
232
233#ifdef CONFIG_PM /* Minimal support for suspend and resume */
234
235static int storage_suspend(struct usb_interface *iface, pm_message_t message)

--- 243 unchanged lines hidden (view full) ---

479 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
480 if (!us->sensebuf) {
481 US_DEBUGP("Sense buffer allocation failed\n");
482 return -ENOMEM;
483 }
484 return 0;
485}
486
176 /* Terminating entry */
177 { NULL }
178};
179
180
181#ifdef CONFIG_PM /* Minimal support for suspend and resume */
182
183static int storage_suspend(struct usb_interface *iface, pm_message_t message)

--- 243 unchanged lines hidden (view full) ---

427 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
428 if (!us->sensebuf) {
429 US_DEBUGP("Sense buffer allocation failed\n");
430 return -ENOMEM;
431 }
432 return 0;
433}
434
435/* Find an unusual_dev descriptor (always succeeds in the current code) */
436static struct us_unusual_dev *find_unusual(const struct usb_device_id *id)
437{
438 const int id_index = id - storage_usb_ids;
439 return &us_unusual_dev_list[id_index];
440}
441
487/* Get the unusual_devs entries and the string descriptors */
442/* Get the unusual_devs entries and the string descriptors */
488static void get_device_info(struct us_data *us, int id_index)
443static void get_device_info(struct us_data *us, const struct usb_device_id *id)
489{
490 struct usb_device *dev = us->pusb_dev;
491 struct usb_interface_descriptor *idesc =
492 &us->pusb_intf->cur_altsetting->desc;
444{
445 struct usb_device *dev = us->pusb_dev;
446 struct usb_interface_descriptor *idesc =
447 &us->pusb_intf->cur_altsetting->desc;
493 struct us_unusual_dev *unusual_dev = &us_unusual_dev_list[id_index];
494 struct usb_device_id *id = &storage_usb_ids[id_index];
448 struct us_unusual_dev *unusual_dev = find_unusual(id);
495
496 /* Store the entries */
497 us->unusual_dev = unusual_dev;
498 us->subclass = (unusual_dev->useProtocol == US_SC_DEVICE) ?
499 idesc->bInterfaceSubClass :
500 unusual_dev->useProtocol;
501 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ?
502 idesc->bInterfaceProtocol :
503 unusual_dev->useTransport;
449
450 /* Store the entries */
451 us->unusual_dev = unusual_dev;
452 us->subclass = (unusual_dev->useProtocol == US_SC_DEVICE) ?
453 idesc->bInterfaceSubClass :
454 unusual_dev->useProtocol;
455 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ?
456 idesc->bInterfaceProtocol :
457 unusual_dev->useTransport;
504 us->flags = unusual_dev->flags;
458 us->flags = USB_US_ORIG_FLAGS(id->driver_info);
505
506 /*
507 * This flag is only needed when we're in high-speed, so let's
508 * disable it if we're in full-speed
509 */
510 if (dev->speed != USB_SPEED_HIGH)
511 us->flags &= ~US_FL_GO_SLOW;
512

--- 11 unchanged lines hidden (view full) ---

524 int msg = -1;
525
526 if (unusual_dev->useProtocol != US_SC_DEVICE &&
527 us->subclass == idesc->bInterfaceSubClass)
528 msg += 1;
529 if (unusual_dev->useTransport != US_PR_DEVICE &&
530 us->protocol == idesc->bInterfaceProtocol)
531 msg += 2;
459
460 /*
461 * This flag is only needed when we're in high-speed, so let's
462 * disable it if we're in full-speed
463 */
464 if (dev->speed != USB_SPEED_HIGH)
465 us->flags &= ~US_FL_GO_SLOW;
466

--- 11 unchanged lines hidden (view full) ---

478 int msg = -1;
479
480 if (unusual_dev->useProtocol != US_SC_DEVICE &&
481 us->subclass == idesc->bInterfaceSubClass)
482 msg += 1;
483 if (unusual_dev->useTransport != US_PR_DEVICE &&
484 us->protocol == idesc->bInterfaceProtocol)
485 msg += 2;
532 if (msg >= 0 && !(unusual_dev->flags & US_FL_NEED_OVERRIDE))
486 if (msg >= 0 && !(us->flags & US_FL_NEED_OVERRIDE))
533 printk(KERN_NOTICE USB_STORAGE "This device "
534 "(%04x,%04x,%04x S %02x P %02x)"
535 " has %s in unusual_devs.h\n"
536 " Please send a copy of this message to "
537 "<linux-usb-devel@lists.sourceforge.net>\n",
538 le16_to_cpu(ddesc->idVendor),
539 le16_to_cpu(ddesc->idProduct),
540 le16_to_cpu(ddesc->bcdDevice),

--- 375 unchanged lines hidden (view full) ---

916
917
918/* Probe to see if we can drive a newly-connected USB device */
919static int storage_probe(struct usb_interface *intf,
920 const struct usb_device_id *id)
921{
922 struct Scsi_Host *host;
923 struct us_data *us;
487 printk(KERN_NOTICE USB_STORAGE "This device "
488 "(%04x,%04x,%04x S %02x P %02x)"
489 " has %s in unusual_devs.h\n"
490 " Please send a copy of this message to "
491 "<linux-usb-devel@lists.sourceforge.net>\n",
492 le16_to_cpu(ddesc->idVendor),
493 le16_to_cpu(ddesc->idProduct),
494 le16_to_cpu(ddesc->bcdDevice),

--- 375 unchanged lines hidden (view full) ---

870
871
872/* Probe to see if we can drive a newly-connected USB device */
873static int storage_probe(struct usb_interface *intf,
874 const struct usb_device_id *id)
875{
876 struct Scsi_Host *host;
877 struct us_data *us;
924 const int id_index = id - storage_usb_ids;
925 int result;
926 struct task_struct *th;
927
878 int result;
879 struct task_struct *th;
880
881 if (usb_usual_check_type(id, USB_US_TYPE_STOR))
882 return -ENXIO;
883
928 US_DEBUGP("USB Mass Storage device detected\n");
929
930 /*
931 * Ask the SCSI layer to allocate a host structure, with extra
932 * space at the end for our private us_data structure.
933 */
934 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
935 if (!host) {

--- 16 unchanged lines hidden (view full) ---

952
953 /*
954 * Get the unusual_devs entries and the descriptors
955 *
956 * id_index is calculated in the declaration to be the index number
957 * of the match from the usb_device_id table, so we can find the
958 * corresponding entry in the private table.
959 */
884 US_DEBUGP("USB Mass Storage device detected\n");
885
886 /*
887 * Ask the SCSI layer to allocate a host structure, with extra
888 * space at the end for our private us_data structure.
889 */
890 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
891 if (!host) {

--- 16 unchanged lines hidden (view full) ---

908
909 /*
910 * Get the unusual_devs entries and the descriptors
911 *
912 * id_index is calculated in the declaration to be the index number
913 * of the match from the usb_device_id table, so we can find the
914 * corresponding entry in the private table.
915 */
960 get_device_info(us, id_index);
916 get_device_info(us, id);
961
962#ifdef CONFIG_USB_STORAGE_SDDR09
963 if (us->protocol == US_PR_EUSB_SDDR09 ||
964 us->protocol == US_PR_DPCM_USB) {
965 /* set the configuration -- STALL is an acceptable response here */
966 if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) {
967 US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev
968 ->actconfig->desc.bConfigurationValue);

--- 88 unchanged lines hidden (view full) ---

1057
1058static int __init usb_stor_init(void)
1059{
1060 int retval;
1061 printk(KERN_INFO "Initializing USB Mass Storage driver...\n");
1062
1063 /* register the driver, return usb_register return code if error */
1064 retval = usb_register(&usb_storage_driver);
917
918#ifdef CONFIG_USB_STORAGE_SDDR09
919 if (us->protocol == US_PR_EUSB_SDDR09 ||
920 us->protocol == US_PR_DPCM_USB) {
921 /* set the configuration -- STALL is an acceptable response here */
922 if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) {
923 US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev
924 ->actconfig->desc.bConfigurationValue);

--- 88 unchanged lines hidden (view full) ---

1013
1014static int __init usb_stor_init(void)
1015{
1016 int retval;
1017 printk(KERN_INFO "Initializing USB Mass Storage driver...\n");
1018
1019 /* register the driver, return usb_register return code if error */
1020 retval = usb_register(&usb_storage_driver);
1065 if (retval == 0)
1021 if (retval == 0) {
1066 printk(KERN_INFO "USB Mass Storage support registered.\n");
1022 printk(KERN_INFO "USB Mass Storage support registered.\n");
1067
1023 usb_usual_set_present(USB_US_TYPE_STOR);
1024 }
1068 return retval;
1069}
1070
1071static void __exit usb_stor_exit(void)
1072{
1073 US_DEBUGP("usb_stor_exit() called\n");
1074
1075 /* Deregister the driver

--- 7 unchanged lines hidden (view full) ---

1083 * have exited. Since each thread signals threads_gone as its
1084 * last act, we have to call wait_for_completion the right number
1085 * of times.
1086 */
1087 while (atomic_read(&total_threads) > 0) {
1088 wait_for_completion(&threads_gone);
1089 atomic_dec(&total_threads);
1090 }
1025 return retval;
1026}
1027
1028static void __exit usb_stor_exit(void)
1029{
1030 US_DEBUGP("usb_stor_exit() called\n");
1031
1032 /* Deregister the driver

--- 7 unchanged lines hidden (view full) ---

1040 * have exited. Since each thread signals threads_gone as its
1041 * last act, we have to call wait_for_completion the right number
1042 * of times.
1043 */
1044 while (atomic_read(&total_threads) > 0) {
1045 wait_for_completion(&threads_gone);
1046 atomic_dec(&total_threads);
1047 }
1048
1049 usb_usual_clear_present(USB_US_TYPE_STOR);
1091}
1092
1093module_init(usb_stor_init);
1094module_exit(usb_stor_exit);
1050}
1051
1052module_init(usb_stor_init);
1053module_exit(usb_stor_exit);