linux-m68k.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-scsi@vger.kernel.org
Cc: Finn Thain <fthain@telegraphics.com.au>,
	GR-QLogic-Storage-Upstream@marvell.com,
	Hannes Reinecke <hare@kernel.org>,
	Jack Wang <jinpu.wang@cloud.ionos.com>,
	John Garry <john.garry@huawei.com>,
	linux-m68k@lists.linux-m68k.org,
	Manish Rangankar <mrangankar@marvell.com>,
	Michael Schmitz <schmitzmic@gmail.com>,
	MPT-FusionLinux.pdl@broadcom.com,
	Nilesh Javali <njavali@marvell.com>,
	Sathya Prakash <sathya.prakash@broadcom.com>,
	Sreekanth Reddy <sreekanth.reddy@broadcom.com>,
	Suganath Prabu Subramani  <suganath-prabu.subramani@broadcom.com>,
	Vikram Auradkar <auradkar@google.com>,
	Xiang Chen <chenxiang66@hisilicon.com>,
	Xiaofei Tan <tanxiaofei@huawei.com>,
	"James E . J . Bottomley" <jejb@linux.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Ahmed S . Darwish" <a.darwish@linutronix.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 03/14] scsi: qla4xxx: qla4_82xx_crb_win_lock(): Remove in_interrupt().
Date: Thu, 26 Nov 2020 14:29:41 +0100	[thread overview]
Message-ID: <20201126132952.2287996-4-bigeasy@linutronix.de> (raw)
In-Reply-To: <20201126132952.2287996-1-bigeasy@linutronix.de>

From: "Ahmed S. Darwish" <a.darwish@linutronix.de>

qla4_82xx_crb_win_lock() spins on a certain hardware state until it's
updated. At the end of each spin, if in_interrupt() is true, it does 20
loops of cpu_relax(). Otherwise, it yields the CPU.

The in_interrupt() macro is ill-defined as it does not provide what the
name suggests, and it does not catch the intended use-case here.

qla4_82xx_crb_win_lock() is always invoked with scsi_qla_host::hw_lock
acquired, with disabled interrupts. If the caller is in process context,
as in qla4_82xx_need_reset_handler(), then in_interrupt() will return
false even though it is not allowed to call schedule().

Remove the in_interrupt() check.

Change qla4_82xx_crb_win_lock() specification to a purely atomic
function. Mark it as static, remove its forward declaration, and move it
above its callers. To avoid hammering the PCI bus while spinning, use a
10 micro-second delay instead of cpu_relax().

Fixes: f4f5df23bf72 ("[SCSI] qla4xxx: Added support for ISP82XX")
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Nilesh Javali <njavali@marvell.com>
Cc: Manish Rangankar <mrangankar@marvell.com>
Cc: <GR-QLogic-Storage-Upstream@marvell.com>
---
 drivers/scsi/qla4xxx/ql4_glbl.h |  1 -
 drivers/scsi/qla4xxx/ql4_nx.c   | 63 +++++++++++++++------------------
 2 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index b8f02210aeb03..ea60057b2e20a 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -114,7 +114,6 @@ irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id);
 void qla4_82xx_queue_iocb(struct scsi_qla_host *ha);
 void qla4_82xx_complete_iocb(struct scsi_qla_host *ha);
 
-int qla4_82xx_crb_win_lock(struct scsi_qla_host *);
 void qla4_82xx_crb_win_unlock(struct scsi_qla_host *);
 int qla4_82xx_pci_get_crb_addr_2M(struct scsi_qla_host *, ulong *);
 void qla4_82xx_wr_32(struct scsi_qla_host *, ulong, u32);
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index f1767b21076f7..da903a545b2c0 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -375,6 +375,35 @@ qla4_82xx_pci_set_crbwindow_2M(struct scsi_qla_host *ha, ulong *off)
 	*off = (*off & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
 }
 
+#define CRB_WIN_LOCK_TIMEOUT 100000000
+
+/*
+ * Context: atomic
+ */
+static int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha)
+{
+	int done = 0, timeout = 0;
+
+	while (!done) {
+		/* acquire semaphore3 from PCI HW block */
+		done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK));
+		if (done == 1)
+			break;
+		if (timeout >= CRB_WIN_LOCK_TIMEOUT)
+			return -1;
+
+		timeout++;
+		udelay(10);
+	}
+	qla4_82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num);
+	return 0;
+}
+
+void qla4_82xx_crb_win_unlock(struct scsi_qla_host *ha)
+{
+	qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
+}
+
 void
 qla4_82xx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data)
 {
@@ -475,40 +504,6 @@ int qla4_82xx_md_wr_32(struct scsi_qla_host *ha, uint32_t off, uint32_t data)
 	return rval;
 }
 
