Blame SOURCES/0031-scsi-scsi-qla2xxx-Fix-routine-qla27xx_dump_-mpi-ram.patch

3c6e85
From 47f61786dc2bbf5f0c95248ac91e7855e5a89272 Mon Sep 17 00:00:00 2001
3c6e85
From: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Date: Thu, 1 Aug 2019 15:54:51 -0400
3c6e85
Subject: [PATCH 031/124] [scsi] scsi: qla2xxx: Fix routine
3c6e85
 qla27xx_dump_{mpi|ram}()
3c6e85
3c6e85
Message-id: <20190801155618.12650-32-hmadhani@redhat.com>
3c6e85
Patchwork-id: 267804
3c6e85
O-Subject: [RHEL 7.8 e-stor PATCH 031/118] scsi: qla2xxx: Fix routine qla27xx_dump_{mpi|ram}()
3c6e85
Bugzilla: 1729270
3c6e85
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
3c6e85
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
3c6e85
3c6e85
From: Joe Carnuccio <joe.carnuccio@cavium.com>
3c6e85
3c6e85
Bugzilla 1729270
3c6e85
3c6e85
This patch fixes qla27xx_dump_{mpi|ram} api for ISP27XX.
3c6e85
3c6e85
Signed-off-by: Joe Carnuccio <joe.carnuccio@cavium.com>
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
3c6e85
(cherry picked from commit 24ef8f7eb5d03480e09ce28f0bb905398a0d57c8)
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Signed-off-by: Jan Stancek <jstancek@redhat.com>
3c6e85
---
3c6e85
 drivers/scsi/qla2xxx/qla_dbg.c | 166 ++++++++++++++++++++---------------------
3c6e85
 1 file changed, 81 insertions(+), 85 deletions(-)
3c6e85
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
3c6e85
index 5e5ab360fc44..fa4d8fe9c41d 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_dbg.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
3c6e85
@@ -112,30 +112,25 @@ int
3c6e85
 qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
3c6e85
 	uint32_t ram_dwords, void **nxt)
