All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
	Hannes Reinecke <hare@suse.com>,
	Saurav Kashyap <skashyap@marvell.com>
Subject: [PATCH 23/51] bnx2fc: Do not rely on a scsi command when issueing lun or target reset
Date: Tue, 17 Aug 2021 11:14:28 +0200	[thread overview]
Message-ID: <20210817091456.73342-24-hare@suse.de> (raw)
In-Reply-To: <20210817091456.73342-1-hare@suse.de>

When a LUN or target reset is issued we should not rely on a scsi
command to be present; this isn't very reliable and is going away
with the next patch anyway.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Cc: Saurav Kashyap <skashyap@marvell.com>
---
 drivers/scsi/bnx2fc/bnx2fc.h     |  1 +
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 14 +++--
 drivers/scsi/bnx2fc/bnx2fc_io.c  | 91 +++++++++++++++-----------------
 3 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index b4cea8b06ea1..4e0434f70092 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -386,6 +386,7 @@ struct bnx2fc_rport {
 };
 
 struct bnx2fc_mp_req {
+	u64 tm_lun;
 	u8 tm_flags;
 
 	u32 req_len;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index 0103f811cc25..a08e89dad29d 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -1709,7 +1709,8 @@ void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
 	struct fcoe_cached_sge_ctx *cached_sge;
 	struct fcoe_ext_mul_sges_ctx *sgl;
 	int dev_type = tgt->dev_type;
-	u64 *fcp_cmnd;
+	struct fcp_cmnd *fcp_cmnd;
+	u64 *raw_fcp_cmnd;
 	u64 tmp_fcp_cmnd[4];
 	u32 context_id;
 	int cnt, i;
@@ -1778,16 +1779,19 @@ void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
 	task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
 
 	/* Fill FCP_CMND IU */
-	fcp_cmnd = (u64 *)
+	fcp_cmnd = (struct fcp_cmnd *)&tmp_fcp_cmnd;
+	bnx2fc_build_fcp_cmnd(io_req, fcp_cmnd);
+	int_to_scsilun(sc_cmd->device->lun, &fcp_cmnd->fc_lun);
+	memcpy(fcp_cmnd->fc_cdb, sc_cmd->cmnd, sc_cmd->cmd_len);
+	raw_fcp_cmnd = (u64 *)
 		    task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
-	bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
 
 	/* swap fcp_cmnd */
 	cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
 
 	for (i = 0; i < cnt; i++) {
-		*fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
-		fcp_cmnd++;
+		*raw_fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
+		raw_fcp_cmnd++;
 	}
 
 	/* Rx Write Tx Read */
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index f2996a9b2f63..28e858325d38 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -658,10 +658,9 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
 	return SUCCESS;
 }
 
-static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
+static int bnx2fc_initiate_tmf(struct fc_lport *lport, struct fc_rport *rport,
+			       u64 tm_lun, u8 tm_flags)
 {
-	struct fc_lport *lport;
-	struct fc_rport *rport;
 	struct fc_rport_libfc_priv *rp;
 	struct fcoe_port *port;
 	struct bnx2fc_interface *interface;
@@ -670,7 +669,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 	struct bnx2fc_mp_req *tm_req;
 	struct fcoe_task_ctx_entry *task;
 	struct fcoe_task_ctx_entry *task_page;
-	struct Scsi_Host *host = sc_cmd->device->host;
 	struct fc_frame_header *fc_hdr;
 	struct fcp_cmnd *fcp_cmnd;
 	int task_idx, index;
@@ -679,8 +677,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 	u32 sid, did;
 	unsigned long start = jiffies;
 
-	lport = shost_priv(host);
-	rport = starget_to_rport(scsi_target(sc_cmd->device));
 	port = lport_priv(lport);
 	interface = port->priv;
 
@@ -691,7 +687,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 	}
 	rp = rport->dd_data;
 
-	rc = fc_block_scsi_eh(sc_cmd);
+	rc = fc_block_rport(rport);
 	if (rc)
 		return rc;
 
@@ -720,7 +716,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 		goto retry_tmf;
 	}
 	/* Initialize rest of io_req fields */
-	io_req->sc_cmd = sc_cmd;
+	io_req->sc_cmd = NULL;
 	io_req->port = port;
 	io_req->tgt = tgt;
 
