]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/message/fusion/mptspi.c
[SCSI] mptspi: fix oops in mptspi_dv_renegotiate_work()
[linux-2.6-omap-h63xx.git] / drivers / message / fusion / mptspi.c
index 02062f198be39d9cfb403960d639aee74f9f8718..1effca4e40e119d28f5ae3b9ed681f60eaa026f0 100644 (file)
@@ -397,7 +397,7 @@ 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;
 
@@ -514,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;
@@ -535,9 +535,9 @@ 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(MYIOC_s_ERR_FMT, starget,
+       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;
        }
@@ -552,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(MYIOC_s_ERR_FMT, starget, "mpt_config failed\n", ioc->name);
+               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;
 }
 
@@ -594,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;
@@ -681,7 +681,7 @@ 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(MYIOC_s_ERR_FMT, scsi_target(sdev),
+               starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
                    "Integrated RAID quiesce failed\n", ioc->name);
                return;
        }
@@ -692,7 +692,7 @@ 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(MYIOC_s_ERR_FMT, scsi_target(sdev),
+               starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
                    "Integrated RAID resume failed\n", ioc->name);
 
        mptspi_read_parameters(sdev->sdev_target);
@@ -702,7 +702,7 @@ 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              *vdevice;
        struct scsi_target      *starget;
@@ -735,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;
 
@@ -764,7 +763,7 @@ 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;
+       struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host);
        VirtDevice      *vdevice = SCpnt->device->hostdata;
        MPT_ADAPTER *ioc = hd->ioc;
 
@@ -839,7 +838,7 @@ 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;
@@ -857,7 +856,7 @@ 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(MYIOC_s_ERR_FMT, starget,
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT
                    "dma_alloc_coherent for parameters failed\n", ioc->name);
                return -EINVAL;
        }
@@ -887,7 +886,7 @@ 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(MYIOC_s_ERR_FMT, starget,
+               starget_printk(KERN_ERR, starget, MYIOC_s_FMT
                    "mpt_config failed\n", ioc->name);
                goto out_free;
        }
@@ -1027,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;
 
@@ -1105,11 +1104,11 @@ static void mpt_work_wrapper(struct work_struct *work)
                if(vtarget->id != disk)
                        continue;
 
-               starget_printk(MYIOC_s_INFO_FMT, vtarget->starget,
+               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(MYIOC_s_INFO_FMT, shost,
+       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);
 }
@@ -1121,7 +1120,7 @@ static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
        MPT_ADAPTER *ioc = hd->ioc;
 
        if (!wqw) {
-               shost_printk(MYIOC_s_ERR_FMT, ioc->sh,
+               shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
                    "Failed to act on RAID event for physical disk %d\n",
                    ioc->name, disk);
                return;
@@ -1137,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
@@ -1267,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;
 }
@@ -1286,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);
@@ -1441,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(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
-                ioc->name, hd->ScsiLookup));
+                ioc->name, ioc->ScsiLookup));
 
        /* Clear the TM flags
         */