Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / scsi / aha152x.c
index d11f869..de80cdf 100644 (file)
 #include <scsi/scsicam.h>
 
 #include "scsi.h"
+#include <scsi/scsi_dbg.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport_spi.h>
 #include "aha152x.h"
 
 
@@ -353,58 +355,58 @@ MODULE_LICENSE("GPL");
 
 #if !defined(PCMCIA)
 #if defined(MODULE)
-MODULE_PARM(io, "1-2i");
-MODULE_PARM_DESC(io,"base io address of controller");
 static int io[] = {0, 0};
+module_param_array(io, int, NULL, 0);
+MODULE_PARM_DESC(io,"base io address of controller");
 
-MODULE_PARM(irq, "1-2i");
-MODULE_PARM_DESC(irq,"interrupt for controller");
 static int irq[] = {0, 0};
+module_param_array(irq, int, NULL, 0);
+MODULE_PARM_DESC(irq,"interrupt for controller");
 
-MODULE_PARM(scsiid, "1-2i");
-MODULE_PARM_DESC(scsiid,"scsi id of controller");
 static int scsiid[] = {7, 7};
+module_param_array(scsiid, int, NULL, 0);
+MODULE_PARM_DESC(scsiid,"scsi id of controller");
 
-MODULE_PARM(reconnect, "1-2i");
-MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
 static int reconnect[] = {1, 1};
+module_param_array(reconnect, int, NULL, 0);
+MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
 
-MODULE_PARM(parity, "1-2i");
-MODULE_PARM_DESC(parity,"use scsi parity");
 static int parity[] = {1, 1};
+module_param_array(parity, int, NULL, 0);
+MODULE_PARM_DESC(parity,"use scsi parity");
 
-MODULE_PARM(sync, "1-2i");
-MODULE_PARM_DESC(sync,"use synchronous transfers");
 static int sync[] = {1, 1};
+module_param_array(sync, int, NULL, 0);
+MODULE_PARM_DESC(sync,"use synchronous transfers");
 
-MODULE_PARM(delay, "1-2i");
-MODULE_PARM_DESC(delay,"scsi reset delay");
 static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
+module_param_array(delay, int, NULL, 0);
+MODULE_PARM_DESC(delay,"scsi reset delay");
 
-MODULE_PARM(exttrans, "1-2i");
-MODULE_PARM_DESC(exttrans,"use extended translation");
 static int exttrans[] = {0, 0};
+module_param_array(exttrans, int, NULL, 0);
+MODULE_PARM_DESC(exttrans,"use extended translation");
 
 #if !defined(AHA152X_DEBUG)
-MODULE_PARM(aha152x, "1-8i");
-MODULE_PARM_DESC(aha152x, "parameters for first controller");
 static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
+module_param_array(aha152x, int, NULL, 0);
+MODULE_PARM_DESC(aha152x, "parameters for first controller");
 
-MODULE_PARM(aha152x1, "1-8i");
-MODULE_PARM_DESC(aha152x1, "parameters for second controller");
 static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
+module_param_array(aha152x1, int, NULL, 0);
+MODULE_PARM_DESC(aha152x1, "parameters for second controller");
 #else
-MODULE_PARM(debug, "1-2i");
-MODULE_PARM_DESC(debug, "flags for driver debugging");
 static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
+module_param_array(debug, int, NULL, 0);
+MODULE_PARM_DESC(debug, "flags for driver debugging");
 
-MODULE_PARM(aha152x, "1-9i");
-MODULE_PARM_DESC(aha152x, "parameters for first controller");
 static int aha152x[]   = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
+module_param_array(aha152x, int, NULL, 0);
+MODULE_PARM_DESC(aha152x, "parameters for first controller");
 
-MODULE_PARM(aha152x1, "1-9i");
-MODULE_PARM_DESC(aha152x1, "parameters for second controller");
 static int aha152x1[]  = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
+module_param_array(aha152x1, int, NULL, 0);
+MODULE_PARM_DESC(aha152x1, "parameters for second controller");
 #endif /* !defined(AHA152X_DEBUG) */
 #endif /* MODULE */
 
