Skip to contentSkip to conversation

mac_esp, zorro_esp, esp_scsi: Various improvements

PATCH Superseded Finn Thain 4 participants 16 messages Oct 13, 2018 – Oct 15, 2018 SCSI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Finn Thain

author
#0 lore raw

cover mac_esp, zorro_esp, esp_scsi: Various improvements

This series has fixes and cleanup for mac_esp, zorro_esp and the core esp_scsi driver.

The improvements include elimination of duplicated code temporarily introduced for zorro_esp.

Michael, would you please regression test this series on elgar, if convenient? So far, only mac_esp has been tested with this code.

Finn Thain (6):
zorro_esp: Limit DMA transfers to 65535 bytes
esp_scsi: Track residual for PIO transfers
esp_scsi: Grant disconnect privilege for untagged commands
esp_scsi: Eliminate ESP_FLAG_DOING_SLOWCMD
esp_scsi: De-duplicate PIO routines
esp_scsi: Optimize PIO loops

 drivers/scsi/esp_scsi.c  | 192 +++++++++++++++++++++++++++++--------
 drivers/scsi/esp_scsi.h  |  10 +-
 drivers/scsi/mac_esp.c   | 171 ++-------------------------------
 drivers/scsi/zorro_esp.c | 240 +++++++----------------------------------------
 4 files changed, 201 insertions(+), 412 deletions(-)
Signature · 1 line
2.16.4
author
#1 lore raw

PATCH 1/6 zorro_esp: Limit DMA transfers to 65535 bytes

The core driver, esp_scsi, does not use the ESP_CONFIG2_FENAB bit, so the chip's Transfer Counter register is only 16 bits wide (not 24). A larger transfer cannot work and will theoretically result in a failed command and a "DMA length is zero" error.

Fixes 3109e5ae0311
Cc Michael Schmitz <[email protected]>
---
 drivers/scsi/zorro_esp.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/scsi/zorro_esp.c +1 -7
index bb70882e6b56..be79127db594 100644
@@ -245,7 +245,7 @@ static int fastlane_esp_irq_pending(struct esp *esp)
 static u32 zorro_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
 					u32 dma_len)
 {
-	return dma_len > 0xFFFFFF ? 0xFFFFFF : dma_len;
+	return dma_len > 0xFFFF ? 0xFFFF : dma_len;
 }
 
 static void zorro_esp_reset_dma(struct esp *esp)
@@ -484,7 +484,6 @@ static void zorro_esp_send_blz1230_dma_cmd(struct esp *esp, u32 addr,
 	scsi_esp_cmd(esp, ESP_CMD_DMA);
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	scsi_esp_cmd(esp, cmd);
 }
@@ -529,7 +528,6 @@ static void zorro_esp_send_blz1230II_dma_cmd(struct esp *esp, u32 addr,
 	scsi_esp_cmd(esp, ESP_CMD_DMA);
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	scsi_esp_cmd(esp, cmd);
 }
@@ -574,7 +572,6 @@ static void zorro_esp_send_blz2060_dma_cmd(struct esp *esp, u32 addr,
 	scsi_esp_cmd(esp, ESP_CMD_DMA);
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	scsi_esp_cmd(esp, cmd);
 }
