[PATCH] USB Storage: port reset on transport error
This patch causes a port reset whenever there's a transport error or abort. If that fails it reverts back to doing a mass-storage device reset. It started life as as497 and was rediffed by me. This makes error recovery a lot quicker and more reliable. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
5203ad4413
commit
4d07ef762f
|
@ -255,50 +255,23 @@ static int device_reset(struct scsi_cmnd *srb)
|
||||||
|
|
||||||
/* lock the device pointers and do the reset */
|
/* lock the device pointers and do the reset */
|
||||||
down(&(us->dev_semaphore));
|
down(&(us->dev_semaphore));
|
||||||
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
|
||||||
result = FAILED;
|
|
||||||
US_DEBUGP("No reset during disconnect\n");
|
|
||||||
} else
|
|
||||||
result = us->transport_reset(us);
|
result = us->transport_reset(us);
|
||||||
up(&(us->dev_semaphore));
|
up(&(us->dev_semaphore));
|
||||||
|
|
||||||
return result;
|
return result < 0 ? FAILED : SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This resets the device's USB port. */
|
/* Simulate a SCSI bus reset by resetting the device's USB port. */
|
||||||
/* It refuses to work if there's more than one interface in
|
|
||||||
* the device, so that other users are not affected. */
|
|
||||||
/* This is always called with scsi_lock(host) held */
|
/* This is always called with scsi_lock(host) held */
|
||||||
static int bus_reset(struct scsi_cmnd *srb)
|
static int bus_reset(struct scsi_cmnd *srb)
|
||||||
{
|
{
|
||||||
struct us_data *us = host_to_us(srb->device->host);
|
struct us_data *us = host_to_us(srb->device->host);
|
||||||
int result, rc;
|
int result;
|
||||||
|
|
||||||
US_DEBUGP("%s called\n", __FUNCTION__);
|
US_DEBUGP("%s called\n", __FUNCTION__);
|
||||||
|
|
||||||
/* The USB subsystem doesn't handle synchronisation between
|
|
||||||
* a device's several drivers. Therefore we reset only devices
|
|
||||||
* with just one interface, which we of course own. */
|
|
||||||
|
|
||||||
down(&(us->dev_semaphore));
|
down(&(us->dev_semaphore));
|
||||||
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
result = usb_stor_port_reset(us);
|
||||||
result = -EIO;
|
|
||||||
US_DEBUGP("No reset during disconnect\n");
|
|
||||||
} else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
|
|
||||||
result = -EBUSY;
|
|
||||||
US_DEBUGP("Refusing to reset a multi-interface device\n");
|
|
||||||
} else {
|
|
||||||
rc = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
|
|
||||||
if (rc < 0) {
|
|
||||||
US_DEBUGP("unable to lock device for reset: %d\n", rc);
|
|
||||||
result = rc;
|
|
||||||
} else {
|
|
||||||
result = usb_reset_device(us->pusb_dev);
|
|
||||||
if (rc)
|
|
||||||
usb_unlock_device(us->pusb_dev);
|
|
||||||
US_DEBUGP("usb_reset_device returns %d\n", result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
up(&(us->dev_semaphore));
|
up(&(us->dev_semaphore));
|
||||||
|
|
||||||
/* lock the host for the return */
|
/* lock the host for the return */
|
||||||
|
@ -320,6 +293,14 @@ void usb_stor_report_device_reset(struct us_data *us)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Report a driver-initiated bus reset to the SCSI layer.
|
||||||
|
* Calling this for a SCSI-initiated reset is unnecessary but harmless.
|
||||||
|
* The caller must own the SCSI host lock. */
|
||||||
|
void usb_stor_report_bus_reset(struct us_data *us)
|
||||||
|
{
|
||||||
|
scsi_report_bus_reset(us_to_host(us), 0);
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* /proc/scsi/ functions
|
* /proc/scsi/ functions
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#define _SCSIGLUE_H_
|
#define _SCSIGLUE_H_
|
||||||
|
|
||||||
extern void usb_stor_report_device_reset(struct us_data *us);
|
extern void usb_stor_report_device_reset(struct us_data *us);
|
||||||
|
extern void usb_stor_report_bus_reset(struct us_data *us);
|
||||||
|
|
||||||
extern unsigned char usb_stor_sense_invalidCDB[18];
|
extern unsigned char usb_stor_sense_invalidCDB[18];
|
||||||
extern struct scsi_host_template usb_stor_host_template;
|
extern struct scsi_host_template usb_stor_host_template;
|
||||||
|
|
|
@ -541,15 +541,15 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
|
||||||
*/
|
*/
|
||||||
if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
|
if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
|
||||||
US_DEBUGP("-- command was aborted\n");
|
US_DEBUGP("-- command was aborted\n");
|
||||||
goto Handle_Abort;
|
srb->result = DID_ABORT << 16;
|
||||||
|
goto Handle_Errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there is a transport error, reset and don't auto-sense */
|
/* if there is a transport error, reset and don't auto-sense */
|
||||||
if (result == USB_STOR_TRANSPORT_ERROR) {
|
if (result == USB_STOR_TRANSPORT_ERROR) {
|
||||||
US_DEBUGP("-- transport indicates error, resetting\n");
|
US_DEBUGP("-- transport indicates error, resetting\n");
|
||||||
us->transport_reset(us);
|
|
||||||
srb->result = DID_ERROR << 16;
|
srb->result = DID_ERROR << 16;
|
||||||
return;
|
goto Handle_Errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the transport provided its own sense data, don't auto-sense */
|
/* if the transport provided its own sense data, don't auto-sense */
|
||||||
|
@ -669,7 +669,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
|
||||||
|
|
||||||
if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
|
if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
|
||||||
US_DEBUGP("-- auto-sense aborted\n");
|
US_DEBUGP("-- auto-sense aborted\n");
|
||||||
goto Handle_Abort;
|
srb->result = DID_ABORT << 16;
|
||||||
|
goto Handle_Errors;
|
||||||
}
|
}
|
||||||
if (temp_result != USB_STOR_TRANSPORT_GOOD) {
|
if (temp_result != USB_STOR_TRANSPORT_GOOD) {
|
||||||
US_DEBUGP("-- auto-sense failure\n");
|
US_DEBUGP("-- auto-sense failure\n");
|
||||||
|
@ -678,9 +679,9 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
|
||||||
* multi-target device, since failure of an
|
* multi-target device, since failure of an
|
||||||
* auto-sense is perfectly valid
|
* auto-sense is perfectly valid
|
||||||
*/
|
*/
|
||||||
if (!(us->flags & US_FL_SCM_MULT_TARG))
|
|
||||||
us->transport_reset(us);
|
|
||||||
srb->result = DID_ERROR << 16;
|
srb->result = DID_ERROR << 16;
|
||||||
|
if (!(us->flags & US_FL_SCM_MULT_TARG))
|
||||||
|
goto Handle_Errors;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,12 +722,28 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* abort processing: the bulk-only transport requires a reset
|
/* Error and abort processing: try to resynchronize with the device
|
||||||
* following an abort */
|
* by issuing a port reset. If that fails, try a class-specific
|
||||||
Handle_Abort:
|
* device reset. */
|
||||||
srb->result = DID_ABORT << 16;
|
Handle_Errors:
|
||||||
if (us->protocol == US_PR_BULK)
|
|
||||||
|
/* Let the SCSI layer know we are doing a reset, set the
|
||||||
|
* RESETTING bit, and clear the ABORTING bit so that the reset
|
||||||
|
* may proceed. */
|
||||||
|
scsi_lock(us_to_host(us));
|
||||||
|
usb_stor_report_bus_reset(us);
|
||||||
|
set_bit(US_FLIDX_RESETTING, &us->flags);
|
||||||
|
clear_bit(US_FLIDX_ABORTING, &us->flags);
|
||||||
|
scsi_unlock(us_to_host(us));
|
||||||
|
|
||||||
|
result = usb_stor_port_reset(us);
|
||||||
|
if (result < 0) {
|
||||||
|
scsi_lock(us_to_host(us));
|
||||||
|
usb_stor_report_device_reset(us);
|
||||||
|
scsi_unlock(us_to_host(us));
|
||||||
us->transport_reset(us);
|
us->transport_reset(us);
|
||||||
|
}
|
||||||
|
clear_bit(US_FLIDX_RESETTING, &us->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the current URB transfer */
|
/* Stop the current URB transfer */
|
||||||
|
@ -1134,24 +1151,18 @@ static int usb_stor_reset_common(struct us_data *us,
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int result2;
|
int result2;
|
||||||
int rc = FAILED;
|
|
||||||
|
|
||||||
/* Let the SCSI layer know we are doing a reset, set the
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
||||||
* RESETTING bit, and clear the ABORTING bit so that the reset
|
US_DEBUGP("No reset during disconnect\n");
|
||||||
* may proceed.
|
return -EIO;
|
||||||
*/
|
}
|
||||||
scsi_lock(us_to_host(us));
|
|
||||||
usb_stor_report_device_reset(us);
|
|
||||||
set_bit(US_FLIDX_RESETTING, &us->flags);
|
|
||||||
clear_bit(US_FLIDX_ABORTING, &us->flags);
|
|
||||||
scsi_unlock(us_to_host(us));
|
|
||||||
|
|
||||||
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
|
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
|
||||||
request, requesttype, value, index, data, size,
|
request, requesttype, value, index, data, size,
|
||||||
5*HZ);
|
5*HZ);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
US_DEBUGP("Soft reset failed: %d\n", result);
|
US_DEBUGP("Soft reset failed: %d\n", result);
|
||||||
goto Done;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Give the device some time to recover from the reset,
|
/* Give the device some time to recover from the reset,
|
||||||
|
@ -1161,7 +1172,7 @@ static int usb_stor_reset_common(struct us_data *us,
|
||||||
HZ*6);
|
HZ*6);
|
||||||
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
||||||
US_DEBUGP("Reset interrupted by disconnect\n");
|
US_DEBUGP("Reset interrupted by disconnect\n");
|
||||||
goto Done;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n");
|
US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n");
|
||||||
|
@ -1173,16 +1184,11 @@ static int usb_stor_reset_common(struct us_data *us,
|
||||||
/* return a result code based on the result of the clear-halts */
|
/* return a result code based on the result of the clear-halts */
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
result = result2;
|
result = result2;
|
||||||
if (result < 0) {
|
if (result < 0)
|
||||||
US_DEBUGP("Soft reset failed\n");
|
US_DEBUGP("Soft reset failed\n");
|
||||||
goto Done;
|
else
|
||||||
}
|
|
||||||
US_DEBUGP("Soft reset done\n");
|
US_DEBUGP("Soft reset done\n");
|
||||||
rc = SUCCESS;
|
return result;
|
||||||
|
|
||||||
Done:
|
|
||||||
clear_bit(US_FLIDX_RESETTING, &us->flags);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This issues a CB[I] Reset to the device in question
|
/* This issues a CB[I] Reset to the device in question
|
||||||
|
@ -1212,3 +1218,32 @@ int usb_stor_Bulk_reset(struct us_data *us)
|
||||||
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
||||||
0, us->ifnum, NULL, 0);
|
0, us->ifnum, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Issue a USB port reset to the device. But don't do anything if
|
||||||
|
* there's more than one interface in the device, so that other users
|
||||||
|
* are not affected. */
|
||||||
|
int usb_stor_port_reset(struct us_data *us)
|
||||||
|
{
|
||||||
|
int result, rc;
|
||||||
|
|
||||||
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
|
||||||
|
result = -EIO;
|
||||||
|
US_DEBUGP("No reset during disconnect\n");
|
||||||
|
} else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
|
||||||
|
result = -EBUSY;
|
||||||
|
US_DEBUGP("Refusing to reset a multi-interface device\n");
|
||||||
|
} else {
|
||||||
|
result = rc =
|
||||||
|
usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
|
||||||
|
if (result < 0) {
|
||||||
|
US_DEBUGP("unable to lock device for reset: %d\n",
|
||||||
|
result);
|
||||||
|
} else {
|
||||||
|
result = usb_reset_device(us->pusb_dev);
|
||||||
|
if (rc)
|
||||||
|
usb_unlock_device(us->pusb_dev);
|
||||||
|
US_DEBUGP("usb_reset_device returns %d\n", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -171,4 +171,5 @@ extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
|
||||||
extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
|
extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
|
||||||
void *buf, unsigned int length, int use_sg, int *residual);
|
void *buf, unsigned int length, int use_sg, int *residual);
|
||||||
|
|
||||||
|
extern int usb_stor_port_reset(struct us_data *us);
|
||||||
#endif
|
#endif
|
||||||
|
|
Reference in New Issue