Blame SOURCES/0121-scsi-scsi-qla2xxx-cleanup-trace-buffer-initializatio.patch

3c6e85
From c4057d8b60cf06e57bee74fb596f64291803852e Mon Sep 17 00:00:00 2001
3c6e85
From: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Date: Wed, 4 Sep 2019 21:04:19 -0400
3c6e85
Subject: [PATCH 121/124] [scsi] scsi: qla2xxx: cleanup trace buffer
3c6e85
 initialization
3c6e85
3c6e85
Message-id: <20190904210419.3503-3-hmadhani@redhat.com>
3c6e85
Patchwork-id: 270922
3c6e85
O-Subject: [RHEL7.8 e-stor PATCH 2/2] scsi: qla2xxx: cleanup trace buffer initialization
3c6e85
Bugzilla: 1749039
3c6e85
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
3c6e85
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
3c6e85
RH-Acked-by: Maurizio Lombardi <mlombard@redhat.com>
3c6e85
RH-Acked-by: Ewan Milne <emilne@redhat.com>
3c6e85
3c6e85
From: Martin Wilck <mwilck@suse.com>
3c6e85
3c6e85
Bugzilla 1749039
3c6e85
3c6e85
Avoid code duplication between qla2x00_alloc_offload_mem() and
3c6e85
qla2x00_alloc_fw_dump() by moving the FCE and EFT buffer allocation and
3c6e85
initialization to separate functions. Cleanly track failure and success by
3c6e85
making sure that the ha->eft, ha->fce and respective eft_dma, fce_dma
3c6e85
members are set if and only if the buffers are properly allocated and
3c6e85
initialized. Avoid pointless buffer reallocation.  Eliminate some goto
3c6e85
statements. Make sure the fce_enabled flag is cleared when the FCE buffer
3c6e85
is freed.
3c6e85
3c6e85
Fixes: ad0a0b01f088 ("scsi: qla2xxx: Fix Firmware dump size for Extended login and Exchange Offload")
3c6e85
Fixes: a28d9e4ef997 ("scsi: qla2xxx: Add support for multiple fwdump templates/segments")
3c6e85
Cc: Joe Carnuccio <joe.carnuccio@cavium.com>
3c6e85
Cc: Quinn Tran <qutran@marvell.com>
3c6e85
Cc: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Cc: Bart Van Assche <bvanassche@acm.org>
3c6e85
Signed-off-by: Martin Wilck <mwilck@suse.com>
3c6e85
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
3c6e85
(cherry picked from commit 3cf92f4bfccbb3e378cd86dc46e09c2bc18cda26)
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Signed-off-by: Jan Stancek <jstancek@redhat.com>
3c6e85
---
3c6e85
 drivers/scsi/qla2xxx/qla_init.c | 216 ++++++++++++++++++----------------------
3c6e85
 drivers/scsi/qla2xxx/qla_os.c   |   1 +
3c6e85
 2 files changed, 100 insertions(+), 117 deletions(-)
3c6e85
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
3c6e85
index 52d336706349..4ca6fc8dce63 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_init.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_init.c
3c6e85
@@ -3113,103 +3113,113 @@ qla24xx_chip_diag(scsi_qla_host_t *vha)
3c6e85
 }
3c6e85
 
3c6e85
 static void
