Merge branch 'merge'
[pandora-kernel.git] / drivers / scsi / sym53c8xx_2 / sym_glue.c
index 052ce11..739d3ef 100644 (file)
 #define NAME53C                "sym53c"
 #define NAME53C8XX     "sym53c8xx"
 
-/* SPARC just has to be different ... */
-#ifdef __sparc__
-#define IRQ_FMT "%s"
-#define IRQ_PRM(x) __irq_itoa(x)
-#else
 #define IRQ_FMT "%d"
 #define IRQ_PRM(x) (x)
-#endif
 
 struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
 unsigned int sym_debug_flags = 0;
@@ -136,25 +130,15 @@ static void sym2_setup_params(void)
 
 static struct scsi_transport_template *sym2_transport_template = NULL;
 
-/*
- *  Used by the eh thread to wait for command completion.
- *  It is allocated on the eh thread stack.
- */
-struct sym_eh_wait {
-       struct completion done;
-       struct timer_list timer;
-       void (*old_done)(struct scsi_cmnd *);
-       int to_do;
-       int timed_out;
-};
-
 /*
  *  Driver private area in the SCSI command structure.
  */
 struct sym_ucmd {              /* Override the SCSI pointer structure */
-       dma_addr_t data_mapping;
-       u_char  data_mapped;
-       struct sym_eh_wait *eh_wait;
+       dma_addr_t      data_mapping;
+       unsigned char   data_mapped;
+       unsigned char   to_do;                  /* For error handling */
+       void (*old_done)(struct scsi_cmnd *);   /* For error handling */
+       struct completion *eh_done;             /* For error handling */
 };
 
 #define SYM_UCMD_PTR(cmd)  ((struct sym_ucmd *)(&(cmd)->SCp))
