Merge commit 'v2.6.26' into x86/core
[pandora-kernel.git] / drivers / message / fusion / mptspi.c
index 6b3e0c0..1effca4 100644 (file)
@@ -1,9 +1,9 @@
 /*
  *  linux/drivers/message/fusion/mptspi.c
- *      For use with LSI Logic PCI chip/adapter(s)
- *      running LSI Logic Fusion MPT (Message Passing Technology) firmware.
+ *      For use with LSI PCI chip/adapter(s)
+ *      running LSI Fusion MPT (Message Passing Technology) firmware.
  *
- *  Copyright (c) 1999-2007 LSI Logic Corporation
+ *  Copyright (c) 1999-2007 LSI Corporation
  *  (mailto:DL-MPTFusionLinux@lsi.com)
  *
  */
@@ -90,9 +90,9 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *,
 
 static struct scsi_transport_template *mptspi_transport_template = NULL;
 
-static int     mptspiDoneCtx = -1;
-static int     mptspiTaskCtx = -1;
-static int     mptspiInternalCtx = -1; /* Used only for internal commands */
+static u8      mptspiDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
+static u8      mptspiTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
+static u8      mptspiInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
 
 /**
  *     mptspi_setTargetNegoParms  - Update the target negotiation parameters
@@ -107,7 +107,8 @@ static void
 mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
                            struct scsi_device *sdev)
 {
-       SpiCfgData *pspi_data = &hd->ioc->spi_data;
+       MPT_ADAPTER *ioc = hd->ioc;
+       SpiCfgData *pspi_data = &ioc->spi_data;
        int  id = (int) target->id;
        int  nvram;
        u8 width = MPT_NARROW;
@@ -138,7 +139,10 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
                                else {
                                        factor = MPT_ULTRA320;
                                        if (scsi_device_qas(sdev)) {
-                                               ddvprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", scsi_device_qas(sdev), id));
+                                               ddvprintk(ioc,
+                                               printk(MYIOC_s_DEBUG_FMT "Enabling QAS due to "
+                                               "byte56=%02x on id=%d!\n", ioc->name,
+                                               scsi_device_qas(sdev), id));
                                                noQas = 0;
                                        }
                                        if (sdev->type == TYPE_TAPE &&
@@ -225,7 +229,8 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
                /* Disable QAS in a mixed configuration case
                 */
 
-               ddvprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
+               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
        }
 }
 
@@ -256,8 +261,8 @@ mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id)
        /* Get a MF for this command.
         */
        if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
-               dfailprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
-                                       ioc->name));
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
+                               "writeIOCPage4 : no msg frames!\n",ioc->name));
                return -EAGAIN;
        }
 
@@ -297,9 +302,9 @@ mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id)
 
        mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
 