3c6e85
-qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3c6e85
+qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3c6e85
 {
3c6e85
 	int rval;
3c6e85
 	dma_addr_t tc_dma;
3c6e85
 	void *tc;
3c6e85
 	struct qla_hw_data *ha = vha->hw;
3c6e85
 
3c6e85
-	if (ha->eft) {
3c6e85
+	if (!IS_FWI2_CAPABLE(ha))
3c6e85
+		return;
3c6e85
+
3c6e85
+	if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3c6e85
+	    !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3c6e85
+		return;
3c6e85
+
3c6e85
+	if (ha->fce) {
3c6e85
 		ql_dbg(ql_dbg_init, vha, 0x00bd,
3c6e85
-		    "%s: Offload Mem is already allocated.\n",
3c6e85
-		    __func__);
3c6e85
+		       "%s: FCE Mem is already allocated.\n",
3c6e85
+		       __func__);
3c6e85
 		return;
3c6e85
 	}
3c6e85
 
3c6e85
-	if (IS_FWI2_CAPABLE(ha)) {
3c6e85
-		/* Allocate memory for Fibre Channel Event Buffer. */
3c6e85
-		if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3c6e85
-		    !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3c6e85
-			goto try_eft;
3c6e85
+	/* Allocate memory for Fibre Channel Event Buffer. */
3c6e85
+	tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3c6e85
+				GFP_KERNEL);
3c6e85
+	if (!tc) {
3c6e85
+		ql_log(ql_log_warn, vha, 0x00be,
3c6e85
+		       "Unable to allocate (%d KB) for FCE.\n",
3c6e85
+		       FCE_SIZE / 1024);
3c6e85
+		return;
3c6e85
+	}
3c6e85
 
3c6e85
-		if (ha->fce)
3c6e85
-			dma_free_coherent(&ha->pdev->dev,
3c6e85
-			    FCE_SIZE, ha->fce, ha->fce_dma);
3c6e85
-
3c6e85
-		/* Allocate memory for Fibre Channel Event Buffer. */
3c6e85
-		tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3c6e85
-					GFP_KERNEL);
3c6e85
-		if (!tc) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00be,
3c6e85
-			    "Unable to allocate (%d KB) for FCE.\n",
3c6e85
-			    FCE_SIZE / 1024);
3c6e85
-			goto try_eft;
3c6e85
-		}
3c6e85
-
3c6e85
-		rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3c6e85
-		    ha->fce_mb, &ha->fce_bufs);
3c6e85
-		if (rval) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00bf,
3c6e85
-			    "Unable to initialize FCE (%d).\n", rval);
3c6e85
-			dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3c6e85
-			    tc_dma);
3c6e85
-			ha->flags.fce_enabled = 0;
3c6e85
-			goto try_eft;
3c6e85
-		}
3c6e85
-		ql_dbg(ql_dbg_init, vha, 0x00c0,
3c6e85
-		    "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3c6e85
-
3c6e85
-		ha->flags.fce_enabled = 1;
3c6e85
-		ha->fce_dma = tc_dma;
3c6e85
-		ha->fce = tc;
3c6e85
-
3c6e85
-try_eft:
3c6e85
-		if (ha->eft)
3c6e85
-			dma_free_coherent(&ha->pdev->dev,
3c6e85
-			    EFT_SIZE, ha->eft, ha->eft_dma);
3c6e85
+	rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3c6e85
+					ha->fce_mb, &ha->fce_bufs);
3c6e85
+	if (rval) {
3c6e85
+		ql_log(ql_log_warn, vha, 0x00bf,
3c6e85
+		       "Unable to initialize FCE (%d).\n", rval);
3c6e85
+		dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3c6e85
+		return;
3c6e85
+	}
3c6e85
 
