diff options
Diffstat (limited to 'drivers/usb/storage/usb.c')
-rw-r--r-- | drivers/usb/storage/usb.c | 98 |
1 files changed, 63 insertions, 35 deletions
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 9de988a0f856..ef2d8cde6ef7 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* Driver for USB Mass Storage compliant devices | 1 | /* |
2 | * Driver for USB Mass Storage compliant devices | ||
2 | * | 3 | * |
3 | * Current development and maintenance by: | 4 | * Current development and maintenance by: |
4 | * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net) | 5 | * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net) |
@@ -97,7 +98,8 @@ MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks"); | |||
97 | * with the entries in usb_storage_usb_ids[], defined in usual-tables.c. | 98 | * with the entries in usb_storage_usb_ids[], defined in usual-tables.c. |
98 | */ | 99 | */ |
99 | 100 | ||
100 | /* The vendor name should be kept at eight characters or less, and | 101 | /* |
102 | *The vendor name should be kept at eight characters or less, and | ||
101 | * the product name should be kept at 16 characters or less. If a device | 103 | * the product name should be kept at 16 characters or less. If a device |
102 | * has the US_FL_FIX_INQUIRY flag, then the vendor and product names | 104 | * has the US_FL_FIX_INQUIRY flag, then the vendor and product names |
103 | * normally generated by a device through the INQUIRY response will be | 105 | * normally generated by a device through the INQUIRY response will be |
@@ -191,8 +193,10 @@ int usb_stor_suspend(struct usb_interface *iface, pm_message_t message) | |||
191 | if (us->suspend_resume_hook) | 193 | if (us->suspend_resume_hook) |
192 | (us->suspend_resume_hook)(us, US_SUSPEND); | 194 | (us->suspend_resume_hook)(us, US_SUSPEND); |
193 | 195 | ||
194 | /* When runtime PM is working, we'll set a flag to indicate | 196 | /* |
195 | * whether we should autoresume when a SCSI request arrives. */ | 197 | * When runtime PM is working, we'll set a flag to indicate |
198 | * whether we should autoresume when a SCSI request arrives. | ||
199 | */ | ||
196 | 200 | ||
197 | mutex_unlock(&us->dev_mutex); | 201 | mutex_unlock(&us->dev_mutex); |
198 | return 0; | 202 | return 0; |
@@ -220,8 +224,10 @@ int usb_stor_reset_resume(struct usb_interface *iface) | |||
220 | /* Report the reset to the SCSI core */ | 224 | /* Report the reset to the SCSI core */ |
221 | usb_stor_report_bus_reset(us); | 225 | usb_stor_report_bus_reset(us); |
222 | 226 | ||
223 | /* FIXME: Notify the subdrivers that they need to reinitialize | 227 | /* |
224 | * the device */ | 228 | * FIXME: Notify the subdrivers that they need to reinitialize |
229 | * the device | ||
230 | */ | ||
225 | return 0; | 231 | return 0; |
226 | } | 232 | } |
227 | EXPORT_SYMBOL_GPL(usb_stor_reset_resume); | 233 | EXPORT_SYMBOL_GPL(usb_stor_reset_resume); |
@@ -250,8 +256,10 @@ int usb_stor_post_reset(struct usb_interface *iface) | |||
250 | /* Report the reset to the SCSI core */ | 256 | /* Report the reset to the SCSI core */ |
251 | usb_stor_report_bus_reset(us); | 257 | usb_stor_report_bus_reset(us); |
252 | 258 | ||
253 | /* FIXME: Notify the subdrivers that they need to reinitialize | 259 | /* |
254 | * the device */ | 260 | * FIXME: Notify the subdrivers that they need to reinitialize |
261 | * the device | ||
262 | */ | ||
255 | 263 | ||
256 | mutex_unlock(&us->dev_mutex); | 264 | mutex_unlock(&us->dev_mutex); |
257 | return 0; | 265 | return 0; |
@@ -274,15 +282,17 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data, | |||
274 | return; | 282 | return; |
275 | 283 | ||
276 | memset(data+8, ' ', 28); | 284 | memset(data+8, ' ', 28); |
277 | if (data[0]&0x20) { /* USB device currently not connected. Return | 285 | if (data[0]&0x20) { /* |
278 | peripheral qualifier 001b ("...however, the | 286 | * USB device currently not connected. Return |
279 | physical device is not currently connected | 287 | * peripheral qualifier 001b ("...however, the |
280 | to this logical unit") and leave vendor and | 288 | * physical device is not currently connected |
281 | product identification empty. ("If the target | 289 | * to this logical unit") and leave vendor and |
282 | does store some of the INQUIRY data on the | 290 | * product identification empty. ("If the target |
283 | device, it may return zeros or ASCII spaces | 291 | * does store some of the INQUIRY data on the |
284 | (20h) in those fields until the data is | 292 | * device, it may return zeros or ASCII spaces |
285 | available from the device."). */ | 293 | * (20h) in those fields until the data is |
294 | * available from the device."). | ||
295 | */ | ||
286 | } else { | 296 | } else { |
287 | u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); | 297 | u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); |
288 | int n; | 298 | int n; |
@@ -336,7 +346,8 @@ static int usb_stor_control_thread(void * __us) | |||
336 | 346 | ||
337 | scsi_unlock(host); | 347 | scsi_unlock(host); |
338 | 348 | ||
339 | /* reject the command if the direction indicator | 349 | /* |
350 | * reject the command if the direction indicator | ||
340 | * is UNKNOWN | 351 | * is UNKNOWN |
341 | */ | 352 | */ |
342 | if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { | 353 | if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { |
@@ -344,7 +355,8 @@ static int usb_stor_control_thread(void * __us) | |||
344 | us->srb->result = DID_ERROR << 16; | 355 | us->srb->result = DID_ERROR << 16; |
345 | } | 356 | } |
346 | 357 | ||
347 | /* reject if target != 0 or if LUN is higher than | 358 | /* |
359 | * reject if target != 0 or if LUN is higher than | ||
348 | * the maximum known LUN | 360 | * the maximum known LUN |
349 | */ | 361 | */ |
350 | else if (us->srb->device->id && | 362 | else if (us->srb->device->id && |
@@ -362,8 +374,10 @@ static int usb_stor_control_thread(void * __us) | |||
362 | us->srb->result = DID_BAD_TARGET << 16; | 374 | us->srb->result = DID_BAD_TARGET << 16; |
363 | } | 375 | } |
364 | 376 | ||
365 | /* Handle those devices which need us to fake | 377 | /* |
366 | * their inquiry data */ | 378 | * Handle those devices which need us to fake |
379 | * their inquiry data | ||
380 | */ | ||
367 | else if ((us->srb->cmnd[0] == INQUIRY) && | 381 | else if ((us->srb->cmnd[0] == INQUIRY) && |
368 | (us->fflags & US_FL_FIX_INQUIRY)) { | 382 | (us->fflags & US_FL_FIX_INQUIRY)) { |
369 | unsigned char data_ptr[36] = { | 383 | unsigned char data_ptr[36] = { |
@@ -395,11 +409,13 @@ SkipForAbort: | |||
395 | usb_stor_dbg(us, "scsi command aborted\n"); | 409 | usb_stor_dbg(us, "scsi command aborted\n"); |
396 | } | 410 | } |
397 | 411 | ||
398 | /* If an abort request was received we need to signal that | 412 | /* |
413 | * If an abort request was received we need to signal that | ||
399 | * the abort has finished. The proper test for this is | 414 | * the abort has finished. The proper test for this is |
400 | * the TIMED_OUT flag, not srb->result == DID_ABORT, because | 415 | * the TIMED_OUT flag, not srb->result == DID_ABORT, because |
401 | * the timeout might have occurred after the command had | 416 | * the timeout might have occurred after the command had |
402 | * already completed with a different result code. */ | 417 | * already completed with a different result code. |
418 | */ | ||
403 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { | 419 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { |
404 | complete(&(us->notify)); | 420 | complete(&(us->notify)); |
405 | 421 | ||
@@ -610,7 +626,8 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id, | |||
610 | le16_to_cpu(dev->descriptor.idProduct), | 626 | le16_to_cpu(dev->descriptor.idProduct), |
611 | us->fflags); | 627 | us->fflags); |
612 | 628 | ||
613 | /* Log a message if a non-generic unusual_dev entry contains an | 629 | /* |
630 | * Log a message if a non-generic unusual_dev entry contains an | ||
614 | * unnecessary subclass or protocol override. This may stimulate | 631 | * unnecessary subclass or protocol override. This may stimulate |
615 | * reports from users that will help us remove unneeded entries | 632 | * reports from users that will help us remove unneeded entries |
616 | * from the unusual_devs.h table. | 633 | * from the unusual_devs.h table. |
@@ -782,8 +799,10 @@ static int usb_stor_acquire_resources(struct us_data *us) | |||
782 | return -ENOMEM; | 799 | return -ENOMEM; |
783 | } | 800 | } |
784 | 801 | ||
785 | /* Just before we start our control thread, initialize | 802 | /* |
786 | * the device if it needs initialization */ | 803 | * Just before we start our control thread, initialize |
804 | * the device if it needs initialization | ||
805 | */ | ||
787 | if (us->unusual_dev->initFunction) { | 806 | if (us->unusual_dev->initFunction) { |
788 | p = us->unusual_dev->initFunction(us); | 807 | p = us->unusual_dev->initFunction(us); |
789 | if (p) | 808 | if (p) |
@@ -805,7 +824,8 @@ static int usb_stor_acquire_resources(struct us_data *us) | |||
805 | /* Release all our dynamic resources */ | 824 | /* Release all our dynamic resources */ |
806 | static void usb_stor_release_resources(struct us_data *us) | 825 | static void usb_stor_release_resources(struct us_data *us) |
807 | { | 826 | { |
808 | /* Tell the control thread to exit. The SCSI host must | 827 | /* |
828 | * Tell the control thread to exit. The SCSI host must | ||
809 | * already have been removed and the DISCONNECTING flag set | 829 | * already have been removed and the DISCONNECTING flag set |
810 | * so that we won't accept any more commands. | 830 | * so that we won't accept any more commands. |
811 | */ | 831 | */ |
@@ -836,7 +856,8 @@ static void dissociate_dev(struct us_data *us) | |||
836 | usb_set_intfdata(us->pusb_intf, NULL); | 856 | usb_set_intfdata(us->pusb_intf, NULL); |
837 | } | 857 | } |
838 | 858 | ||
839 | /* First stage of disconnect processing: stop SCSI scanning, | 859 | /* |
860 | * First stage of disconnect processing: stop SCSI scanning, | ||
840 | * remove the host, and stop accepting new commands | 861 | * remove the host, and stop accepting new commands |
841 | */ | 862 | */ |
842 | static void quiesce_and_remove_host(struct us_data *us) | 863 | static void quiesce_and_remove_host(struct us_data *us) |
@@ -849,7 +870,8 @@ static void quiesce_and_remove_host(struct us_data *us) | |||
849 | wake_up(&us->delay_wait); | 870 | wake_up(&us->delay_wait); |
850 | } | 871 | } |
851 | 872 | ||
852 | /* Prevent SCSI scanning (if it hasn't started yet) | 873 | /* |
874 | * Prevent SCSI scanning (if it hasn't started yet) | ||
853 | * or wait for the SCSI-scanning routine to stop. | 875 | * or wait for the SCSI-scanning routine to stop. |
854 | */ | 876 | */ |
855 | cancel_delayed_work_sync(&us->scan_dwork); | 877 | cancel_delayed_work_sync(&us->scan_dwork); |
@@ -858,12 +880,14 @@ static void quiesce_and_remove_host(struct us_data *us) | |||
858 | if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags)) | 880 | if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags)) |
859 | usb_autopm_put_interface_no_suspend(us->pusb_intf); | 881 | usb_autopm_put_interface_no_suspend(us->pusb_intf); |
860 | 882 | ||
861 | /* Removing the host will perform an orderly shutdown: caches | 883 | /* |
884 | * Removing the host will perform an orderly shutdown: caches | ||
862 | * synchronized, disks spun down, etc. | 885 | * synchronized, disks spun down, etc. |
863 | */ | 886 | */ |
864 | scsi_remove_host(host); | 887 | scsi_remove_host(host); |
865 | 888 | ||
866 | /* Prevent any new commands from being accepted and cut short | 889 | /* |
890 | * Prevent any new commands from being accepted and cut short | ||
867 | * reset delays. | 891 | * reset delays. |
868 | */ | 892 | */ |
869 | scsi_lock(host); | 893 | scsi_lock(host); |
@@ -878,8 +902,10 @@ static void release_everything(struct us_data *us) | |||
878 | usb_stor_release_resources(us); | 902 | usb_stor_release_resources(us); |
879 | dissociate_dev(us); | 903 | dissociate_dev(us); |
880 | 904 | ||
881 | /* Drop our reference to the host; the SCSI core will free it | 905 | /* |
882 | * (and "us" along with it) when the refcount becomes 0. */ | 906 | * Drop our reference to the host; the SCSI core will free it |
907 | * (and "us" along with it) when the refcount becomes 0. | ||
908 | */ | ||
883 | scsi_host_put(us_to_host(us)); | 909 | scsi_host_put(us_to_host(us)); |
884 | } | 910 | } |
885 | 911 | ||
@@ -900,7 +926,8 @@ static void usb_stor_scan_dwork(struct work_struct *work) | |||
900 | us->max_lun = usb_stor_Bulk_max_lun(us); | 926 | us->max_lun = usb_stor_Bulk_max_lun(us); |
901 | /* | 927 | /* |
902 | * Allow proper scanning of devices that present more than 8 LUNs | 928 | * Allow proper scanning of devices that present more than 8 LUNs |
903 | * While not affecting other devices that may need the previous behavior | 929 | * While not affecting other devices that may need the previous |
930 | * behavior | ||
904 | */ | 931 | */ |
905 | if (us->max_lun >= 8) | 932 | if (us->max_lun >= 8) |
906 | us_to_host(us)->max_lun = us->max_lun+1; | 933 | us_to_host(us)->max_lun = us->max_lun+1; |
@@ -975,7 +1002,8 @@ int usb_stor_probe1(struct us_data **pus, | |||
975 | get_transport(us); | 1002 | get_transport(us); |
976 | get_protocol(us); | 1003 | get_protocol(us); |
977 | 1004 | ||
978 | /* Give the caller a chance to fill in specialized transport | 1005 | /* |
1006 | * Give the caller a chance to fill in specialized transport | ||
979 | * or protocol settings. | 1007 | * or protocol settings. |
980 | */ | 1008 | */ |
981 | return 0; | 1009 | return 0; |