-       ddvprintk((MYIOC_s_INFO_FMT
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
-                       ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
+               ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
 
        mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
 
@@ -371,14 +376,15 @@ static int
 mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
 {
        int i, rc = 0;
+       MPT_ADAPTER *ioc = hd->ioc;
 
-       if (!hd->ioc->raid_data.pIocPg2)
+       if (!ioc->raid_data.pIocPg2)
                goto out;
 
-       if (!hd->ioc->raid_data.pIocPg2->NumActiveVolumes)
+       if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
                goto out;
-       for (i=0; i < hd->ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
-               if (hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) {
+       for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
+               if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) {
                        rc = 1;
                        goto out;
                }
@@ -391,17 +397,19 @@ mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
 static int mptspi_target_alloc(struct scsi_target *starget)
 {
        struct Scsi_Host *shost = dev_to_shost(&starget->dev);
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
        VirtTarget              *vtarget;
+       MPT_ADAPTER *ioc;
 
        if (hd == NULL)
                return -ENODEV;
 
+       ioc = hd->ioc;
        vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
        if (!vtarget)
                return -ENOMEM;
 
-       vtarget->ioc_id = hd->ioc->id;
+       vtarget->ioc_id = ioc->id;
        vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
        vtarget->id = (u8)starget->id;
        vtarget->channel = (u8)starget->channel;
@@ -409,34 +417,34 @@ static int mptspi_target_alloc(struct scsi_target *starget)
        starget->hostdata = vtarget;
 
        if (starget->channel == 1) {
-               if (mptscsih_is_phys_disk(hd->ioc, 0, starget->id) == 0)
+               if (mptscsih_is_phys_disk(ioc, 0, starget->id) == 0)
                        return 0;
                vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
                /* The real channel for this device is zero */
                vtarget->channel = 0;
                /* The actual physdisknum (for RAID passthrough) */
-               vtarget->id = mptscsih_raid_id_to_num(hd->ioc, 0,
+               vtarget->id = mptscsih_raid_id_to_num(ioc, 0,
                    starget->id);
        }
 
        if (starget->channel == 0 &&
            mptspi_is_raid(hd, starget->id)) {
                vtarget->raidVolume = 1;
-               ddvprintk((KERN_INFO
-                   "RAID Volume @ channel=%d id=%d\n", starget->channel,
+               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "RAID Volume @ channel=%d id=%d\n", ioc->name, starget->channel,
                    starget->id));
        }
 
-       if (hd->ioc->spi_data.nvram &&
-           hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
-               u32 nvram = hd->ioc->spi_data.nvram[starget->id];
+       if (ioc->spi_data.nvram &&
+           ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
+               u32 nvram = ioc->spi_data.nvram[starget->id];
                spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
                spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
        } else {
-               spi_min_period(starget) = hd->ioc->spi_data.minSyncFactor;
-               spi_max_width(starget) = hd->ioc->spi_data.maxBusWidth;
+               spi_min_period(starget) = ioc->spi_data.minSyncFactor;
+               spi_max_width(starget) = ioc->spi_data.maxBusWidth;
        }
-       spi_max_offset(starget) = hd->ioc->spi_data.maxSyncOffset;
+       spi_max_offset(starget) = ioc->spi_data.maxSyncOffset;
 
        spi_offset(starget) = 0;
        mptspi_write_width(starget, 0);
@@ -462,7 +470,7 @@ mptspi_target_destroy(struct scsi_target *starget)
 static void
 mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
 {
-       ddvprintk((MYIOC_s_INFO_FMT "id=%d Requested = 0x%08x"
+       ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Requested = 0x%08x"
            " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
            hd->ioc->name, starget->id, ii,
            ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
@@ -487,7 +495,7 @@ mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget,
 static void
 mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
 {
-       ddvprintk((MYIOC_s_INFO_FMT "id=%d Read = 0x%08x"
+       ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Read = 0x%08x"
            " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
            hd->ioc->name, starget->id, ii,
            ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
@@ -506,10 +514,10 @@ static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
                             struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
 {
        struct Scsi_Host *shost = dev_to_shost(&starget->dev);
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
        struct _MPT_ADAPTER *ioc = hd->ioc;
-       struct _CONFIG_PAGE_SCSI_DEVICE_0 *pg0;
-       dma_addr_t pg0_dma;
+       struct _CONFIG_PAGE_SCSI_DEVICE_0 *spi_dev_pg0;
+       dma_addr_t spi_dev_pg0_dma;
        int size;
        struct _x_config_parms cfg;
        struct _CONFIG_PAGE_HEADER hdr;
@@ -527,9 +535,10 @@ static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
        size += 2048;
        */
 
-       pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg0_dma, GFP_KERNEL);
-       if (pg0 == NULL) {
-               starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
+       spi_dev_pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &spi_dev_pg0_dma, GFP_KERNEL);
+       if (spi_dev_pg0 == NULL) {
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT
+                   "dma_alloc_coherent for parameters failed\n", ioc->name);
                return -EINVAL;
        }
 
@@ -543,22 +552,22 @@ static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
        memset(&cfg, 0, sizeof(cfg));
 
        cfg.cfghdr.hdr = &hdr;
-       cfg.physAddr = pg0_dma;
+       cfg.physAddr = spi_dev_pg0_dma;
        cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
        cfg.dir = 0;
        cfg.pageAddr = starget->id;
 
        if (mpt_config(ioc, &cfg)) {
-               starget_printk(KERN_ERR, starget, "mpt_config failed\n");
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT "mpt_config failed\n", ioc->name);
                goto out_free;
        }
        err = 0;
-       memcpy(pass_pg0, pg0, size);
+       memcpy(pass_pg0, spi_dev_pg0, size);
 
-       mptspi_print_read_nego(hd, starget, le32_to_cpu(pg0->NegotiatedParameters));
+       mptspi_print_read_nego(hd, starget, le32_to_cpu(spi_dev_pg0->NegotiatedParameters));
 
  out_free:
-       dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma);
+       dma_free_coherent(&ioc->pcidev->dev, size, spi_dev_pg0, spi_dev_pg0_dma);
        return err;
 }
 
@@ -585,11 +594,11 @@ static u32 mptspi_getRP(struct scsi_target *starget)
 static void mptspi_read_parameters(struct scsi_target *starget)
 {
        int nego;
-       struct _CONFIG_PAGE_SCSI_DEVICE_0 pg0;
+       struct _CONFIG_PAGE_SCSI_DEVICE_0 spi_dev_pg0;
 
-       mptspi_read_spi_device_pg0(starget, &pg0);
+       mptspi_read_spi_device_pg0(starget, &spi_dev_pg0);
 
-       nego = le32_to_cpu(pg0.NegotiatedParameters);
+       nego = le32_to_cpu(spi_dev_pg0.NegotiatedParameters);
 
        spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;
        spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;
@@ -609,12 +618,13 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
 {
        MpiRaidActionRequest_t  *pReq;
        MPT_FRAME_HDR           *mf;
+       MPT_ADAPTER *ioc = hd->ioc;
 
        /* Get and Populate a free Frame
         */
-       if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
-               ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
-                                       hd->ioc->name));
+       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
+               ddvprintk(ioc, printk(MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
+                                       ioc->name));
                return -EAGAIN;
        }
        pReq = (MpiRaidActionRequest_t *)mf;
@@ -635,8 +645,8 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
        mpt_add_sge((char *)&pReq->ActionDataSGE,
                MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
 
-       ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action=%x channel=%d id=%d\n",
-                       hd->ioc->name, pReq->Action, channel, id));
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
+                       ioc->name, pReq->Action, channel, id));
 
        hd->pLocal = NULL;
        hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
@@ -648,7 +658,7 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
        hd->cmdPtr = mf;
 
        add_timer(&hd->timer);
-       mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
+       mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
        wait_event(hd->scandv_waitq, hd->scandv_wait_done);
 
        if ((hd->pLocal == NULL) || (hd->pLocal->completion != 0))
@@ -661,6 +671,7 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
                             struct scsi_device *sdev)
 {
        VirtTarget *vtarget = scsi_target(sdev)->hostdata;
+       MPT_ADAPTER *ioc = hd->ioc;
 
        /* no DV on RAID devices */
        if (sdev->channel == 0 &&
@@ -670,8 +681,8 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
        /* If this is a piece of a RAID, then quiesce first */
        if (sdev->channel == 1 &&
            mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) {
-               starget_printk(KERN_ERR, scsi_target(sdev),
-                              "Integrated RAID quiesce failed\n");
+               starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
+                   "Integrated RAID quiesce failed\n", ioc->name);
                return;
        }
 
@@ -681,8 +692,8 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
 
        if (sdev->channel == 1 &&
            mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0)
-               starget_printk(KERN_ERR, scsi_target(sdev),
-                              "Integrated RAID resume failed\n");
+               starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
+                   "Integrated RAID resume failed\n", ioc->name);
 
        mptspi_read_parameters(sdev->sdev_target);
        spi_display_xfer_agreement(sdev->sdev_target);
@@ -691,28 +702,29 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
 
 static int mptspi_slave_alloc(struct scsi_device *sdev)
 {
-       MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
+       MPT_SCSI_HOST *hd = shost_priv(sdev->host);
        VirtTarget              *vtarget;
-       VirtDevice              *vdev;
+       VirtDevice              *vdevice;
        struct scsi_target      *starget;
+       MPT_ADAPTER *ioc = hd->ioc;
 
        if (sdev->channel == 1 &&
-               mptscsih_is_phys_disk(hd->ioc, 0, sdev->id) == 0)
+               mptscsih_is_phys_disk(ioc, 0, sdev->id) == 0)
                        return -ENXIO;
 
-       vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
-       if (!vdev) {
+       vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
+       if (!vdevice) {
                printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
-                               hd->ioc->name, sizeof(VirtDevice));
+                               ioc->name, sizeof(VirtDevice));
                return -ENOMEM;
        }
 
-       vdev->lun = sdev->lun;
-       sdev->hostdata = vdev;
+       vdevice->lun = sdev->lun;
+       sdev->hostdata = vdevice;
 
        starget = scsi_target(sdev);
        vtarget = starget->hostdata;
-       vdev->vtarget = vtarget;
+       vdevice->vtarget = vtarget;
        vtarget->num_luns++;
 
        if (sdev->channel == 1)
@@ -723,8 +735,7 @@ static int mptspi_slave_alloc(struct scsi_device *sdev)
 
 static int mptspi_slave_configure(struct scsi_device *sdev)
 {
-       struct _MPT_SCSI_HOST *hd =
-               (struct _MPT_SCSI_HOST *)sdev->host->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(sdev->host);
        VirtTarget *vtarget = scsi_target(sdev)->hostdata;
        int ret;
 
@@ -735,7 +746,7 @@ static int mptspi_slave_configure(struct scsi_device *sdev)
        if (ret)
                return ret;
 
-       ddvprintk((MYIOC_s_INFO_FMT "id=%d min_period=0x%02x"
+       ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d min_period=0x%02x"
                " max_offset=0x%02x max_width=%d\n", hd->ioc->name,
                sdev->id, spi_min_period(scsi_target(sdev)),
                spi_max_offset(scsi_target(sdev)),
@@ -752,26 +763,25 @@ static int mptspi_slave_configure(struct scsi_device *sdev)
 static int
 mptspi_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
 {
-       struct _MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
-       VirtDevice      *vdev = SCpnt->device->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host);
+       VirtDevice      *vdevice = SCpnt->device->hostdata;
+       MPT_ADAPTER *ioc = hd->ioc;
 
-       if (!vdev || !vdev->vtarget) {
+       if (!vdevice || !vdevice->vtarget) {
                SCpnt->result = DID_NO_CONNECT << 16;
                done(SCpnt);
                return 0;
        }
 
        if (SCpnt->device->channel == 1 &&
-               mptscsih_is_phys_disk(hd->ioc, 0, SCpnt->device->id) == 0) {
+               mptscsih_is_phys_disk(ioc, 0, SCpnt->device->id) == 0) {
                SCpnt->result = DID_NO_CONNECT << 16;
                done(SCpnt);
                return 0;
        }
 
-#ifdef MPT_DEBUG_DV
        if (spi_dv_pending(scsi_target(SCpnt->device)))
-               scsi_print_command(SCpnt);
-#endif
+               ddvprintk(ioc, scsi_print_command(SCpnt));
 
        return mptscsih_qcmd(SCpnt,done);
 }
@@ -821,13 +831,14 @@ static struct scsi_host_template mptspi_driver_template = {
        .max_sectors                    = 8192,
        .cmd_per_lun                    = 7,
        .use_clustering                 = ENABLE_CLUSTERING,
+       .shost_attrs                    = mptscsih_host_attrs,
 };
 
 static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
                               struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1)
 {
        struct Scsi_Host *shost = dev_to_shost(&starget->dev);
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
        struct _MPT_ADAPTER *ioc = hd->ioc;
        struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1;
        dma_addr_t pg1_dma;
@@ -845,7 +856,8 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
 
        pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
        if (pg1 == NULL) {
-               starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT
+                   "dma_alloc_coherent for parameters failed\n", ioc->name);
                return -EINVAL;
        }
 
@@ -874,7 +886,8 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
        mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters));
 
        if (mpt_config(ioc, &cfg)) {
-               starget_printk(KERN_ERR, starget, "mpt_config failed\n");
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT
+                   "mpt_config failed\n", ioc->name);
                goto out_free;
        }
        err = 0;
@@ -1013,7 +1026,7 @@ static void mptspi_write_qas(struct scsi_target *starget, int qas)
 {
        struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
        struct Scsi_Host *shost = dev_to_shost(&starget->dev);
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
        VirtTarget *vtarget = starget->hostdata;
        u32 nego;
 
@@ -1065,15 +1078,16 @@ static void mpt_work_wrapper(struct work_struct *work)
        struct work_queue_wrapper *wqw =
                container_of(work, struct work_queue_wrapper, work);
        struct _MPT_SCSI_HOST *hd = wqw->hd;
-       struct Scsi_Host *shost = hd->ioc->sh;
+       MPT_ADAPTER *ioc = hd->ioc;
+       struct Scsi_Host *shost = ioc->sh;
        struct scsi_device *sdev;
        int disk = wqw->disk;
        struct _CONFIG_PAGE_IOC_3 *pg3;
 
        kfree(wqw);
 
-       mpt_findImVolumes(hd->ioc);
-       pg3 = hd->ioc->raid_data.pIocPg3;
+       mpt_findImVolumes(ioc);
+       pg3 = ioc->raid_data.pIocPg3;
        if (!pg3)
                return;
 
@@ -1090,24 +1104,25 @@ static void mpt_work_wrapper(struct work_struct *work)
                if(vtarget->id != disk)
                        continue;
 
-               starget_printk(KERN_INFO, vtarget->starget,
-                              "Integrated RAID requests DV of new device\n");
+               starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT
+                   "Integrated RAID requests DV of new device\n", ioc->name);
                mptspi_dv_device(hd, sdev);
        }
-       shost_printk(KERN_INFO, shost,
-                    "Integrated RAID detects new device %d\n", disk);
-       scsi_scan_target(&hd->ioc->sh->shost_gendev, 1, disk, 0, 1);
+       shost_printk(KERN_INFO, shost, MYIOC_s_FMT
+           "Integrated RAID detects new device %d\n", ioc->name, disk);
+       scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, 1);
 }
 
 
 static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
 {
        struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
+       MPT_ADAPTER *ioc = hd->ioc;
 
        if (!wqw) {
-               shost_printk(KERN_ERR, hd->ioc->sh,
-                            "Failed to act on RAID event for physical disk %d\n",
-                          disk);
+               shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
+                   "Failed to act on RAID event for physical disk %d\n",
+                   ioc->name, disk);
                return;
        }
        INIT_WORK(&wqw->work, mpt_work_wrapper);
