[SCSI] mpt fusion: rewrite of all internal generated functions
[safe/jmp/linux-2.6] / drivers / message / fusion / mptfc.c
index 0586f87..d093871 100644 (file)
@@ -3,7 +3,7 @@
  *      For use with LSI PCI chip/adapter(s)
  *      running LSI Fusion MPT (Message Passing Technology) firmware.
  *
- *  Copyright (c) 1999-2007 LSI Corporation
+ *  Copyright (c) 1999-2008 LSI Corporation
  *  (mailto:DL-MPTFusionLinux@lsi.com)
  *
  */
@@ -194,37 +194,36 @@ mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
        struct fc_rport         *rport = starget_to_rport(scsi_target(sdev));
        unsigned long           flags;
        int                     ready;
+       MPT_ADAPTER             *ioc;
 
-       hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
+       hd = shost_priv(SCpnt->device->host);
+       ioc = hd->ioc;
        spin_lock_irqsave(shost->host_lock, flags);
        while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY) {
                spin_unlock_irqrestore(shost->host_lock, flags);
-               dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
+               dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
                        "mptfc_block_error_handler.%d: %d:%d, port status is "
                        "DID_IMM_RETRY, deferring %s recovery.\n",
-                       ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
-                       ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
-                       SCpnt->device->id,SCpnt->device->lun,caller));
+                       ioc->name, ioc->sh->host_no,
+                       SCpnt->device->id, SCpnt->device->lun, caller));
                msleep(1000);
                spin_lock_irqsave(shost->host_lock, flags);
        }
        spin_unlock_irqrestore(shost->host_lock, flags);
 
        if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata) {
-               dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
+               dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
                        "%s.%d: %d:%d, failing recovery, "
-                       "port state %d, vdev %p.\n", caller,
-                       ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
-                       ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
-                       SCpnt->device->id,SCpnt->device->lun,ready,
+                       "port state %d, vdevice %p.\n", caller,
+                       ioc->name, ioc->sh->host_no,
+                       SCpnt->device->id, SCpnt->device->lun, ready,
                        SCpnt->device->hostdata));
                return FAILED;
        }
-       dfcprintk (hd->ioc, printk(MYIOC_s_DEBUG_FMT
+       dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
                "%s.%d: %d:%d, executing recovery.\n", caller,
-               ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
-               ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
-               SCpnt->device->id,SCpnt->device->lun));
+               ioc->name, ioc->sh->host_no,
+               SCpnt->device->id, SCpnt->device->lun));
        return (*func)(SCpnt);
 }
 
@@ -232,28 +231,28 @@ static int
 mptfc_abort(struct scsi_cmnd *SCpnt)
 {
        return
-           mptfc_block_error_handler(SCpnt, mptscsih_abort, __FUNCTION__);
+           mptfc_block_error_handler(SCpnt, mptscsih_abort, __func__);
 }
 
 static int
 mptfc_dev_reset(struct scsi_cmnd *SCpnt)
 {
        return
-           mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __FUNCTION__);
+           mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __func__);
 }
 
 static int
 mptfc_bus_reset(struct scsi_cmnd *SCpnt)
 {
        return
-           mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __FUNCTION__);
+           mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __func__);
 }
 
 static int
 mptfc_host_reset(struct scsi_cmnd *SCpnt)
 {
        return
-           mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __FUNCTION__);
+           mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __func__);
 }
 
 static void
