PATCH: usb-storage: bugfixes for Freecom driver
Subsystems (2)
Attached is a patch to the usb-storage driver. Linus and Alan, please apply. The patch is against 2.4.14.
Sorry for not sending this patch in time for 2.4.14, but it needed more testing than time allowed.
This patch resolves the problems with detecting and initializing devices behind a Freecom USB/ATA bridge, as well as problems with transfer length calculations which were affecting CD-ROM users. The algorithm implemented for initialization is the one recommended by Freecom based on their experience with a wide variety of devices -- it's sub-optimal in many cases, but you often can't identify those cases until much later.
As a side note, this is a great example of why the scsi command structure needs a request_tranferlen as well as the existing request_bufflen fields. It would be much easier all around if the various drivers told the low-level controllers how much data to expect to move, in addition to the total buffer allocation (which is always as big or larger).
I'm still working on a patch to resolve the one last issue with this driver, where the driver fails if a command takes longer than 20 seconds to execute. The bug is in the code that's supposed to recover from a device timeout (the bridge has a 20 sec internal timeout), but it doesn't work right. I'm working with Freecom on this, and should have a patch soon.
Matthew Dharm
Signature · 7 lines
Matthew Dharm Home: [email protected] Maintainer, Linux USB Mass Storage Driver C: They kicked your ass, didn't they? S: They were cheating! -- The Chief and Stef User Friendly, 11/19/1997
Only in linux-2.4.14/drivers/usb/storage: CVS
drivers/usb/storage/freecom.c renamed from drivers/usb/storage.old/freecom.c +42 -46
@@ -1,6 +1,6 @@/* Driver for Freecom USB/IDE adaptor * -* $Id: freecom.c,v 1.15 2001/06/27 23:50:28 mdharm Exp $ +* $Id: freecom.c,v 1.18 2001/11/04 13:01:17 mdharm Exp $ * * Freecom v0.1: *
@@ -132,6 +132,12 @@ sg = (struct scatterlist *) srb->request_buffer;for (i =0 ; i < srb->use_sg; i++) { +US_DEBUGP ("transfer_amount: %d and total_transferred: %d\n" , transfer_amount, total_transferred); + +/* End this if we're done */ +if (transfer_amount == total_transferred) +break ; +/* transfer the lesser of the next buffer or the * remaining data */ if (transfer_amount - total_transferred >=
@@ -139,10 +145,12 @@ result =usb_stor_transfer_partial (us, sg[i].address, sg[i].length); total_transferred += sg[i].length; - }else + }else { result =usb_stor_transfer_partial (us, sg[i].address, transfer_amount - total_transferred); + total_transferred += transfer_amount - total_transferred; + }/* if we get an error, end the loop here */ if (result)
@@ -158,7 +166,7 @@ srb->result = result; } - +#if 0 /* Write a value to an ide register. */ static int freecom_ide_write (struct us_data *us,int reg,int value)
@@ -255,6 +263,7 @@return USB_STOR_TRANSPORT_GOOD ; } +#endif static int freecom_readdata (Scsi_Cmnd *srb, struct us_data *us,
@@ -470,13 +479,15 @@US_DEBUGP ("Device indicates that it has %d bytes available\n" ,le16_to_cpu (fst->Count)); -/* Find the length we desire to read. It is the lesser of the SCSI -* layer's requested length, and the length the device claims to -* have available. */ +/* Find the length we desire to read. */ length =usb_stor_transfer_length (srb);US_DEBUGP ("SCSI requested %d\n" , length); -if (length >le16_to_cpu (fst->Count)) - length =le16_to_cpu (fst->Count); + +/* verify that this amount is legal */ +if (length > srb->request_bufflen) { + length = srb->request_bufflen; +US_DEBUGP ("Truncating request to match buffer length: %d\n" , length); + }/* What we do now depends on what direction the data is supposed to * move in. */
@@ -522,7 +533,6 @@if (result !=USB_STOR_TRANSPORT_GOOD )return result; -#if 1 US_DEBUGP ("FCM: Waiting for status\n" ); result =usb_stor_bulk_msg (us, fst, ipipe,FCM_PACKET_LENGTH , &partial);
@@ -540,7 +550,7 @@US_DEBUGP ("Drive seems still hungry\n" );return USB_STOR_TRANSPORT_FAILED ; } -#endif +US_DEBUGP ("Transfer happy\n" );break ;
@@ -570,8 +580,7 @@int freecom_init (struct us_data *us) { -int result, value; -int counter; +int result;char buffer[33 ];/* Allocate a buffer for us. The upper usb transport code will
@@ -591,42 +600,29 @@ buffer[32 ] ='\0' ;US_DEBUGP ("String returned from FC init is: %s\n" , buffer); - result =freecom_ide_write (us,0x06 ,0xA0 ); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; - result =freecom_ide_write (us,0x01 ,0x00 ); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; - - counter =50 ; -do { - result =freecom_ide_read (us,0x07 , &value); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; -if (counter-- <0 ) { -US_DEBUGP ("Timeout in freecom" ); -return USB_STOR_TRANSPORT_ERROR ; - } - }while ((value &0x80 ) !=0 ); +/* Special thanks to the people at Freecom for providing me with +* this "magic sequence", which they use in their Windows and MacOS +* drivers to make sure that all the attached perhiperals are +* properly reset. +*/ - result =freecom_ide_write (us,0x07 ,0x08 ); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; - - counter =50 ; -do { - result =freecom_ide_read (us,0x07 , &value); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; -if (counter-- <0 ) { -US_DEBUGP ("Timeout in freecom" ); -return USB_STOR_TRANSPORT_ERROR ; - } - }while ((value &0x80 ) !=0 ); +/* send reset */ + result =usb_control_msg (us->pusb_dev, +usb_sndctrlpipe (us->pusb_dev,0 ), +0x4d ,0x40 ,0x24d8 ,0x0 ,NULL ,0x0 ,3 *HZ ); +US_DEBUGP ("result from activate reset is %d\n" , result); + +/* wait 250ms */ +mdelay (250 ); + +/* clear reset */ + result =usb_control_msg (us->pusb_dev, +usb_sndctrlpipe (us->pusb_dev,0 ), +0x4d ,0x40 ,0x24f8 ,0x0 ,NULL ,0x0 ,3 *HZ ); +US_DEBUGP ("result from clear reset is %d\n" , result); - result =freecom_ide_write (us,0x08 ,0x08 ); -if (result !=USB_STOR_TRANSPORT_GOOD ) -return result; +/* wait 3 seconds */ +mdelay (3 *1000 );return USB_STOR_TRANSPORT_GOOD ; }
drivers/usb/storage/scsiglue.c renamed from drivers/usb/storage.old/scsiglue.c +1 -1
@@ -1,7 +1,7 @@/* Driver for USB Mass Storage compliant devices * SCSI layer glue code * -* $Id: scsiglue.c,v 1.22 2001/09/02 04:29:27 mdharm Exp $ +* $Id: scsiglue.c,v 1.23 2001/10/15 07:02:32 mdharm Exp $ * * Current development and maintenance by: * (c) 1999, 2000 Matthew Dharm ([email protected])
drivers/usb/storage/sddr09.c renamed from drivers/usb/storage.old/sddr09.c +1 -1
@@ -1,6 +1,6 @@/* Driver for SanDisk SDDR-09 SmartMedia reader * -* $Id: sddr09.c,v 1.19 2001/09/02 06:07:20 mdharm Exp $ +* $Id: sddr09.c,v 1.21 2001/11/06 03:18:36 mdharm Exp $ * * SDDR09 driver v0.1: *
drivers/usb/storage/transport.c renamed from drivers/usb/storage.old/transport.c +1 -1
@@ -1,6 +1,6 @@/* Driver for USB Mass Storage compliant devices * -* $Id: transport.c,v 1.40 2001/08/18 08:37:46 mdharm Exp $ +* $Id: transport.c,v 1.41 2001/10/15 07:02:32 mdharm Exp $ * * Current development and maintenance by: * (c) 1999, 2000 Matthew Dharm ([email protected])
drivers/usb/storage/usb.c renamed from drivers/usb/storage.old/usb.c +1 -1
@@ -1,6 +1,6 @@/* Driver for USB Mass Storage compliant devices * -* $Id: usb.c,v 1.67 2001/07/29 23:41:52 mdharm Exp $ +* $Id: usb.c,v 1.68 2001/10/15 07:02:33 mdharm Exp $ * * Current development and maintenance by: * (c) 1999, 2000 Matthew Dharm ([email protected])