@@ -1121,7 +1136,7 @@ static int
 mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
 {
        u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
 
        if (hd && event ==  MPI_EVENT_INTEGRATED_RAID) {
                int reason
@@ -1188,6 +1203,8 @@ static struct spi_function_template mptspi_transport_functions = {
 static struct pci_device_id mptspi_pci_table[] = {
        { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030,
                PCI_ANY_ID, PCI_ANY_ID },
+       { PCI_VENDOR_ID_ATTO, MPI_MANUFACTPAGE_DEVID_53C1030,
+               PCI_ANY_ID, PCI_ANY_ID },
        { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035,
                PCI_ANY_ID, PCI_ANY_ID },
        {0}     /* Terminating entry */
@@ -1208,11 +1225,12 @@ mptspi_dv_renegotiate_work(struct work_struct *work)
        struct scsi_target *starget;
        struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
        u32 nego;
+       MPT_ADAPTER *ioc = hd->ioc;
 
        kfree(wqw);
 
        if (hd->spi_pending) {
-               shost_for_each_device(sdev, hd->ioc->sh) {
+               shost_for_each_device(sdev, ioc->sh) {
                        if  (hd->spi_pending & (1 << sdev->id))
                                continue;
                        starget = scsi_target(sdev);
@@ -1223,7 +1241,7 @@ mptspi_dv_renegotiate_work(struct work_struct *work)
                        mptspi_write_spi_device_pg1(starget, &pg1);
                }
        } else {
-               shost_for_each_device(sdev, hd->ioc->sh)
+               shost_for_each_device(sdev, ioc->sh)
                        mptspi_dv_device(hd, sdev);
        }
 }
@@ -1248,13 +1266,18 @@ mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd)
 static int
 mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
 {
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
        int rc;
 
        rc = mptscsih_ioc_reset(ioc, reset_phase);
 
-       if (reset_phase == MPT_IOC_POST_RESET)
+       /* only try to do a renegotiation if we're properly set up
+        * if we get an ioc fault on bringup, ioc->sh will be NULL */
+       if (reset_phase == MPT_IOC_POST_RESET &&
+           ioc->sh) {
+               struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
+
                mptspi_dv_renegotiate(hd);
+       }
 
        return rc;
 }
@@ -1267,7 +1290,7 @@ static int
 mptspi_resume(struct pci_dev *pdev)
 {
        MPT_ADAPTER     *ioc = pci_get_drvdata(pdev);
-       struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
+       struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
        int rc;
 
        rc = mptscsih_resume(pdev);
@@ -1414,7 +1437,7 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        if (numSGE < sh->sg_tablesize) {
                /* Reset this value */
-               dprintk((MYIOC_s_INFO_FMT
+               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                  "Resetting sg_tablesize to %d from %d\n",
                  ioc->name, numSGE, sh->sg_tablesize));
                sh->sg_tablesize = numSGE;
@@ -1422,20 +1445,21 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        spin_unlock_irqrestore(&ioc->FreeQlock, flags);
 
-       hd = (MPT_SCSI_HOST *) sh->hostdata;
+       hd = shost_priv(sh);
        hd->ioc = ioc;
 
        /* SCSI needs scsi_cmnd lookup table!
         * (with size equal to req_depth*PtrSz!)
         */
-       hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
-       if (!hd->ScsiLookup) {
+       ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
+       if (!ioc->ScsiLookup) {
                error = -ENOMEM;
                goto out_mptspi_probe;
        }
+       spin_lock_init(&ioc->scsi_lookup_lock);
 
-       dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
-                ioc->name, hd->ScsiLookup));
+       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
+                ioc->name, ioc->ScsiLookup));
 
        /* Clear the TM flags
         */
@@ -1462,7 +1486,7 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        ioc->spi_data.Saf_Te = mpt_saf_te;
 
        hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
-       ddvprintk((MYIOC_s_INFO_FMT
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "saf_te %x\n",
                ioc->name,
                mpt_saf_te));
@@ -1475,13 +1499,13 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        /* Some versions of the firmware don't support page 0; without
         * that we can't get the parameters */
-       if (hd->ioc->spi_data.sdp0length != 0)
+       if (ioc->spi_data.sdp0length != 0)
                sh->transportt = mptspi_transport_template;
 
        error = scsi_add_host (sh, &ioc->pcidev->dev);
        if(error) {
-               dprintk((KERN_ERR MYNAM
-                 "scsi_add_host failed\n"));
+               dprintk(ioc, printk(MYIOC_s_ERR_FMT
+                 "scsi_add_host failed\n", ioc->name));
                goto out_mptspi_probe;
        }
 
@@ -1523,6 +1547,8 @@ static struct pci_driver mptspi_driver = {
 static int __init
 mptspi_init(void)
 {
+       int error;
+
        show_mptmod_ver(my_NAME, my_VERSION);
 
        mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions);
@@ -1533,17 +1559,14 @@ mptspi_init(void)
        mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER);
        mptspiInternalCtx = mpt_register(mptscsih_scandv_complete, MPTSPI_DRIVER);
 
-       if (mpt_event_register(mptspiDoneCtx, mptspi_event_process) == 0) {
-               devtverboseprintk((KERN_INFO MYNAM
-                 ": Registered for IOC event notifications\n"));
-       }
+       mpt_event_register(mptspiDoneCtx, mptspi_event_process);
+       mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset);
 
-       if (mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset) == 0) {
-               dprintk((KERN_INFO MYNAM
-                 ": Registered for IOC reset notifications\n"));
-       }
+       error = pci_register_driver(&mptspi_driver);
+       if (error)
+               spi_release_transport(mptspi_transport_template);
 
-       return pci_register_driver(&mptspi_driver);
+       return error;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1557,12 +1580,7 @@ mptspi_exit(void)
        pci_unregister_driver(&mptspi_driver);
 
        mpt_reset_deregister(mptspiDoneCtx);
-       dprintk((KERN_INFO MYNAM
-         ": Deregistered for IOC reset notifications\n"));
-
        mpt_event_deregister(mptspiDoneCtx);
-       dprintk((KERN_INFO MYNAM
-         ": Deregistered for IOC event notifications\n"));
 
        mpt_deregister(mptspiInternalCtx);
        mpt_deregister(mptspiTaskCtx);