@@ -423,7 +425,7 @@ MODULE_DEVICE_TABLE(isapnp, id_table);
 
 static int registered_count=0;
 static struct Scsi_Host *aha152x_host[2];
-static Scsi_Host_Template aha152x_driver_template;
+static struct scsi_host_template aha152x_driver_template;
 
 /*
  * internal states of the host
@@ -986,7 +988,7 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct semaphore *sem, int p
        if (HOSTDATA(shpnt)->debug & debug_queue) {
                printk(INFO_LEAD "queue: %p; cmd_len=%d pieces=%d size=%u cmnd=",
                       CMDINFO(SCpnt), SCpnt, SCpnt->cmd_len, SCpnt->use_sg, SCpnt->request_bufflen);
-               print_command(SCpnt->cmnd);
+               __scsi_print_command(SCpnt->cmnd);
        }
 #endif
 
@@ -1224,8 +1226,6 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
        }
 
        DO_UNLOCK(flags);
-
-       spin_lock_irq(shpnt->host_lock);
        return ret;
 }
 
@@ -1260,16 +1260,15 @@ static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
  * Reset the bus
  *
  */
-static int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
+static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
 {
-       struct Scsi_Host *shpnt = SCpnt->device->host;
        unsigned long flags;
 
        DO_LOCK(flags);
 
 #if defined(AHA152X_DEBUG)
        if(HOSTDATA(shpnt)->debug & debug_eh) {
-               printk(DEBUG_LEAD "aha152x_bus_reset(%p)", CMDINFO(SCpnt), SCpnt);
+               printk(KERN_DEBUG "scsi%d: bus reset", shpnt->host_no);
                show_queues(shpnt);
        }
 #endif
@@ -1277,14 +1276,14 @@ static int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
        free_hard_reset_SCs(shpnt, &ISSUE_SC);
        free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
 
-       DPRINTK(debug_eh, DEBUG_LEAD "resetting bus\n", CMDINFO(SCpnt));
+       DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting bus\n", shpnt->host_no);
 
        SETPORT(SCSISEQ, SCSIRSTO);
        mdelay(256);
        SETPORT(SCSISEQ, 0);
        mdelay(DELAY);
 
-       DPRINTK(debug_eh, DEBUG_LEAD "bus resetted\n", CMDINFO(SCpnt));
+       DPRINTK(debug_eh, KERN_DEBUG "scsi%d: bus resetted\n", shpnt->host_no);
 
        setup_expected_interrupts(shpnt);
        if(HOSTDATA(shpnt)->commands==0)
@@ -1295,6 +1294,14 @@ static int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
        return SUCCESS;
 }
 
+/*
+ * Reset the bus
+ *
+ */
+static int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
+{
+       return aha152x_bus_reset_host(SCpnt->device->host);
+}
 
 /*
  *  Restore default values to the AIC-6260 registers and reset the fifos
@@ -1337,22 +1344,27 @@ static void reset_ports(struct Scsi_Host *shpnt)
  * Reset the host (bus and controller)
  *
  */
-int aha152x_host_reset(Scsi_Cmnd * SCpnt)
+int aha152x_host_reset_host(struct Scsi_Host *shpnt)
 {
-#if defined(AHA152X_DEBUG)
-       struct Scsi_Host *shpnt = SCpnt->device->host;
-#endif
-
-       DPRINTK(debug_eh, DEBUG_LEAD "aha152x_host_reset(%p)\n", CMDINFO(SCpnt), SCpnt);
+       DPRINTK(debug_eh, KERN_DEBUG "scsi%d: host reset\n", shpnt->host_no);
 
-       aha152x_bus_reset(SCpnt);
+       aha152x_bus_reset_host(shpnt);
 
-       DPRINTK(debug_eh, DEBUG_LEAD "resetting ports\n", CMDINFO(SCpnt));
-       reset_ports(SCpnt->device->host);
+       DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting ports\n", shpnt->host_no);
+       reset_ports(shpnt);
 
        return SUCCESS;
 }
 