@@ -599,7 +596,6 @@ static void zorro_esp_send_cyber_dma_cmd(struct esp *esp, u32 addr,
 
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	if (write) {
 		/* DMA receive */
@@ -649,7 +645,6 @@ static void zorro_esp_send_cyberII_dma_cmd(struct esp *esp, u32 addr,
 
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	if (write) {
 		/* DMA receive */
@@ -691,7 +686,6 @@ static void zorro_esp_send_fastlane_dma_cmd(struct esp *esp, u32 addr,
 
 	zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
 	zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-	zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
 
 	if (write) {
 		/* DMA receive */
Signature · 1 line
2.16.4
author
#2 lore raw

PATCH 2/6 esp_scsi: Track residual for PIO transfers

In reply to Finn Thain

If a target disconnects during a PIO data transfer the command may fail when the target reconnects:

scsi host1: DMA length is zero!
scsi host1: cur adr[04380000] len[00000000]

The scsi bus is then reset. This happens because the residual reached zero before the transfer was completed.

The usual residual calculation relies on the Transfer Count registers which works for DMA transfers but not for PIO transfers. Fix the problem by storing the PIO transfer residual and using that to correctly calculate bytes_sent.

---
 drivers/scsi/esp_scsi.c | 1 +
 drivers/scsi/esp_scsi.h | 2 ++
 drivers/scsi/mac_esp.c  | 2 ++
 3 files changed, 5 insertions(+)
drivers/scsi/esp_scsi.c +1 -0
index c3fc34b9964d..9e5d3f7d29ae 100644
@@ -1338,6 +1338,7 @@ static int esp_data_bytes_sent(struct esp *esp, struct esp_cmd_entry *ent,
 
 	bytes_sent = esp->data_dma_len;
 	bytes_sent -= ecount;
+	bytes_sent -= esp->send_cmd_residual;
 
 	/*
 	 * The am53c974 has a DMA 'pecularity'. The doc states:
drivers/scsi/esp_scsi.h +2 -0
index 8163dca2071b..db4b6ea94caa 100644
@@ -540,6 +540,8 @@ struct esp {
 
 	void			*dma;
 	int			dmarev;
+
+	int			send_cmd_residual;
 };
 
 /* A front-end driver for the ESP chip should do the following in
drivers/scsi/mac_esp.c +2 -0
index eb551f3cc471..71879f2207e0 100644
@@ -427,6 +427,8 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			scsi_esp_cmd(esp, ESP_CMD_TI);
 		}
 	}
+
+	esp->send_cmd_residual = esp_count;
 }
 
 static int mac_esp_irq_pending(struct esp *esp)
Signature · 1 line
2.16.4
author
#3 lore raw

PATCH 3/6 esp_scsi: Grant disconnect privilege for untagged commands

In reply to Finn Thain

A SCSI device is not granted disconnect privilege by an esp_scsi host unless that device has its simple_tags flag set. However, a device may support disconnect/reselect and not support command queueing. Allow these devices to disconnect and improve bus utilization.

---
 drivers/scsi/esp_scsi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/scsi/esp_scsi.c +2 -6
index 9e5d3f7d29ae..b7c41aa9927c 100644
@@ -800,13 +800,9 @@ static void esp_maybe_execute_command(struct esp *esp)
 
 build_identify:
 	/* If we don't have a lun-data struct yet, we're probing
-	 * so do not disconnect.  Also, do not disconnect unless
-	 * we have a tag on this command.
+	 * so do not disconnect.
 	 */
-	if (lp && (tp->flags & ESP_TGT_DISCONNECT) && ent->tag[0])
-		*p++ = IDENTIFY(1, lun);
-	else
-		*p++ = IDENTIFY(0, lun);
+	*p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);
 
 	if (ent->tag[0] && esp->rev == ESP100) {
 		/* ESP100 lacks select w/atn3 command, use select
Signature · 1 line
2.16.4
author
#4 lore raw

PATCH 4/6 esp_scsi: Eliminate ESP_FLAG_DOING_SLOWCMD

In reply to Finn Thain

The concept of a 'slow command' as it appears in esp_scsi is confusing because it could refer to an ESP command or a SCSI command. It turns out that it refers to a particular ESP select command which the driver also tracks as 'ESP_SELECT_MSGOUT'. For readability, it is better to use the terminology from the datasheets.

The global ESP_FLAG_DOING_SLOWCMD flag is redundant anyway, as it can be inferred from esp->select_state. Remove the ESP_FLAG_DOING_SLOWCMD cruft and just use a boolean local variable.

---
 drivers/scsi/esp_scsi.c | 57 ++++++++++++++++++++-----------------------------
 drivers/scsi/esp_scsi.h |  3 +--
 2 files changed, 24 insertions(+), 36 deletions(-)
drivers/scsi/esp_scsi.c +23 -34
index b7c41aa9927c..6ccaf818357e 100644
@@ -478,17 +478,6 @@ static void esp_restore_pointers(struct esp *esp, struct esp_cmd_entry *ent)
 	spriv->tot_residue = ent->saved_tot_residue;
 }
 
-static void esp_check_command_len(struct esp *esp, struct scsi_cmnd *cmd)
-{
-	if (cmd->cmd_len == 6 ||
-	    cmd->cmd_len == 10 ||
-	    cmd->cmd_len == 12) {
-		esp->flags &= ~ESP_FLAG_DOING_SLOWCMD;
-	} else {
-		esp->flags |= ESP_FLAG_DOING_SLOWCMD;
-	}
-}
-
 static void esp_write_tgt_config3(struct esp *esp, int tgt)
 {
 	if (esp->rev > ESP100A) {
@@ -721,6 +710,7 @@ static void esp_maybe_execute_command(struct esp *esp)
 	struct scsi_device *dev;
 	struct scsi_cmnd *cmd;
 	struct esp_cmd_entry *ent;
+	bool select_and_stop = false;
 	int tgt, lun, i;
 	u32 val, start_cmd;
 	u8 *p;
@@ -752,7 +742,8 @@ static void esp_maybe_execute_command(struct esp *esp)
 	esp_map_dma(esp, cmd);
 	esp_save_pointers(esp, ent);
 
-	esp_check_command_len(esp, cmd);
+	if (!(cmd->cmd_len == 6 || cmd->cmd_len == 10 || cmd->cmd_len == 12))
+		select_and_stop = true;
 
 	p = esp->command_block;
 
@@ -793,9 +784,9 @@ static void esp_maybe_execute_command(struct esp *esp)
 			tp->flags &= ~ESP_TGT_CHECK_NEGO;
 		}
 
-		/* Process it like a slow command.  */
-		if (tp->flags & (ESP_TGT_NEGO_WIDE | ESP_TGT_NEGO_SYNC))
-			esp->flags |= ESP_FLAG_DOING_SLOWCMD;
+		/* If there are multiple message bytes, use Select and Stop */
+		if (esp->msg_out_len)
+			select_and_stop = true;
 	}
 
 build_identify:
@@ -808,23 +799,10 @@ static void esp_maybe_execute_command(struct esp *esp)
 		/* ESP100 lacks select w/atn3 command, use select
 		 * and stop instead.
 		 */
-		esp->flags |= ESP_FLAG_DOING_SLOWCMD;
+		select_and_stop = true;
 	}
 
-	if (!(esp->flags & ESP_FLAG_DOING_SLOWCMD)) {
-		start_cmd = ESP_CMD_SELA;
-		if (ent->tag[0]) {
-			*p++ = ent->tag[0];
-			*p++ = ent->tag[1];
-
-			start_cmd = ESP_CMD_SA3;
-		}
-
-		for (i = 0; i < cmd->cmd_len; i++)
-			*p++ = cmd->cmnd[i];
-
-		esp->select_state = ESP_SELECT_BASIC;
-	} else {
+	if (select_and_stop) {
 		esp->cmd_bytes_left = cmd->cmd_len;
 		esp->cmd_bytes_ptr = &cmd->cmnd[0];
 
@@ -839,6 +817,19 @@ static void esp_maybe_execute_command(struct esp *esp)
 
 		start_cmd = ESP_CMD_SELAS;
 		esp->select_state = ESP_SELECT_MSGOUT;
+	} else {
+		start_cmd = ESP_CMD_SELA;
+		if (ent->tag[0]) {
+			*p++ = ent->tag[0];
+			*p++ = ent->tag[1];
+
+			start_cmd = ESP_CMD_SA3;
+		}
+
+		for (i = 0; i < cmd->cmd_len; i++)
+			*p++ = cmd->cmnd[i];
+
+		esp->select_state = ESP_SELECT_BASIC;
 	}
 	val = tgt;
 	if (esp->rev == FASHME)
@@ -1248,7 +1239,6 @@ static int esp_finish_select(struct esp *esp)
 			esp_unmap_dma(esp, cmd);
 			esp_free_lun_tag(ent, cmd->device->hostdata);
 			tp->flags &= ~(ESP_TGT_NEGO_SYNC | ESP_TGT_NEGO_WIDE);
-			esp->flags &= ~ESP_FLAG_DOING_SLOWCMD;
 			esp->cmd_bytes_ptr = NULL;
 			esp->cmd_bytes_left = 0;
 		} else {
@@ -1299,9 +1289,8 @@ static int esp_finish_select(struct esp *esp)
 				esp_flush_fifo(esp);
 		}
 
-		/* If we are doing a slow command, negotiation, etc.
-		 * we'll do the right thing as we transition to the
-		 * next phase.
+		/* If we are doing a Select And Stop command, negotiation, etc.
+		 * we'll do the right thing as we transition to the next phase.
 		 */
 		esp_event(esp, ESP_EVENT_CHECK_PHASE);
 		return 0;
drivers/scsi/esp_scsi.h +1 -2
index db4b6ea94caa..d0c032803749 100644
@@ -490,7 +490,6 @@ struct esp {
 	u32			flags;
 #define ESP_FLAG_DIFFERENTIAL	0x00000001
 #define ESP_FLAG_RESETTING	0x00000002
-#define ESP_FLAG_DOING_SLOWCMD	0x00000004
 #define ESP_FLAG_WIDE_CAPABLE	0x00000008
 #define ESP_FLAG_QUICKIRQ_CHECK	0x00000010
 #define ESP_FLAG_DISABLE_SYNC	0x00000020
@@ -532,7 +531,7 @@ struct esp {
 	u32			min_period;
 	u32			radelay;
 
-	/* Slow command state.  */
+	/* ESP_CMD_SELAS command state */
 	u8			*cmd_bytes_ptr;
 	int			cmd_bytes_left;
 
Signature · 1 line
2.16.4
author
#5 lore raw

PATCH 5/6 esp_scsi: De-duplicate PIO routines

In reply to Finn Thain

As a temporary measure, the code to implement PIO transfers was duplicated in zorro_esp and mac_esp. Now that this code has stabilized, move it into the core driver to eliminate the duplication.

This replaces the inline assembler with more portable writesb() calls. Optimizing the m68k writesb() implementation is a separate patch.

---
 drivers/scsi/esp_scsi.c  | 126 +++++++++++++++++++++++++
 drivers/scsi/esp_scsi.h  |   5 +
 drivers/scsi/mac_esp.c   | 173 ++---------------------------------
 drivers/scsi/zorro_esp.c | 232 +++++++----------------------------------------
 4 files changed, 171 insertions(+), 365 deletions(-)
drivers/scsi/esp_scsi.c +126 -0
index 6ccaf818357e..646701fc22a4 100644
@@ -2776,3 +2776,129 @@ MODULE_PARM_DESC(esp_debug,
 
 module_init(esp_init);
 module_exit(esp_exit);
+
+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)
+static inline unsigned int esp_wait_for_fifo(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
+
+		if (fbytes)
+			return fbytes;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
+	return 0;
+}
+
+static inline int esp_wait_for_intr(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		esp->sreg = esp_read8(ESP_STATUS);
+		if (esp->sreg & ESP_STAT_INTR)
+			return 0;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
+	return 1;
+}
+
+#define ESP_FIFO_SIZE 16
+
+void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
+		      u32 dma_count, int write, u8 cmd)
+{
+	u8 phase = esp->sreg & ESP_STAT_PMASK;
+
+	cmd &= ~ESP_CMD_DMA;
+	esp->send_cmd_error = 0;
+
+	if (write) {
+		u8 *dst = (u8 *)addr;
+		u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (1) {
+			if (!esp_wait_for_fifo(esp))
+				break;
+
+			*dst++ = esp_read8(ESP_FDATA);
+			--esp_count;
+
+			if (!esp_count)
+				break;
+
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & mask) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if (phase == ESP_MIP)
+				scsi_esp_cmd(esp, ESP_CMD_MOK);
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	} else {
+		unsigned int n = ESP_FIFO_SIZE;
+		u8 *src = (u8 *)addr;
+
+		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+
+		if (n > esp_count)
+			n = esp_count;
+		writesb(esp->fifo_reg, src, n);
+		src += n;
+		esp_count -= n;
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (esp_count) {
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & ~ESP_INTR_BSERV) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			n = ESP_FIFO_SIZE -
+			    (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
+
+			if (n > esp_count)
+				n = esp_count;
+			writesb(esp->fifo_reg, src, n);
+			src += n;
+			esp_count -= n;
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	}
+
+	esp->send_cmd_residual = esp_count;
+}
+EXPORT_SYMBOL(esp_send_pio_cmd);
+#endif
drivers/scsi/esp_scsi.h +5 -0
index d0c032803749..2590e5eda595 100644
@@ -431,6 +431,7 @@ struct esp_driver_ops {
 struct esp {
 	void __iomem		*regs;
 	void __iomem		*dma_regs;
+	u8 __iomem		*fifo_reg;
 
 	const struct esp_driver_ops *ops;
 
@@ -540,6 +541,7 @@ struct esp {
 	void			*dma;
 	int			dmarev;
 
+	int			send_cmd_error;
 	int			send_cmd_residual;
 };
 
@@ -581,4 +583,7 @@ extern void scsi_esp_unregister(struct esp *);
 extern irqreturn_t scsi_esp_intr(int, void *);
 extern void scsi_esp_cmd(struct esp *, u8);
 
+extern void esp_send_pio_cmd(struct esp *esp, u32 dma_addr, u32 esp_count,
+			     u32 dma_count, int write, u8 cmd);
+
 #endif /* !(_ESP_SCSI_H) */
drivers/scsi/mac_esp.c +6 -167

225 lines not on this page · raw message

drivers/scsi/zorro_esp.c +34 -198

343 lines not on this page · raw message

Signature · 1 line
2.16.4
#6 lore raw

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

Quoted 1 line

+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)

Please add a new CONFIG_SCSI_ESP_PIO symbol that is selected by the mac and zorro drivers instead.

drivers/scsi/esp_scsi.c MODULE_PARM_DESC(esp_debug, · line 2794

Quoted 1 line
drivers/scsi/esp_scsi.c +1 -0
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));

This should probably use dev_err (at least with my series).

author
#7 lore raw

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

Quoted 5 lines · Christoph Hellwig
Quoted 1 line

+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)

Please add a new CONFIG_SCSI_ESP_PIO symbol that is selected by the mac and zorro drivers instead.

OK.

Quoted 4 lines

drivers/scsi/esp_scsi.c MODULE_PARM_DESC(esp_debug, · line 2794

Quoted 1 line
drivers/scsi/esp_scsi.c +1 -0
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));

This should probably use dev_err (at least with my series).

How about shost_printk()? That would be consistent with the rest of esp_scsi.c. It also means my series need not depend on yours which would complicate things.

#8 lore raw

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

Quoted 8 lines · Finn Thain
Quoted 4 lines

drivers/scsi/esp_scsi.c MODULE_PARM_DESC(esp_debug, · line 2794

Quoted 1 line
drivers/scsi/esp_scsi.c +1 -0
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));

This should probably use dev_err (at least with my series).

How about shost_printk()? That would be consistent with the rest of esp_scsi.c. It also means my series need not depend on yours which would complicate things.

Yes, that sounds even better.

#9 lore raw

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

In reply to Finn Thain
Quoted 140 lines · Finn Thain

As a temporary measure, the code to implement PIO transfers was duplicated in zorro_esp and mac_esp. Now that this code has stabilized, move it into the core driver to eliminate the duplication.

This replaces the inline assembler with more portable writesb() calls. Optimizing the m68k writesb() implementation is a separate patch.

---
  drivers/scsi/esp_scsi.c  | 126 +++++++++++++++++++++++++
  drivers/scsi/esp_scsi.h  |   5 +
  drivers/scsi/mac_esp.c   | 173 ++---------------------------------
  drivers/scsi/zorro_esp.c | 232 +++++++----------------------------------------
  4 files changed, 171 insertions(+), 365 deletions(-)
drivers/scsi/esp_scsi.c +116 -0
index 6ccaf818357e..646701fc22a4 100644
@@ -2776,3 +2776,129 @@ MODULE_PARM_DESC(esp_debug,
 
  module_init(esp_init);
  module_exit(esp_exit);
+
+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)
+static inline unsigned int esp_wait_for_fifo(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
+
+		if (fbytes)
+			return fbytes;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
+	return 0;
+}
+
+static inline int esp_wait_for_intr(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		esp->sreg = esp_read8(ESP_STATUS);
+		if (esp->sreg & ESP_STAT_INTR)
+			return 0;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
+	return 1;
+}
+
+#define ESP_FIFO_SIZE 16
+
+void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
+		      u32 dma_count, int write, u8 cmd)
+{
+	u8 phase = esp->sreg & ESP_STAT_PMASK;
+
+	cmd &= ~ESP_CMD_DMA;
+	esp->send_cmd_error = 0;
+
+	if (write) {
+		u8 *dst = (u8 *)addr;
+		u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (1) {
+			if (!esp_wait_for_fifo(esp))
+				break;
+
+			*dst++ = esp_read8(ESP_FDATA);
+			--esp_count;
+
+			if (!esp_count)
+				break;
+
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & mask) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if (phase == ESP_MIP)
+				scsi_esp_cmd(esp, ESP_CMD_MOK);
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	} else {
+		unsigned int n = ESP_FIFO_SIZE;
+		u8 *src = (u8 *)addr;
+
+		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+
+		if (n > esp_count)
+			n = esp_count;
+		writesb(esp->fifo_reg, src, n);
+		src += n;
+		esp_count -= n;
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (esp_count) {
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & ~ESP_INTR_BSERV) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			n = ESP_FIFO_SIZE -
+			    (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
+
+			if (n > esp_count)
+				n = esp_count;
+			writesb(esp->fifo_reg, src, n);
+			src += n;

drivers/scsi/esp_scsi.c MODULE_PARM_DESC(esp_debug, · line 2904

Quoted 10 lines
drivers/scsi/esp_scsi.c +10 -0
+			esp_count -= n;
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	}
+
+	esp->send_cmd_residual = esp_count;
+}
+EXPORT_SYMBOL(esp_send_pio_cmd);
+#endif

These function are conditional, but

Quoted 21 lines
drivers/scsi/esp_scsi.h +2 -0
index d0c032803749..2590e5eda595 100644
@@ -431,6 +431,7 @@ struct esp_driver_ops {
  struct esp {
  	void __iomem		*regs;
  	void __iomem		*dma_regs;
+	u8 __iomem		*fifo_reg;
 
  	const struct esp_driver_ops *ops;
 
@@ -540,6 +541,7 @@ struct esp {
  	void			*dma;
  	int			dmarev;
 
+	int			send_cmd_error;
  	int			send_cmd_residual;
  };
 

drivers/scsi/esp_scsi.h extern void scsi_esp_unregister(struct esp *); · line 589

Quoted 7 lines
drivers/scsi/esp_scsi.h +3 -0
@@ -581,4 +583,7 @@ extern void scsi_esp_unregister(struct esp *);
  extern irqreturn_t scsi_esp_intr(int, void *);
  extern void scsi_esp_cmd(struct esp *, u8);
 
+extern void esp_send_pio_cmd(struct esp *esp, u32 dma_addr, u32 esp_count,
+			     u32 dma_count, int write, u8 cmd);
+
  #endif /* !(_ESP_SCSI_H) */

These are not.

Which will result in building errors when the said configuration is not enabled. Please fix by either making everything conditional or remove the conditional completely.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
author
#10 lore raw

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

Quoted 178 lines · Hannes Reinecke
Quoted 140 lines · Finn Thain

As a temporary measure, the code to implement PIO transfers was duplicated in zorro_esp and mac_esp. Now that this code has stabilized, move it into the core driver to eliminate the duplication.

This replaces the inline assembler with more portable writesb() calls. Optimizing the m68k writesb() implementation is a separate patch.

---
  drivers/scsi/esp_scsi.c  | 126 +++++++++++++++++++++++++
  drivers/scsi/esp_scsi.h  |   5 +
  drivers/scsi/mac_esp.c   | 173 ++---------------------------------
  drivers/scsi/zorro_esp.c | 232 +++++++----------------------------------------
  4 files changed, 171 insertions(+), 365 deletions(-)
drivers/scsi/esp_scsi.c +116 -0
index 6ccaf818357e..646701fc22a4 100644
@@ -2776,3 +2776,129 @@ MODULE_PARM_DESC(esp_debug,
 
  module_init(esp_init);
  module_exit(esp_exit);
+
+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)
+static inline unsigned int esp_wait_for_fifo(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
+
+		if (fbytes)
+			return fbytes;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
+	return 0;
+}
+
+static inline int esp_wait_for_intr(struct esp *esp)
+{
+	int i = 500000;
+
+	do {
+		esp->sreg = esp_read8(ESP_STATUS);
+		if (esp->sreg & ESP_STAT_INTR)
+			return 0;
+
+		udelay(2);
+	} while (--i);
+
+	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
+	return 1;
+}
+
+#define ESP_FIFO_SIZE 16
+
+void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
+		      u32 dma_count, int write, u8 cmd)
+{
+	u8 phase = esp->sreg & ESP_STAT_PMASK;
+
+	cmd &= ~ESP_CMD_DMA;
+	esp->send_cmd_error = 0;
+
+	if (write) {
+		u8 *dst = (u8 *)addr;
+		u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (1) {
+			if (!esp_wait_for_fifo(esp))
+				break;
+
+			*dst++ = esp_read8(ESP_FDATA);
+			--esp_count;
+
+			if (!esp_count)
+				break;
+
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & mask) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if (phase == ESP_MIP)
+				scsi_esp_cmd(esp, ESP_CMD_MOK);
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	} else {
+		unsigned int n = ESP_FIFO_SIZE;
+		u8 *src = (u8 *)addr;
+
+		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+
+		if (n > esp_count)
+			n = esp_count;
+		writesb(esp->fifo_reg, src, n);
+		src += n;
+		esp_count -= n;
+
+		scsi_esp_cmd(esp, cmd);
+
+		while (esp_count) {
+			if (esp_wait_for_intr(esp)) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			if ((esp->sreg & ESP_STAT_PMASK) != phase)
+				break;
+
+			esp->ireg = esp_read8(ESP_INTRPT);
+			if (esp->ireg & ~ESP_INTR_BSERV) {
+				esp->send_cmd_error = 1;
+				break;
+			}
+
+			n = ESP_FIFO_SIZE -
+			    (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
+
+			if (n > esp_count)
+				n = esp_count;
+			writesb(esp->fifo_reg, src, n);
+			src += n;

drivers/scsi/esp_scsi.c MODULE_PARM_DESC(esp_debug, · line 2904

Quoted 10 lines
drivers/scsi/esp_scsi.c +10 -0
+			esp_count -= n;
+
+			scsi_esp_cmd(esp, ESP_CMD_TI);
+		}
+	}
+
+	esp->send_cmd_residual = esp_count;
+}
+EXPORT_SYMBOL(esp_send_pio_cmd);
+#endif

These function are conditional, but

Quoted 24 lines
drivers/scsi/esp_scsi.h +2 -0
index d0c032803749..2590e5eda595 100644
@@ -431,6 +431,7 @@ struct esp_driver_ops {
  struct esp {
  	void __iomem		*regs;
  	void __iomem		*dma_regs;
+	u8 __iomem		*fifo_reg;
 
  	const struct esp_driver_ops *ops;
 
@@ -540,6 +541,7 @@ struct esp {
  	void			*dma;
  	int			dmarev;
 
+	int			send_cmd_error;
  	int			send_cmd_residual;
  };
 
@@ -581,4 +583,7 @@ extern void scsi_esp_unregister(struct esp *);
  extern irqreturn_t scsi_esp_intr(int, void *);
  extern void scsi_esp_cmd(struct esp *, u8);
 
Quoted 8 lines

drivers/scsi/esp_scsi.h extern void scsi_esp_unregister(struct esp *); · line 589

Quoted 4 lines
drivers/scsi/esp_scsi.h +3 -0
+extern void esp_send_pio_cmd(struct esp *esp, u32 dma_addr, u32 esp_count,
+			     u32 dma_count, int write, u8 cmd);
+
  #endif /* !(_ESP_SCSI_H) */

These are not.

Which will result in building errors when the said configuration is not enabled.

I didn't see errors or new warnings when build-testing with CONFIG_SCSI_AM53C974=y with gcc-5.4 or gcc-7.3, nor when build-testing CONFIG_SUN3X_ESP=y with gcc-4.4.

Are you perhaps thinking of "declared static but never defined"? That doesn't apply here because esp_send_pio_cmd() isn't static. Likewise "static declaration of 'foo' follows non-static declaration"...

Quoted 10 lines

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)
author
#11 lore raw

PATCH 6/6 esp_scsi: Optimize PIO loops

In reply to Finn Thain

Avoid function calls in the inner PIO loops. On a Centris 660av this improves throughput for sequential read transfers by about 40% and sequential write by about 10%.

Unfortunately it is not possible to have method calls like esp_write8() placed inline so this is always going to be slow (even with LTO).

---
 drivers/scsi/esp_scsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/esp_scsi.c +7 -7
index 646701fc22a4..9f0e68cd0e99 100644
@@ -2788,7 +2788,7 @@ static inline unsigned int esp_wait_for_fifo(struct esp *esp)
 		if (fbytes)
 			return fbytes;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
@@ -2804,7 +2804,7 @@ static inline int esp_wait_for_intr(struct esp *esp)
 		if (esp->sreg & ESP_STAT_INTR)
 			return 0;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
@@ -2831,7 +2831,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			if (!esp_wait_for_fifo(esp))
 				break;
 
-			*dst++ = esp_read8(ESP_FDATA);
+			*dst++ = readb(esp->fifo_reg);
 			--esp_count;
 
 			if (!esp_count)
@@ -2852,15 +2852,15 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			}
 
 			if (phase == ESP_MIP)
-				scsi_esp_cmd(esp, ESP_CMD_MOK);
+				esp_write8(ESP_CMD_MOK, ESP_CMD);
 
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);
 		}
 	} else {
 		unsigned int n = ESP_FIFO_SIZE;
 		u8 *src = (u8 *)addr;
 
-		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+		esp_write8(ESP_CMD_FLUSH, ESP_CMD);
 
 		if (n > esp_count)
 			n = esp_count;
@@ -2894,7 +2894,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			src += n;
 			esp_count -= n;
 
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);
 		}
 	}
 
Signature · 1 line
2.16.4
#12 lore raw

Re: [PATCH 6/6] esp_scsi: Optimize PIO loops

Hi Finn,

Am 13.10.2018 um 13:51 schrieb Finn Thain:

Quoted 45 lines

Avoid function calls in the inner PIO loops. On a Centris 660av this improves throughput for sequential read transfers by about 40% and sequential write by about 10%.

Unfortunately it is not possible to have method calls like esp_write8() placed inline so this is always going to be slow (even with LTO).

---
 drivers/scsi/esp_scsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/esp_scsi.c +3 -3
index 646701fc22a4..9f0e68cd0e99 100644
@@ -2788,7 +2788,7 @@ static inline unsigned int esp_wait_for_fifo(struct esp *esp)
 		if (fbytes)
 			return fbytes;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
@@ -2804,7 +2804,7 @@ static inline int esp_wait_for_intr(struct esp *esp)
 		if (esp->sreg & ESP_STAT_INTR)
 			return 0;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
@@ -2831,7 +2831,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			if (!esp_wait_for_fifo(esp))
 				break;
 
-			*dst++ = esp_read8(ESP_FDATA);
+			*dst++ = readb(esp->fifo_reg);
 			--esp_count;
 
 			if (!esp_count)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2855

Quoted 5 lines
drivers/scsi/esp_scsi.c +1 -1
@@ -2852,15 +2852,15 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			}
 
 			if (phase == ESP_MIP)
-				scsi_esp_cmd(esp, ESP_CMD_MOK);
+				esp_write8(ESP_CMD_MOK, ESP_CMD);

You're no longer logging this command with this patch. (That'll be the reason for the speedup you saw ...)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2856

Quoted 3 lines
drivers/scsi/esp_scsi.c +1 -1
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

Same here..

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2863

Quoted 7 lines
drivers/scsi/esp_scsi.c +1 -1
 		}
 	} else {
 		unsigned int n = ESP_FIFO_SIZE;
 		u8 *src = (u8 *)addr;
 
-		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+		esp_write8(ESP_CMD_FLUSH, ESP_CMD);

here..

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2897

Quoted 9 lines
drivers/scsi/esp_scsi.c +1 -1
 		if (n > esp_count)
 			n = esp_count;
@@ -2894,7 +2894,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
 			src += n;
 			esp_count -= n;
 
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

and here.

The burst of ESP_CMD_TI's in the log was quite useful to spot what went wrong during PIO. Maybe mention in the changelog that commands during PIO are no longer logged? Or introduce a new ESP_EVENT_PIO and log that at the start of PIO?

Cheers,

Michael

Quoted 4 lines
drivers/scsi/esp_scsi.c +0 -0
 		}
 	}
 
