@@ -24,6 +24,7 @@ void qla2x00_bsg_job_done(srb_t *sp, int res)
2424{
2525 struct bsg_job * bsg_job = sp -> u .bsg_job ;
2626 struct fc_bsg_reply * bsg_reply = bsg_job -> reply ;
27+ struct completion * comp = sp -> comp ;
2728
2829 ql_dbg (ql_dbg_user , sp -> vha , 0x7009 ,
2930 "%s: sp hdl %x, result=%x bsg ptr %p\n" ,
@@ -35,6 +36,9 @@ void qla2x00_bsg_job_done(srb_t *sp, int res)
3536 bsg_reply -> result = res ;
3637 bsg_job_done (bsg_job , bsg_reply -> result ,
3738 bsg_reply -> reply_payload_rcv_len );
39+
40+ if (comp )
41+ complete (comp );
3842}
3943
4044void qla2x00_bsg_sp_free (srb_t * sp )
@@ -490,16 +494,6 @@ qla2x00_process_ct(struct bsg_job *bsg_job)
490494 goto done ;
491495 }
492496
493- if ((req_sg_cnt != bsg_job -> request_payload .sg_cnt ) ||
494- (rsp_sg_cnt != bsg_job -> reply_payload .sg_cnt )) {
495- ql_log (ql_log_warn , vha , 0x7011 ,
496- "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
497- "dma_reply_sg_cnt: %x\n" , bsg_job -> request_payload .sg_cnt ,
498- req_sg_cnt , bsg_job -> reply_payload .sg_cnt , rsp_sg_cnt );
499- rval = - EAGAIN ;
500- goto done_unmap_sg ;
501- }
502-
503497 if (!vha -> flags .online ) {
504498 ql_log (ql_log_warn , vha , 0x7012 ,
505499 "Host is not online.\n" );
@@ -3061,14 +3055,19 @@ qla24xx_bsg_request(struct bsg_job *bsg_job)
30613055
30623056static bool qla_bsg_found (struct qla_qpair * qpair , struct bsg_job * bsg_job )
30633057{
3064- bool found = false ;
3058+ bool found , do_bsg_done ;
30653059 struct fc_bsg_reply * bsg_reply = bsg_job -> reply ;
30663060 scsi_qla_host_t * vha = shost_priv (fc_bsg_to_shost (bsg_job ));
30673061 struct qla_hw_data * ha = vha -> hw ;
30683062 srb_t * sp = NULL ;
30693063 int cnt ;
30703064 unsigned long flags ;
30713065 struct req_que * req ;
3066+ int rval ;
3067+ DECLARE_COMPLETION_ONSTACK (comp );
3068+ uint32_t ratov_j ;
3069+
3070+ found = do_bsg_done = false;
30723071
30733072 spin_lock_irqsave (qpair -> qp_lock_ptr , flags );
30743073 req = qpair -> req ;
@@ -3080,42 +3079,104 @@ static bool qla_bsg_found(struct qla_qpair *qpair, struct bsg_job *bsg_job)
30803079 sp -> type == SRB_ELS_CMD_HST ||
30813080 sp -> type == SRB_ELS_CMD_HST_NOLOGIN ) &&
30823081 sp -> u .bsg_job == bsg_job ) {
3083- req -> outstanding_cmds [cnt ] = NULL ;
3084- spin_unlock_irqrestore (qpair -> qp_lock_ptr , flags );
3085-
3086- if (!ha -> flags .eeh_busy && ha -> isp_ops -> abort_command (sp )) {
3087- ql_log (ql_log_warn , vha , 0x7089 ,
3088- "mbx abort_command failed.\n" );
3089- bsg_reply -> result = - EIO ;
3090- } else {
3091- ql_dbg (ql_dbg_user , vha , 0x708a ,
3092- "mbx abort_command success.\n" );
3093- bsg_reply -> result = 0 ;
3094- }
3095- /* ref: INIT */
3096- kref_put (& sp -> cmd_kref , qla2x00_sp_release );
30973082
30983083 found = true;
3099- goto done ;
3084+ sp -> comp = & comp ;
3085+ break ;
31003086 }
31013087 }
31023088 spin_unlock_irqrestore (qpair -> qp_lock_ptr , flags );
31033089
3104- done :
3105- return found ;
3090+ if (!found )
3091+ return false;
3092+
3093+ if (ha -> flags .eeh_busy ) {
3094+ /* skip over abort. EEH handling will return the bsg. Wait for it */
3095+ rval = QLA_SUCCESS ;
3096+ ql_dbg (ql_dbg_user , vha , 0x802c ,
3097+ "eeh encounter. bsg %p sp=%p handle=%x \n" ,
3098+ bsg_job , sp , sp -> handle );
3099+ } else {
3100+ rval = ha -> isp_ops -> abort_command (sp );
3101+ ql_dbg (ql_dbg_user , vha , 0x802c ,
3102+ "Aborting bsg %p sp=%p handle=%x rval=%x\n" ,
3103+ bsg_job , sp , sp -> handle , rval );
3104+ }
3105+
3106+ switch (rval ) {
3107+ case QLA_SUCCESS :
3108+ /* Wait for the command completion. */
3109+ ratov_j = ha -> r_a_tov / 10 * 4 * 1000 ;
3110+ ratov_j = msecs_to_jiffies (ratov_j );
3111+
3112+ if (!wait_for_completion_timeout (& comp , ratov_j )) {
3113+ ql_log (ql_log_info , vha , 0x7089 ,
3114+ "bsg abort timeout. bsg=%p sp=%p handle %#x .\n" ,
3115+ bsg_job , sp , sp -> handle );
3116+
3117+ do_bsg_done = true;
3118+ } else {
3119+ /* fw had returned the bsg */
3120+ ql_dbg (ql_dbg_user , vha , 0x708a ,
3121+ "bsg abort success. bsg %p sp=%p handle=%#x\n" ,
3122+ bsg_job , sp , sp -> handle );
3123+ do_bsg_done = false;
3124+ }
3125+ break ;
3126+ default :
3127+ ql_log (ql_log_info , vha , 0x704f ,
3128+ "bsg abort fail. bsg=%p sp=%p rval=%x.\n" ,
3129+ bsg_job , sp , rval );
3130+
3131+ do_bsg_done = true;
3132+ break ;
3133+ }
3134+
3135+ if (!do_bsg_done )
3136+ return true;
3137+
3138+ spin_lock_irqsave (qpair -> qp_lock_ptr , flags );
3139+ /*
3140+ * recheck to make sure it's still the same bsg_job due to
3141+ * qp_lock_ptr was released earlier.
3142+ */
3143+ if (req -> outstanding_cmds [cnt ] &&
3144+ req -> outstanding_cmds [cnt ]-> u .bsg_job != bsg_job ) {
3145+ /* fw had returned the bsg */
3146+ spin_unlock_irqrestore (qpair -> qp_lock_ptr , flags );
3147+ return true;
3148+ }
3149+ req -> outstanding_cmds [cnt ] = NULL ;
3150+ spin_unlock_irqrestore (qpair -> qp_lock_ptr , flags );
3151+
3152+ /* ref: INIT */
3153+ sp -> comp = NULL ;
3154+ kref_put (& sp -> cmd_kref , qla2x00_sp_release );
3155+ bsg_reply -> result = - ENXIO ;
3156+ bsg_reply -> reply_payload_rcv_len = 0 ;
3157+
3158+ ql_dbg (ql_dbg_user , vha , 0x7051 ,
3159+ "%s bsg_job_done : bsg %p result %#x sp %p.\n" ,
3160+ __func__ , bsg_job , bsg_reply -> result , sp );
3161+
3162+ bsg_job_done (bsg_job , bsg_reply -> result , bsg_reply -> reply_payload_rcv_len );
3163+
3164+ return true;
31063165}
31073166
31083167int
31093168qla24xx_bsg_timeout (struct bsg_job * bsg_job )
31103169{
3111- struct fc_bsg_reply * bsg_reply = bsg_job -> reply ;
3170+ struct fc_bsg_request * bsg_request = bsg_job -> request ;
31123171 scsi_qla_host_t * vha = shost_priv (fc_bsg_to_shost (bsg_job ));
31133172 struct qla_hw_data * ha = vha -> hw ;
31143173 int i ;
31153174 struct qla_qpair * qpair ;
31163175
3117- ql_log (ql_log_info , vha , 0x708b , "%s CMD timeout. bsg ptr %p.\n" ,
3118- __func__ , bsg_job );
3176+ ql_log (ql_log_info , vha , 0x708b ,
3177+ "%s CMD timeout. bsg ptr %p msgcode %x vendor cmd %x\n" ,
3178+ __func__ , bsg_job , bsg_request -> msgcode ,
3179+ bsg_request -> rqst_data .h_vendor .vendor_cmd [0 ]);
31193180
31203181 if (qla2x00_isp_reg_stat (ha )) {
31213182 ql_log (ql_log_info , vha , 0x9007 ,
@@ -3136,7 +3197,6 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job)
31363197 }
31373198
31383199 ql_log (ql_log_info , vha , 0x708b , "SRB not found to abort.\n" );
3139- bsg_reply -> result = - ENXIO ;
31403200
31413201done :
31423202 return 0 ;
0 commit comments