fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / scsi / mesh.c
index f6da46d..1fd3c75 100644 (file)
@@ -18,7 +18,6 @@
  * - retry arbitration if lost (unless higher levels do this for us)
  * - power down the chip when no device is detected
  */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
@@ -186,7 +185,7 @@ struct mesh_state {
  * Driver is too messy, we need a few prototypes...
  */
 static void mesh_done(struct mesh_state *ms, int start_next);
-static void mesh_interrupt(int irq, void *dev_id, struct pt_regs *ptregs);
+static void mesh_interrupt(int irq, void *dev_id);
 static void cmd_complete(struct mesh_state *ms);
 static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd);
 static void halt_dma(struct mesh_state *ms);
@@ -467,7 +466,7 @@ static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd)
                                dlog(ms, "intr b4 arb, intr/exc/err/fc=%.8x",
                                     MKWORD(mr->interrupt, mr->exception,
                                            mr->error, mr->fifo_count));
-                               mesh_interrupt(0, (void *)ms, NULL);
+                               mesh_interrupt(0, (void *)ms);
                                if (ms->phase != arbitrating)
                                        return;
                        }
@@ -505,7 +504,7 @@ static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd)
                dlog(ms, "intr after disresel, intr/exc/err/fc=%.8x",
                     MKWORD(mr->interrupt, mr->exception,
                            mr->error, mr->fifo_count));
-               mesh_interrupt(0, (void *)ms, NULL);
+               mesh_interrupt(0, (void *)ms);
                if (ms->phase != arbitrating)
                        return;
                dlog(ms, "after intr after disresel, intr/exc/err/fc=%.8x",
@@ -730,7 +729,7 @@ static void start_phase(struct mesh_state *ms)
                 * issue a SEQ_MSGOUT to get the mesh to drop ACK.
                 */
                if ((in_8(&mr->bus_status0) & BS0_ATN) == 0) {
-                       dlog(ms, "bus0 was %.2x explictly asserting ATN", mr->bus_status0);
+                       dlog(ms, "bus0 was %.2x explicitly asserting ATN", mr->bus_status0);
                        out_8(&mr->bus_status0, BS0_ATN); /* explicit ATN */
                        mesh_flush_io(mr);
                        udelay(1);
@@ -1016,13 +1015,13 @@ static void handle_reset(struct mesh_state *ms)
        out_8(&mr->sequence, SEQ_ENBRESEL);
 }
 
-static irqreturn_t do_mesh_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
+static irqreturn_t do_mesh_interrupt(int irq, void *dev_id)
 {
        unsigned long flags;
        struct Scsi_Host *dev = ((struct mesh_state *)dev_id)->host;
        
        spin_lock_irqsave(dev->host_lock, flags);
-       mesh_interrupt(irq, dev_id, ptregs);
+       mesh_interrupt(irq, dev_id);
        spin_unlock_irqrestore(dev->host_lock, flags);
        return IRQ_HANDLED;
 }
@@ -1269,7 +1268,7 @@ static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd)
                if (cmd->use_sg > 0) {
                        int nseg;
                        total = 0;
-                       scl = (struct scatterlist *) cmd->buffer;
+                       scl = (struct scatterlist *) cmd->request_buffer;
                        off = ms->data_ptr;
                        nseg = pci_map_sg(ms->pdev, scl, cmd->use_sg,
                                          cmd->sc_data_direction);
@@ -1662,7 +1661,7 @@ static int mesh_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  * handler (do_mesh_interrupt) or by other functions in
  * exceptional circumstances
  */
-static void mesh_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
+static void mesh_interrupt(int irq, void *dev_id)
 {
        struct mesh_state *ms = (struct mesh_state *) dev_id;
        volatile struct mesh_regs __iomem *mr = ms->mesh;
@@ -1715,9 +1714,12 @@ static int mesh_host_reset(struct scsi_cmnd *cmd)
        struct mesh_state *ms = (struct mesh_state *) cmd->device->host->hostdata;
        volatile struct mesh_regs __iomem *mr = ms->mesh;
        volatile struct dbdma_regs __iomem *md = ms->dma;
+       unsigned long flags;
 
        printk(KERN_DEBUG "mesh_host_reset\n");
 
+       spin_lock_irqsave(ms->host->host_lock, flags);
+
        /* Reset the controller & dbdma channel */
        out_le32(&md->control, (RUN|PAUSE|FLUSH|WAKE) << 16);   /* stop dma */
        out_8(&mr->exception, 0xff);    /* clear all exception bits */
@@ -1739,12 +1741,13 @@ static int mesh_host_reset(struct scsi_cmnd *cmd)
        /* Complete pending commands */
        handle_reset(ms);
        
+       spin_unlock_irqrestore(ms->host->host_lock, flags);
        return SUCCESS;
 }
 
 static void set_mesh_power(struct mesh_state *ms, int state)
 {
-       if (_machine != _MACH_Pmac)
+       if (!machine_is(powermac))
                return;
        if (state) {
                pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1);
@@ -1753,16 +1756,23 @@ static void set_mesh_power(struct mesh_state *ms, int state)
                pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0);
                msleep(10);
        }
-}                      
+}
 
 
 #ifdef CONFIG_PM