3c6e85
 {
3c6e85
-	int rval;
3c6e85
-	uint32_t cnt, stat, timer, dwords, idx;
3c6e85
-	uint16_t mb0;
3c6e85
 	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3c6e85
 	dma_addr_t dump_dma = ha->gid_list_dma;
3c6e85
-	uint32_t *dump = (uint32_t *)ha->gid_list;
3c6e85
+	uint32_t *chunk = (void *)ha->gid_list;
3c6e85
+	uint32_t dwords = qla2x00_gid_list_size(ha) / 4;
3c6e85
+	uint32_t stat;
3c6e85
+	ulong i, j, timer = 6000000;
3c6e85
+	int rval = QLA_FUNCTION_FAILED;
3c6e85
 
3c6e85
-	rval = QLA_SUCCESS;
3c6e85
-	mb0 = 0;
3c6e85
-
3c6e85
-	WRT_REG_WORD(&reg->mailbox0, MBC_LOAD_DUMP_MPI_RAM);
3c6e85
 	clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
3c6e85
+	for (i = 0; i < ram_dwords; i += dwords, addr += dwords) {
3c6e85
+		if (i + dwords > ram_dwords)
3c6e85
+			dwords = ram_dwords - i;
3c6e85
 
3c6e85
-	dwords = qla2x00_gid_list_size(ha) / 4;
3c6e85
-	for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
3c6e85
-	    cnt += dwords, addr += dwords) {
3c6e85
-		if (cnt + dwords > ram_dwords)
3c6e85
-			dwords = ram_dwords - cnt;
3c6e85
-
3c6e85
+		WRT_REG_WORD(&reg->mailbox0, MBC_LOAD_DUMP_MPI_RAM);
3c6e85
 		WRT_REG_WORD(&reg->mailbox1, LSW(addr));
3c6e85
 		WRT_REG_WORD(&reg->mailbox8, MSW(addr));
3c6e85
 
3c6e85
-		WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
3c6e85
-		WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
3c6e85
+		WRT_REG_WORD(&reg->mailbox2, MSW(LSD(dump_dma)));
3c6e85
+		WRT_REG_WORD(&reg->mailbox3, LSW(LSD(dump_dma)));
3c6e85
 		WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
3c6e85
 		WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
3c6e85
 
3c6e85
@@ -146,76 +141,75 @@ qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
3c6e85
 		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
3c6e85
 
3c6e85
 		ha->flags.mbox_int = 0;
3c6e85
-		for (timer = 6000000; timer; timer--) {
3c6e85
-			/* Check for pending interrupts. */
3c6e85
-			stat = RD_REG_DWORD(&reg->host_status);
3c6e85
-			if (stat & HSRX_RISC_INT) {
3c6e85
-				stat &= 0xff;
3c6e85
-
3c6e85
-				if (stat == 0x1 || stat == 0x2 ||
3c6e85
-				    stat == 0x10 || stat == 0x11) {
3c6e85
-					set_bit(MBX_INTERRUPT,
3c6e85
-					    &ha->mbx_cmd_flags);
3c6e85
+		while (timer--) {
3c6e85
+			udelay(5);
3c6e85
 
3c6e85
-					mb0 = RD_REG_WORD(&reg->mailbox0);
3c6e85
-					RD_REG_WORD(&reg->mailbox1);
3c6e85
+			stat = RD_REG_DWORD(&reg->host_status);
3c6e85
+			/* Check for pending interrupts. */
3c6e85
+			if (!(stat & HSRX_RISC_INT))
3c6e85
+				continue;
3c6e85
 
3c6e85
-					WRT_REG_DWORD(&reg->hccr,
3c6e85
-					    HCCRX_CLR_RISC_INT);
3c6e85
-					RD_REG_DWORD(&reg->hccr);
3c6e85
-					break;
3c6e85
-				}
3c6e85
+			stat &= 0xff;
3c6e85
+			if (stat != 0x1 && stat != 0x2 &&
3c6e85
+			    stat != 0x10 && stat != 0x11) {
3c6e85
 
3c6e85
 				/* Clear this intr; it wasn't a mailbox intr */
3c6e85
 				WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3c6e85
 				RD_REG_DWORD(&reg->hccr);
3c6e85
+				continue;
3c6e85
 			}
3c6e85
-			udelay(5);
3c6e85
+
3c6e85
+			set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
3c6e85
+			rval = RD_REG_WORD(&reg->mailbox0) & MBS_MASK;
3c6e85
+			WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3c6e85
+			RD_REG_DWORD(&reg->hccr);
3c6e85
+			break;
3c6e85
 		}
3c6e85
 		ha->flags.mbox_int = 1;
3c6e85
+		*nxt = ram + i;
3c6e85
 
3c6e85
-		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
3c6e85
-			rval = mb0 & MBS_MASK;
3c6e85
-			for (idx = 0; idx < dwords; idx++)
3c6e85
-				ram[cnt + idx] = IS_QLA27XX(ha) ?
3c6e85
-				    le32_to_cpu(dump[idx]) : swab32(dump[idx]);
3c6e85
-		} else {
3c6e85
-			rval = QLA_FUNCTION_FAILED;
3c6e85
+		if (!test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
3c6e85
+			/* no interrupt, timed out*/
3c6e85
+			return rval;
3c6e85
+		}
3c6e85
+		if (rval) {
3c6e85
+			/* error completion status */
3c6e85
+			return rval;
3c6e85
+		}
3c6e85
+		for (j = 0; j < dwords; j++) {
3c6e85
+			ram[i + j] = IS_QLA27XX(ha) ?
3c6e85
+			    chunk[j] : swab32(chunk[j]);
3c6e85
 		}
3c6e85
 	}
3c6e85
 
3c6e85
-	*nxt = rval == QLA_SUCCESS ? &ram[cnt] : NULL;
3c6e85
-	return rval;
3c6e85
+	*nxt = ram + i;
3c6e85
+	return QLA_SUCCESS;
3c6e85
 }
3c6e85
 
3c6e85
 int
3c6e85
 qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
3c6e85
     uint32_t ram_dwords, void **nxt)
3c6e85
 {
3c6e85
-	int rval;
3c6e85
-	uint32_t cnt, stat, timer, dwords, idx;
3c6e85
-	uint16_t mb0;
3c6e85
+	int rval = QLA_FUNCTION_FAILED;
3c6e85
 	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3c6e85
 	dma_addr_t dump_dma = ha->gid_list_dma;
3c6e85
-	uint32_t *dump = (uint32_t *)ha->gid_list;
3c6e85
+	uint32_t *chunk = (void *)ha->gid_list;
3c6e85
+	uint32_t dwords = qla2x00_gid_list_size(ha) / 4;
3c6e85
+	uint32_t stat;
3c6e85
+	ulong i, j, timer = 6000000;
3c6e85
 
3c6e85
-	rval = QLA_SUCCESS;
3c6e85
-	mb0 = 0;
3c6e85
-
3c6e85
-	WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
3c6e85
 	clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
3c6e85
 
3c6e85
-	dwords = qla2x00_gid_list_size(ha) / 4;
3c6e85
-	for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
3c6e85
-	    cnt += dwords, addr += dwords) {
3c6e85
-		if (cnt + dwords > ram_dwords)
3c6e85
-			dwords = ram_dwords - cnt;
3c6e85
+	for (i = 0; i < ram_dwords; i += dwords, addr += dwords) {
3c6e85
+		if (i + dwords > ram_dwords)
3c6e85
+			dwords = ram_dwords - i;
3c6e85
 
3c6e85
+		WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
3c6e85
 		WRT_REG_WORD(&reg->mailbox1, LSW(addr));
3c6e85
 		WRT_REG_WORD(&reg->mailbox8, MSW(addr));
3c6e85
 
3c6e85
-		WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
3c6e85
-		WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
3c6e85
+		WRT_REG_WORD(&reg->mailbox2, MSW(LSD(dump_dma)));
3c6e85
+		WRT_REG_WORD(&reg->mailbox3, LSW(LSD(dump_dma)));
3c6e85
 		WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
3c6e85
 		WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
3c6e85
 
3c6e85
@@ -224,45 +218,47 @@ qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
3c6e85
 		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
3c6e85
 
3c6e85
 		ha->flags.mbox_int = 0;
3c6e85
-		for (timer = 6000000; timer; timer--) {
3c6e85
-			/* Check for pending interrupts. */
3c6e85
+		while (timer--) {
3c6e85
+			udelay(5);
3c6e85
 			stat = RD_REG_DWORD(&reg->host_status);
3c6e85
-			if (stat & HSRX_RISC_INT) {
3c6e85
-				stat &= 0xff;
3c6e85
 
3c6e85
-				if (stat == 0x1 || stat == 0x2 ||
3c6e85
-				    stat == 0x10 || stat == 0x11) {
3c6e85
-					set_bit(MBX_INTERRUPT,
3c6e85
-					    &ha->mbx_cmd_flags);
3c6e85
-
3c6e85
-					mb0 = RD_REG_WORD(&reg->mailbox0);
3c6e85
-
3c6e85
-					WRT_REG_DWORD(&reg->hccr,
3c6e85
-					    HCCRX_CLR_RISC_INT);
3c6e85
-					RD_REG_DWORD(&reg->hccr);
3c6e85
-					break;
3c6e85
-				}
3c6e85
+			/* Check for pending interrupts. */
3c6e85
+			if (!(stat & HSRX_RISC_INT))
3c6e85
+				continue;
3c6e85
 
3c6e85
-				/* Clear this intr; it wasn't a mailbox intr */
3c6e85
+			stat &= 0xff;
3c6e85
+			if (stat != 0x1 && stat != 0x2 &&
3c6e85
+			    stat != 0x10 && stat != 0x11) {
3c6e85
 				WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3c6e85
 				RD_REG_DWORD(&reg->hccr);
3c6e85
+				continue;
3c6e85
 			}
3c6e85
-			udelay(5);
3c6e85
+
3c6e85
+			set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
3c6e85
+			rval = RD_REG_WORD(&reg->mailbox0) & MBS_MASK;
3c6e85
+			WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3c6e85
+			RD_REG_DWORD(&reg->hccr);
3c6e85
+			break;
3c6e85
 		}
3c6e85
 		ha->flags.mbox_int = 1;
3c6e85
+		*nxt = ram + i;
3c6e85
 
3c6e85
-		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
3c6e85
-			rval = mb0 & MBS_MASK;
3c6e85
-			for (idx = 0; idx < dwords; idx++)
3c6e85
-				ram[cnt + idx] = IS_QLA27XX(ha) ?
3c6e85
-				    le32_to_cpu(dump[idx]) : swab32(dump[idx]);
3c6e85
-		} else {
3c6e85
-			rval = QLA_FUNCTION_FAILED;
3c6e85
+		if (!test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
3c6e85
+			/* no interrupt, timed out*/
3c6e85
+			return rval;
3c6e85
+		}
3c6e85
+		if (rval) {
3c6e85
+			/* error completion status */
3c6e85
+			return rval;
3c6e85
+		}
3c6e85
+		for (j = 0; j < dwords; j++) {
3c6e85
+			ram[i + j] = IS_QLA27XX(ha) ?
3c6e85
+			    chunk[j] : swab32(chunk[j]);
3c6e85
 		}
3c6e85
 	}
3c6e85
 
3c6e85
-	*nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
3c6e85
-	return rval;
3c6e85
+	*nxt = ram + i;
3c6e85
+	return QLA_SUCCESS;
3c6e85
 }
3c6e85
 
3c6e85
 static int
3c6e85
-- 
3c6e85
2.13.6
3c6e85