@@ -470,7 +469,7 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
                        /*
                         * if already mapped, remap here.  If not mapped,
                         * target_alloc will allocate vtarget and map,
-                        * slave_alloc will fill in vdev from vtarget.
+                        * slave_alloc will fill in vdevice from vtarget.
                         */
                        if (ri->starget) {
                                vtarget = ri->starget->hostdata;
@@ -602,10 +601,10 @@ mptfc_slave_alloc(struct scsi_device *sdev)
 {
        MPT_SCSI_HOST           *hd;
        VirtTarget              *vtarget;
-       VirtDevice              *vdev;
+       VirtDevice              *vdevice;
        struct scsi_target      *starget;
        struct fc_rport         *rport;
-
+       MPT_ADAPTER             *ioc;
 
        starget = scsi_target(sdev);
        rport = starget_to_rport(starget);
@@ -613,31 +612,32 @@ mptfc_slave_alloc(struct scsi_device *sdev)
        if (!rport || fc_remote_port_chkready(rport))
                return -ENXIO;
 
-       hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
+       hd = shost_priv(sdev->host);
+       ioc = hd->ioc;
 
-       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;
        }
 
 
-       sdev->hostdata = vdev;
+       sdev->hostdata = vdevice;
        vtarget = starget->hostdata;
 
        if (vtarget->num_luns == 0) {
-               vtarget->ioc_id = hd->ioc->id;
+               vtarget->ioc_id = ioc->id;
                vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
        }
 
-       vdev->vtarget = vtarget;
-       vdev->lun = sdev->lun;
+       vdevice->vtarget = vtarget;
+       vdevice->lun = sdev->lun;
 
        vtarget->num_luns++;
 
 
-       mptfc_dump_lun_info(hd->ioc, rport, sdev, vtarget);
+       mptfc_dump_lun_info(ioc, rport, sdev, vtarget);
 
        return 0;
 }
@@ -648,9 +648,9 @@ mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
        struct mptfc_rport_info *ri;
        struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
        int             err;
-       VirtDevice      *vdev = SCpnt->device->hostdata;
+       VirtDevice      *vdevice = SCpnt->device->hostdata;
 
-       if (!vdev || !vdev->vtarget) {
+       if (!vdevice || !vdevice->vtarget) {
                SCpnt->result = DID_NO_CONNECT << 16;
                done(SCpnt);
                return 0;
@@ -1238,8 +1238,6 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        sh->max_id = ioc->pfacts->MaxDevices;
        sh->max_lun = max_lun;
 
-       sh->this_id = ioc->pfacts[0].PortSCSIID;
-
        /* Required entry.
         */
        sh->unique_id = ioc->id;
@@ -1253,17 +1251,15 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         * A slightly different algorithm is required for
         * 64bit SGEs.
         */
-       scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
+       scale = ioc->req_sz/ioc->SGE_size;
+       if (ioc->sg_addr_size == sizeof(u64)) {
                numSGE = (scale - 1) *
                  (ioc->facts.MaxChainDepth-1) + scale +
-                 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
-                 sizeof(u32));
+                 (ioc->req_sz - 60) / ioc->SGE_size;
        } else {
                numSGE = 1 + (scale - 1) *
                  (ioc->facts.MaxChainDepth-1) + scale +
-                 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
-                 sizeof(u32));
+                 (ioc->req_sz - 64) / ioc->SGE_size;
        }
 
        if (numSGE < sh->sg_tablesize) {
@@ -1276,20 +1272,21 @@ mptfc_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_mptfc_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
         */
@@ -1313,22 +1310,20 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        hd->timer.data = (unsigned long) hd;
        hd->timer.function = mptscsih_timer_expired;
 
-       init_waitqueue_head(&hd->scandv_waitq);
-       hd->scandv_wait_done = 0;
        hd->last_queue_full = 0;
 
        sh->transportt = mptfc_transport_template;
        error = scsi_add_host (sh, &ioc->pcidev->dev);
        if(error) {
-               dprintk(ioc, printk(KERN_ERR MYNAM
-                 "scsi_add_host failed\n"));
+               dprintk(ioc, printk(MYIOC_s_ERR_FMT
+                 "scsi_add_host failed\n", ioc->name));
                goto out_mptfc_probe;
        }
 
        /* initialize workqueue */
 
-       snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d",
-               sh->host_no);
+       snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name),
+                "mptfc_wq_%d", sh->host_no);
        ioc->fc_rescan_work_q =
                create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
        if (!ioc->fc_rescan_work_q)
@@ -1383,7 +1378,7 @@ mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
                        ioc->name, event));
 
        if (ioc->sh == NULL ||
-               ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
+               ((hd = shost_priv(ioc->sh)) == NULL))
                return 1;
 
        switch (event) {