-static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
+static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg)
 {
        struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
        unsigned long flags;
 
-       if (state == mdev->ofdev.dev.power.power_state || state < 2)
+       switch (mesg.event) {
+       case PM_EVENT_SUSPEND:
+       case PM_EVENT_FREEZE:
+               break;
+       default:
+               return 0;
+       }
+       if (mesg.event == mdev->ofdev.dev.power.power_state.event)
                return 0;
 
        scsi_block_requests(ms->host);
@@ -1777,7 +1787,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
        disable_irq(ms->meshintr);
        set_mesh_power(ms, 0);
 
-       mdev->ofdev.dev.power.power_state = state;
+       mdev->ofdev.dev.power.power_state = mesg;
 
        return 0;
 }
@@ -1787,7 +1797,7 @@ static int mesh_resume(struct macio_dev *mdev)
        struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
        unsigned long flags;
 
-       if (mdev->ofdev.dev.power.power_state == 0)
+       if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON)
                return 0;
 
        set_mesh_power(ms, 1);
@@ -1798,7 +1808,7 @@ static int mesh_resume(struct macio_dev *mdev)
        enable_irq(ms->meshintr);
        scsi_unblock_requests(ms->host);
 
-       mdev->ofdev.dev.power.power_state = 0;
+       mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON;
 
        return 0;
 }
@@ -1843,11 +1853,12 @@ static struct scsi_host_template mesh_template = {
        .use_clustering                 = DISABLE_CLUSTERING,
 };
 
-static int mesh_probe(struct macio_dev *mdev, const struct of_match *match)
+static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match)
 {
        struct device_node *mesh = macio_get_of_node(mdev);
        struct pci_dev* pdev = macio_get_pci_dev(mdev);
-       int tgt, *cfp, minper;
+       int tgt, minper;
+       const int *cfp;
        struct mesh_state *ms;
        struct Scsi_Host *mesh_host;
        void *dma_cmd_space;
@@ -1865,7 +1876,8 @@ static int mesh_probe(struct macio_dev *mdev, const struct of_match *match)
 
        if (macio_resource_count(mdev) != 2 || macio_irq_count(mdev) != 2) {
                        printk(KERN_ERR "mesh: expected 2 addrs and 2 intrs"
-                      " (got %d,%d)\n", mesh->n_addrs, mesh->n_intrs);
+                      " (got %d,%d)\n", macio_resource_count(mdev),
+                      macio_irq_count(mdev));
                return -ENODEV;
        }
 
@@ -1935,7 +1947,7 @@ static int mesh_probe(struct macio_dev *mdev, const struct of_match *match)
                ms->tgts[tgt].current_req = NULL;
                }
 
-       if ((cfp = (int *) get_property(mesh, "clock-frequency", NULL)))
+       if ((cfp = get_property(mesh, "clock-frequency", NULL)))
                        ms->clk_freq = *cfp;
        else {
                        printk(KERN_INFO "mesh: assuming 50MHz clock frequency\n");
@@ -1955,22 +1967,35 @@ static int mesh_probe(struct macio_dev *mdev, const struct of_match *match)
        /* Set it up */
                mesh_init(ms);
 
-       /* XXX FIXME: error should be fatal */
-               if (request_irq(ms->meshintr, do_mesh_interrupt, 0, "MESH", ms))
+       /* Request interrupt */
+               if (request_irq(ms->meshintr, do_mesh_interrupt, 0, "MESH", ms)) {
                printk(KERN_ERR "MESH: can't get irq %d\n", ms->meshintr);
+               goto out_shutdown;
+       }
 
-       /* XXX FIXME: handle failure */
-       scsi_add_host(mesh_host, &mdev->ofdev.dev);
+       /* Add scsi host & scan */
+       if (scsi_add_host(mesh_host, &mdev->ofdev.dev))
+               goto out_release_irq;
        scsi_scan_host(mesh_host);
 
        return 0;
 
-out_unmap:
+ out_release_irq:
+       free_irq(ms->meshintr, ms);
+ out_shutdown:
+       /* shutdown & reset bus in case of error or macos can be confused
+        * at reboot if the bus was set to synchronous mode already
+        */
+       mesh_shutdown(mdev);
+       set_mesh_power(ms, 0);
+       pci_free_consistent(macio_get_pci_dev(mdev), ms->dma_cmd_size,
+                           ms->dma_cmd_space, ms->dma_cmd_bus);
+ out_unmap:
        iounmap(ms->dma);
        iounmap(ms->mesh);
-out_free:
+ out_free:
        scsi_host_put(mesh_host);
-out_release:
+ out_release:
        macio_release_resources(mdev);
 
        return -ENODEV;
@@ -1997,7 +2022,7 @@ static int mesh_remove(struct macio_dev *mdev)
 
        /* Free DMA commands memory */
        pci_free_consistent(macio_get_pci_dev(mdev), ms->dma_cmd_size,
-                         ms->dma_cmd_space, ms->dma_cmd_bus);
+                           ms->dma_cmd_space, ms->dma_cmd_bus);
 
        /* Release memory resources */
        macio_release_resources(mdev);
@@ -2008,20 +2033,18 @@ static int mesh_remove(struct macio_dev *mdev)
 }
 
 
-static struct of_match mesh_match[] = 
+static struct of_device_id mesh_match[] = 
 {
        {
        .name           = "mesh",
-       .type           = OF_ANY_MATCH,
-       .compatible     = OF_ANY_MATCH
        },
        {
-       .name           = OF_ANY_MATCH,
        .type           = "scsi",
        .compatible     = "chrp,mesh0"
        },
        {},
 };
+MODULE_DEVICE_TABLE (of, mesh_match);
 
 static struct macio_driver mesh_driver = 
 {