@@ -738,11 +734,13 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 	/* Set TM flags */
 	io_req->io_req_flags = 0;
 	tm_req->tm_flags = tm_flags;
+	tm_req->tm_lun = tm_lun;
 
 	/* Fill FCP_CMND */
 	bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)tm_req->req_buf);
 	fcp_cmnd = (struct fcp_cmnd *)tm_req->req_buf;
-	memset(fcp_cmnd->fc_cdb, 0,  sc_cmd->cmd_len);
+	int_to_scsilun(tm_lun, &fcp_cmnd->fc_lun);
+	memset(fcp_cmnd->fc_cdb, 0,  BNX2FC_MAX_CMD_LEN);
 	fcp_cmnd->fc_dl = 0;
 
 	/* Fill FC header */
@@ -765,8 +763,6 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
 	task = &(task_page[index]);
 	bnx2fc_init_mp_task(io_req, task);
 
-	sc_cmd->SCp.ptr = (char *)io_req;
-
 	/* Obtain free SQ entry */
 	spin_lock_bh(&tgt->tgt_lock);
 	bnx2fc_add_2_sq(tgt, xid);
@@ -1064,7 +1060,10 @@ int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
  */
 int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd)
 {
-	return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_TGT_RESET);
+	struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
+	struct fc_lport *lport = shost_priv(rport_to_shost(rport));
+
+	return bnx2fc_initiate_tmf(lport, rport, 0, FCP_TMF_TGT_RESET);
 }
 
 /**
@@ -1077,7 +1076,11 @@ int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd)
  */
 int bnx2fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
 {
-	return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_LUN_RESET);
+	struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
+	struct fc_lport *lport = shost_priv(rport_to_shost(rport));
+
+	return bnx2fc_initiate_tmf(lport, rport, sc_cmd->device->lun,
+				   FCP_TMF_LUN_RESET);
 }
 
 static int bnx2fc_abts_cleanup(struct bnx2fc_cmd *io_req)