author
#13 lore raw

Re: [PATCH 6/6] esp_scsi: Optimize PIO loops

Quoted 84 lines · Michael Schmitz

Hi Finn,

Am 13.10.2018 um 13:51 schrieb Finn Thain:

Quoted 47 lines

Avoid function calls in the inner PIO loops. On a Centris 660av this improves throughput for sequential read transfers by about 40% and sequential write by about 10%.

Unfortunately it is not possible to have method calls like esp_write8() placed inline so this is always going to be slow (even with LTO).

---
 drivers/scsi/esp_scsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/esp_scsi.c +1 -1
index 646701fc22a4..9f0e68cd0e99 100644
@@ -2788,7 +2788,7 @@ static inline unsigned int esp_wait_for_fifo(struct
 esp *esp)
 		if (fbytes)
 			return fbytes;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
drivers/scsi/esp_scsi.c +2 -2
 	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
@@ -2804,7 +2804,7 @@ static inline int esp_wait_for_intr(struct esp *esp)
 		if (esp->sreg & ESP_STAT_INTR)
 			return 0;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
@@ -2831,7 +2831,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			if (!esp_wait_for_fifo(esp))
 				break;
 
-			*dst++ = esp_read8(ESP_FDATA);
+			*dst++ = readb(esp->fifo_reg);
 			--esp_count;
 
