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.c661
1 files changed, 326 insertions, 335 deletions
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 7991ba1980a..da59c4f0168 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -116,6 +116,27 @@ lpfc_debug_save_dif(struct scsi_cmnd *cmnd)
116} 116}
117 117
118/** 118/**
119 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
120 * @phba: Pointer to HBA object.
121 * @lpfc_cmd: lpfc scsi command object pointer.
122 *
123 * This function is called from the lpfc_prep_task_mgmt_cmd function to
124 * set the last bit in the response sge entry.
125 **/
126static void
127lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
128 struct lpfc_scsi_buf *lpfc_cmd)
129{
130 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
131 if (sgl) {
132 sgl += 1;
133 sgl->word2 = le32_to_cpu(sgl->word2);
134 bf_set(lpfc_sli4_sge_last, sgl, 1);
135 sgl->word2 = cpu_to_le32(sgl->word2);
136 }
137}
138
139/**
119 * lpfc_update_stats - Update statistical data for the command completion 140 * lpfc_update_stats - Update statistical data for the command completion
120 * @phba: Pointer to HBA object. 141 * @phba: Pointer to HBA object.
121 * @lpfc_cmd: lpfc scsi command object pointer. 142 * @lpfc_cmd: lpfc scsi command object pointer.
@@ -1978,7 +1999,7 @@ lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
1978} 1999}
1979 2000
1980/** 2001/**
1981 * lpfc_scsi_unprep_dma_buf_s3 - Un-map DMA mapping of SG-list for SLI3 dev 2002 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
1982 * @phba: The HBA for which this call is being executed. 2003 * @phba: The HBA for which this call is being executed.
1983 * @psb: The scsi buffer which is going to be un-mapped. 2004 * @psb: The scsi buffer which is going to be un-mapped.
1984 * 2005 *
@@ -1986,7 +2007,7 @@ lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
1986 * field of @lpfc_cmd for device with SLI-3 interface spec. 2007 * field of @lpfc_cmd for device with SLI-3 interface spec.
1987 **/ 2008 **/
1988static void 2009static void
1989lpfc_scsi_unprep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) 2010lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1990{ 2011{
1991 /* 2012 /*
1992 * There are only two special cases to consider. (1) the scsi command 2013 * There are only two special cases to consider. (1) the scsi command
@@ -2003,36 +2024,6 @@ lpfc_scsi_unprep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
2003} 2024}
2004 2025
2005/** 2026/**
2006 * lpfc_scsi_unprep_dma_buf_s4 - Un-map DMA mapping of SG-list for SLI4 dev
2007 * @phba: The Hba for which this call is being executed.
2008 * @psb: The scsi buffer which is going to be un-mapped.
2009 *
2010 * This routine does DMA un-mapping of scatter gather list of scsi command
2011 * field of @lpfc_cmd for device with SLI-4 interface spec. If we have to
2012 * remove the sgl for this scsi buffer then we will do it here. For now
2013 * we should be able to just call the sli3 unprep routine.
2014 **/
2015static void
2016lpfc_scsi_unprep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
2017{
2018 lpfc_scsi_unprep_dma_buf_s3(phba, psb);
2019}
2020
2021/**
2022 * lpfc_scsi_unprep_dma_buf - Wrapper function for unmap DMA mapping of SG-list
2023 * @phba: The Hba for which this call is being executed.
2024 * @psb: The scsi buffer which is going to be un-mapped.
2025 *
2026 * This routine does DMA un-mapping of scatter gather list of scsi command
2027 * field of @lpfc_cmd for device with SLI-4 interface spec.
2028 **/
2029static void
2030lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
2031{
2032 phba->lpfc_scsi_unprep_dma_buf(phba, psb);
2033}
2034
2035/**
2036 * lpfc_handler_fcp_err - FCP response handler 2027 * lpfc_handler_fcp_err - FCP response handler
2037 * @vport: The virtual port for which this call is being executed. 2028 * @vport: The virtual port for which this call is being executed.
2038 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. 2029 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
@@ -2461,7 +2452,7 @@ lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
2461} 2452}
2462 2453
2463/** 2454/**
2464 * lpfc_scsi_prep_cmnd_s3 - Convert scsi cmnd to FCP infor unit for SLI3 dev 2455 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
2465 * @vport: The virtual port for which this call is being executed. 2456 * @vport: The virtual port for which this call is being executed.
2466 * @lpfc_cmd: The scsi command which needs to send. 2457 * @lpfc_cmd: The scsi command which needs to send.
2467 * @pnode: Pointer to lpfc_nodelist. 2458 * @pnode: Pointer to lpfc_nodelist.
@@ -2470,7 +2461,7 @@ lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
2470 * to transfer for device with SLI3 interface spec. 2461 * to transfer for device with SLI3 interface spec.
2471 **/ 2462 **/
2472static void 2463static void
2473lpfc_scsi_prep_cmnd_s3(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, 2464lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2474 struct lpfc_nodelist *pnode) 2465 struct lpfc_nodelist *pnode)
2475{ 2466{
2476 struct lpfc_hba *phba = vport->phba; 2467 struct lpfc_hba *phba = vport->phba;
@@ -2558,46 +2549,7 @@ lpfc_scsi_prep_cmnd_s3(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2558} 2549}
2559 2550
2560/** 2551/**
2561 * lpfc_scsi_prep_cmnd_s4 - Convert scsi cmnd to FCP infor unit for SLI4 dev 2552 * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit
2562 * @vport: The virtual port for which this call is being executed.
2563 * @lpfc_cmd: The scsi command which needs to send.
2564 * @pnode: Pointer to lpfc_nodelist.
2565 *
2566 * This routine initializes fcp_cmnd and iocb data structure from scsi command
2567 * to transfer for device with SLI4 interface spec.
2568 **/
2569static void
2570lpfc_scsi_prep_cmnd_s4(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2571 struct lpfc_nodelist *pnode)
2572{
2573 /*
2574 * The prep cmnd routines do not touch the sgl or its
2575 * entries. We may not have to do anything different.
2576 * I will leave this function in place until we can
2577 * run some IO through the driver and determine if changes
2578 * are needed.
2579 */
2580 return lpfc_scsi_prep_cmnd_s3(vport, lpfc_cmd, pnode);
2581}
2582
2583/**
2584 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
2585 * @vport: The virtual port for which this call is being executed.
2586 * @lpfc_cmd: The scsi command which needs to send.
2587 * @pnode: Pointer to lpfc_nodelist.
2588 *
2589 * This routine wraps the actual convert SCSI cmnd function pointer from
2590 * the lpfc_hba struct.
2591 **/
2592static inline void
2593lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2594 struct lpfc_nodelist *pnode)
2595{
2596 vport->phba->lpfc_scsi_prep_cmnd(vport, lpfc_cmd, pnode);
2597}
2598
2599/**
2600 * lpfc_scsi_prep_task_mgmt_cmnd_s3 - Convert SLI3 scsi TM cmd to FCP info unit
2601 * @vport: The virtual port for which this call is being executed. 2553 * @vport: The virtual port for which this call is being executed.
2602 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. 2554 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2603 * @lun: Logical unit number. 2555 * @lun: Logical unit number.
@@ -2611,7 +2563,7 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2611 * 1 - Success 2563 * 1 - Success
2612 **/ 2564 **/
2613static int 2565static int
2614lpfc_scsi_prep_task_mgmt_cmd_s3(struct lpfc_vport *vport, 2566lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
2615 struct lpfc_scsi_buf *lpfc_cmd, 2567 struct lpfc_scsi_buf *lpfc_cmd,
2616 unsigned int lun, 2568 unsigned int lun,
2617 uint8_t task_mgmt_cmd) 2569 uint8_t task_mgmt_cmd)
@@ -2653,68 +2605,13 @@ lpfc_scsi_prep_task_mgmt_cmd_s3(struct lpfc_vport *vport,
2653 * The driver will provide the timeout mechanism. 2605 * The driver will provide the timeout mechanism.
2654 */ 2606 */
2655 piocb->ulpTimeout = 0; 2607 piocb->ulpTimeout = 0;
2656 } else { 2608 } else
2657 piocb->ulpTimeout = lpfc_cmd->timeout; 2609 piocb->ulpTimeout = lpfc_cmd->timeout;
2658 }
2659
2660 return 1;
2661}
2662
2663/**
2664 * lpfc_scsi_prep_task_mgmt_cmnd_s4 - Convert SLI4 scsi TM cmd to FCP info unit
2665 * @vport: The virtual port for which this call is being executed.
2666 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2667 * @lun: Logical unit number.
2668 * @task_mgmt_cmd: SCSI task management command.
2669 *
2670 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
2671 * for device with SLI-4 interface spec.
2672 *
2673 * Return codes:
2674 * 0 - Error
2675 * 1 - Success
2676 **/
2677static int
2678lpfc_scsi_prep_task_mgmt_cmd_s4(struct lpfc_vport *vport,
2679 struct lpfc_scsi_buf *lpfc_cmd,
2680 unsigned int lun,
2681 uint8_t task_mgmt_cmd)
2682{
2683 /*
2684 * The prep cmnd routines do not touch the sgl or its
2685 * entries. We may not have to do anything different.
2686 * I will leave this function in place until we can
2687 * run some IO through the driver and determine if changes
2688 * are needed.
2689 */
2690 return lpfc_scsi_prep_task_mgmt_cmd_s3(vport, lpfc_cmd, lun,
2691 task_mgmt_cmd);
2692}
2693 2610
2694/** 2611 if (vport->phba->sli_rev == LPFC_SLI_REV4)
2695 * lpfc_scsi_prep_task_mgmt_cmnd - Wrapper func convert scsi TM cmd to FCP info 2612 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
2696 * @vport: The virtual port for which this call is being executed.
2697 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2698 * @lun: Logical unit number.
2699 * @task_mgmt_cmd: SCSI task management command.
2700 *
2701 * This routine wraps the actual convert SCSI TM to FCP information unit
2702 * function pointer from the lpfc_hba struct.
2703 *
2704 * Return codes:
2705 * 0 - Error
2706 * 1 - Success
2707 **/
2708static inline int
2709lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
2710 struct lpfc_scsi_buf *lpfc_cmd,
2711 unsigned int lun,
2712 uint8_t task_mgmt_cmd)
2713{
2714 struct lpfc_hba *phba = vport->phba;
2715 2613
2716 return phba->lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, 2614 return 1;
2717 task_mgmt_cmd);
2718} 2615}
2719 2616
2720/** 2617/**
@@ -2730,23 +2627,19 @@ int
2730lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) 2627lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2731{ 2628{
2732 2629
2630 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
2631 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
2632 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2633
2733 switch (dev_grp) { 2634 switch (dev_grp) {
2734 case LPFC_PCI_DEV_LP: 2635 case LPFC_PCI_DEV_LP:
2735 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; 2636 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
2736 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; 2637 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
2737 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd_s3;
2738 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf_s3;
2739 phba->lpfc_scsi_prep_task_mgmt_cmd =
2740 lpfc_scsi_prep_task_mgmt_cmd_s3;
2741 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; 2638 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
2742 break; 2639 break;
2743 case LPFC_PCI_DEV_OC: 2640 case LPFC_PCI_DEV_OC:
2744 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; 2641 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
2745 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; 2642 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
2746 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd_s4;
2747 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf_s4;
2748 phba->lpfc_scsi_prep_task_mgmt_cmd =
2749 lpfc_scsi_prep_task_mgmt_cmd_s4;
2750 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; 2643 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
2751 break; 2644 break;
2752 default: 2645 default:
@@ -2783,72 +2676,6 @@ lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
2783} 2676}
2784 2677
2785/** 2678/**
2786 * lpfc_scsi_tgt_reset - Target reset handler
2787 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure
2788 * @vport: The virtual port for which this call is being executed.
2789 * @tgt_id: Target ID.
2790 * @lun: Lun number.
2791 * @rdata: Pointer to lpfc_rport_data.
2792 *
2793 * This routine issues a TARGET RESET iocb to reset a target with @tgt_id ID.
2794 *
2795 * Return Code:
2796 * 0x2003 - Error
2797 * 0x2002 - Success.
2798 **/
2799static int
2800lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
2801 unsigned tgt_id, unsigned int lun,
2802 struct lpfc_rport_data *rdata)
2803{
2804 struct lpfc_hba *phba = vport->phba;
2805 struct lpfc_iocbq *iocbq;
2806 struct lpfc_iocbq *iocbqrsp;
2807 int ret;
2808 int status;
2809
2810 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
2811 return FAILED;
2812
2813 lpfc_cmd->rdata = rdata;
2814 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
2815 FCP_TARGET_RESET);
2816 if (!status)
2817 return FAILED;
2818
2819 iocbq = &lpfc_cmd->cur_iocbq;
2820 iocbqrsp = lpfc_sli_get_iocbq(phba);
2821
2822 if (!iocbqrsp)
2823 return FAILED;
2824
2825 /* Issue Target Reset to TGT <num> */
2826 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
2827 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
2828 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
2829 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
2830 iocbq, iocbqrsp, lpfc_cmd->timeout);
2831 if (status != IOCB_SUCCESS) {
2832 if (status == IOCB_TIMEDOUT) {
2833 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
2834 ret = TIMEOUT_ERROR;
2835 } else
2836 ret = FAILED;
2837 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
2838 } else {
2839 ret = SUCCESS;
2840 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
2841 lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
2842 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
2843 (lpfc_cmd->result & IOERR_DRVR_MASK))
2844 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
2845 }
2846
2847 lpfc_sli_release_iocbq(phba, iocbqrsp);
2848 return ret;
2849}
2850
2851/**
2852 * lpfc_info - Info entry point of scsi_host_template data structure 2679 * lpfc_info - Info entry point of scsi_host_template data structure
2853 * @host: The scsi host for which this call is being executed. 2680 * @host: The scsi host for which this call is being executed.
2854 * 2681 *
@@ -3228,156 +3055,334 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
3228 return ret; 3055 return ret;
3229} 3056}
3230 3057
3058static char *
3059lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
3060{
3061 switch (task_mgmt_cmd) {
3062 case FCP_ABORT_TASK_SET:
3063 return "ABORT_TASK_SET";
3064 case FCP_CLEAR_TASK_SET:
3065 return "FCP_CLEAR_TASK_SET";
3066 case FCP_BUS_RESET:
3067 return "FCP_BUS_RESET";
3068 case FCP_LUN_RESET:
3069 return "FCP_LUN_RESET";
3070 case FCP_TARGET_RESET:
3071 return "FCP_TARGET_RESET";
3072 case FCP_CLEAR_ACA:
3073 return "FCP_CLEAR_ACA";
3074 case FCP_TERMINATE_TASK:
3075 return "FCP_TERMINATE_TASK";
3076 default:
3077 return "unknown";
3078 }
3079}
3080
3231/** 3081/**
3232 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point 3082 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
3233 * @cmnd: Pointer to scsi_cmnd data structure. 3083 * @vport: The virtual port for which this call is being executed.
3084 * @rdata: Pointer to remote port local data
3085 * @tgt_id: Target ID of remote device.
3086 * @lun_id: Lun number for the TMF
3087 * @task_mgmt_cmd: type of TMF to send
3234 * 3088 *
3235 * This routine does a device reset by sending a TARGET_RESET task management 3089 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
3236 * command. 3090 * a remote port.
3237 * 3091 *
3238 * Return code : 3092 * Return Code:
3239 * 0x2003 - Error 3093 * 0x2003 - Error
3240 * 0x2002 - Success 3094 * 0x2002 - Success.
3241 **/ 3095 **/
3242static int 3096static int
3243lpfc_device_reset_handler(struct scsi_cmnd *cmnd) 3097lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
3098 unsigned tgt_id, unsigned int lun_id,
3099 uint8_t task_mgmt_cmd)
3244{ 3100{
3245 struct Scsi_Host *shost = cmnd->device->host;
3246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3247 struct lpfc_hba *phba = vport->phba; 3101 struct lpfc_hba *phba = vport->phba;
3248 struct lpfc_scsi_buf *lpfc_cmd; 3102 struct lpfc_scsi_buf *lpfc_cmd;
3249 struct lpfc_iocbq *iocbq, *iocbqrsp; 3103 struct lpfc_iocbq *iocbq;
3250 struct lpfc_rport_data *rdata = cmnd->device->hostdata; 3104 struct lpfc_iocbq *iocbqrsp;
3251 struct lpfc_nodelist *pnode = rdata->pnode; 3105 int ret;
3252 unsigned long later;
3253 int ret = SUCCESS;
3254 int status; 3106 int status;
3255 int cnt;
3256 struct lpfc_scsi_event_header scsi_event;
3257 3107
3258 lpfc_block_error_handler(cmnd); 3108 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
3259 /*
3260 * If target is not in a MAPPED state, delay the reset until
3261 * target is rediscovered or devloss timeout expires.
3262 */
3263 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3264 while (time_after(later, jiffies)) {
3265 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3266 return FAILED;
3267 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
3268 break;
3269 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
3270 rdata = cmnd->device->hostdata;
3271 if (!rdata)
3272 break;
3273 pnode = rdata->pnode;
3274 }
3275
3276 scsi_event.event_type = FC_REG_SCSI_EVENT;
3277 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
3278 scsi_event.lun = 0;
3279 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3280 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3281
3282 fc_host_post_vendor_event(shost,
3283 fc_get_event_number(),
3284 sizeof(scsi_event),
3285 (char *)&scsi_event,
3286 LPFC_NL_VENDOR_ID);
3287
3288 if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
3289 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3290 "0721 LUN Reset rport "
3291 "failure: msec x%x rdata x%p\n",
3292 jiffies_to_msecs(jiffies - later), rdata);
3293 return FAILED; 3109 return FAILED;
3294 } 3110
3295 lpfc_cmd = lpfc_get_scsi_buf(phba); 3111 lpfc_cmd = lpfc_get_scsi_buf(phba);
3296 if (lpfc_cmd == NULL) 3112 if (lpfc_cmd == NULL)
3297 return FAILED; 3113 return FAILED;
3298 lpfc_cmd->timeout = 60; 3114 lpfc_cmd->timeout = 60;
3299 lpfc_cmd->rdata = rdata; 3115 lpfc_cmd->rdata = rdata;
3300 3116
3301 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, 3117 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
3302 cmnd->device->lun, 3118 task_mgmt_cmd);
3303 FCP_TARGET_RESET);
3304 if (!status) { 3119 if (!status) {
3305 lpfc_release_scsi_buf(phba, lpfc_cmd); 3120 lpfc_release_scsi_buf(phba, lpfc_cmd);
3306 return FAILED; 3121 return FAILED;
3307 } 3122 }
3308 iocbq = &lpfc_cmd->cur_iocbq;
3309 3123
3310 /* get a buffer for this IOCB command response */ 3124 iocbq = &lpfc_cmd->cur_iocbq;
3311 iocbqrsp = lpfc_sli_get_iocbq(phba); 3125 iocbqrsp = lpfc_sli_get_iocbq(phba);
3312 if (iocbqrsp == NULL) { 3126 if (iocbqrsp == NULL) {
3313 lpfc_release_scsi_buf(phba, lpfc_cmd); 3127 lpfc_release_scsi_buf(phba, lpfc_cmd);
3314 return FAILED; 3128 return FAILED;
3315 } 3129 }
3130
3316 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, 3131 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3317 "0703 Issue target reset to TGT %d LUN %d " 3132 "0702 Issue %s to TGT %d LUN %d "
3318 "rpi x%x nlp_flag x%x\n", cmnd->device->id, 3133 "rpi x%x nlp_flag x%x\n",
3319 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); 3134 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
3135 rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
3136
3320 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, 3137 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
3321 iocbq, iocbqrsp, lpfc_cmd->timeout); 3138 iocbq, iocbqrsp, lpfc_cmd->timeout);
3322 if (status == IOCB_TIMEDOUT) { 3139 if (status != IOCB_SUCCESS) {
3323 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; 3140 if (status == IOCB_TIMEDOUT) {
3324 ret = TIMEOUT_ERROR; 3141 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
3325 } else { 3142 ret = TIMEOUT_ERROR;
3326 if (status != IOCB_SUCCESS) 3143 } else
3327 ret = FAILED; 3144 ret = FAILED;
3328 lpfc_release_scsi_buf(phba, lpfc_cmd); 3145 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3329 } 3146 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3330 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 3147 "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n",
3331 "0713 SCSI layer issued device reset (%d, %d) " 3148 lpfc_taskmgmt_name(task_mgmt_cmd),
3332 "return x%x status x%x result x%x\n", 3149 tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
3333 cmnd->device->id, cmnd->device->lun, ret,
3334 iocbqrsp->iocb.ulpStatus,
3335 iocbqrsp->iocb.un.ulpWord[4]); 3150 iocbqrsp->iocb.un.ulpWord[4]);
3151 } else
3152 ret = SUCCESS;
3153
3336 lpfc_sli_release_iocbq(phba, iocbqrsp); 3154 lpfc_sli_release_iocbq(phba, iocbqrsp);
3337 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun, 3155
3338 LPFC_CTX_TGT); 3156 if (ret != TIMEOUT_ERROR)
3157 lpfc_release_scsi_buf(phba, lpfc_cmd);
3158
3159 return ret;
3160}
3161
3162/**
3163 * lpfc_chk_tgt_mapped -
3164 * @vport: The virtual port to check on
3165 * @cmnd: Pointer to scsi_cmnd data structure.
3166 *
3167 * This routine delays until the scsi target (aka rport) for the
3168 * command exists (is present and logged in) or we declare it non-existent.
3169 *
3170 * Return code :
3171 * 0x2003 - Error
3172 * 0x2002 - Success
3173 **/
3174static int
3175lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
3176{
3177 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
3178 struct lpfc_nodelist *pnode = rdata->pnode;
3179 unsigned long later;
3180
3181 /*
3182 * If target is not in a MAPPED state, delay until
3183 * target is rediscovered or devloss timeout expires.
3184 */
3185 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3186 while (time_after(later, jiffies)) {
3187 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3188 return FAILED;
3189 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
3190 return SUCCESS;
3191 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
3192 rdata = cmnd->device->hostdata;
3193 if (!rdata)
3194 return FAILED;
3195 pnode = rdata->pnode;
3196 }
3197 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
3198 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
3199 return FAILED;
3200 return SUCCESS;
3201}
3202
3203/**
3204 * lpfc_reset_flush_io_context -
3205 * @vport: The virtual port (scsi_host) for the flush context
3206 * @tgt_id: If aborting by Target contect - specifies the target id
3207 * @lun_id: If aborting by Lun context - specifies the lun id
3208 * @context: specifies the context level to flush at.
3209 *
3210 * After a reset condition via TMF, we need to flush orphaned i/o
3211 * contexts from the adapter. This routine aborts any contexts
3212 * outstanding, then waits for their completions. The wait is
3213 * bounded by devloss_tmo though.
3214 *
3215 * Return code :
3216 * 0x2003 - Error
3217 * 0x2002 - Success
3218 **/
3219static int
3220lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
3221 uint64_t lun_id, lpfc_ctx_cmd context)
3222{
3223 struct lpfc_hba *phba = vport->phba;
3224 unsigned long later;
3225 int cnt;
3226
3227 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3339 if (cnt) 3228 if (cnt)
3340 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], 3229 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
3341 cmnd->device->id, cmnd->device->lun, 3230 tgt_id, lun_id, context);
3342 LPFC_CTX_TGT);
3343 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; 3231 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3344 while (time_after(later, jiffies) && cnt) { 3232 while (time_after(later, jiffies) && cnt) {
3345 schedule_timeout_uninterruptible(msecs_to_jiffies(20)); 3233 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
3346 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, 3234 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3347 cmnd->device->lun, LPFC_CTX_TGT);
3348 } 3235 }
3349 if (cnt) { 3236 if (cnt) {
3350 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 3237 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3351 "0719 device reset I/O flush failure: " 3238 "0724 I/O flush failure for context %s : cnt x%x\n",
3352 "cnt x%x\n", cnt); 3239 ((context == LPFC_CTX_LUN) ? "LUN" :
3353 ret = FAILED; 3240 ((context == LPFC_CTX_TGT) ? "TGT" :
3241 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
3242 cnt);
3243 return FAILED;
3354 } 3244 }
3355 return ret; 3245 return SUCCESS;
3246}
3247
3248/**
3249 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
3250 * @cmnd: Pointer to scsi_cmnd data structure.
3251 *
3252 * This routine does a device reset by sending a LUN_RESET task management
3253 * command.
3254 *
3255 * Return code :
3256 * 0x2003 - Error
3257 * 0x2002 - Success
3258 **/
3259static int
3260lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
3261{
3262 struct Scsi_Host *shost = cmnd->device->host;
3263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3264 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
3265 struct lpfc_nodelist *pnode = rdata->pnode;
3266 unsigned tgt_id = cmnd->device->id;
3267 unsigned int lun_id = cmnd->device->lun;
3268 struct lpfc_scsi_event_header scsi_event;
3269 int status;
3270
3271 lpfc_block_error_handler(cmnd);
3272
3273 status = lpfc_chk_tgt_mapped(vport, cmnd);
3274 if (status == FAILED) {
3275 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3276 "0721 Device Reset rport failure: rdata x%p\n", rdata);
3277 return FAILED;
3278 }
3279
3280 scsi_event.event_type = FC_REG_SCSI_EVENT;
3281 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
3282 scsi_event.lun = lun_id;
3283 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3284 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3285
3286 fc_host_post_vendor_event(shost, fc_get_event_number(),
3287 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
3288
3289 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3290 FCP_LUN_RESET);
3291
3292 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3293 "0713 SCSI layer issued Device Reset (%d, %d) "
3294 "return x%x\n", tgt_id, lun_id, status);
3295
3296 /*
3297 * We have to clean up i/o as : they may be orphaned by the TMF;
3298 * or if the TMF failed, they may be in an indeterminate state.
3299 * So, continue on.
3300 * We will report success if all the i/o aborts successfully.
3301 */
3302 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3303 LPFC_CTX_LUN);
3304 return status;
3305}
3306
3307/**
3308 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
3309 * @cmnd: Pointer to scsi_cmnd data structure.
3310 *
3311 * This routine does a target reset by sending a TARGET_RESET task management
3312 * command.
3313 *
3314 * Return code :
3315 * 0x2003 - Error
3316 * 0x2002 - Success
3317 **/
3318static int
3319lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
3320{
3321 struct Scsi_Host *shost = cmnd->device->host;
3322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3323 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
3324 struct lpfc_nodelist *pnode = rdata->pnode;
3325 unsigned tgt_id = cmnd->device->id;
3326 unsigned int lun_id = cmnd->device->lun;
3327 struct lpfc_scsi_event_header scsi_event;
3328 int status;
3329
3330 lpfc_block_error_handler(cmnd);
3331
3332 status = lpfc_chk_tgt_mapped(vport, cmnd);
3333 if (status == FAILED) {
3334 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3335 "0722 Target Reset rport failure: rdata x%p\n", rdata);
3336 return FAILED;
3337 }
3338
3339 scsi_event.event_type = FC_REG_SCSI_EVENT;
3340 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
3341 scsi_event.lun = 0;
3342 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3343 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3344
3345 fc_host_post_vendor_event(shost, fc_get_event_number(),
3346 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
3347
3348 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3349 FCP_TARGET_RESET);
3350
3351 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3352 "0723 SCSI layer issued Target Reset (%d, %d) "
3353 "return x%x\n", tgt_id, lun_id, status);
3354
3355 /*
3356 * We have to clean up i/o as : they may be orphaned by the TMF;
3357 * or if the TMF failed, they may be in an indeterminate state.
3358 * So, continue on.
3359 * We will report success if all the i/o aborts successfully.
3360 */
3361 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3362 LPFC_CTX_TGT);
3363 return status;
3356} 3364}
3357 3365
3358/** 3366/**
3359 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point 3367 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
3360 * @cmnd: Pointer to scsi_cmnd data structure. 3368 * @cmnd: Pointer to scsi_cmnd data structure.
3361 * 3369 *
3362 * This routine does target reset to all target on @cmnd->device->host. 3370 * This routine does target reset to all targets on @cmnd->device->host.
3371 * This emulates Parallel SCSI Bus Reset Semantics.
3363 * 3372 *
3364 * Return Code: 3373 * Return code :
3365 * 0x2003 - Error 3374 * 0x2003 - Error
3366 * 0x2002 - Success 3375 * 0x2002 - Success
3367 **/ 3376 **/
3368static int 3377static int
3369lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) 3378lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
3370{ 3379{
3371 struct Scsi_Host *shost = cmnd->device->host; 3380 struct Scsi_Host *shost = cmnd->device->host;
3372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3373 struct lpfc_hba *phba = vport->phba;
3374 struct lpfc_nodelist *ndlp = NULL; 3382 struct lpfc_nodelist *ndlp = NULL;
3375 int match;
3376 int ret = SUCCESS, status = SUCCESS, i;
3377 int cnt;
3378 struct lpfc_scsi_buf * lpfc_cmd;
3379 unsigned long later;
3380 struct lpfc_scsi_event_header scsi_event; 3383 struct lpfc_scsi_event_header scsi_event;
3384 int match;
3385 int ret = SUCCESS, status, i;
3381 3386
3382 scsi_event.event_type = FC_REG_SCSI_EVENT; 3387 scsi_event.event_type = FC_REG_SCSI_EVENT;
3383 scsi_event.subcategory = LPFC_EVENT_BUSRESET; 3388 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
@@ -3385,13 +3390,11 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
3385 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); 3390 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
3386 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); 3391 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
3387 3392
3388 fc_host_post_vendor_event(shost, 3393 fc_host_post_vendor_event(shost, fc_get_event_number(),
3389 fc_get_event_number(), 3394 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
3390 sizeof(scsi_event),
3391 (char *)&scsi_event,
3392 LPFC_NL_VENDOR_ID);
3393 3395
3394 lpfc_block_error_handler(cmnd); 3396 lpfc_block_error_handler(cmnd);
3397
3395 /* 3398 /*
3396 * Since the driver manages a single bus device, reset all 3399 * Since the driver manages a single bus device, reset all
3397 * targets known to the driver. Should any target reset 3400 * targets known to the driver. Should any target reset
@@ -3414,16 +3417,11 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
3414 spin_unlock_irq(shost->host_lock); 3417 spin_unlock_irq(shost->host_lock);
3415 if (!match) 3418 if (!match)
3416 continue; 3419 continue;
3417 lpfc_cmd = lpfc_get_scsi_buf(phba); 3420
3418 if (lpfc_cmd) { 3421 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
3419 lpfc_cmd->timeout = 60; 3422 i, 0, FCP_TARGET_RESET);
3420 status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i, 3423
3421 cmnd->device->lun, 3424 if (status != SUCCESS) {
3422 ndlp->rport->dd_data);
3423 if (status != TIMEOUT_ERROR)
3424 lpfc_release_scsi_buf(phba, lpfc_cmd);
3425 }
3426 if (!lpfc_cmd || status != SUCCESS) {
3427 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 3425 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3428 "0700 Bus Reset on target %d failed\n", 3426 "0700 Bus Reset on target %d failed\n",
3429 i); 3427 i);
@@ -3431,25 +3429,16 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
3431 } 3429 }
3432 } 3430 }
3433 /* 3431 /*
3434 * All outstanding txcmplq I/Os should have been aborted by 3432 * We have to clean up i/o as : they may be orphaned by the TMFs
3435 * the targets. Unfortunately, some targets do not abide by 3433 * above; or if any of the TMFs failed, they may be in an
3436 * this forcing the driver to double check. 3434 * indeterminate state.
3435 * We will report success if all the i/o aborts successfully.
3437 */ 3436 */
3438 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST); 3437
3439 if (cnt) 3438 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
3440 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], 3439 if (status != SUCCESS)
3441 0, 0, LPFC_CTX_HOST);
3442 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3443 while (time_after(later, jiffies) && cnt) {
3444 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
3445 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
3446 }
3447 if (cnt) {
3448 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3449 "0715 Bus Reset I/O flush failure: "
3450 "cnt x%x left x%x\n", cnt, i);
3451 ret = FAILED; 3440 ret = FAILED;
3452 } 3441
3453 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 3442 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3454 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); 3443 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
3455 return ret; 3444 return ret;
@@ -3582,7 +3571,8 @@ struct scsi_host_template lpfc_template = {
3582 .info = lpfc_info, 3571 .info = lpfc_info,
3583 .queuecommand = lpfc_queuecommand, 3572 .queuecommand = lpfc_queuecommand,
3584 .eh_abort_handler = lpfc_abort_handler, 3573 .eh_abort_handler = lpfc_abort_handler,
3585 .eh_device_reset_handler= lpfc_device_reset_handler, 3574 .eh_device_reset_handler = lpfc_device_reset_handler,
3575 .eh_target_reset_handler = lpfc_target_reset_handler,
3586 .eh_bus_reset_handler = lpfc_bus_reset_handler, 3576 .eh_bus_reset_handler = lpfc_bus_reset_handler,
3587 .slave_alloc = lpfc_slave_alloc, 3577 .slave_alloc = lpfc_slave_alloc,
3588 .slave_configure = lpfc_slave_configure, 3578 .slave_configure = lpfc_slave_configure,
@@ -3602,7 +3592,8 @@ struct scsi_host_template lpfc_vport_template = {
3602 .info = lpfc_info, 3592 .info = lpfc_info,
3603 .queuecommand = lpfc_queuecommand, 3593 .queuecommand = lpfc_queuecommand,
3604 .eh_abort_handler = lpfc_abort_handler, 3594 .eh_abort_handler = lpfc_abort_handler,
3605 .eh_device_reset_handler= lpfc_device_reset_handler, 3595 .eh_device_reset_handler = lpfc_device_reset_handler,
3596 .eh_target_reset_handler = lpfc_target_reset_handler,
3606 .eh_bus_reset_handler = lpfc_bus_reset_handler, 3597 .eh_bus_reset_handler = lpfc_bus_reset_handler,
3607 .slave_alloc = lpfc_slave_alloc, 3598 .slave_alloc = lpfc_slave_alloc,
3608 .slave_configure = lpfc_slave_configure, 3599 .slave_configure = lpfc_slave_configure,