@@ -656,10 +656,9 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
656656 return SUCCESS ;
657657}
658658
659- static int bnx2fc_initiate_tmf (struct scsi_cmnd * sc_cmd , u8 tm_flags )
659+ static int bnx2fc_initiate_tmf (struct fc_lport * lport , struct fc_rport * rport ,
660+ u64 tm_lun , u8 tm_flags )
660661{
661- struct fc_lport * lport ;
662- struct fc_rport * rport ;
663662 struct fc_rport_libfc_priv * rp ;
664663 struct fcoe_port * port ;
665664 struct bnx2fc_interface * interface ;
@@ -668,7 +667,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
668667 struct bnx2fc_mp_req * tm_req ;
669668 struct fcoe_task_ctx_entry * task ;
670669 struct fcoe_task_ctx_entry * task_page ;
671- struct Scsi_Host * host = sc_cmd -> device -> host ;
672670 struct fc_frame_header * fc_hdr ;
673671 struct fcp_cmnd * fcp_cmnd ;
674672 int task_idx , index ;
@@ -677,8 +675,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
677675 u32 sid , did ;
678676 unsigned long start = jiffies ;
679677
680- lport = shost_priv (host );
681- rport = starget_to_rport (scsi_target (sc_cmd -> device ));
682678 port = lport_priv (lport );
683679 interface = port -> priv ;
684680
@@ -689,7 +685,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
689685 }
690686 rp = rport -> dd_data ;
691687
692- rc = fc_block_scsi_eh ( sc_cmd );
688+ rc = fc_block_rport ( rport );
693689 if (rc )
694690 return rc ;
695691
@@ -718,7 +714,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
718714 goto retry_tmf ;
719715 }
720716 /* Initialize rest of io_req fields */
721- io_req -> sc_cmd = sc_cmd ;
717+ io_req -> sc_cmd = NULL ;
722718 io_req -> port = port ;
723719 io_req -> tgt = tgt ;
724720
@@ -736,11 +732,13 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
736732 /* Set TM flags */
737733 io_req -> io_req_flags = 0 ;
738734 tm_req -> tm_flags = tm_flags ;
735+ tm_req -> tm_lun = tm_lun ;
739736
740737 /* Fill FCP_CMND */
741738 bnx2fc_build_fcp_cmnd (io_req , (struct fcp_cmnd * )tm_req -> req_buf );
742739 fcp_cmnd = (struct fcp_cmnd * )tm_req -> req_buf ;
743- memset (fcp_cmnd -> fc_cdb , 0 , sc_cmd -> cmd_len );
740+ int_to_scsilun (tm_lun , & fcp_cmnd -> fc_lun );
741+ memset (fcp_cmnd -> fc_cdb , 0 , BNX2FC_MAX_CMD_LEN );
744742 fcp_cmnd -> fc_dl = 0 ;
745743
746744 /* Fill FC header */
@@ -763,8 +761,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
763761 task = & (task_page [index ]);
764762 bnx2fc_init_mp_task (io_req , task );
765763
766- bnx2fc_priv (sc_cmd )-> io_req = io_req ;
767-
768764 /* Obtain free SQ entry */
769765 spin_lock_bh (& tgt -> tgt_lock );
770766 bnx2fc_add_2_sq (tgt , xid );
@@ -1062,7 +1058,10 @@ int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
10621058 */
10631059int bnx2fc_eh_target_reset (struct scsi_cmnd * sc_cmd )
10641060{
1065- return bnx2fc_initiate_tmf (sc_cmd , FCP_TMF_TGT_RESET );
1061+ struct fc_rport * rport = starget_to_rport (scsi_target (sc_cmd -> device ));
1062+ struct fc_lport * lport = shost_priv (rport_to_shost (rport ));
1063+
1064+ return bnx2fc_initiate_tmf (lport , rport , 0 , FCP_TMF_TGT_RESET );
10661065}
10671066
10681067/**
@@ -1075,7 +1074,11 @@ int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd)
10751074 */
10761075int bnx2fc_eh_device_reset (struct scsi_cmnd * sc_cmd )
10771076{
1078- return bnx2fc_initiate_tmf (sc_cmd , FCP_TMF_LUN_RESET );
1077+ struct fc_rport * rport = starget_to_rport (scsi_target (sc_cmd -> device ));
1078+ struct fc_lport * lport = shost_priv (rport_to_shost (rport ));
1079+
1080+ return bnx2fc_initiate_tmf (lport , rport , sc_cmd -> device -> lun ,
1081+ FCP_TMF_LUN_RESET );
10791082}
10801083
10811084static int bnx2fc_abts_cleanup (struct bnx2fc_cmd * io_req )
@@ -1450,10 +1453,9 @@ void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
14501453
14511454static void bnx2fc_lun_reset_cmpl (struct bnx2fc_cmd * io_req )
14521455{
1453- struct scsi_cmnd * sc_cmd = io_req -> sc_cmd ;
14541456 struct bnx2fc_rport * tgt = io_req -> tgt ;
14551457 struct bnx2fc_cmd * cmd , * tmp ;
1456- u64 tm_lun = sc_cmd -> device -> lun ;
1458+ struct bnx2fc_mp_req * tm_req = & io_req -> mp_req ;
14571459 u64 lun ;
14581460 int rc = 0 ;
14591461
@@ -1465,8 +1467,10 @@ static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
14651467 */
14661468 list_for_each_entry_safe (cmd , tmp , & tgt -> active_cmd_queue , link ) {
14671469 BNX2FC_TGT_DBG (tgt , "LUN RST cmpl: scan for pending IOs\n" );
1470+ if (!cmd -> sc_cmd )
1471+ continue ;
14681472 lun = cmd -> sc_cmd -> device -> lun ;
1469- if (lun == tm_lun ) {
1473+ if (lun == tm_req -> tm_lun ) {
14701474 /* Initiate ABTS on this cmd */
14711475 if (!test_and_set_bit (BNX2FC_FLAG_ISSUE_ABTS ,
14721476 & cmd -> req_flags )) {
@@ -1570,31 +1574,36 @@ void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
15701574 printk (KERN_ERR PFX "tmf's fc_hdr r_ctl = 0x%x\n" ,
15711575 fc_hdr -> fh_r_ctl );
15721576 }
1573- if (!bnx2fc_priv (sc_cmd )-> io_req ) {
1574- printk (KERN_ERR PFX "tm_compl: io_req is NULL\n" );
1575- return ;
1576- }
1577- switch (io_req -> fcp_status ) {
1578- case FC_GOOD :
1579- if (io_req -> cdb_status == 0 ) {
1580- /* Good IO completion */
1581- sc_cmd -> result = DID_OK << 16 ;
1582- } else {
1583- /* Transport status is good, SCSI status not good */
1584- sc_cmd -> result = (DID_OK << 16 ) | io_req -> cdb_status ;
1577+ if (sc_cmd ) {
1578+ if (!bnx2fc_priv (sc_cmd )-> io_req ) {
1579+ printk (KERN_ERR PFX "tm_compl: io_req is NULL\n" );
1580+ return ;
1581+ }
1582+ switch (io_req -> fcp_status ) {
1583+ case FC_GOOD :
1584+ if (io_req -> cdb_status == 0 ) {
1585+ /* Good IO completion */
1586+ sc_cmd -> result = DID_OK << 16 ;
1587+ } else {
1588+ /* Transport status is good, SCSI status not good */
1589+ sc_cmd -> result = (DID_OK << 16 ) | io_req -> cdb_status ;
1590+ }
1591+ if (io_req -> fcp_resid )
1592+ scsi_set_resid (sc_cmd , io_req -> fcp_resid );
1593+ break ;
1594+
1595+ default :
1596+ BNX2FC_IO_DBG (io_req , "process_tm_compl: fcp_status = %d\n" ,
1597+ io_req -> fcp_status );
1598+ break ;
15851599 }
1586- if (io_req -> fcp_resid )
1587- scsi_set_resid (sc_cmd , io_req -> fcp_resid );
1588- break ;
15891600
1590- default :
1591- BNX2FC_IO_DBG (io_req , "process_tm_compl: fcp_status = %d\n" ,
1592- io_req -> fcp_status );
1593- break ;
1594- }
1601+ sc_cmd = io_req -> sc_cmd ;
1602+ io_req -> sc_cmd = NULL ;
15951603
1596- sc_cmd = io_req -> sc_cmd ;
1597- io_req -> sc_cmd = NULL ;
1604+ bnx2fc_priv (sc_cmd )-> io_req = NULL ;
1605+ scsi_done (sc_cmd );
1606+ }
15981607
15991608 /* check if the io_req exists in tgt's tmf_q */
16001609 if (io_req -> on_tmf_queue ) {
@@ -1607,9 +1616,6 @@ void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
16071616 return ;
16081617 }
16091618
1610- bnx2fc_priv (sc_cmd )-> io_req = NULL ;
1611- scsi_done (sc_cmd );
1612-
16131619 kref_put (& io_req -> refcount , bnx2fc_cmd_release );
16141620 if (io_req -> wait_for_abts_comp ) {
16151621 BNX2FC_IO_DBG (io_req , "tm_compl - wake up the waiter\n" );
@@ -1738,15 +1744,9 @@ static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
17381744void bnx2fc_build_fcp_cmnd (struct bnx2fc_cmd * io_req ,
17391745 struct fcp_cmnd * fcp_cmnd )
17401746{
1741- struct scsi_cmnd * sc_cmd = io_req -> sc_cmd ;
1742-
17431747 memset (fcp_cmnd , 0 , sizeof (struct fcp_cmnd ));
17441748
1745- int_to_scsilun (sc_cmd -> device -> lun , & fcp_cmnd -> fc_lun );
1746-
17471749 fcp_cmnd -> fc_dl = htonl (io_req -> data_xfer_len );
1748- memcpy (fcp_cmnd -> fc_cdb , sc_cmd -> cmnd , sc_cmd -> cmd_len );
1749-
17501750 fcp_cmnd -> fc_cmdref = 0 ;
17511751 fcp_cmnd -> fc_pri_ta = 0 ;
17521752 fcp_cmnd -> fc_tm_flags = io_req -> mp_req .tm_flags ;
0 commit comments