drivers/scsi/esp_scsi.c +0 -0
 			if (!esp_count)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2856

Quoted 6 lines
drivers/scsi/esp_scsi.c +1 -1
@@ -2852,15 +2852,15 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			}
 
 			if (phase == ESP_MIP)
-				scsi_esp_cmd(esp, ESP_CMD_MOK);
+				esp_write8(ESP_CMD_MOK, ESP_CMD);

You're no longer logging this command with this patch. (That'll be the reason for the speedup you saw ...)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2857

Quoted 3 lines
drivers/scsi/esp_scsi.c +1 -1
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

Same here..

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2863

Quoted 7 lines
drivers/scsi/esp_scsi.c +1 -1
 		}
 	} else {
 		unsigned int n = ESP_FIFO_SIZE;
 		u8 *src = (u8 *)addr;
 
-		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+		esp_write8(ESP_CMD_FLUSH, ESP_CMD);

here..

Quoted 8 lines
drivers/scsi/esp_scsi.c +0 -0
 		if (n > esp_count)
 			n = esp_count;
@@ -2894,7 +2894,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			src += n;
 			esp_count -= n;
 
Quoted 5 lines

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2898

Quoted 2 lines
drivers/scsi/esp_scsi.c +1 -1
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

and here.

Yes, it's deliberate.

Quoted 2 lines

The burst of ESP_CMD_TI's in the log was quite useful to spot what went wrong during PIO.

I don't think it's as useful as you seem to think. Compare mac_esp_send_pdma_cmd().

Quoted 4 lines

Maybe mention in the changelog that commands during PIO are no longer logged? Or introduce a new ESP_EVENT_PIO and log that at the start of PIO?

Yes, and I did leave a scsi_esp_cmd(esp, cmd) call at the start of PIO.

That should be sufficient, right?

Quoted 11 lines

Cheers,

Michael

Quoted 4 lines
drivers/scsi/esp_scsi.c +0 -0
 		}
 	}
