scsi: Add QEMU CD-ROM to VPD Inquiry Blacklist
[cascardo/linux.git] / drivers / scsi / atari_scsi.c
index 78d1b29..a59ad94 100644 (file)
  *
  */
 
-
-/**************************************************************************/
-/*                                                                        */
-/* Notes for Falcon SCSI:                                                 */
-/* ----------------------                                                 */
-/*                                                                        */
-/* Since the Falcon SCSI uses the ST-DMA chip, that is shared among       */
-/* several device drivers, locking and unlocking the access to this       */
-/* chip is required. But locking is not possible from an interrupt,       */
-/* since it puts the process to sleep if the lock is not available.       */
-/* This prevents "late" locking of the DMA chip, i.e. locking it just     */
-/* before using it, since in case of disconnection-reconnection           */
-/* commands, the DMA is started from the reselection interrupt.           */
-/*                                                                        */
-/* Two possible schemes for ST-DMA-locking would be:                      */
-/*  1) The lock is taken for each command separately and disconnecting    */
-/*     is forbidden (i.e. can_queue = 1).                                 */
-/*  2) The DMA chip is locked when the first command comes in and         */
-/*     released when the last command is finished and all queues are      */
-/*     empty.                                                             */
-/* The first alternative would result in bad performance, since the       */
-/* interleaving of commands would not be used. The second is unfair to    */
-/* other drivers using the ST-DMA, because the queues will seldom be      */
-/* totally empty if there is a lot of disk traffic.                       */
-/*                                                                        */
-/* For this reasons I decided to employ a more elaborate scheme:          */
-/*  - First, we give up the lock every time we can (for fairness), this    */
-/*    means every time a command finishes and there are no other commands */
-/*    on the disconnected queue.                                          */
-/*  - If there are others waiting to lock the DMA chip, we stop           */
-/*    issuing commands, i.e. moving them onto the issue queue.           */
-/*    Because of that, the disconnected queue will run empty in a         */
-/*    while. Instead we go to sleep on a 'fairness_queue'.                */
-/*  - If the lock is released, all processes waiting on the fairness      */
-/*    queue will be woken. The first of them tries to re-lock the DMA,     */
-/*    the others wait for the first to finish this task. After that,      */
-/*    they can all run on and do their commands...                        */
-/* This sounds complicated (and it is it :-(), but it seems to be a       */
-/* good compromise between fairness and performance: As long as no one     */
-/* else wants to work with the ST-DMA chip, SCSI can go along as          */
-/* usual. If now someone else comes, this behaviour is changed to a       */
-/* "fairness mode": just already initiated commands are finished and      */
-/* then the lock is released. The other one waiting will probably win     */
-/* the race for locking the DMA, since it was waiting for longer. And     */
-/* after it has finished, SCSI can go ahead again. Finally: I hope I      */
-/* have not produced any deadlock possibilities!                          */
-/*                                                                        */
-/**************************************************************************/
-
+/*
+ * Notes for Falcon SCSI DMA
+ *
+ * The 5380 device is one of several that all share the DMA chip. Hence
+ * "locking" and "unlocking" access to this chip is required.
+ *
+ * Two possible schemes for ST DMA acquisition by atari_scsi are:
+ * 1) The lock is taken for each command separately (i.e. can_queue == 1).
+ * 2) The lock is taken when the first command arrives and released
+ * when the last command is finished (i.e. can_queue > 1).
+ *
+ * The first alternative limits SCSI bus utilization, since interleaving
+ * commands is not possible. The second gives better performance but is
+ * unfair to other drivers needing to use the ST DMA chip. In order to
+ * allow the IDE and floppy drivers equal access to the ST DMA chip
+ * the default is can_queue == 1.
+ */
 
 #include <linux/module.h>
 #include <linux/types.h>
 
 #include <scsi/scsi_host.h>
 
-/* Definitions for the core NCR5380 driver. */
-
-#define REAL_DMA
-#define SUPPORT_TAGS
-#define MAX_TAGS                        32
 #define DMA_MIN_SIZE                    32
 
+/* Definitions for the core NCR5380 driver. */
+
 #define NCR5380_implementation_fields   /* none */
 
 #define NCR5380_read(reg)               atari_scsi_reg_read(reg)
@@ -99,9 +64,9 @@
 #define NCR5380_abort                   atari_scsi_abort
 #define NCR5380_info                    atari_scsi_info
 
-#define NCR5380_dma_read_setup(instance, data, count) \
+#define NCR5380_dma_recv_setup(instance, data, count) \
         atari_scsi_dma_setup(instance, data, count, 0)
-#define NCR5380_dma_write_setup(instance, data, count) \
+#define NCR5380_dma_send_setup(instance, data, count) \
         atari_scsi_dma_setup(instance, data, count, 1)
 #define NCR5380_dma_residual(instance) \
         atari_scsi_dma_residual(instance)
