]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/lpfc/lpfc_scsi.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/perex/alsa
[linux-2.6-omap-h63xx.git] / drivers / scsi / lpfc / lpfc_scsi.c
index 7dc7810b748239e6c865514f39ea064f807ff556..f93799873721290c38b774b9668ad5bb0dd91365 100644 (file)
@@ -1,7 +1,7 @@
 /*******************************************************************
  * This file is part of the Emulex Linux Device Driver for         *
  * Fibre Channel Host Bus Adapters.                                *
- * Copyright (C) 2004-2005 Emulex.  All rights reserved.           *
+ * Copyright (C) 2004-2006 Emulex.  All rights reserved.           *
  * EMULEX and SLI are trademarks of Emulex.                        *
  * www.emulex.com                                                  *
  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
@@ -150,19 +150,23 @@ lpfc_new_scsi_buf(struct lpfc_hba * phba)
        return psb;
 }
 
-struct  lpfc_scsi_buf*
-lpfc_sli_get_scsi_buf(struct lpfc_hba * phba)
+static struct lpfc_scsi_buf*
+lpfc_get_scsi_buf(struct lpfc_hba * phba)
 {
        struct  lpfc_scsi_buf * lpfc_cmd = NULL;
        struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
+       unsigned long iflag = 0;
 
+       spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
        list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
+       spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
        return  lpfc_cmd;
 }
 
 static void
 lpfc_release_scsi_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
 {
+       unsigned long iflag = 0;
        /*
         * There are only two special cases to consider.  (1) the scsi command
         * requested scatter-gather usage or (2) the scsi command allocated
@@ -180,8 +184,10 @@ lpfc_release_scsi_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
                 }
        }
 
+       spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
        psb->pCmd = NULL;
        list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
+       spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
 }
 
 static int
@@ -403,7 +409,9 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
        struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
        struct lpfc_nodelist *pnode = rdata->pnode;
        struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
-       unsigned long iflag;
+       int result;
+       struct scsi_device *sdev, *tmp_sdev;
+       int depth = 0;
 
        lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
        lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
@@ -455,11 +463,69 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
                                *lp, *(lp + 3), cmd->retries, cmd->resid);
        }
 
+       result = cmd->result;
+       sdev = cmd->device;
        cmd->scsi_done(cmd);
 
-       spin_lock_irqsave(phba->host->host_lock, iflag);
+       if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
+               lpfc_release_scsi_buf(phba, lpfc_cmd);
+               return;
+       }
+
+       if (!result && pnode != NULL &&
+          ((jiffies - pnode->last_ramp_up_time) >
+               LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
+          ((jiffies - pnode->last_q_full_time) >
+               LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
+          (phba->cfg_lun_queue_depth > sdev->queue_depth)) {
+               shost_for_each_device(tmp_sdev, sdev->host) {
+                       if (phba->cfg_lun_queue_depth > tmp_sdev->queue_depth) {
+                               if (tmp_sdev->id != sdev->id)
+                                       continue;
+                               if (tmp_sdev->ordered_tags)
+                                       scsi_adjust_queue_depth(tmp_sdev,
+                                               MSG_ORDERED_TAG,
+                                               tmp_sdev->queue_depth+1);
+                               else
+                                       scsi_adjust_queue_depth(tmp_sdev,
+                                               MSG_SIMPLE_TAG,
+                                               tmp_sdev->queue_depth+1);
+
+                               pnode->last_ramp_up_time = jiffies;
+                       }
+               }
+       }
+
+       /*
+        * Check for queue full.  If the lun is reporting queue full, then
+        * back off the lun queue depth to prevent target overloads.
+        */
+       if (result == SAM_STAT_TASK_SET_FULL && pnode != NULL) {
+               pnode->last_q_full_time = jiffies;
+
+               shost_for_each_device(tmp_sdev, sdev->host) {
+                       if (tmp_sdev->id != sdev->id)
+                               continue;
+                       depth = scsi_track_queue_full(tmp_sdev,
+                                       tmp_sdev->queue_depth - 1);
+               }
+               /*
+                * The queue depth cannot be lowered any more.
+                * Modify the returned error code to store
+                * the final depth value set by
+                * scsi_track_queue_full.
+                */
+               if (depth == -1)
+                       depth = sdev->host->cmd_per_lun;
+
+               if (depth) {
+                       lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+                               "%d:0711 detected queue full - lun queue depth "
+                               " adjusted to %d.\n", phba->brd_no, depth);
+               }
+       }
+
        lpfc_release_scsi_buf(phba, lpfc_cmd);
-       spin_unlock_irqrestore(phba->host->host_lock, iflag);
 }
 
 static void
@@ -682,7 +748,7 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba)
 const char *
 lpfc_info(struct Scsi_Host *host)
 {
-       struct lpfc_hba    *phba = (struct lpfc_hba *) host->hostdata[0];
+       struct lpfc_hba    *phba = (struct lpfc_hba *) host->hostdata;
        int len;
        static char  lpfcinfobuf[384];
 
@@ -707,11 +773,42 @@ lpfc_info(struct Scsi_Host *host)
        return lpfcinfobuf;
 }
 
