diff mbox series

[08/14] scsi: qla4xxx: qla4_82xx_rom_lock(): Remove in_interrupt().

Message ID 20201126132952.2287996-9-bigeasy@linutronix.de
State New
Headers show
Series scsi: Remove in_interrupt() usage. | expand

Commit Message

Sebastian Andrzej Siewior Nov. 26, 2020, 1:29 p.m. UTC
From: "Ahmed S. Darwish" <a.darwish@linutronix.de>

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

While in_interrupt() is ill-defined and does not provide what the name
suggests, it is not needed here: qla4_82xx_rom_lock() is always called
from process context. Below is an analysis of its callers:

  - ql4_nx.c: qla4_82xx_rom_fast_read(), all process context callers:
    => ql4_nx.c: qla4_82xx_pinit_from_rom(), GFP_KERNEL allocation
    => ql4_nx.c: qla4_82xx_load_from_flash(), msleep() in a loop

  - ql4_nx.c: qla4_82xx_pinit_from_rom(), earlier discussed

  - ql4_nx.c: qla4_82xx_rom_lock_recovery(), bound to "isp_operations"
    ->rom_lock_recovery() hook, which has one process context caller,
    qla4_8xxx_device_bootstrap(), with callers:
      => ql4_83xx.c: qla4_83xx_need_reset_handler(), process, msleep()
      => ql4_nx.c: qla4_8xxx_device_state_handler(), multiple msleep()s

  - ql4_nx.c: qla4_82xx_read_flash_data(), has cond_resched()

Remove the in_interrupt() check. Mark, qla4_82xx_rom_lock(), and the
->rom_lock_recovery() hook, with "Context: task, can sleep".

Change qla4_82xx_rom_lock() implementation to sleep 20ms, instead of a
schedule(), for each spin. This is more deterministic, and it matches
the other implementations bound to ->rom_lock_recovery().

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_def.h |  2 +-
 drivers/scsi/qla4xxx/ql4_nx.c  | 16 ++++++----------
 2 files changed, 7 insertions(+), 11 deletions(-)

Comments

Daniel Wagner Nov. 30, 2020, 2:33 p.m. UTC | #1
On Thu, Nov 26, 2020 at 02:29:46PM +0100, Sebastian Andrzej Siewior wrote:
> From: "Ahmed S. Darwish" <a.darwish@linutronix.de>

> 

> qla4_82xx_rom_lock() spins on a certain hardware state until it is

> updated. At the end of each spin, if in_interrupt() is true, it does 20

> loops of cpu_relax(). Otherwise, it yields the CPU.

> 

> While in_interrupt() is ill-defined and does not provide what the name

> suggests, it is not needed here: qla4_82xx_rom_lock() is always called

> from process context. Below is an analysis of its callers:

> 

>   - ql4_nx.c: qla4_82xx_rom_fast_read(), all process context callers:

>     => ql4_nx.c: qla4_82xx_pinit_from_rom(), GFP_KERNEL allocation

>     => ql4_nx.c: qla4_82xx_load_from_flash(), msleep() in a loop

> 

>   - ql4_nx.c: qla4_82xx_pinit_from_rom(), earlier discussed

> 

>   - ql4_nx.c: qla4_82xx_rom_lock_recovery(), bound to "isp_operations"

>     ->rom_lock_recovery() hook, which has one process context caller,

>     qla4_8xxx_device_bootstrap(), with callers:

>       => ql4_83xx.c: qla4_83xx_need_reset_handler(), process, msleep()

>       => ql4_nx.c: qla4_8xxx_device_state_handler(), multiple msleep()s

> 

>   - ql4_nx.c: qla4_82xx_read_flash_data(), has cond_resched()

> 

> Remove the in_interrupt() check. Mark, qla4_82xx_rom_lock(), and the

> ->rom_lock_recovery() hook, with "Context: task, can sleep".

> 

> Change qla4_82xx_rom_lock() implementation to sleep 20ms, instead of a

> schedule(), for each spin. This is more deterministic, and it matches

> the other implementations bound to ->rom_lock_recovery().

> 

> 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>


Reviewed-by: Daniel Wagner <dwagner@suse.de>
diff mbox series

Patch

diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
index 9210547483886..031569c496e57 100644
--- a/drivers/scsi/qla4xxx/ql4_def.h
+++ b/drivers/scsi/qla4xxx/ql4_def.h
@@ -437,7 +437,7 @@  struct isp_operations {
 	int (*wr_reg_indirect) (struct scsi_qla_host *, uint32_t, uint32_t);
 	int (*idc_lock) (struct scsi_qla_host *); /* Context: task, can sleep */
 	void (*idc_unlock) (struct scsi_qla_host *);
-	void (*rom_lock_recovery) (struct scsi_qla_host *);
+	void (*rom_lock_recovery) (struct scsi_qla_host *); /* Context: task, can sleep */
 	void (*queue_mailbox_command) (struct scsi_qla_host *, uint32_t *, int);
 	void (*process_mailbox_interrupt) (struct scsi_qla_host *, int);
 };
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index 4362d0ebe0e15..fd30fbd0d33cb 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -871,15 +871,18 @@  qla4_82xx_decode_crb_addr(unsigned long addr)
 static long rom_max_timeout = 100;
 static long qla4_82xx_rom_lock_timeout = 100;
 
+/*
+ * Context: task, can_sleep
+ */
 static int
 qla4_82xx_rom_lock(struct scsi_qla_host *ha)
 {
-	int i;
 	int done = 0, timeout = 0;
 
+	might_sleep();
+
 	while (!done) {
 		/* acquire semaphore2 from PCI HW block */
-
 		done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK));
 		if (done == 1)
 			break;
@@ -887,14 +890,7 @@  qla4_82xx_rom_lock(struct scsi_qla_host *ha)
 			return -1;
 
 		timeout++;
-
-		/* Yield CPU */
-		if (!in_interrupt())
-			schedule();
-		else {
-			for (i = 0; i < 20; i++)
-				cpu_relax();    /*This a nop instr on i386*/
-		}
+		msleep(20);
 	}
 	qla4_82xx_wr_32(ha, QLA82XX_ROM_LOCK_ID, ROM_LOCK_DRIVER);
 	return 0;