+/*
+ * Reset the host (bus and controller)
+ * 
+ */
+static int aha152x_host_reset(Scsi_Cmnd *SCpnt)
+{
+       return aha152x_host_reset_host(SCpnt->device->host);
+}
+
 /*
  * Return the "logical geometry"
  *
@@ -1431,22 +1443,18 @@ static void run(void)
 {
        int i;
        for (i = 0; i<ARRAY_SIZE(aha152x_host); i++) {
-               struct Scsi_Host *shpnt = aha152x_host[i];
-               if (shpnt && HOSTDATA(shpnt)->service) {
-                       HOSTDATA(shpnt)->service=0;
-                       is_complete(shpnt);
-               }
+               is_complete(aha152x_host[i]);
        }
 }
 
 /*
- *    Interrupts handler
+ * Interrupt handler
  *
  */
-
 static irqreturn_t intr(int irqno, void *dev_id, struct pt_regs *regs)
 {
        struct Scsi_Host *shpnt = lookup_irq(irqno);
+       unsigned long flags;
        unsigned char rev, dmacntrl0;
 
        if (!shpnt) {
@@ -1472,23 +1480,23 @@ static irqreturn_t intr(int irqno, void *dev_id, struct pt_regs *regs)
        if ((rev == 0xFF) && (dmacntrl0 == 0xFF))
                return IRQ_NONE;
 
+       if( TESTLO(DMASTAT, INTSTAT) )
+               return IRQ_NONE;        
+
        /* no more interrupts from the controller, while we're busy.
           INTEN is restored by the BH handler */
        CLRBITS(DMACNTRL0, INTEN);
 
-#if 0
-       /* check if there is already something to be
-           serviced; should not happen */
-       if(HOSTDATA(shpnt)->service) {
-               printk(KERN_ERR "aha152x%d: lost interrupt (%d)\n", HOSTNO, HOSTDATA(shpnt)->service);
-               show_queues(shpnt);
+       DO_LOCK(flags);
+       if( HOSTDATA(shpnt)->service==0 ) {
+               HOSTDATA(shpnt)->service=1;
+
+               /* Poke the BH handler */
+               INIT_WORK(&aha152x_tq, (void *) run, NULL);
+               schedule_work(&aha152x_tq);
        }
-#endif
-       
-       /* Poke the BH handler */
-       HOSTDATA(shpnt)->service++;
-       INIT_WORK(&aha152x_tq, (void *) run, NULL);
-       schedule_work(&aha152x_tq);
+       DO_UNLOCK(flags);
+
        return IRQ_HANDLED;
 }
 
@@ -1560,7 +1568,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
 #if 0
                        if(HOSTDATA(shpnt)->debug & debug_eh) {
                                printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC));
-                               print_sense("bh", DONE_SC);
+                               scsi_print_sense("bh", DONE_SC);
                        }
 #endif
 
@@ -1708,12 +1716,7 @@ static void seldo_run(struct Scsi_Host *shpnt)
                ADDMSGO(BUS_DEVICE_RESET);
        } else if (SYNCNEG==0 && SYNCHRONOUS) {
                CURRENT_SC->SCp.phase |= syncneg;
-               ADDMSGO(EXTENDED_MESSAGE);
-               ADDMSGO(3);
-               ADDMSGO(EXTENDED_SDTR);
-               ADDMSGO(50);            /* 200ns */
-               ADDMSGO(8);             /* 8 byte req/ack offset */
-
+               MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
                SYNCNEG=1;              /* negotiation in progress */
        }
 
@@ -1846,7 +1849,7 @@ static void msgi_run(struct Scsi_Host *shpnt)
 #if defined(AHA152X_DEBUG)
                if (HOSTDATA(shpnt)->debug & debug_msgi) {
                        printk(INFO_LEAD "inbound message %02x ", CMDINFO(CURRENT_SC), MSGI(0));
-                       print_msg(&MSGI(0));
+                       spi_print_msg(&MSGI(0));
                        printk("\n");
                }
 #endif