+static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
+{
+       unsigned long  poll_tmo_expires =
+               (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
+
+       if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
+               mod_timer(&phba->fcp_poll_timer,
+                         poll_tmo_expires);
+}
+
+void lpfc_poll_start_timer(struct lpfc_hba * phba)
+{
+       lpfc_poll_rearm_timer(phba);
+}
+
+void lpfc_poll_timeout(unsigned long ptr)
+{
+       struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
+       unsigned long iflag;
+
+       spin_lock_irqsave(phba->host->host_lock, iflag);
+
+       if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
+               lpfc_sli_poll_fcp_ring (phba);
+               if (phba->cfg_poll & DISABLE_FCP_RING_INT)
+                       lpfc_poll_rearm_timer(phba);
+       }
+
+       spin_unlock_irqrestore(phba->host->host_lock, iflag);
+}
+
 static int
 lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
 {
        struct lpfc_hba *phba =
-               (struct lpfc_hba *) cmnd->device->host->hostdata[0];
+               (struct lpfc_hba *) cmnd->device->host->hostdata;
        struct lpfc_sli *psli = &phba->sli;
        struct lpfc_rport_data *rdata = cmnd->device->hostdata;
        struct lpfc_nodelist *ndlp = rdata->pnode;
@@ -733,7 +830,7 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
                cmnd->result = ScsiResult(DID_BUS_BUSY, 0);
                goto out_fail_command;
        }
-       lpfc_cmd = lpfc_sli_get_scsi_buf (phba);
+       lpfc_cmd = lpfc_get_scsi_buf (phba);
        if (lpfc_cmd == NULL) {
                lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
                                "%d:0707 driver's buffer pool is empty, "
@@ -761,11 +858,17 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
                                &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
        if (err)
                goto out_host_busy_free_buf;
+
+       if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
+               lpfc_sli_poll_fcp_ring(phba);
+               if (phba->cfg_poll & DISABLE_FCP_RING_INT)
+                       lpfc_poll_rearm_timer(phba);
+       }
+
        return 0;
 
  out_host_busy_free_buf:
        lpfc_release_scsi_buf(phba, lpfc_cmd);
-       cmnd->host_scribble = NULL;
  out_host_busy:
        return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -779,7 +882,7 @@ static int
 lpfc_abort_handler(struct scsi_cmnd *cmnd)
 {
        struct Scsi_Host *shost = cmnd->device->host;
-       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
        struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
        struct lpfc_iocbq *iocb;
        struct lpfc_iocbq *abtsiocb;
@@ -839,9 +942,15 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
                goto out;
        }
 
+       if (phba->cfg_poll & DISABLE_FCP_RING_INT)
+               lpfc_sli_poll_fcp_ring (phba);
+
        /* Wait for abort to complete */
        while (lpfc_cmd->pCmd == cmnd)
        {
+               if (phba->cfg_poll & DISABLE_FCP_RING_INT)
+                       lpfc_sli_poll_fcp_ring (phba);
+
                spin_unlock_irq(phba->host->host_lock);
                        schedule_timeout_uninterruptible(LPFC_ABORT_WAIT*HZ);
                spin_lock_irq(phba->host->host_lock);
@@ -877,7 +986,7 @@ static int
 lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
 {
        struct Scsi_Host *shost = cmnd->device->host;
-       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
        struct lpfc_scsi_buf *lpfc_cmd;
        struct lpfc_iocbq *iocbq, *iocbqrsp;
        struct lpfc_rport_data *rdata = cmnd->device->hostdata;
@@ -905,7 +1014,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
                        break;
        }
 
-       lpfc_cmd = lpfc_sli_get_scsi_buf (phba);
+       lpfc_cmd = lpfc_get_scsi_buf (phba);
        if (lpfc_cmd == NULL)
                goto out;
 
@@ -990,7 +1099,7 @@ static int
 lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
 {
        struct Scsi_Host *shost = cmnd->device->host;
-       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
        struct lpfc_nodelist *ndlp = NULL;
        int match;
        int ret = FAILED, i, err_count = 0;
@@ -1001,7 +1110,7 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
        lpfc_block_requests(phba);
        spin_lock_irq(shost->host_lock);
 
-       lpfc_cmd = lpfc_sli_get_scsi_buf (phba);
+       lpfc_cmd = lpfc_get_scsi_buf(phba);
        if (lpfc_cmd == NULL)
                goto out;
 
@@ -1091,7 +1200,7 @@ out:
 static int
 lpfc_slave_alloc(struct scsi_device *sdev)
 {
-       struct lpfc_hba *phba = (struct lpfc_hba *)sdev->host->hostdata[0];
+       struct lpfc_hba *phba = (struct lpfc_hba *)sdev->host->hostdata;
        struct lpfc_scsi_buf *scsi_buf = NULL;
        struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
        uint32_t total = 0, i;
@@ -1136,10 +1245,10 @@ lpfc_slave_alloc(struct scsi_device *sdev)
                        break;
                }
 
-               spin_lock_irqsave(phba->host->host_lock, flags);
+               spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
                phba->total_scsi_bufs++;
                list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
-               spin_unlock_irqrestore(phba->host->host_lock, flags);
+               spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
        }
        return 0;
 }
@@ -1147,7 +1256,7 @@ lpfc_slave_alloc(struct scsi_device *sdev)
 static int
 lpfc_slave_configure(struct scsi_device *sdev)
 {
-       struct lpfc_hba *phba = (struct lpfc_hba *) sdev->host->hostdata[0];
+       struct lpfc_hba *phba = (struct lpfc_hba *) sdev->host->hostdata;
        struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
 
        if (sdev->tagged_supported)
@@ -1163,6 +1272,12 @@ lpfc_slave_configure(struct scsi_device *sdev)
         */
        rport->dev_loss_tmo = phba->cfg_nodev_tmo + 5;
 
+       if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
+               lpfc_sli_poll_fcp_ring(phba);
+               if (phba->cfg_poll & DISABLE_FCP_RING_INT)
+                       lpfc_poll_rearm_timer(phba);
+       }
+
        return 0;
 }