3c6e85
-		/* Allocate memory for Extended Trace Buffer. */
3c6e85
-		tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3c6e85
-					 GFP_KERNEL);
3c6e85
-		if (!tc) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00c1,
3c6e85
-			    "Unable to allocate (%d KB) for EFT.\n",
3c6e85
-			    EFT_SIZE / 1024);
3c6e85
-			goto eft_err;
3c6e85
-		}
3c6e85
+	ql_dbg(ql_dbg_init, vha, 0x00c0,
3c6e85
+	       "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3c6e85
 
3c6e85
-		rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3c6e85
-		if (rval) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00c2,
3c6e85
-			    "Unable to initialize EFT (%d).\n", rval);
3c6e85
-			dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3c6e85
-			    tc_dma);
3c6e85
-			goto eft_err;
3c6e85
-		}
3c6e85
-		ql_dbg(ql_dbg_init, vha, 0x00c3,
3c6e85
-		    "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3c6e85
+	ha->flags.fce_enabled = 1;
3c6e85
+	ha->fce_dma = tc_dma;
3c6e85
+	ha->fce = tc;
3c6e85
+}
3c6e85
+
3c6e85
+static void
3c6e85
+qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3c6e85
+{
3c6e85
+	int rval;
3c6e85
+	dma_addr_t tc_dma;
3c6e85
+	void *tc;
3c6e85
+	struct qla_hw_data *ha = vha->hw;
3c6e85
+
3c6e85
+	if (!IS_FWI2_CAPABLE(ha))
3c6e85
+		return;
3c6e85
 
3c6e85
-		ha->eft_dma = tc_dma;
3c6e85
-		ha->eft = tc;
3c6e85
+	if (ha->eft) {
3c6e85
+		ql_dbg(ql_dbg_init, vha, 0x00bd,
3c6e85
+		    "%s: EFT Mem is already allocated.\n",
3c6e85
+		    __func__);
3c6e85
+		return;
3c6e85
 	}
3c6e85
 
3c6e85
-eft_err:
3c6e85
-	return;
3c6e85
+	/* Allocate memory for Extended Trace Buffer. */
3c6e85
+	tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3c6e85
+				GFP_KERNEL);
3c6e85
+	if (!tc) {
3c6e85
+		ql_log(ql_log_warn, vha, 0x00c1,
3c6e85
+		       "Unable to allocate (%d KB) for EFT.\n",
3c6e85
+		       EFT_SIZE / 1024);
3c6e85
+		return;
3c6e85
+	}
3c6e85
+
3c6e85
+	rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3c6e85
+	if (rval) {
3c6e85
+		ql_log(ql_log_warn, vha, 0x00c2,
3c6e85
+		       "Unable to initialize EFT (%d).\n", rval);
3c6e85
+		dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3c6e85
+		return;
3c6e85
+	}
3c6e85
+
3c6e85
+	ql_dbg(ql_dbg_init, vha, 0x00c3,
3c6e85
+	       "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3c6e85
+
3c6e85
+	ha->eft_dma = tc_dma;
3c6e85
+	ha->eft = tc;
3c6e85
+}
3c6e85
+
3c6e85
+static void
3c6e85
+qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3c6e85
+{
3c6e85
+	qla2x00_init_fce_trace(vha);
3c6e85
+	qla2x00_init_eft_trace(vha);
3c6e85
 }
3c6e85
 
3c6e85
 void
3c6e85
 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3c6e85
 {
3c6e85
-	int rval;
3c6e85
 	uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3c6e85
 	    eft_size, fce_size, mq_size;
3c6e85
 	struct qla_hw_data *ha = vha->hw;
3c6e85
 	struct req_que *req = ha->req_q_map[0];
3c6e85
 	struct rsp_que *rsp = ha->rsp_q_map[0];
3c6e85
 	struct qla2xxx_fw_dump *fw_dump;
3c6e85
-	dma_addr_t tc_dma;
3c6e85
-	void *tc;
3c6e85
 
3c6e85
 	dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3c6e85
 	req_q_size = rsp_q_size = 0;
3c6e85
@@ -3247,39 +3257,13 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3c6e85
 		}
3c6e85
 		if (ha->tgt.atio_ring)
3c6e85
 			mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3c6e85
-		/* Allocate memory for Fibre Channel Event Buffer. */
3c6e85
-		if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3c6e85
-		    !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3c6e85
-			goto try_eft;
3c6e85
 
3c6e85
-		fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3c6e85
-try_eft:
3c6e85
+		qla2x00_init_fce_trace(vha);
3c6e85
+		if (ha->fce)
3c6e85
+			fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3c6e85
+		qla2x00_init_eft_trace(vha);
3c6e85
 		if (ha->eft)
