linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_scsi.c
index 7dc4c2e..dafabee 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-2006 Emulex.  All rights reserved.           *
+ * Copyright (C) 2004-2005 Emulex.  All rights reserved.           *
  * EMULEX and SLI are trademarks of Emulex.                        *
  * www.emulex.com                                                  *
  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
@@ -467,12 +467,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
        sdev = cmd->device;
        cmd->scsi_done(cmd);
 
-       if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
-               lpfc_release_scsi_buf(phba, lpfc_cmd);
-               return;
-       }
-
-       if (!result && pnode != NULL &&
+       if (!result &&
           ((jiffies - pnode->last_ramp_up_time) >
                LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
           ((jiffies - pnode->last_q_full_time) >
@@ -500,7 +495,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
         * 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) {
+       if (result == SAM_STAT_TASK_SET_FULL) {
                pnode->last_q_full_time = jiffies;
 
                shost_for_each_device(tmp_sdev, sdev->host) {
@@ -629,7 +624,8 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
        struct lpfc_iocbq *piocbq;
        IOCB_t *piocb;
        struct fcp_cmnd *fcp_cmnd;
-       struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
+       struct scsi_device *scsi_dev = lpfc_cmd->pCmd->device;
+       struct lpfc_rport_data *rdata = scsi_dev->hostdata;
        struct lpfc_nodelist *ndlp = rdata->pnode;
 
        if ((ndlp == NULL) || (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
@@ -664,18 +660,56 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
                piocb->ulpTimeout = lpfc_cmd->timeout;
        }
 
+       lpfc_cmd->rdata = rdata;
+
+       switch (task_mgmt_cmd) {
+       case FCP_LUN_RESET:
+               /* Issue LUN Reset to TGT <num> LUN <num> */
+               lpfc_printf_log(phba,
+                               KERN_INFO,
+                               LOG_FCP,
+                               "%d:0703 Issue LUN Reset to TGT %d LUN %d "
+                               "Data: x%x x%x\n",
+                               phba->brd_no,
+                               scsi_dev->id, scsi_dev->lun,
+                               ndlp->nlp_rpi, ndlp->nlp_flag);
+
+               break;
+       case FCP_ABORT_TASK_SET:
+               /* Issue Abort Task Set to TGT <num> LUN <num> */
+               lpfc_printf_log(phba,
+                               KERN_INFO,
+                               LOG_FCP,
+                               "%d:0701 Issue Abort Task Set to TGT %d LUN %d "
+                               "Data: x%x x%x\n",
+                               phba->brd_no,
+                               scsi_dev->id, scsi_dev->lun,
+                               ndlp->nlp_rpi, ndlp->nlp_flag);
+
+               break;
+       case FCP_TARGET_RESET:
+               /* Issue Target Reset to TGT <num> */
+               lpfc_printf_log(phba,
+                               KERN_INFO,
+                               LOG_FCP,
+                               "%d:0702 Issue Target Reset to TGT %d "
+                               "Data: x%x x%x\n",
+                               phba->brd_no,
+                               scsi_dev->id, ndlp->nlp_rpi,
+                               ndlp->nlp_flag);
+               break;
+       }
+
        return (1);
 }
 
 static int
-lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
-                   unsigned  tgt_id, struct lpfc_rport_data *rdata)
+lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba)
 {
        struct lpfc_iocbq *iocbq;
        struct lpfc_iocbq *iocbqrsp;
        int ret;
 
-       lpfc_cmd->rdata = rdata;
        ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_TARGET_RESET);
        if (!ret)
                return FAILED;
@@ -687,13 +721,6 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
        if (!iocbqrsp)
                return FAILED;
 
-       /* Issue Target Reset to TGT <num> */
-       lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
-                       "%d:0702 Issue Target Reset to TGT %d "
-                       "Data: x%x x%x\n",
-                       phba->brd_no, tgt_id, rdata->pnode->nlp_rpi,
-                       rdata->pnode->nlp_flag);
-
        ret = lpfc_sli_issue_iocb_wait(phba,
                                       &phba->sli.ring[phba->sli.fcp_ring],
                                       iocbq, iocbqrsp, lpfc_cmd->timeout);
@@ -716,7 +743,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;
+       struct lpfc_hba    *phba = (struct lpfc_hba *) host->hostdata[0];
        int len;
        static char  lpfcinfobuf[384];
 
@@ -776,7 +803,7 @@ static int
 lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
 {
        struct lpfc_hba *phba =
-               (struct lpfc_hba *) cmnd->device->host->hostdata;
+               (struct lpfc_hba *) cmnd->device->host->hostdata[0];
        struct lpfc_sli *psli = &phba->sli;
        struct lpfc_rport_data *rdata = cmnd->device->hostdata;
        struct lpfc_nodelist *ndlp = rdata->pnode;
@@ -850,7 +877,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;
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
        struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
        struct lpfc_iocbq *iocb;
        struct lpfc_iocbq *abtsiocb;
@@ -954,7 +981,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;
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
        struct lpfc_scsi_buf *lpfc_cmd;
        struct lpfc_iocbq *iocbq, *iocbqrsp;
        struct lpfc_rport_data *rdata = cmnd->device->hostdata;
@@ -989,7 +1016,6 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
        lpfc_cmd->pCmd = cmnd;
        lpfc_cmd->timeout = 60;
        lpfc_cmd->scsi_hba = phba;
-       lpfc_cmd->rdata = rdata;
 
        ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_LUN_RESET);
        if (!ret)
@@ -1002,11 +1028,6 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
        if (iocbqrsp == NULL)
                goto out_free_scsi_buf;
 
-       lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
-                       "%d:0703 Issue LUN Reset to TGT %d LUN %d "
-                       "Data: x%x x%x\n", phba->brd_no, cmnd->device->id,
-                       cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
-
        ret = lpfc_sli_issue_iocb_wait(phba,
                                       &phba->sli.ring[phba->sli.fcp_ring],
                                       iocbq, iocbqrsp, lpfc_cmd->timeout);
@@ -1073,11 +1094,12 @@ 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;
+       struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
        struct lpfc_nodelist *ndlp = NULL;
        int match;
        int ret = FAILED, i, err_count = 0;
        int cnt, loopcnt;
+       unsigned int midlayer_id = 0;
        struct lpfc_scsi_buf * lpfc_cmd;
 
        lpfc_block_requests(phba);
@@ -1097,6 +1119,7 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
         * targets known to the driver.  Should any target reset
         * fail, this routine returns failure to the midlayer.
         */
+       midlayer_id = cmnd->device->id;
        for (i = 0; i < MAX_FCP_TARGET; i++) {
                /* Search the mapped list for this target ID */
                match = 0;
@@ -1109,8 +1132,9 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
                if (!match)
                        continue;
 
-               ret = lpfc_scsi_tgt_reset(lpfc_cmd, phba,
-                                         i, ndlp->rport->dd_data);
+               lpfc_cmd->pCmd->device->id = i;
+               lpfc_cmd->pCmd->device->hostdata = ndlp->rport->dd_data;
+               ret = lpfc_scsi_tgt_reset(lpfc_cmd, phba);
                if (ret != SUCCESS) {
                        lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
                                "%d:0713 Bus Reset on target %d failed\n",
@@ -1129,6 +1153,7 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
         * the targets.  Unfortunately, some targets do not abide by
         * this forcing the driver to double check.
         */
+       cmnd->device->id = midlayer_id;
        cnt = lpfc_sli_sum_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
                                0, 0, LPFC_CTX_HOST);
        if (cnt)
@@ -1170,7 +1195,7 @@ out:
 static int
 lpfc_slave_alloc(struct scsi_device *sdev)
 {
-       struct lpfc_hba *phba = (struct lpfc_hba *)sdev->host->hostdata;
+       struct lpfc_hba *phba = (struct lpfc_hba *)sdev->host->hostdata[0];
        struct lpfc_scsi_buf *scsi_buf = NULL;
        struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
        uint32_t total = 0, i;
@@ -1226,7 +1251,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;
+       struct lpfc_hba *phba = (struct lpfc_hba *) sdev->host->hostdata[0];
        struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
 
        if (sdev->tagged_supported)