#14 lore raw

Re: [PATCH 6/6] esp_scsi: Optimize PIO loops

Hi Finn,

Am 13.10.2018 um 17:09 schrieb Finn Thain:

Quoted 86 lines · Michael Schmitz
Quoted 85 lines

Hi Finn,

Am 13.10.2018 um 13:51 schrieb Finn Thain:

Quoted 47 lines

Avoid function calls in the inner PIO loops. On a Centris 660av this improves throughput for sequential read transfers by about 40% and sequential write by about 10%.

Unfortunately it is not possible to have method calls like esp_write8() placed inline so this is always going to be slow (even with LTO).

---
 drivers/scsi/esp_scsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/esp_scsi.c +1 -1
index 646701fc22a4..9f0e68cd0e99 100644
@@ -2788,7 +2788,7 @@ static inline unsigned int esp_wait_for_fifo(struct
 esp *esp)
 		if (fbytes)
 			return fbytes;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
drivers/scsi/esp_scsi.c +2 -2
 	pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
@@ -2804,7 +2804,7 @@ static inline int esp_wait_for_intr(struct esp *esp)
 		if (esp->sreg & ESP_STAT_INTR)
 			return 0;
 
-		udelay(2);
+		udelay(1);
 	} while (--i);
 
 	pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
@@ -2831,7 +2831,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			if (!esp_wait_for_fifo(esp))
 				break;
 