@@ -1452,10 +1455,9 @@ void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
 
 static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
 {
-	struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
 	struct bnx2fc_rport *tgt = io_req->tgt;
 	struct bnx2fc_cmd *cmd, *tmp;
-	u64 tm_lun = sc_cmd->device->lun;
+	struct bnx2fc_mp_req *tm_req = &io_req->mp_req;
 	u64 lun;
 	int rc = 0;
 
@@ -1467,8 +1469,10 @@ static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
 	 */
 	list_for_each_entry_safe(cmd, tmp, &tgt->active_cmd_queue, link) {
 		BNX2FC_TGT_DBG(tgt, "LUN RST cmpl: scan for pending IOs\n");
+		if (!cmd->sc_cmd)
+			continue;
 		lun = cmd->sc_cmd->device->lun;
-		if (lun == tm_lun) {
+		if (lun == tm_req->tm_lun) {
 			/* Initiate ABTS on this cmd */
 			if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
 					      &cmd->req_flags)) {
@@ -1572,32 +1576,32 @@ void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
 		printk(KERN_ERR PFX "tmf's fc_hdr r_ctl = 0x%x\n",
 			fc_hdr->fh_r_ctl);
 	}
-	if (!sc_cmd->SCp.ptr) {
-		printk(KERN_ERR PFX "tm_compl: SCp.ptr is NULL\n");
-		return;
-	}
-	switch (io_req->fcp_status) {
-	case FC_GOOD:
-		if (io_req->cdb_status == 0) {
-			/* Good IO completion */
-			sc_cmd->result = DID_OK << 16;
-		} else {
-			/* Transport status is good, SCSI status not good */
-			sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+	if (sc_cmd && sc_cmd->SCp.ptr) {
+		switch (io_req->fcp_status) {
+		case FC_GOOD:
+			if (io_req->cdb_status == 0) {
+				/* Good IO completion */
+				sc_cmd->result = DID_OK << 16;
+			} else {
+				/* Transport status is good, SCSI status not good */
+				sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+			}
+			if (io_req->fcp_resid)
+				scsi_set_resid(sc_cmd, io_req->fcp_resid);
+			break;
+
+		default:
+			BNX2FC_IO_DBG(io_req, "process_tm_compl: fcp_status = %d\n",
+				      io_req->fcp_status);
+			break;
 		}
-		if (io_req->fcp_resid)
-			scsi_set_resid(sc_cmd, io_req->fcp_resid);
-		break;
 
-	default:
-		BNX2FC_IO_DBG(io_req, "process_tm_compl: fcp_status = %d\n",
-			   io_req->fcp_status);
-		break;
-	}
-
-	sc_cmd = io_req->sc_cmd;
-	io_req->sc_cmd = NULL;
+		sc_cmd = io_req->sc_cmd;
+		io_req->sc_cmd = NULL;
 
+		sc_cmd->SCp.ptr = NULL;
+		sc_cmd->scsi_done(sc_cmd);
+	}
 	/* check if the io_req exists in tgt's tmf_q */
 	if (io_req->on_tmf_queue) {
 
@@ -1609,9 +1613,6 @@ void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
 		return;
 	}
 
-	sc_cmd->SCp.ptr = NULL;
-	sc_cmd->scsi_done(sc_cmd);
-
 	kref_put(&io_req->refcount, bnx2fc_cmd_release);
 	if (io_req->wait_for_abts_comp) {
 		BNX2FC_IO_DBG(io_req, "tm_compl - wake up the waiter\n");
@@ -1740,15 +1741,9 @@ static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
 void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
 				  struct fcp_cmnd *fcp_cmnd)
 {
-	struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
-
 	memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
 
-	int_to_scsilun(sc_cmd->device->lun, &fcp_cmnd->fc_lun);
-
 	fcp_cmnd->fc_dl = htonl(io_req->data_xfer_len);
-	memcpy(fcp_cmnd->fc_cdb, sc_cmd->cmnd, sc_cmd->cmd_len);
-
 	fcp_cmnd->fc_cmdref = 0;
 	fcp_cmnd->fc_pri_ta = 0;
 	fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
-- 
2.29.2


  parent reply	other threads:[~2021-08-17  9:17 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17  9:14 [PATCHv2 00/51] SCSI EH argument reshuffle part II Hannes Reinecke
2021-08-17  9:14 ` [PATCH 01/51] lpfc: kill lpfc_bus_reset_handler Hannes Reinecke
2021-08-17 17:37   ` James Smart
2021-08-17  9:14 ` [PATCH 02/51] lpfc: drop lpfc_no_handler() Hannes Reinecke
2021-08-17 12:13   ` Christoph Hellwig
2021-08-17 17:36   ` James Smart
2021-08-17  9:14 ` [PATCH 03/51] sym53c8xx_2: split off bus reset from host reset Hannes Reinecke
2021-08-17 12:18   ` Christoph Hellwig
2021-08-17  9:14 ` [PATCH 04/51] ips: Do not try to abort command " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 05/51] snic: reserve tag for TMF Hannes Reinecke
2021-08-17 12:21   ` Christoph Hellwig
2021-08-17  9:14 ` [PATCH 06/51] qla1280: separate out host reset function from qla1280_error_action() Hannes Reinecke
2021-08-17 12:22   ` Christoph Hellwig
2021-08-17 14:05     ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 07/51] megaraid: pass in NULL scb for host reset Hannes Reinecke
2021-08-17 12:26   ` Christoph Hellwig
2021-08-17 13:46     ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 08/51] zfcp: open-code fc_block_scsi_eh() " Hannes Reinecke
2021-08-17 11:53   ` Benjamin Block
2021-08-17 12:54     ` Hannes Reinecke
2021-08-17 14:03       ` Steffen Maier
2021-08-17 14:10         ` Hannes Reinecke
2021-08-18 11:00           ` Steffen Maier
2021-08-18 11:58             ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 09/51] mpi3mr: split off bus_reset function from host_reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 10/51] scsi: Use Scsi_Host as argument for eh_host_reset_handler Hannes Reinecke
2021-08-17 14:55   ` Steffen Maier
2021-08-19 18:34   ` Bart Van Assche
2021-08-17  9:14 ` [PATCH 11/51] mptfc: simplify mpt_fc_block_error_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 12/51] mptfusion: correct definitions for mptscsih_dev_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 13/51] mptfc: open-code mptfc_block_error_handler() for bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 14/51] pmcraid: Select device in pmcraid_eh_bus_reset_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 15/51] qla2xxx: open-code qla2xxx_generic_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 16/51] qla2xxx: Do not call fc_block_scsi_eh() during bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 17/51] visorhba: select first device on the bus for bus_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 18/51] ncr53c8xx: remove 'sync_reset' argument from ncr_reset_bus() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 19/51] ncr53c8xx: Complete all commands during bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 20/51] ncr53c8xx: Remove unused code Hannes Reinecke
2021-08-17  9:14 ` [PATCH 21/51] scsi: Use Scsi_Host and channel number as argument for eh_bus_reset_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 22/51] libiscsi: use cls_session as argument for target and session reset Hannes Reinecke
2021-08-17  9:14 ` Hannes Reinecke [this message]
2021-08-17  9:14 ` [PATCH 24/51] ibmvfc: open-code reset loop for target reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 25/51] lpfc: use fc_block_rport() Hannes Reinecke
2021-08-18 16:35   ` James Smart
2021-08-17  9:14 ` [PATCH 26/51] lpfc: use rport as argument for lpfc_send_taskmgmt() Hannes Reinecke
2021-08-18 16:35   ` James Smart
2021-08-17  9:14 ` [PATCH 27/51] lpfc: use rport as argument for lpfc_chk_tgt_mapped() Hannes Reinecke
2021-08-18 16:36   ` James Smart
2021-08-17  9:14 ` [PATCH 28/51] csiostor: use fc_block_rport() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 29/51] qla2xxx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 30/51] fc_fcp: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 31/51] qedf: use fc rport as argument for qedf_initiate_tmf() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 32/51] sym53c8xx_2: rework reset handling Hannes Reinecke
2021-08-17  9:14 ` [PATCH 33/51] bfa: Do not use scsi command to signal TMF status Hannes Reinecke
2021-08-17  9:14 ` [PATCH 34/51] scsi_transport_iscsi: use session as argument for iscsi_block_scsi_eh() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 35/51] pmcraid: select first available device for target reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 36/51] scsi: Use scsi_target as argument for eh_target_reset_handler() Hannes Reinecke
2021-08-17 15:53   ` Steffen Maier
2021-08-18 16:37   ` James Smart
2021-08-19 18:37   ` Bart Van Assche
2021-08-17  9:14 ` [PATCH 37/51] aha152x: look for stuck command when resetting device Hannes Reinecke
2021-08-18  0:43   ` Finn Thain
2021-08-17  9:14 ` [PATCH 38/51] fnic: use dedicated device reset command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 39/51] a1000u2w: do not rely on the command for inia100_device_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 40/51] aic7xxx: use scsi device as argument for BUILD_SCSIID() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 41/51] aic79xx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 42/51] aic7xxx: do not reference scsi command when resetting device Hannes Reinecke
2021-08-17  9:14 ` [PATCH 43/51] aic79xx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 44/51] xen-scsifront: add scsi device as argument to scsifront_do_request() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 45/51] fas216: Rework device reset to not rely on SCSI command pointer Hannes Reinecke
2021-08-17  9:14 ` [PATCH 46/51] csiostor: use separate TMF command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 47/51] snic: use dedicated device reset command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 48/51] snic: Use scsi_host_busy_iter() to traverse commands Hannes Reinecke
2021-08-17  9:14 ` [PATCH 49/51] scsi: Move eh_device_reset_handler() to use scsi_device as argument Hannes Reinecke
2021-08-17 16:13   ` Steffen Maier
2021-08-17 18:09     ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 50/51] scsi: Do not allocate scsi command in scsi_ioctl_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 51/51] scsi_error: streamline scsi_eh_bus_device_reset() Hannes Reinecke
2021-08-17 12:13 ` [PATCHv2 00/51] SCSI EH argument reshuffle part II Christoph Hellwig
2021-08-17 12:55   ` Hannes Reinecke
2022-02-23 12:49     ` Christoph Hellwig
2022-02-23 13:03       ` Hannes Reinecke
2022-02-23 13:05         ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210817091456.73342-24-hare@suse.de \
    --to=hare@suse.de \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=skashyap@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.