3c6e85
-			dma_free_coherent(&ha->pdev->dev,
3c6e85
-			    EFT_SIZE, ha->eft, ha->eft_dma);
3c6e85
-
3c6e85
-		/* Allocate memory for Extended Trace Buffer. */
3c6e85
-		tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3c6e85
-					 GFP_KERNEL);
3c6e85
-		if (!tc) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00c1,
3c6e85
-			    "Unable to allocate (%d KB) for EFT.\n",
3c6e85
-			    EFT_SIZE / 1024);
3c6e85
-			goto allocate;
3c6e85
-		}
3c6e85
-
3c6e85
-		rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3c6e85
-		if (rval) {
3c6e85
-			ql_log(ql_log_warn, vha, 0x00c2,
3c6e85
-			    "Unable to initialize EFT (%d).\n", rval);
3c6e85
-			dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3c6e85
-			    tc_dma);
3c6e85
-		}
3c6e85
-		ql_dbg(ql_dbg_init, vha, 0x00c3,
3c6e85
-		    "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3c6e85
-		eft_size = EFT_SIZE;
3c6e85
-		ha->eft_dma = tc_dma;
3c6e85
-		ha->eft = tc;
3c6e85
+			eft_size = EFT_SIZE;
3c6e85
 	}
3c6e85
 
3c6e85
 	if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3c6e85
@@ -3301,24 +3285,22 @@ try_eft:
3c6e85
 			    j, fwdt->dump_size);
3c6e85
 			dump_size += fwdt->dump_size;
3c6e85
 		}
3c6e85
-		goto allocate;
3c6e85
+	} else {
3c6e85
+		req_q_size = req->length * sizeof(request_t);
3c6e85
+		rsp_q_size = rsp->length * sizeof(response_t);
3c6e85
+		dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3c6e85
+		dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3c6e85
+			+ eft_size;
3c6e85
+		ha->chain_offset = dump_size;
3c6e85
+		dump_size += mq_size + fce_size;
3c6e85
+		if (ha->exchoffld_buf)
3c6e85
+			dump_size += sizeof(struct qla2xxx_offld_chain) +
3c6e85
+				ha->exchoffld_size;
3c6e85
+		if (ha->exlogin_buf)
3c6e85
+			dump_size += sizeof(struct qla2xxx_offld_chain) +
3c6e85
+				ha->exlogin_size;
3c6e85
 	}
3c6e85
 
3c6e85
-	req_q_size = req->length * sizeof(request_t);
3c6e85
-	rsp_q_size = rsp->length * sizeof(response_t);
3c6e85
-	dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3c6e85
-	dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3c6e85
-	ha->chain_offset = dump_size;
3c6e85
-	dump_size += mq_size + fce_size;
3c6e85
-
3c6e85
-	if (ha->exchoffld_buf)
3c6e85
-		dump_size += sizeof(struct qla2xxx_offld_chain) +
3c6e85
-			ha->exchoffld_size;
3c6e85
-	if (ha->exlogin_buf)
3c6e85
-		dump_size += sizeof(struct qla2xxx_offld_chain) +
3c6e85
-			ha->exlogin_size;
3c6e85
-
3c6e85
-allocate:
3c6e85
 	if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3c6e85
 
3c6e85
 		ql_dbg(ql_dbg_init, vha, 0x00c5,
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
index 542a97d713cc..0eb37e0a8985 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_os.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
@@ -4740,6 +4740,7 @@ qla2x00_free_fw_dump(struct qla_hw_data *ha)
3c6e85
 
3c6e85
 	ha->fce = NULL;
3c6e85
 	ha->fce_dma = 0;
3c6e85
+	ha->flags.fce_enabled = 0;
3c6e85
 	ha->eft = NULL;
3c6e85
 	ha->eft_dma = 0;
3c6e85
 	ha->fw_dumped = 0;
3c6e85
-- 
3c6e85
2.13.6
3c6e85