@@ -159,14 +124,11 @@ static inline unsigned long SCSI_DMA_GETADR(void)
        return adr;
 }
 
-#ifdef REAL_DMA
 static void atari_scsi_fetch_restbytes(void);
-#endif
 
 static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
 static void (*atari_scsi_reg_write)(unsigned char reg, unsigned char value);
 
-#ifdef REAL_DMA
 static unsigned long   atari_dma_residual, atari_dma_startaddr;
 static short           atari_dma_active;
 /* pointer to the dribble buffer */
@@ -185,7 +147,6 @@ static char         *atari_dma_orig_addr;
 /* mask for address bits that can't be used with the ST-DMA */
 static unsigned long   atari_dma_stram_mask;
 #define STRAM_ADDR(a)  (((a) & atari_dma_stram_mask) == 0)
-#endif
 
 static int setup_can_queue = -1;
 module_param(setup_can_queue, int, 0);
@@ -193,16 +154,12 @@ static int setup_cmd_per_lun = -1;
 module_param(setup_cmd_per_lun, int, 0);
 static int setup_sg_tablesize = -1;
 module_param(setup_sg_tablesize, int, 0);
-static int setup_use_tagged_queuing = -1;
-module_param(setup_use_tagged_queuing, int, 0);
 static int setup_hostid = -1;
 module_param(setup_hostid, int, 0);
 static int setup_toshiba_delay = -1;
 module_param(setup_toshiba_delay, int, 0);
 
 
-#if defined(REAL_DMA)
-
 static int scsi_dma_is_ignored_buserr(unsigned char dma_stat)
 {
        int i;
@@ -255,12 +212,9 @@ static void scsi_dma_buserr(int irq, void *dummy)
 }
 #endif
 
-#endif
-
 
 static irqreturn_t scsi_tt_intr(int irq, void *dev)
 {
-#ifdef REAL_DMA
        struct Scsi_Host *instance = dev;
        struct NCR5380_hostdata *hostdata = shost_priv(instance);
        int dma_stat;
@@ -342,8 +296,6 @@ static irqreturn_t scsi_tt_intr(int irq, void *dev)
                tt_scsi_dma.dma_ctrl = 0;
        }
 
-#endif /* REAL_DMA */
-
        NCR5380_intr(irq, dev);
 
        return IRQ_HANDLED;
@@ -352,7 +304,6 @@ static irqreturn_t scsi_tt_intr(int irq, void *dev)
 
 static irqreturn_t scsi_falcon_intr(int irq, void *dev)
 {
-#ifdef REAL_DMA
        struct Scsi_Host *instance = dev;
        struct NCR5380_hostdata *hostdata = shost_priv(instance);
        int dma_stat;
@@ -405,15 +356,12 @@ static irqreturn_t scsi_falcon_intr(int irq, void *dev)
                atari_dma_orig_addr = NULL;
        }
 
-#endif /* REAL_DMA */
-
        NCR5380_intr(irq, dev);
 
        return IRQ_HANDLED;
 }
 
 
-#ifdef REAL_DMA
 static void atari_scsi_fetch_restbytes(void)
 {
        int nr;
@@ -436,7 +384,6 @@ static void atari_scsi_fetch_restbytes(void)
                        *dst++ = *src++;
        }
 }
-#endif /* REAL_DMA */
 
 
 /* This function releases the lock on the DMA chip if there is no
@@ -464,6 +411,10 @@ static int falcon_get_lock(struct Scsi_Host *instance)
        if (IS_A_TT())
                return 1;
 
+       if (stdma_is_locked_by(scsi_falcon_intr) &&
+           instance->hostt->can_queue > 1)
+               return 1;
+
        if (in_interrupt())
                return stdma_try_lock(scsi_falcon_intr, instance);
 
@@ -495,8 +446,7 @@ static int __init atari_scsi_setup(char *str)
                setup_sg_tablesize = ints[3];
        if (ints[0] >= 4)
                setup_hostid = ints[4];
-       if (ints[0] >= 5)
-               setup_use_tagged_queuing = ints[5];
+       /* ints[5] (use_tagged_queuing) is ignored */
        /* ints[6] (use_pdma) is ignored */
        if (ints[0] >= 7)
                setup_toshiba_delay = ints[7];
@@ -508,8 +458,6 @@ __setup("atascsi=", atari_scsi_setup);
 #endif /* !MODULE */
 
 
-#if defined(REAL_DMA)
-
 static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance,
                                          void *data, unsigned long count,
                                          int dir)
@@ -545,9 +493,6 @@ static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance,
         */
        dma_cache_maintenance(addr, count, dir);
 
