fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / scsi / aacraid / sa.c
index 13e8818..511b0a9 100644 (file)
@@ -46,7 +46,7 @@
 
 #include "aacraid.h"
 
-static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t aac_sa_intr(int irq, void *dev_id)
 {
        struct aac_dev *dev = dev_id;
        unsigned short intstat, mask;
@@ -62,15 +62,15 @@ static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
 
        if (intstat & mask) {
                if (intstat & PrintfReady) {
-                       aac_printf(dev, le32_to_cpu(sa_readl(dev, Mailbox5)));
+                       aac_printf(dev, sa_readl(dev, Mailbox5));
                        sa_writew(dev, DoorbellClrReg_p, PrintfReady); /* clear PrintfReady */
                        sa_writew(dev, DoorbellReg_s, PrintfDone);
                } else if (intstat & DOORBELL_1) {      // dev -> Host Normal Command Ready
-                       aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
                        sa_writew(dev, DoorbellClrReg_p, DOORBELL_1);
+                       aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
                } else if (intstat & DOORBELL_2) {      // dev -> Host Normal Response Ready
-                       aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
                        sa_writew(dev, DoorbellClrReg_p, DOORBELL_2);
+                       aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
                } else if (intstat & DOORBELL_3) {      // dev -> Host Normal Command Not Full
                        sa_writew(dev, DoorbellClrReg_p, DOORBELL_3);
                } else if (intstat & DOORBELL_4) {      // dev -> Host Normal Response Not Full
@@ -81,6 +81,16 @@ static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_NONE;
 }
 
+/**
+ *     aac_sa_disable_interrupt        -       disable interrupt
+ *     @dev: Which adapter to enable.
+ */
+
+static void aac_sa_disable_interrupt (struct aac_dev *dev)
+{
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
+}
+
 /**
  *     aac_sa_notify_adapter           -       handle adapter notification
  *     @dev:   Adapter that notification is for
@@ -89,7 +99,7 @@ static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
  *     Notify the adapter of an event
  */
  
-void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
+static void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
 {
        switch (event) {
 
@@ -106,7 +116,10 @@ void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
                sa_writew(dev, DoorbellReg_s,DOORBELL_3);
                break;
        case HostShutdown:
-               //sa_sync_cmd(dev, HOST_CRASHING, 0, &ret);
+               /*
+               sa_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
+               NULL, NULL, NULL, NULL, NULL);
+               */
                break;
        case FastIo:
                sa_writew(dev, DoorbellReg_s,DOORBELL_6);
@@ -128,25 +141,28 @@ void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
  *     @p1: first parameter
  *     @ret: adapter status
  *
- *     This routine will send a synchronous comamnd to the adapter and wait 
+ *     This routine will send a synchronous command to the adapter and wait 
  *     for its completion.
  */
 
-static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
+static int sa_sync_cmd(struct aac_dev *dev, u32 command, 
+               u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
+               u32 *ret, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
 {
        unsigned long start;
        int ok;
        /*
         *      Write the Command into Mailbox 0
         */
-       sa_writel(dev, Mailbox0, cpu_to_le32(command));
+       sa_writel(dev, Mailbox0, command);
        /*
         *      Write the parameters into Mailboxes 1 - 4
         */
-       sa_writel(dev, Mailbox1, cpu_to_le32(p1));
-       sa_writel(dev, Mailbox2, 0);
-       sa_writel(dev, Mailbox3, 0);
-       sa_writel(dev, Mailbox4, 0);
+       sa_writel(dev, Mailbox1, p1);
+       sa_writel(dev, Mailbox2, p2);
+       sa_writel(dev, Mailbox3, p3);
+       sa_writel(dev, Mailbox4, p4);
+
        /*
         *      Clear the synch command doorbell to start on a clean slate.
         */
@@ -173,8 +189,7 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
                        ok = 1;
                        break;
                }
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(1);
+               msleep(1);
        }
 
        if (ok != 1)
@@ -186,7 +201,16 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
        /*
         *      Pull the synch status from Mailbox 0.
         */
-       *ret = le32_to_cpu(sa_readl(dev, Mailbox0));
+       if (ret)
+               *ret = sa_readl(dev, Mailbox0);
+       if (r1)
+               *r1 = sa_readl(dev, Mailbox1);
+       if (r2)
+               *r2 = sa_readl(dev, Mailbox2);
+       if (r3)
+               *r3 = sa_readl(dev, Mailbox3);
+       if (r4)
+               *r4 = sa_readl(dev, Mailbox4);
        return 0;
 }
 
@@ -199,8 +223,8 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
  
 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
 {
-       u32 ret;
-       sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
+       sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
+                       NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -212,30 +236,16 @@ static void aac_sa_interrupt_adapter (struct aac_dev *dev)
 
 static void aac_sa_start_adapter(struct aac_dev *dev)
 {
-       u32 ret;
        struct aac_init *init;
        /*
         * Fill in the remaining pieces of the init.
         */
        init = dev->init;
-       init->HostElapsedSeconds = cpu_to_le32(jiffies/HZ);
-
-       dprintk(("INIT\n"));
-       /*
-        * Tell the adapter we are back and up and running so it will scan its command
-        * queues and enable our interrupts
-        */
-       dev->irq_mask = (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4);
-       /*
-        *      First clear out all interrupts.  Then enable the one's that 
-        *      we can handle.
-        */
-       dprintk(("MASK\n"));
-       sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
-       sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
-       dprintk(("SYNCCMD\n"));
+       init->HostElapsedSeconds = cpu_to_le32(get_seconds());
        /* We can only use a 32 bit address here */
-       sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &ret);
+       sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, 
+                       (u32)(ulong)dev->init_pa, 0, 0, 0, 0, 0,
+                       NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -270,6 +280,21 @@ static int aac_sa_check_health(struct aac_dev *dev)
        return 0;
 }
 
+/**
+ *     aac_sa_ioremap
+ *     @size: mapping resize request
+ *
+ */
+static int aac_sa_ioremap(struct aac_dev * dev, u32 size)
+{
+       if (!size) {
+               iounmap(dev->regs.sa);
+               return 0;
+       }
+       dev->base = dev->regs.sa = ioremap(dev->scsi_host_ptr->base, size);
+       return (dev->base == NULL) ? -1 : 0;
+}
+
 /**
  *     aac_sa_init     -       initialize an ARM based AAC card
  *     @dev: device to configure
@@ -286,20 +311,14 @@ int aac_sa_init(struct aac_dev *dev)
        int instance;
        const char *name;
 
-       dprintk(("PREINST\n"));
        instance = dev->id;
        name     = dev->name;
 
-       /*
-        *      Map in the registers from the adapter.
-        */
-       dprintk(("PREMAP\n"));
-
-       if((dev->regs.sa = ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
-       {       
-               printk(KERN_WARNING "aacraid: unable to map ARM.\n" );
+       if (aac_sa_ioremap(dev, dev->base_size)) {
+               printk(KERN_WARNING "%s: unable to map adapter.\n", name);
                goto error_iounmap;
        }
+
        /*
         *      Check to see if the board failed any self tests.
         */
@@ -319,17 +338,16 @@ int aac_sa_init(struct aac_dev *dev)
         *      Wait for the adapter to be up and running. Wait up to 3 minutes.
         */
        while (!(sa_readl(dev, Mailbox7) & KERNEL_UP_AND_RUNNING)) {
-               if (time_after(jiffies, start+180*HZ)) {
-                       status = sa_readl(dev, Mailbox7) >> 16;
-                       printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %d.\n", name, instance, le32_to_cpu(status));
+               if (time_after(jiffies, start+startup_timeout*HZ)) {
+                       status = sa_readl(dev, Mailbox7);
+                       printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %lx.\n", 
+                                       name, instance, status);
                        goto error_iounmap;
                }
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(1);
+               msleep(1);
        }
 
-       dprintk(("ATIRQ\n"));
-       if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) {
+       if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, IRQF_SHARED|IRQF_DISABLED, "aacraid", (void *)dev ) < 0) {
                printk(KERN_WARNING "%s%d: Interrupt unavailable.\n", name, instance);
                goto error_iounmap;
        }
@@ -339,43 +357,35 @@ int aac_sa_init(struct aac_dev *dev)
         */
 
        dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
+       dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
        dev->a_ops.adapter_notify = aac_sa_notify_adapter;
        dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
        dev->a_ops.adapter_check_health = aac_sa_check_health;
+       dev->a_ops.adapter_ioremap = aac_sa_ioremap;
 
-       dprintk(("FUNCDONE\n"));
+       /*
+        *      First clear out all interrupts.  Then enable the one's that 
+        *      we can handle.
+        */
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
+       sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | 
+                               DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
 
        if(aac_init_adapter(dev) == NULL)
                goto error_irq;
 
-       dprintk(("NEWADAPTDONE\n"));
-       /*
-        *      Start any kernel threads needed
-        */
-       dev->thread_pid = kernel_thread((int (*)(void *))aac_command_thread, dev, 0);
-       if (dev->thread_pid < 0) {
-               printk(KERN_ERR "aacraid: Unable to create command thread.\n");
-               goto error_kfree;
-       }
-
        /*
         *      Tell the adapter that all is configure, and it can start 
         *      accepting requests
         */
-       dprintk(("STARTING\n"));
        aac_sa_start_adapter(dev);
-       dprintk(("STARTED\n"));
        return 0;
 
-
-error_kfree:
-       kfree(dev->queues);
-
 error_irq:
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
        free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
-       iounmap(dev->regs.sa);
 
        return -1;
 }