@@ -1934,7 +1937,7 @@ static void msgi_run(struct Scsi_Host *shpnt)
                                                break;
 
                                        printk(INFO_LEAD, CMDINFO(CURRENT_SC));
-                                       print_msg(&MSGI(0));
+                                       spi_print_msg(&MSGI(0));
                                        printk("\n");
 
                                        ticks = (MSGI(3) * 4 + 49) / 50;
@@ -2032,7 +2035,7 @@ static void msgo_init(struct Scsi_Host *shpnt)
                int i;
 
                printk(DEBUG_LEAD "messages( ", CMDINFO(CURRENT_SC));
-               for (i=0; i<MSGOLEN; i+=print_msg(&MSGO(i)), printk(" "))
+               for (i=0; i<MSGOLEN; i+=spi_print_msg(&MSGO(i)), printk(" "))
                        ;
                printk(")\n");
        }
@@ -2104,7 +2107,7 @@ static void cmd_init(struct Scsi_Host *shpnt)
 #if defined(AHA152X_DEBUG)
        if (HOSTDATA(shpnt)->debug & debug_cmd) {
                printk(DEBUG_LEAD "cmd_init: ", CMDINFO(CURRENT_SC));
-               print_command(CURRENT_SC->cmnd);
+               __scsi_print_command(CURRENT_SC->cmnd);
        }
 #endif
 
@@ -2158,7 +2161,7 @@ static void status_run(struct Scsi_Host *shpnt)
 #if defined(AHA152X_DEBUG)
        if (HOSTDATA(shpnt)->debug & debug_status) {
                printk(DEBUG_LEAD "inbound status %02x ", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.Status);
-               print_status(CURRENT_SC->SCp.Status);
+               scsi_print_status(CURRENT_SC->SCp.Status);
                printk("\n");
        }
 #endif
@@ -2527,7 +2530,18 @@ static void is_complete(struct Scsi_Host *shpnt)
        unsigned long flags;
        int pending;
 
+       if(!shpnt)
+               return;
+
        DO_LOCK(flags);
+
+       if( HOSTDATA(shpnt)->service==0 )  {
+               DO_UNLOCK(flags);
+               return;
+       }
+
+       HOSTDATA(shpnt)->service = 0;
+
        if(HOSTDATA(shpnt)->in_intr) {
                DO_UNLOCK(flags);
                /* aha152x_error never returns.. */
@@ -2922,10 +2936,9 @@ static void disp_enintr(struct Scsi_Host *shpnt)
  */
 static void show_command(Scsi_Cmnd *ptr)
 {
-       printk(KERN_DEBUG "0x%08x: target=%d; lun=%d; cmnd=(",
-              (unsigned int) ptr, ptr->device->id, ptr->device->lun);
+       scmd_printk(KERN_DEBUG, ptr, "%p: cmnd=(", ptr);
 
-       print_command(ptr->cmnd);
+       __scsi_print_command(ptr->cmnd);
 
        printk(KERN_DEBUG "); request_bufflen=%d; resid=%d; phase |",
               ptr->request_bufflen, ptr->resid);
@@ -3466,7 +3479,7 @@ static int aha152x_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start
        return thislength < length ? thislength : length;
 }
 
-static Scsi_Host_Template aha152x_driver_template = {
+static struct scsi_host_template aha152x_driver_template = {
        .module                         = THIS_MODULE,
        .name                           = AHA152X_REVID,
        .proc_name                      = "aha152x",
@@ -3830,10 +3843,15 @@ static int __init aha152x_init(void)
        if (setup_count<ARRAY_SIZE(setup)) {
 #if !defined(SKIP_BIOSTEST)
                ok = 0;
-               for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++)
+               for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++) {
+                       void __iomem *p = ioremap(addresses[i], 0x4000);
+                       if (!p)
+                               continue;
                        for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
-                               ok = isa_check_signature(addresses[i] + signatures[j].sig_offset,
+                               ok = check_signature(p + signatures[j].sig_offset,
                                                                signatures[j].signature, signatures[j].sig_length);
+                       iounmap(p);
+               }
                if (!ok && setup_count == 0)
                        return 0;