-       if (count == 0)
-               printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n");
-
        if (IS_A_TT()) {
                tt_scsi_dma.dma_ctrl = dir;
                SCSI_DMA_WRITE_P(dma_addr, addr);
@@ -624,6 +569,9 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
 {
        unsigned long   possible_len, limit;
 
+       if (wanted_len < DMA_MIN_SIZE)
+               return 0;
+
        if (IS_A_TT())
                /* TT SCSI DMA can transfer arbitrary #bytes */
                return wanted_len;
@@ -703,9 +651,6 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
 }
 
 
-#endif /* REAL_DMA */
-
-
 /* NCR5380 register access functions
  *
  * There are separate functions for TT and Falcon, because the access
@@ -736,7 +681,7 @@ static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
 }
 
 
-#include "atari_NCR5380.c"
+#include "NCR5380.c"
 
 static int atari_scsi_bus_reset(struct scsi_cmnd *cmd)
 {
@@ -745,7 +690,6 @@ static int atari_scsi_bus_reset(struct scsi_cmnd *cmd)
 
        local_irq_save(flags);
 
-#ifdef REAL_DMA
        /* Abort a maybe active DMA transfer */
        if (IS_A_TT()) {
                tt_scsi_dma.dma_ctrl = 0;
@@ -754,7 +698,6 @@ static int atari_scsi_bus_reset(struct scsi_cmnd *cmd)
                atari_dma_active = 0;
                atari_dma_orig_addr = NULL;
        }
-#endif
 
        rv = NCR5380_bus_reset(cmd);
 
@@ -781,6 +724,7 @@ static struct scsi_host_template atari_scsi_template = {
        .eh_abort_handler       = atari_scsi_abort,
        .eh_bus_reset_handler   = atari_scsi_bus_reset,
        .this_id                = 7,
+       .cmd_per_lun            = 2,
        .use_clustering         = DISABLE_CLUSTERING,
        .cmd_size               = NCR5380_CMD_SIZE,
 };
@@ -804,24 +748,11 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
                atari_scsi_reg_write = atari_scsi_falcon_reg_write;
        }
 
-       /* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary.
-        * Higher values should work, too; try it!
-        * (But cmd_per_lun costs memory!)
-        *
-        * But there seems to be a bug somewhere that requires CAN_QUEUE to be
-        * 2*CMD_PER_LUN. At least on a TT, no spurious timeouts seen since
-        * changed CMD_PER_LUN...
-        *
-        * Note: The Falcon currently uses 8/1 setting due to unsolved problems
-        * with cmd_per_lun != 1
-        */
        if (ATARIHW_PRESENT(TT_SCSI)) {
                atari_scsi_template.can_queue    = 16;
-               atari_scsi_template.cmd_per_lun  = 8;
                atari_scsi_template.sg_tablesize = SG_ALL;
        } else {
-               atari_scsi_template.can_queue    = 8;
-               atari_scsi_template.cmd_per_lun  = 1;
+               atari_scsi_template.can_queue    = 1;
                atari_scsi_template.sg_tablesize = SG_NONE;
        }
 
@@ -850,8 +781,6 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
                }
        }
 
-
-#ifdef REAL_DMA
        /* If running on a Falcon and if there's TT-Ram (i.e., more than one
         * memory block, since there's always ST-Ram in a Falcon), then
         * allocate a STRAM_BUFFER_SIZE byte dribble buffer for transfers
@@ -867,7 +796,6 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
                atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
                atari_dma_orig_addr = 0;
        }
-#endif
 
        instance = scsi_host_alloc(&atari_scsi_template,
                                   sizeof(struct NCR5380_hostdata));
@@ -879,9 +807,6 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
        instance->irq = irq->start;
 
        host_flags |= IS_A_TT() ? 0 : FLAG_LATE_DMA_SETUP;
-#ifdef SUPPORT_TAGS
-       host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0;
-#endif
        host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0;
 
        error = NCR5380_init(instance, host_flags);
@@ -897,7 +822,7 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
                        goto fail_irq;
                }
                tt_mfp.active_edge |= 0x80;     /* SCSI int on L->H */
-#ifdef REAL_DMA
+
                tt_scsi_dma.dma_ctrl = 0;
                atari_dma_residual = 0;
 
@@ -919,17 +844,14 @@ static int __init atari_scsi_probe(struct platform_device *pdev)
 
                        hostdata->read_overruns = 4;
                }
-#endif
        } else {
                /* Nothing to do for the interrupt: the ST-DMA is initialized
                 * already.
                 */
-#ifdef REAL_DMA
                atari_dma_residual = 0;
                atari_dma_active = 0;
                atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
                                        : 0xff000000);
-#endif
        }
 
        NCR5380_maybe_reset_bus(instance);