ChangeSet 1.1512, 2004/01/20 16:02:47-08:00, stern@rowland.harvard.edu [PATCH] USB Storage: Notify the SCSI layer about device resets According to James Bottomley, we need to notify the SCSI midlayer whenever we issue a driver-initiated device reset. That can happen in several places, most notably following a transport error. This patch adds code to the reset routine to take care of it. (Notifying about resets requested by the midlayer itself is unnecessary but harmless.) Alan Stern On 15 Dec 2003, James Bottomley wrote: > It looks like the driver sent a reset to the device on its own without > reporting it to the mid-layer. > > There's an expecting_cc_ua flag in the scsi_device. It gets set on > error recovery actions, or if the device does something to detect or > trigger a reset (that's the scsi_report_device_reset() and > scsi_report_bus_reset() API's). > > James drivers/usb/storage/scsiglue.c | 15 +++++++++++++++ drivers/usb/storage/scsiglue.h | 3 +++ drivers/usb/storage/transport.c | 3 +++ 3 files changed, 21 insertions(+) diff -Nru a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c --- a/drivers/usb/storage/scsiglue.c Tue Jan 20 17:33:27 2004 +++ b/drivers/usb/storage/scsiglue.c Tue Jan 20 17:33:27 2004 @@ -229,6 +229,21 @@ return result < 0 ? FAILED : SUCCESS; } +/* Report a driver-initiated device reset to the SCSI layer. + * Calling this for a SCSI-initiated reset is unnecessary but harmless. */ +void usb_stor_report_device_reset(struct us_data *us) +{ + int i; + + scsi_lock(us->host); + scsi_report_device_reset(us->host, 0, 0); + if (us->flags & US_FL_SCM_MULT_TARG) { + for (i = 1; i < us->host->max_id; ++i) + scsi_report_device_reset(us->host, 0, i); + } + scsi_unlock(us->host); +} + /*********************************************************************** * /proc/scsi/ functions ***********************************************************************/ diff -Nru a/drivers/usb/storage/scsiglue.h b/drivers/usb/storage/scsiglue.h --- a/drivers/usb/storage/scsiglue.h Tue Jan 20 17:33:27 2004 +++ b/drivers/usb/storage/scsiglue.h Tue Jan 20 17:33:27 2004 @@ -44,6 +44,9 @@ #include #include "scsi.h" #include "hosts.h" +#include "usb.h" + +extern void usb_stor_report_device_reset(struct us_data *us); extern unsigned char usb_stor_sense_notready[18]; extern unsigned char usb_stor_sense_invalidCDB[18]; diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c --- a/drivers/usb/storage/transport.c Tue Jan 20 17:33:27 2004 +++ b/drivers/usb/storage/transport.c Tue Jan 20 17:33:27 2004 @@ -1067,6 +1067,9 @@ int result; int result2; + /* Let the SCSI layer know we are doing a reset */ + usb_stor_report_device_reset(us); + /* A 20-second timeout may seem rather long, but a LaCie * StudioDrive USB2 device takes 16+ seconds to get going * following a powerup or USB attach event. */