aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_scsi.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c119
1 files changed, 55 insertions, 64 deletions
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 9a12d05e99e4..6db7ad83cc39 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -41,7 +41,6 @@
41#define LPFC_RESET_WAIT 2 41#define LPFC_RESET_WAIT 2
42#define LPFC_ABORT_WAIT 2 42#define LPFC_ABORT_WAIT 2
43 43
44
45/* 44/*
46 * This routine allocates a scsi buffer, which contains all the necessary 45 * This routine allocates a scsi buffer, which contains all the necessary
47 * information needed to initiate a SCSI I/O. The non-DMAable buffer region 46 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
@@ -51,8 +50,9 @@
51 * and the BPL BDE is setup in the IOCB. 50 * and the BPL BDE is setup in the IOCB.
52 */ 51 */
53static struct lpfc_scsi_buf * 52static struct lpfc_scsi_buf *
54lpfc_new_scsi_buf(struct lpfc_hba * phba) 53lpfc_new_scsi_buf(struct lpfc_vport *vport)
55{ 54{
55 struct lpfc_hba *phba = vport->phba;
56 struct lpfc_scsi_buf *psb; 56 struct lpfc_scsi_buf *psb;
57 struct ulp_bde64 *bpl; 57 struct ulp_bde64 *bpl;
58 IOCB_t *iocb; 58 IOCB_t *iocb;
@@ -63,7 +63,6 @@ lpfc_new_scsi_buf(struct lpfc_hba * phba)
63 if (!psb) 63 if (!psb)
64 return NULL; 64 return NULL;
65 memset(psb, 0, sizeof (struct lpfc_scsi_buf)); 65 memset(psb, 0, sizeof (struct lpfc_scsi_buf));
66 psb->scsi_hba = phba;
67 66
68 /* 67 /*
69 * Get memory from the pci pool to map the virt space to pci bus space 68 * Get memory from the pci pool to map the virt space to pci bus space
@@ -292,12 +291,13 @@ lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
292} 291}
293 292
294static void 293static void
295lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) 294lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
295 struct lpfc_iocbq *rsp_iocb)
296{ 296{
297 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; 297 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
298 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; 298 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
299 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; 299 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
300 struct lpfc_hba *phba = lpfc_cmd->scsi_hba; 300 struct lpfc_hba *phba = vport->phba;
301 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; 301 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
302 uint32_t resp_info = fcprsp->rspStatus2; 302 uint32_t resp_info = fcprsp->rspStatus2;
303 uint32_t scsi_status = fcprsp->rspStatus3; 303 uint32_t scsi_status = fcprsp->rspStatus3;
@@ -429,6 +429,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
429{ 429{
430 struct lpfc_scsi_buf *lpfc_cmd = 430 struct lpfc_scsi_buf *lpfc_cmd =
431 (struct lpfc_scsi_buf *) pIocbIn->context1; 431 (struct lpfc_scsi_buf *) pIocbIn->context1;
432 struct lpfc_vport *vport = pIocbIn->vport;
432 struct lpfc_rport_data *rdata = lpfc_cmd->rdata; 433 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
433 struct lpfc_nodelist *pnode = rdata->pnode; 434 struct lpfc_nodelist *pnode = rdata->pnode;
434 struct scsi_cmnd *cmd = lpfc_cmd->pCmd; 435 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
@@ -457,7 +458,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
457 switch (lpfc_cmd->status) { 458 switch (lpfc_cmd->status) {
458 case IOSTAT_FCP_RSP_ERROR: 459 case IOSTAT_FCP_RSP_ERROR:
459 /* Call FCP RSP handler to determine result */ 460 /* Call FCP RSP handler to determine result */
460 lpfc_handle_fcp_err(lpfc_cmd,pIocbOut); 461 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
461 break; 462 break;
462 case IOSTAT_NPORT_BSY: 463 case IOSTAT_NPORT_BSY:
463 case IOSTAT_FABRIC_BSY: 464 case IOSTAT_FABRIC_BSY:
@@ -534,7 +535,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
534 tmp_sdev->queue_depth - 1); 535 tmp_sdev->queue_depth - 1);
535 } 536 }
536 /* 537 /*
537 * The queue depth cannot be lowered any more. 538 * The queue depth cannot be lowered any more.
538 * Modify the returned error code to store 539 * Modify the returned error code to store
539 * the final depth value set by 540 * the final depth value set by
540 * scsi_track_queue_full. 541 * scsi_track_queue_full.
@@ -553,9 +554,10 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
553} 554}
554 555
555static void 556static void
556lpfc_scsi_prep_cmnd(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd, 557lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
557 struct lpfc_nodelist *pnode) 558 struct lpfc_nodelist *pnode)
558{ 559{
560 struct lpfc_hba *phba = vport->phba;
559 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; 561 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
560 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; 562 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
561 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; 563 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
@@ -642,15 +644,15 @@ lpfc_scsi_prep_cmnd(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd,
642 piocbq->context1 = lpfc_cmd; 644 piocbq->context1 = lpfc_cmd;
643 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; 645 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
644 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; 646 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
647 piocbq->vport = vport;
645} 648}
646 649
647static int 650static int
648lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba, 651lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
649 struct lpfc_scsi_buf *lpfc_cmd, 652 struct lpfc_scsi_buf *lpfc_cmd,
650 unsigned int lun, 653 unsigned int lun,
651 uint8_t task_mgmt_cmd) 654 uint8_t task_mgmt_cmd)
652{ 655{
653 struct lpfc_sli *psli;
654 struct lpfc_iocbq *piocbq; 656 struct lpfc_iocbq *piocbq;
655 IOCB_t *piocb; 657 IOCB_t *piocb;
656 struct fcp_cmnd *fcp_cmnd; 658 struct fcp_cmnd *fcp_cmnd;
@@ -661,8 +663,9 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
661 return 0; 663 return 0;
662 } 664 }
663 665
664 psli = &phba->sli;
665 piocbq = &(lpfc_cmd->cur_iocbq); 666 piocbq = &(lpfc_cmd->cur_iocbq);
667 piocbq->vport = vport;
668
666 piocb = &piocbq->iocb; 669 piocb = &piocbq->iocb;
667 670
668 fcp_cmnd = lpfc_cmd->fcp_cmnd; 671 fcp_cmnd = lpfc_cmd->fcp_cmnd;
@@ -688,7 +691,7 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
688 piocb->ulpTimeout = lpfc_cmd->timeout; 691 piocb->ulpTimeout = lpfc_cmd->timeout;
689 } 692 }
690 693
691 return (1); 694 return 1;
692} 695}
693 696
694static void 697static void
@@ -704,10 +707,11 @@ lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
704} 707}
705 708
706static int 709static int
707lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba, 710lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
708 unsigned tgt_id, unsigned int lun, 711 unsigned tgt_id, unsigned int lun,
709 struct lpfc_rport_data *rdata) 712 struct lpfc_rport_data *rdata)
710{ 713{
714 struct lpfc_hba *phba = vport->phba;
711 struct lpfc_iocbq *iocbq; 715 struct lpfc_iocbq *iocbq;
712 struct lpfc_iocbq *iocbqrsp; 716 struct lpfc_iocbq *iocbqrsp;
713 int ret; 717 int ret;
@@ -716,12 +720,11 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
716 return FAILED; 720 return FAILED;
717 721
718 lpfc_cmd->rdata = rdata; 722 lpfc_cmd->rdata = rdata;
719 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, lun, 723 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
720 FCP_TARGET_RESET); 724 FCP_TARGET_RESET);
721 if (!ret) 725 if (!ret)
722 return FAILED; 726 return FAILED;
723 727
724 lpfc_cmd->scsi_hba = phba;
725 iocbq = &lpfc_cmd->cur_iocbq; 728 iocbq = &lpfc_cmd->cur_iocbq;
726 iocbqrsp = lpfc_sli_get_iocbq(phba); 729 iocbqrsp = lpfc_sli_get_iocbq(phba);
727 730
@@ -758,7 +761,8 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
758const char * 761const char *
759lpfc_info(struct Scsi_Host *host) 762lpfc_info(struct Scsi_Host *host)
760{ 763{
761 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata; 764 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
765 struct lpfc_hba *phba = vport->phba;
762 int len; 766 int len;
763 static char lpfcinfobuf[384]; 767 static char lpfcinfobuf[384];
764 768
@@ -800,26 +804,22 @@ void lpfc_poll_start_timer(struct lpfc_hba * phba)
800 804
801void lpfc_poll_timeout(unsigned long ptr) 805void lpfc_poll_timeout(unsigned long ptr)
802{ 806{
803 struct lpfc_hba *phba = (struct lpfc_hba *)ptr; 807 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
804 unsigned long iflag;
805
806 spin_lock_irqsave(phba->host->host_lock, iflag);
807 808
808 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 809 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
809 lpfc_sli_poll_fcp_ring (phba); 810 lpfc_sli_poll_fcp_ring (phba);
810 if (phba->cfg_poll & DISABLE_FCP_RING_INT) 811 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
811 lpfc_poll_rearm_timer(phba); 812 lpfc_poll_rearm_timer(phba);
812 } 813 }
813
814 spin_unlock_irqrestore(phba->host->host_lock, iflag);
815} 814}
816 815
817static int 816static int
818lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) 817lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
819{ 818{
820 struct lpfc_hba *phba = 819 struct Scsi_Host *shost = cmnd->device->host;
821 (struct lpfc_hba *) cmnd->device->host->hostdata; 820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
822 struct lpfc_sli *psli = &phba->sli; 821 struct lpfc_hba *phba = vport->phba;
822 struct lpfc_sli *psli = &phba->sli;
823 struct lpfc_rport_data *rdata = cmnd->device->hostdata; 823 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
824 struct lpfc_nodelist *ndlp = rdata->pnode; 824 struct lpfc_nodelist *ndlp = rdata->pnode;
825 struct lpfc_scsi_buf *lpfc_cmd; 825 struct lpfc_scsi_buf *lpfc_cmd;
@@ -862,7 +862,7 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
862 if (err) 862 if (err)
863 goto out_host_busy_free_buf; 863 goto out_host_busy_free_buf;
864 864
865 lpfc_scsi_prep_cmnd(phba, lpfc_cmd, ndlp); 865 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
866 866
867 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], 867 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
868 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); 868 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
@@ -907,8 +907,9 @@ lpfc_block_error_handler(struct scsi_cmnd *cmnd)
907static int 907static int
908lpfc_abort_handler(struct scsi_cmnd *cmnd) 908lpfc_abort_handler(struct scsi_cmnd *cmnd)
909{ 909{
910 struct Scsi_Host *shost = cmnd->device->host; 910 struct Scsi_Host *shost = cmnd->device->host;
911 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
912 struct lpfc_hba *phba = vport->phba;
912 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring]; 913 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
913 struct lpfc_iocbq *iocb; 914 struct lpfc_iocbq *iocb;
914 struct lpfc_iocbq *abtsiocb; 915 struct lpfc_iocbq *abtsiocb;
@@ -918,8 +919,6 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
918 int ret = SUCCESS; 919 int ret = SUCCESS;
919 920
920 lpfc_block_error_handler(cmnd); 921 lpfc_block_error_handler(cmnd);
921 spin_lock_irq(shost->host_lock);
922
923 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; 922 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
924 BUG_ON(!lpfc_cmd); 923 BUG_ON(!lpfc_cmd);
925 924
@@ -956,12 +955,13 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
956 955
957 icmd->ulpLe = 1; 956 icmd->ulpLe = 1;
958 icmd->ulpClass = cmd->ulpClass; 957 icmd->ulpClass = cmd->ulpClass;
959 if (phba->hba_state >= LPFC_LINK_UP) 958 if (lpfc_is_link_up(phba))
960 icmd->ulpCommand = CMD_ABORT_XRI_CN; 959 icmd->ulpCommand = CMD_ABORT_XRI_CN;
961 else 960 else
962 icmd->ulpCommand = CMD_CLOSE_XRI_CN; 961 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
963 962
964 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; 963 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
964 abtsiocb->vport = vport;
965 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) { 965 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
966 lpfc_sli_release_iocbq(phba, abtsiocb); 966 lpfc_sli_release_iocbq(phba, abtsiocb);
967 ret = FAILED; 967 ret = FAILED;
@@ -977,9 +977,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
977 if (phba->cfg_poll & DISABLE_FCP_RING_INT) 977 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
978 lpfc_sli_poll_fcp_ring (phba); 978 lpfc_sli_poll_fcp_ring (phba);
979 979
980 spin_unlock_irq(phba->host->host_lock); 980 schedule_timeout_uninterruptible(LPFC_ABORT_WAIT * HZ);
981 schedule_timeout_uninterruptible(LPFC_ABORT_WAIT*HZ);
982 spin_lock_irq(phba->host->host_lock);
983 if (++loop_count 981 if (++loop_count
984 > (2 * phba->cfg_devloss_tmo)/LPFC_ABORT_WAIT) 982 > (2 * phba->cfg_devloss_tmo)/LPFC_ABORT_WAIT)
985 break; 983 break;
@@ -1002,16 +1000,15 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
1002 phba->brd_no, ret, cmnd->device->id, 1000 phba->brd_no, ret, cmnd->device->id,
1003 cmnd->device->lun, cmnd->serial_number); 1001 cmnd->device->lun, cmnd->serial_number);
1004 1002
1005 spin_unlock_irq(shost->host_lock);
1006
1007 return ret; 1003 return ret;
1008} 1004}
1009 1005
1010static int 1006static int
1011lpfc_device_reset_handler(struct scsi_cmnd *cmnd) 1007lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1012{ 1008{
1013 struct Scsi_Host *shost = cmnd->device->host; 1009 struct Scsi_Host *shost = cmnd->device->host;
1014 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1011 struct lpfc_hba *phba = vport->phba;
1015 struct lpfc_scsi_buf *lpfc_cmd; 1012 struct lpfc_scsi_buf *lpfc_cmd;
1016 struct lpfc_iocbq *iocbq, *iocbqrsp; 1013 struct lpfc_iocbq *iocbq, *iocbqrsp;
1017 struct lpfc_rport_data *rdata = cmnd->device->hostdata; 1014 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
@@ -1022,7 +1019,6 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1022 int cnt, loopcnt; 1019 int cnt, loopcnt;
1023 1020
1024 lpfc_block_error_handler(cmnd); 1021 lpfc_block_error_handler(cmnd);
1025 spin_lock_irq(shost->host_lock);
1026 loopcnt = 0; 1022 loopcnt = 0;
1027 /* 1023 /*
1028 * If target is not in a MAPPED state, delay the reset until 1024 * If target is not in a MAPPED state, delay the reset until
@@ -1033,9 +1029,7 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1033 goto out; 1029 goto out;
1034 1030
1035 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) { 1031 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1036 spin_unlock_irq(phba->host->host_lock);
1037 schedule_timeout_uninterruptible(msecs_to_jiffies(500)); 1032 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1038 spin_lock_irq(phba->host->host_lock);
1039 loopcnt++; 1033 loopcnt++;
1040 rdata = cmnd->device->hostdata; 1034 rdata = cmnd->device->hostdata;
1041 if (!rdata || 1035 if (!rdata ||
@@ -1054,15 +1048,14 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1054 break; 1048 break;
1055 } 1049 }
1056 1050
1057 lpfc_cmd = lpfc_get_scsi_buf (phba); 1051 lpfc_cmd = lpfc_get_scsi_buf(phba);
1058 if (lpfc_cmd == NULL) 1052 if (lpfc_cmd == NULL)
1059 goto out; 1053 goto out;
1060 1054
1061 lpfc_cmd->timeout = 60; 1055 lpfc_cmd->timeout = 60;
1062 lpfc_cmd->scsi_hba = phba;
1063 lpfc_cmd->rdata = rdata; 1056 lpfc_cmd->rdata = rdata;
1064 1057
1065 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, cmnd->device->lun, 1058 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, cmnd->device->lun,
1066 FCP_TARGET_RESET); 1059 FCP_TARGET_RESET);
1067 if (!ret) 1060 if (!ret)
1068 goto out_free_scsi_buf; 1061 goto out_free_scsi_buf;
@@ -1110,10 +1103,8 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1110 cmnd->device->id, cmnd->device->lun, 1103 cmnd->device->id, cmnd->device->lun,
1111 0, LPFC_CTX_LUN); 1104 0, LPFC_CTX_LUN);
1112 loopcnt = 0; 1105 loopcnt = 0;
1113 while(cnt) { 1106 while (cnt) {
1114 spin_unlock_irq(phba->host->host_lock);
1115 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); 1107 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
1116 spin_lock_irq(phba->host->host_lock);
1117 1108
1118 if (++loopcnt 1109 if (++loopcnt
1119 > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT) 1110 > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT)
@@ -1143,15 +1134,15 @@ out_free_scsi_buf:
1143 ret, cmd_status, cmd_result); 1134 ret, cmd_status, cmd_result);
1144 1135
1145out: 1136out:
1146 spin_unlock_irq(shost->host_lock);
1147 return ret; 1137 return ret;
1148} 1138}
1149 1139
1150static int 1140static int
1151lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) 1141lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1152{ 1142{
1153 struct Scsi_Host *shost = cmnd->device->host; 1143 struct Scsi_Host *shost = cmnd->device->host;
1154 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1144 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1145 struct lpfc_hba *phba = vport->phba;
1155 struct lpfc_nodelist *ndlp = NULL; 1146 struct lpfc_nodelist *ndlp = NULL;
1156 int match; 1147 int match;
1157 int ret = FAILED, i, err_count = 0; 1148 int ret = FAILED, i, err_count = 0;
@@ -1159,7 +1150,6 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1159 struct lpfc_scsi_buf * lpfc_cmd; 1150 struct lpfc_scsi_buf * lpfc_cmd;
1160 1151
1161 lpfc_block_error_handler(cmnd); 1152 lpfc_block_error_handler(cmnd);
1162 spin_lock_irq(shost->host_lock);
1163 1153
1164 lpfc_cmd = lpfc_get_scsi_buf(phba); 1154 lpfc_cmd = lpfc_get_scsi_buf(phba);
1165 if (lpfc_cmd == NULL) 1155 if (lpfc_cmd == NULL)
@@ -1167,7 +1157,6 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1167 1157
1168 /* The lpfc_cmd storage is reused. Set all loop invariants. */ 1158 /* The lpfc_cmd storage is reused. Set all loop invariants. */
1169 lpfc_cmd->timeout = 60; 1159 lpfc_cmd->timeout = 60;
1170 lpfc_cmd->scsi_hba = phba;
1171 1160
1172 /* 1161 /*
1173 * Since the driver manages a single bus device, reset all 1162 * Since the driver manages a single bus device, reset all
@@ -1177,7 +1166,8 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1177 for (i = 0; i < LPFC_MAX_TARGET; i++) { 1166 for (i = 0; i < LPFC_MAX_TARGET; i++) {
1178 /* Search for mapped node by target ID */ 1167 /* Search for mapped node by target ID */
1179 match = 0; 1168 match = 0;
1180 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) { 1169 spin_lock_irq(shost->host_lock);
1170 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1181 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && 1171 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1182 i == ndlp->nlp_sid && 1172 i == ndlp->nlp_sid &&
1183 ndlp->rport) { 1173 ndlp->rport) {
@@ -1185,10 +1175,12 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1185 break; 1175 break;
1186 } 1176 }
1187 } 1177 }
1178 spin_unlock_irq(shost->host_lock);
1188 if (!match) 1179 if (!match)
1189 continue; 1180 continue;
1190 1181
1191 ret = lpfc_scsi_tgt_reset(lpfc_cmd, phba, i, cmnd->device->lun, 1182 ret = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1183 cmnd->device->lun,
1192 ndlp->rport->dd_data); 1184 ndlp->rport->dd_data);
1193 if (ret != SUCCESS) { 1185 if (ret != SUCCESS) {
1194 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1186 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
@@ -1218,10 +1210,8 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1218 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], 1210 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1219 0, 0, 0, LPFC_CTX_HOST); 1211 0, 0, 0, LPFC_CTX_HOST);
1220 loopcnt = 0; 1212 loopcnt = 0;
1221 while(cnt) { 1213 while (cnt) {
1222 spin_unlock_irq(phba->host->host_lock);
1223 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); 1214 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
1224 spin_lock_irq(phba->host->host_lock);
1225 1215
1226 if (++loopcnt 1216 if (++loopcnt
1227 > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT) 1217 > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT)
@@ -1245,14 +1235,14 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1245 "%d:0714 SCSI layer issued Bus Reset Data: x%x\n", 1235 "%d:0714 SCSI layer issued Bus Reset Data: x%x\n",
1246 phba->brd_no, ret); 1236 phba->brd_no, ret);
1247out: 1237out:
1248 spin_unlock_irq(shost->host_lock);
1249 return ret; 1238 return ret;
1250} 1239}
1251 1240
1252static int 1241static int
1253lpfc_slave_alloc(struct scsi_device *sdev) 1242lpfc_slave_alloc(struct scsi_device *sdev)
1254{ 1243{
1255 struct lpfc_hba *phba = (struct lpfc_hba *)sdev->host->hostdata; 1244 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1245 struct lpfc_hba *phba = vport->phba;
1256 struct lpfc_scsi_buf *scsi_buf = NULL; 1246 struct lpfc_scsi_buf *scsi_buf = NULL;
1257 struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 1247 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1258 uint32_t total = 0, i; 1248 uint32_t total = 0, i;
@@ -1289,7 +1279,7 @@ lpfc_slave_alloc(struct scsi_device *sdev)
1289 } 1279 }
1290 1280
1291 for (i = 0; i < num_to_alloc; i++) { 1281 for (i = 0; i < num_to_alloc; i++) {
1292 scsi_buf = lpfc_new_scsi_buf(phba); 1282 scsi_buf = lpfc_new_scsi_buf(vport);
1293 if (!scsi_buf) { 1283 if (!scsi_buf) {
1294 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1284 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1295 "%d:0706 Failed to allocate command " 1285 "%d:0706 Failed to allocate command "
@@ -1308,8 +1298,9 @@ lpfc_slave_alloc(struct scsi_device *sdev)
1308static int 1298static int
1309lpfc_slave_configure(struct scsi_device *sdev) 1299lpfc_slave_configure(struct scsi_device *sdev)
1310{ 1300{
1311 struct lpfc_hba *phba = (struct lpfc_hba *) sdev->host->hostdata; 1301 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1312 struct fc_rport *rport = starget_to_rport(sdev->sdev_target); 1302 struct lpfc_hba *phba = vport->phba;
1303 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1313 1304
1314 if (sdev->tagged_supported) 1305 if (sdev->tagged_supported)
1315 scsi_activate_tcq(sdev, phba->cfg_lun_queue_depth); 1306 scsi_activate_tcq(sdev, phba->cfg_lun_queue_depth);
@@ -1357,6 +1348,6 @@ struct scsi_host_template lpfc_template = {
1357 .sg_tablesize = LPFC_SG_SEG_CNT, 1348 .sg_tablesize = LPFC_SG_SEG_CNT,
1358 .cmd_per_lun = LPFC_CMD_PER_LUN, 1349 .cmd_per_lun = LPFC_CMD_PER_LUN,
1359 .use_clustering = ENABLE_CLUSTERING, 1350 .use_clustering = ENABLE_CLUSTERING,
1360 .shost_attrs = lpfc_host_attrs, 1351 .shost_attrs = lpfc_hba_attrs,
1361 .max_sectors = 0xFFFF, 1352 .max_sectors = 0xFFFF,
1362}; 1353};