-#define CRB_WIN_LOCK_TIMEOUT 100000000
-
-int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha)
-{
-	int i;
-	int done = 0, timeout = 0;
-
-	while (!done) {
-		/* acquire semaphore3 from PCI HW block */
-		done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK));
-		if (done == 1)
-			break;
-		if (timeout >= CRB_WIN_LOCK_TIMEOUT)
-			return -1;
-
-		timeout++;
-
-		/* Yield CPU */
-		if (!in_interrupt())
-			schedule();
-		else {
-			for (i = 0; i < 20; i++)
-				cpu_relax();    /*This a nop instr on i386*/
-		}
-	}
-	qla4_82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num);
-	return 0;
-}
-
-void qla4_82xx_crb_win_unlock(struct scsi_qla_host *ha)
-{
-	qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
-}
-
 #define IDC_LOCK_TIMEOUT 100000000
 
 /**
-- 
2.29.2


  parent reply	other threads:[~2020-11-26 13:30 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 13:29 [PATCH 00/14] scsi: Remove in_interrupt() usage Sebastian Andrzej Siewior
2020-11-26 13:29 ` [PATCH 01/14] scsi: pm80xx: Do not sleep in atomic context Sebastian Andrzej Siewior
2020-11-26 13:58   ` Jinpu Wang
2020-11-26 13:29 ` [PATCH 02/14] scsi: hisi_sas: Remove preemptible() Sebastian Andrzej Siewior
2020-11-26 14:10   ` John Garry
2020-11-26 13:29 ` Sebastian Andrzej Siewior [this message]
2020-11-30 13:54   ` [PATCH 03/14] scsi: qla4xxx: qla4_82xx_crb_win_lock(): Remove in_interrupt() Daniel Wagner
2020-11-26 13:29 ` [PATCH 04/14] scsi: qla2xxx: qla82xx: " Sebastian Andrzej Siewior
2020-11-30 10:59   ` Daniel Wagner
2020-11-30 19:11   ` Himanshu Madhani
2020-11-26 13:29 ` [PATCH 05/14] scsi: qla2xxx: tcm_qla2xxx: Remove BUG_ON(in_interrupt()) Sebastian Andrzej Siewior
2020-11-30 11:02   ` Daniel Wagner
2020-11-30 19:13   ` Himanshu Madhani
2020-11-26 13:29 ` [PATCH 06/14] scsi: qla2xxx: init/os: Remove in_interrupt() Sebastian Andrzej Siewior
2020-11-30 13:26   ` Daniel Wagner
2020-11-30 19:14   ` Himanshu Madhani
2020-11-26 13:29 ` [PATCH 07/14] scsi: qla4xxx: qla4_82xx_idc_lock(): " Sebastian Andrzej Siewior
2020-11-30 14:20   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 08/14] scsi: qla4xxx: qla4_82xx_rom_lock(): " Sebastian Andrzej Siewior
2020-11-30 14:33   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 09/14] scsi: mpt3sas: " Sebastian Andrzej Siewior
2020-11-30 15:16   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 10/14] scsi: myrb: Remove WARN_ON(in_interrupt()) Sebastian Andrzej Siewior
2020-11-30 15:21   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 11/14] scsi: myrs: " Sebastian Andrzej Siewior
2020-11-30 15:21   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 12/14] scsi: NCR5380: Remove in_interrupt() Sebastian Andrzej Siewior
2020-11-27  4:37   ` Finn Thain
2020-11-27 21:15     ` Finn Thain
2020-11-27 21:48       ` Finn Thain
2020-11-28  7:28         ` Ahmed S. Darwish
2020-11-30  0:21           ` Finn Thain
2020-11-29  6:54         ` Michael Schmitz
2020-11-30  0:15           ` Finn Thain
2020-11-30  2:42             ` Michael Schmitz
2020-11-26 13:29 ` [PATCH 13/14] scsi: message: fusion: Remove in_interrupt() usage in mpt_config() Sebastian Andrzej Siewior
2020-11-30 15:30   ` Daniel Wagner
2020-11-26 13:29 ` [PATCH 14/14] scsi: message: fusion: Remove in_interrupt() usage in mptsas_cleanup_fw_event_q() Sebastian Andrzej Siewior
2020-11-30 16:07   ` Daniel Wagner
2020-12-01  5:06 ` [PATCH 00/14] scsi: Remove in_interrupt() usage Martin K. Petersen
2020-12-01  9:08   ` Sebastian Andrzej Siewior
2020-12-08  4:51 ` Martin K. Petersen

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=20201126132952.2287996-4-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=MPT-FusionLinux.pdl@broadcom.com \
    --cc=a.darwish@linutronix.de \
    --cc=auradkar@google.com \
    --cc=chenxiang66@hisilicon.com \
    --cc=fthain@telegraphics.com.au \
    --cc=hare@kernel.org \
    --cc=jejb@linux.ibm.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=john.garry@huawei.com \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mrangankar@marvell.com \
    --cc=njavali@marvell.com \
    --cc=sathya.prakash@broadcom.com \
    --cc=schmitzmic@gmail.com \
    --cc=sreekanth.reddy@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.com \
    --cc=tanxiaofei@huawei.com \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).