-			*dst++ = esp_read8(ESP_FDATA);
+			*dst++ = readb(esp->fifo_reg);
 			--esp_count;
 
drivers/scsi/esp_scsi.c +0 -0
 			if (!esp_count)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2856

Quoted 6 lines
drivers/scsi/esp_scsi.c +1 -1
@@ -2852,15 +2852,15 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			}
 
 			if (phase == ESP_MIP)
-				scsi_esp_cmd(esp, ESP_CMD_MOK);
+				esp_write8(ESP_CMD_MOK, ESP_CMD);

You're no longer logging this command with this patch. (That'll be the reason for the speedup you saw ...)

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2857

Quoted 3 lines
drivers/scsi/esp_scsi.c +1 -1
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

Same here..

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, · line 2863

Quoted 7 lines
drivers/scsi/esp_scsi.c +1 -1
 		}
 	} else {
 		unsigned int n = ESP_FIFO_SIZE;
 		u8 *src = (u8 *)addr;
 
-		scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+		esp_write8(ESP_CMD_FLUSH, ESP_CMD);

here..

Quoted 8 lines
drivers/scsi/esp_scsi.c +0 -0
 		if (n > esp_count)
 			n = esp_count;
@@ -2894,7 +2894,7 @@ void esp_send_pio_cmd(struct esp *esp, u32 addr, u32
 esp_count,
 			src += n;
 			esp_count -= n;
 
Quoted 7 lines
Quoted 5 lines

drivers/scsi/esp_scsi.c void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 · line 2898

Quoted 2 lines
drivers/scsi/esp_scsi.c +1 -1
-			scsi_esp_cmd(esp, ESP_CMD_TI);
+			esp_write8(ESP_CMD_TI, ESP_CMD);

and here.

Yes, it's deliberate.

I'm sure it was... and I wasn't objecting to that.

Quoted 6 lines
Quoted 2 lines

The burst of ESP_CMD_TI's in the log was quite useful to spot what went wrong during PIO.

I don't think it's as useful as you seem to think. Compare mac_esp_send_pdma_cmd().

Quoted 6 lines
Quoted 4 lines

Maybe mention in the changelog that commands during PIO are no longer logged? Or introduce a new ESP_EVENT_PIO and log that at the start of PIO?

Yes, and I did leave a scsi_esp_cmd(esp, cmd) call at the start of PIO.

Which I missed from just looking at the patch, sorry.

Quoted 1 line

That should be sufficient, right?

It would indeed. Thanks for clarifying.

Cheers,

Michael

Tested-by on the v1 series
#15 lore raw
In reply to Finn Thain

Hi Finn,

Am 13.10.2018 um 13:51 schrieb Finn Thain:

Quoted 18 lines

This series has fixes and cleanup for mac_esp, zorro_esp and the core esp_scsi driver.

The improvements include elimination of duplicated code temporarily introduced for zorro_esp.

Michael, would you please regression test this series on elgar, if convenient? So far, only mac_esp has been tested with this code.

Finn Thain (6):
zorro_esp: Limit DMA transfers to 65535 bytes
esp_scsi: Track residual for PIO transfers
esp_scsi: Grant disconnect privilege for untagged commands
esp_scsi: Eliminate ESP_FLAG_DOING_SLOWCMD
esp_scsi: De-duplicate PIO routines
esp_scsi: Optimize PIO loops

Quoted 6 lines
 drivers/scsi/esp_scsi.c  | 192 +++++++++++++++++++++++++++++--------
 drivers/scsi/esp_scsi.h  |  10 +-
 drivers/scsi/mac_esp.c   | 171 ++-------------------------------
 drivers/scsi/zorro_esp.c | 240 +++++++----------------------------------------
 4 files changed, 201 insertions(+), 412 deletions(-)

For Amiga zorro-esp: