vserver 1.9.3
[linux-2.6.git] / drivers / usb / storage / scsiglue.c
index 1bdd367..c18cd06 100644 (file)
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-#include "scsiglue.h"
-#include "usb.h"
-#include "debug.h"
-#include "transport.h"
 
 #include <linux/slab.h>
 #include <linux/module.h>
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_devinfo.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_eh.h>
 #include <scsi/scsi_host.h>
 
+#include "scsiglue.h"
+#include "usb.h"
+#include "debug.h"
+#include "transport.h"
+#include "protocol.h"
 
 /***********************************************************************
  * Host functions 
@@ -68,10 +74,13 @@ static int slave_alloc (struct scsi_device *sdev)
 {
        /*
         * Set default bflags. These can be overridden for individual
-        * models and vendors via the scsi devinfo mechanism.
+        * models and vendors via the scsi devinfo mechanism.  The only
+        * flag we need is to force 36-byte INQUIRYs; we don't use any
+        * of the extra data and many devices choke if asked for more or
+        * less than 36 bytes.
         */
-       sdev->sdev_bflags = (BLIST_MS_SKIP_PAGE_08 | BLIST_MS_SKIP_PAGE_3F |
-                            BLIST_USE_10_BYTE_MS);
+       sdev->sdev_bflags = BLIST_INQUIRY_36;
+
        return 0;
 }
 
@@ -89,24 +98,60 @@ static int slave_configure(struct scsi_device *sdev)
         * the end, scatter-gather buffers follow page boundaries. */
        blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
 
-       /* Devices using Genesys Logic chips cause a lot of trouble for
-        * high-speed transfers; they die unpredictably when given more
-        * than 64 KB of data at a time.  If we detect such a device,
-        * reduce the maximum transfer size to 64 KB = 128 sectors. */
-
-#define USB_VENDOR_ID_GENESYS  0x05e3          // Needs a standard location
+       /* According to the technical support people at Genesys Logic,
+        * devices using their chips have problems transferring more than
+        * 32 KB at a time.  In practice people have found that 64 KB
+        * works okay and that's what Windows does.  But we'll be
+        * conservative; people can always use the sysfs interface to
+        * increase max_sectors. */
        if (us->pusb_dev->descriptor.idVendor == USB_VENDOR_ID_GENESYS &&
-                       us->pusb_dev->speed == USB_SPEED_HIGH)
-               blk_queue_max_sectors(sdev->request_queue, 128);
+                       sdev->request_queue->max_sectors > 64)
+               blk_queue_max_sectors(sdev->request_queue, 64);
+
+       /* We can't put these settings in slave_alloc() because that gets
+        * called before the device type is known.  Consequently these
+        * settings can't be overridden via the scsi devinfo mechanism. */
+       if (sdev->type == TYPE_DISK) {
+
+               /* Disk-type devices use MODE SENSE(6) if the protocol
+                * (SubClass) is Transparent SCSI, otherwise they use
+                * MODE SENSE(10). */
+               if (us->subclass != US_SC_SCSI)
+                       sdev->use_10_for_ms = 1;
+
+               /* Many disks only accept MODE SENSE transfer lengths of
+                * 192 bytes (that's what Windows uses). */
+               sdev->use_192_bytes_for_3f = 1;
+
+               /* A number of devices have problems with MODE SENSE for
+                * page x08, so we will skip it. */
+               sdev->skip_ms_page_8 = 1;
+
+#ifndef CONFIG_USB_STORAGE_RW_DETECT
+               /* Some devices may not like MODE SENSE with page=0x3f.
+                * Now that we're using 192-byte transfers this may no
+                * longer be a problem.  So this will be a configuration
+                * option. */
+               sdev->skip_ms_page_3f = 1;
+#endif
 
-       /* this is to satisify the compiler, tho I don't think the 
+       } else {
+
+               /* Non-disk-type devices don't need to blacklist any pages
+                * or to force 192-byte transfer lengths for MODE SENSE.
+                * But they do need to use MODE SENSE(10). */
+               sdev->use_10_for_ms = 1;
+       }
+
+       /* this is to satisfy the compiler, tho I don't think the 
         * return code is ever checked anywhere. */
        return 0;
 }
 
 /* queue a command */
 /* This is always called with scsi_lock(srb->host) held */
-static int queuecommand( Scsi_Cmnd *srb , void (*done)(Scsi_Cmnd *))
+static int queuecommand(struct scsi_cmnd *srb,
+                       void (*done)(struct scsi_cmnd *))
 {
        struct us_data *us = (struct us_data *)srb->device->host->hostdata[0];
 
@@ -136,7 +181,7 @@ static int queuecommand( Scsi_Cmnd *srb , void (*done)(Scsi_Cmnd *))
 
 /* Command abort */
 /* This is always called with scsi_lock(srb->host) held */
-static int command_abort( Scsi_Cmnd *srb )
+static int command_abort(struct scsi_cmnd *srb )
 {
        struct Scsi_Host *host = srb->device->host;
        struct us_data *us = (struct us_data *) host->hostdata[0];
@@ -159,14 +204,18 @@ static int command_abort( Scsi_Cmnd *srb )
                return FAILED;
        }
 
-       /* Set state to ABORTING, set the ABORTING bit, and release the lock */
+       /* Set state to ABORTING and set the ABORTING bit, but only if
+        * a device reset isn't already in progress (to avoid interfering
+        * with the reset).  To prevent races with auto-reset, we must
+        * stop any ongoing USB transfers while still holding the host
+        * lock. */
        us->sm_state = US_STATE_ABORTING;
-       set_bit(US_FLIDX_ABORTING, &us->flags);
+       if (!test_bit(US_FLIDX_RESETTING, &us->flags)) {
+               set_bit(US_FLIDX_ABORTING, &us->flags);
+               usb_stor_stop_transport(us);
+       }
        scsi_unlock(host);
 
-       /* Stop an ongoing USB transfer */
-       usb_stor_stop_transport(us);
-
        /* Wait for the aborted command to finish */
        wait_for_completion(&us->notify);
 
@@ -179,7 +228,7 @@ static int command_abort( Scsi_Cmnd *srb )
 /* This invokes the transport reset mechanism to reset the state of the
  * device */
 /* This is always called with scsi_lock(srb->host) held */
-static int device_reset( Scsi_Cmnd *srb )
+static int device_reset(struct scsi_cmnd *srb)
 {
        struct us_data *us = (struct us_data *)srb->device->host->hostdata[0];
        int result;
@@ -214,7 +263,7 @@ static int device_reset( Scsi_Cmnd *srb )
 /* 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(srb->host) held */
-static int bus_reset( Scsi_Cmnd *srb )
+static int bus_reset(struct scsi_cmnd *srb)
 {
        struct us_data *us = (struct us_data *)srb->device->host->hostdata[0];
        int result;
@@ -254,18 +303,17 @@ static int bus_reset( Scsi_Cmnd *srb )
 }
 
 /* Report a driver-initiated device reset to the SCSI layer.
- * Calling this for a SCSI-initiated reset is unnecessary but harmless. */
+ * Calling this for a SCSI-initiated reset is unnecessary but harmless.
+ * The caller must own the SCSI host lock. */
 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);
 }
 
 /***********************************************************************
@@ -401,10 +449,13 @@ struct scsi_host_template usb_stor_host_template = {
         * periodically someone should test to see which setting is more
         * optimal.
         */
-       .use_clustering =               TRUE,
+       .use_clustering =               1,
 
        /* emulated HBA */
-       .emulated =                     TRUE,
+       .emulated =                     1,
+
+       /* we do our own delay after a device or bus reset */
+       .skip_settle_delay =            1,
 
        /* sysfs device attributes */
        .sdev_attrs =                   sysfs_device_attr_list,