@@ -166,7 +150,7 @@ static void __unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
 
        switch(SYM_UCMD_PTR(cmd)->data_mapped) {
        case 2:
-               pci_unmap_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
+               pci_unmap_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
                break;
        case 1:
                pci_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
@@ -196,7 +180,7 @@ static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
        int use_sg;
        int dma_dir = cmd->sc_data_direction;
 
-       use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
+       use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
        if (use_sg > 0) {
                SYM_UCMD_PTR(cmd)->data_mapped  = 2;
                SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
@@ -386,7 +370,7 @@ static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd
        if (!use_sg)
                segment = sym_scatter_no_sglist(np, cp, cmd);
        else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
-               struct scatterlist *scatter = (struct scatterlist *)cmd->buffer;
+               struct scatterlist *scatter = (struct scatterlist *)cmd->request_buffer;
                struct sym_tcb *tp = &np->target[cp->target];
                struct sym_tblmove *data;
 
@@ -475,8 +459,6 @@ static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struc
  */
 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
 {
-       struct sym_tcb *tp = &np->target[cp->target];
-       struct sym_lcb *lp = sym_lp(tp, cp->lun);
        u32 lastp, goalp;
        int dir;
 
@@ -557,7 +539,7 @@ int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct s
        /*
         *      activate this job.
         */
-       sym_start_next_ccbs(np, lp, 2);
+       sym_put_start_queue(np, cp);
        return 0;
 
 out_abort:
@@ -715,40 +697,19 @@ static void sym53c8xx_timer(unsigned long npref)
 #define SYM_EH_DO_WAIT         2
 
 /*
- *  Our general completion handler.
+ *  scsi_done() alias when error recovery is in progress.
  */
-static void __sym_eh_done(struct scsi_cmnd *cmd, int timed_out)
+static void sym_eh_done(struct scsi_cmnd *cmd)
 {
-       struct sym_eh_wait *ep = SYM_UCMD_PTR(cmd)->eh_wait;
-       if (!ep)
-               return;
-
-       /* Try to avoid a race here (not 100% safe) */
-       if (!timed_out) {
-               ep->timed_out = 0;
-               if (ep->to_do == SYM_EH_DO_WAIT && !del_timer(&ep->timer))
-                       return;
-       }
+       struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
+       BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
 
-       /* Revert everything */
-       SYM_UCMD_PTR(cmd)->eh_wait = NULL;
-       cmd->scsi_done = ep->old_done;
+       cmd->scsi_done = ucmd->old_done;
 
-       /* Wake up the eh thread if it wants to sleep */
-       if (ep->to_do == SYM_EH_DO_WAIT)
-               complete(&ep->done);
+       if (ucmd->to_do == SYM_EH_DO_WAIT)
+               complete(ucmd->eh_done);
 }
 
-/*
- *  scsi_done() alias when error recovery is in progress. 
- */
-static void sym_eh_done(struct scsi_cmnd *cmd) { __sym_eh_done(cmd, 0); }
-
-/*
- *  Some timeout handler to avoid waiting too long.
- */
-static void sym_eh_timeout(u_long p) { __sym_eh_done((struct scsi_cmnd *)p, 1); }
-
 /*
  *  Generic method for our eh processing.
  *  The 'op' argument tells what we have to do.
@@ -756,14 +717,16 @@ static void sym_eh_timeout(u_long p) { __sym_eh_done((struct scsi_cmnd *)p, 1);
 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
 {
        struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
+       struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
+       struct Scsi_Host *host = cmd->device->host;
        SYM_QUEHEAD *qp;
        int to_do = SYM_EH_DO_IGNORE;
        int sts = -1;
-       struct sym_eh_wait eh, *ep = &eh;
+       struct completion eh_done;
 
        dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
 
-       spin_lock_irq(cmd->device->host->host_lock);
+       spin_lock_irq(host->host_lock);
        /* This one is queued in some place -> to wait for completion */
        FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
                struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
@@ -774,10 +737,11 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
        }
 
        if (to_do == SYM_EH_DO_WAIT) {
-               init_completion(&ep->done);
-               ep->old_done = cmd->scsi_done;
+               init_completion(&eh_done);
+               ucmd->old_done = cmd->scsi_done;
+               ucmd->eh_done = &eh_done;
+               wmb();
                cmd->scsi_done = sym_eh_done;
-               SYM_UCMD_PTR(cmd)->eh_wait = ep;
        }
 
        /* Try to proceed the operation we have been asked for */
@@ -804,28 +768,20 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
 
        /* On error, restore everything and cross fingers :) */
        if (sts) {
-               SYM_UCMD_PTR(cmd)->eh_wait = NULL;
-               cmd->scsi_done = ep->old_done;
+               cmd->scsi_done = ucmd->old_done;
                to_do = SYM_EH_DO_IGNORE;
        }
 
-       ep->to_do = to_do;
+       ucmd->to_do = to_do;
+       spin_unlock_irq(host->host_lock);
 
-       /* Wait for completion with locks released, as required by kernel */
        if (to_do == SYM_EH_DO_WAIT) {
-               init_timer(&ep->timer);
-               ep->timer.expires = jiffies + (5*HZ);
-               ep->timer.function = sym_eh_timeout;
-               ep->timer.data = (u_long)cmd;
-               ep->timed_out = 1;      /* Be pessimistic for once :) */
-               add_timer(&ep->timer);
-               spin_unlock_irq(np->s.host->host_lock);
-               wait_for_completion(&ep->done);
-               spin_lock_irq(np->s.host->host_lock);
-               if (ep->timed_out)
+               if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
+                       ucmd->to_do = SYM_EH_DO_IGNORE;
+                       wmb();
                        sts = -2;
+               }
        }
-       spin_unlock_irq(cmd->device->host->host_lock);
        dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
                        sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
        return sts ? SCSI_FAILED : SCSI_SUCCESS;
@@ -871,15 +827,12 @@ static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
        if (reqtags > lp->s.scdev_depth)
                reqtags = lp->s.scdev_depth;
 
-       lp->started_limit = reqtags ? reqtags : 2;
-       lp->started_max   = 1;
        lp->s.reqtags     = reqtags;
 
        if (reqtags != oldtags) {
                dev_info(&tp->starget->dev,
                         "tagged command queuing %s, command queue depth %d.\n",
-                         lp->s.reqtags ? "enabled" : "disabled",
-                         lp->started_limit);
+                         lp->s.reqtags ? "enabled" : "disabled", reqtags);
        }
 }
 
@@ -1594,7 +1547,7 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
         *  If we synchonize the C code with SCRIPTS on interrupt, 
         *  we do not want to share the INTR line at all.
         */
-       if (request_irq(pdev->irq, sym53c8xx_intr, SA_SHIRQ, NAME53C8XX, np)) {
+       if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
                printf_err("%s: request irq %d failure\n",
                        sym_name(np), pdev->irq);
                goto attach_failed;
@@ -1915,7 +1868,8 @@ static struct scsi_host_template sym2_template = {
        .eh_bus_reset_handler   = sym53c8xx_eh_bus_reset_handler,
        .eh_host_reset_handler  = sym53c8xx_eh_host_reset_handler,
        .this_id                = 7,
-       .use_clustering         = DISABLE_CLUSTERING,
+       .use_clustering         = ENABLE_CLUSTERING,
+       .max_sectors            = 0xFFFF,
 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
        .proc_info              = sym53c8xx_proc_info,
        .proc_name              = NAME53C8XX,
@@ -2130,7 +2084,7 @@ static struct pci_device_id sym2_id_table[] __devinitdata = {
        { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
        { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
+         PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8,  0xffff00, 0UL },
        { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
        { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,