Skip to contentSkip to conversation

NCR5380 drivers: fixes and improvements

PATCH Superseded Finn Thain 3 participants 17 messages Jun 2, 2019 – Jun 5, 2019 1 message not in the archive

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Finn Thain

author
#0 lore raw

cover NCR5380 drivers: fixes and improvements

Among other improvements, this patch series fixes a data corruption bug in the mac_scsi driver and a bug in the EH abort routine in the core 5380 driver.

For consistency I have ignored certain checkpatch.pl complaints about the indentation in mac_scsi.c. The remaining complaints seem to be false positives.

Some of these patches are not trivial to backport. Those patches have been nominated for recent -stable branches only.

Finn Thain (7):
Revert "scsi: ncr5380: Increase register polling limit"
scsi: NCR5380: Always re-enable reselection interrupt
scsi: NCR5380: Handle PDMA failure reliably
scsi: mac_scsi: Increase PIO/PDMA transfer length threshold
scsi: mac_scsi: Fix pseudo DMA implementation, take 2
scsi: mac_scsi: Enable PDMA on Mac IIfx
scsi: mac_scsi: Treat Last Byte Sent time-out as failure

 arch/m68k/include/asm/mac_pdma.h | 179 ++++++++++++++++++++++
 arch/m68k/mac/config.c           |  10 +-
 drivers/scsi/NCR5380.c           |  18 +--
 drivers/scsi/NCR5380.h           |   2 +-
 drivers/scsi/mac_scsi.c          | 249 +++++++++++--------------------
 5 files changed, 280 insertions(+), 178 deletions(-)
 create mode 100644 arch/m68k/include/asm/mac_pdma.h
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 1/7 Revert "scsi: ncr5380: Increase register polling limit"

This reverts commit 4822827a69d7cd3bc5a07b7637484ebd2cf88db6.

The purpose of that commit was to suppress a timeout warning message which appeared to be caused by target latency. But suppressing the warning is undesirable as the warning may indicate a messed up transfer count.

Another problem with that commit is that 15 ms is too long to keep interrupts disabled as interrupt latency can cause system clock drift and other problems.

Cc Michael Schmitz <[email protected]>
Fixes 4822827a69d7 ("scsi: ncr5380: Increase register polling limit")
---
 drivers/scsi/NCR5380.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/NCR5380.h +1 -1
index efca509b92b0..5935fd6d1a05 100644
@@ -235,7 +235,7 @@ struct NCR5380_cmd {
 #define NCR5380_PIO_CHUNK_SIZE		256
 
 /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA */
-#define NCR5380_REG_POLL_TIME		15
+#define NCR5380_REG_POLL_TIME		10
 
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
Signature · 1 line
2.21.0
author
#2 lore raw

PATCH 2/7 scsi: NCR5380: Always re-enable reselection interrupt

In reply to Finn Thain

The reselection interrupt gets disabled during selection and must be re-enabled when hostdata->connected becomes NULL. If it isn't re-enabled a disconnected command may time-out or the target may wedge the bus while trying to reselect the host. This can happen after a command is aborted.

Fix this by enabling the reselection interrupt in NCR5380_main() after calls to NCR5380_select() and NCR5380_information_transfer() return.

Cc Michael Schmitz <[email protected]>
Fixes 8b00c3d5d40d ("ncr5380: Implement new eh_abort_handler")
---
 drivers/scsi/NCR5380.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/scsi/NCR5380.c +2 -10
index fe0535affc14..08e3ea8159b3 100644
@@ -709,6 +709,8 @@ static void NCR5380_main(struct work_struct *work)
 			NCR5380_information_transfer(instance);
 			done = 0;
 		}
+		if (!hostdata->connected)
+			NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 		spin_unlock_irq(&hostdata->lock);
 		if (!done)
 			cond_resched();
@@ -1110,8 +1112,6 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 		spin_lock_irq(&hostdata->lock);
 		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
 		NCR5380_reselect(instance);
-		if (!hostdata->connected)
-			NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 		shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n");
 		goto out;
 	}
@@ -1119,7 +1119,6 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 	if (err < 0) {
 		spin_lock_irq(&hostdata->lock);
 		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 
 		/* Can't touch cmd if it has been reclaimed by the scsi ML */
 		if (!hostdata->selecting)
@@ -1157,7 +1156,6 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 	if (err < 0) {
 		shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
 		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 		goto out;
 	}
 	if (!hostdata->selecting) {
@@ -1826,9 +1824,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					 */
 					NCR5380_write(TARGET_COMMAND_REG, 0);
 
-					/* Enable reselect interrupts */
-					NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
-
 					maybe_release_dma_irq(instance);
 					return;
 				case MESSAGE_REJECT:
@@ -1860,8 +1855,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					 */
 					NCR5380_write(TARGET_COMMAND_REG, 0);
 
-					/* Enable reselect interrupts */
-					NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 #ifdef SUN3_SCSI_VME
 					dregs->csr |= CSR_DMA_ENABLE;
 #endif
@@ -1964,7 +1957,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					cmd->result = DID_ERROR << 16;
 					complete_cmd(instance, cmd);
 					maybe_release_dma_irq(instance);
-					NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
 					return;
 				}
 				msgout = NOP;
Signature · 1 line
2.21.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw

Re: [PATCH 2/7] scsi: NCR5380: Always re-enable reselection interrupt

Quoted 14 lines · Sasha Levin

Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag, fixing commit: 8b00c3d5d40d ncr5380: Implement new eh_abort_handler.

The bot has tested the following trees: v5.1.6, v5.0.20, v4.19.47, v4.14.123, v4.9.180.

v5.1.6: Build OK!
v5.0.20: Build OK!
v4.19.47: Failed to apply! Possible dependencies:

    6a162836997c ("scsi: NCR5380: Reduce goto statements in NCR5380_select()")
Quoted 9 lines

v4.14.123: Failed to apply! Possible dependencies:

    6a162836997c ("scsi: NCR5380: Reduce goto statements in NCR5380_select()")

v4.9.180: Failed to apply! Possible dependencies:

    6a162836997c ("scsi: NCR5380: Reduce goto statements in NCR5380_select()")

How should we proceed with this patch?

Please cherry-pick the dependency, as it does not alter functionality.

$

$ git checkout v4.9
HEAD is now at 69973b830859 Linux 4.9
$ git cherry-pick 6a162836997c
[detached HEAD 0e33d17b7b50] scsi: NCR5380: Reduce goto statements in 
NCR5380_select()
 Date: Thu Sep 27 11:17:11 2018 +1000
 1 file changed, 12 insertions(+), 9 deletions(-)
$ git cherry-pick 61f0c0f6aaf8
[detached HEAD 8ae61212c888] scsi: NCR5380: Always re-enable reselection 
interrupt
 Date: Mon Mar 25 15:45:51 2019 +1100
 1 file changed, 2 insertions(+), 10 deletions(-)
$ 

You could instead apply the patch using more fuzz...

$

$ git checkout v4.9
HEAD is now at 69973b830859 Linux 4.9
$ git show 61f0c0f6aaf8 | patch -p1 -F3
patching file drivers/scsi/NCR5380.c
Hunk #1 succeeded at 813 (offset 104 lines).
Hunk #2 succeeded at 1210 (offset 98 lines).
Hunk #3 succeeded at 1217 with fuzz 3 (offset 98 lines).
Hunk #4 succeeded at 1251 (offset 95 lines).
Hunk #5 succeeded at 1901 (offset 77 lines).
Hunk #6 succeeded at 1932 (offset 77 lines).
Hunk #7 succeeded at 2039 (offset 82 lines).
$ 

This also works but would seem to undermine future backporting.

Thanks.

Quoted 4 lines
Signature · 2 lines
Thanks,
Sasha
author
#5 lore raw

PATCH 3/7 scsi: NCR5380: Handle PDMA failure reliably

In reply to Finn Thain

A PDMA error is handled in the core driver by setting the device's 'borken' flag and aborting the command. Unfortunately, do_abort() is not dependable. Perform a SCSI bus reset instead, to make sure that the command fails and gets retried.

Cc Michael Schmitz <[email protected]>
Cc [email protected] # v4.20+
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/scsi/NCR5380.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/NCR5380.c +2 -4
index 08e3ea8159b3..d9fa9cf2fd8b 100644
@@ -1761,10 +1761,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 						scmd_printk(KERN_INFO, cmd,
 							"switching to slow handshake\n");
 						cmd->device->borken = 1;
-						sink = 1;
-						do_abort(instance);
-						cmd->result = DID_ERROR << 16;
-						/* XXX - need to source or sink data here, as appropriate */
+						do_reset(instance);
+						bus_reset_cleanup(instance);
 					}
 				} else {
 					/* Transfer a small chunk so that the
Signature · 1 line
2.21.0
author
#6 lore raw

PATCH 4/7 scsi: mac_scsi: Increase PIO/PDMA transfer length threshold

In reply to Finn Thain

Some targets introduce delays when handshaking the response to certain commands. For example, a disk may send a 96-byte response to an INQUIRY command (or a 24-byte response to a MODE SENSE command) too slowly.

Apparently the first 12 or 14 bytes are handshaked okay but then the system bus error timeout is reached while transferring the next word.

Since the scsi bus phase hasn't changed, the driver then sets the target borken flag to prevent further PDMA transfers. The driver also logs the warning, "switching to slow handshake".

Raise the PDMA threshold to 512 bytes so that PIO transfers will be used for these commands. This default is sufficiently low that PDMA will still be used for READ and WRITE commands.

The existing threshold (16 bytes) was chosen more or less at random. However, best performance requires the threshold to be as low as possible. Those systems that don't need the PIO workaround at all may benefit from mac_scsi.setup_use_pdma=1

Cc Michael Schmitz <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")
---
 drivers/scsi/mac_scsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/mac_scsi.c +2 -2
index 8b4b5b1a13d7..ba1afcaadae8 100644
@@ -52,7 +52,7 @@ static int setup_cmd_per_lun = -1;
 module_param(setup_cmd_per_lun, int, 0);
 static int setup_sg_tablesize = -1;
 module_param(setup_sg_tablesize, int, 0);
-static int setup_use_pdma = -1;
+static int setup_use_pdma = 512;
 module_param(setup_use_pdma, int, 0);
 static int setup_hostid = -1;
 module_param(setup_hostid, int, 0);
@@ -305,7 +305,7 @@ static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                 struct scsi_cmnd *cmd)
 {
 	if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
-	    cmd->SCp.this_residual < 16)
+	    cmd->SCp.this_residual < setup_use_pdma)
 		return 0;
 
 	return cmd->SCp.this_residual;
Signature · 1 line
2.21.0
author
#7 lore raw

PATCH 5/7 scsi: mac_scsi: Fix pseudo DMA implementation, take 2

In reply to Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------
 2 files changed, 226 insertions(+), 154 deletions(-)
 create mode 100644 arch/m68k/include/asm/mac_pdma.h
arch/m68k/include/asm/mac_pdma.h new file +179 -0
new file mode 100644
index 000000000000..44e2fb6d4b1c
@@ -0,0 +1,179 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+/* Copyright (C) 2019 Finn Thain */
+
+#ifndef _ASM_MAC_PDMA_H_
+#define _ASM_MAC_PDMA_H_
+
+#include <linux/delay.h>
+
+/*
+ * According to "Inside Macintosh: Devices", Mac OS requires disk drivers to
+ * specify the number of bytes between the delays expected from a SCSI target.
+ * This allows the operating system to "prevent bus errors when a target fails
+ * to deliver the next byte within the processor bus error timeout period."
+ * Linux SCSI drivers lack knowledge of the timing behaviour of SCSI targets
+ * so bus errors are unavoidable.
+ *
+ * If a MOVE.B instruction faults, we assume that zero bytes were transferred
+ * and simply retry. That assumption probably depends on target behaviour but
+ * seems to hold up okay. The NOP provides synchronization: without it the
+ * fault can sometimes occur after the program counter has moved past the
+ * offending instruction. Post-increment addressing can't be used.
+ */
+
+#define MOVE_BYTE(operands) \
+	asm volatile ( \
+		"1:     moveb " operands "     \n" \
+		"11:    nop                    \n" \
+		"       addq #1,%0             \n" \
+		"       subq #1,%1             \n" \
+		"40:                           \n" \
+		"                              \n" \
+		".section .fixup,\"ax\"        \n" \
+		".even                         \n" \
+		"90:    movel #1, %2           \n" \
+		"       jra 40b                \n" \
+		".previous                     \n" \
+		"                              \n" \
+		".section __ex_table,\"a\"     \n" \
+		".align  4                     \n" \
+		".long   1b,90b                \n" \
+		".long  11b,90b                \n" \
+		".previous                     \n" \
+		: "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
+
+/*
+ * If a MOVE.W (or MOVE.L) instruction faults, it cannot be retried because
+ * the residual byte count would be uncertain. In that situation the MOVE_WORD
+ * macro clears n in the fixup section to abort the transfer.
+ */
+
+#define MOVE_WORD(operands) \
+	asm volatile ( \
+		"1:     movew " operands "     \n" \
+		"11:    nop                    \n" \
+		"       subq #2,%1             \n" \
+		"40:                           \n" \
+		"                              \n" \
+		".section .fixup,\"ax\"        \n" \
+		".even                         \n" \
+		"90:    movel #0, %1           \n" \
+		"       movel #2, %2           \n" \
+		"       jra 40b                \n" \
+		".previous                     \n" \
+		"                              \n" \
+		".section __ex_table,\"a\"     \n" \
+		".align  4                     \n" \
+		".long   1b,90b                \n" \
+		".long  11b,90b                \n" \
+		".previous                     \n" \
+		: "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
+
+#define MOVE_16_WORDS(operands) \
+	asm volatile ( \
+		"1:     movew " operands "     \n" \
+		"2:     movew " operands "     \n" \
+		"3:     movew " operands "     \n" \
+		"4:     movew " operands "     \n" \
+		"5:     movew " operands "     \n" \
+		"6:     movew " operands "     \n" \
+		"7:     movew " operands "     \n" \
+		"8:     movew " operands "     \n" \
+		"9:     movew " operands "     \n" \
+		"10:    movew " operands "     \n" \
+		"11:    movew " operands "     \n" \
+		"12:    movew " operands "     \n" \
+		"13:    movew " operands "     \n" \
+		"14:    movew " operands "     \n" \
+		"15:    movew " operands "     \n" \
+		"16:    movew " operands "     \n" \
+		"17:    nop                    \n" \
+		"       subl  #32,%1           \n" \
+		"40:                           \n" \
+		"                              \n" \
+		".section .fixup,\"ax\"        \n" \
+		".even                         \n" \
+		"90:    movel #0, %1           \n" \
+		"       movel #2, %2           \n" \
+		"       jra 40b                \n" \
+		".previous                     \n" \
+		"                              \n" \
+		".section __ex_table,\"a\"     \n" \
+		".align  4                     \n" \
+		".long   1b,90b                \n" \
+		".long   2b,90b                \n" \
+		".long   3b,90b                \n" \
+		".long   4b,90b                \n" \
+		".long   5b,90b                \n" \
+		".long   6b,90b                \n" \
+		".long   7b,90b                \n" \
+		".long   8b,90b                \n" \
+		".long   9b,90b                \n" \
+		".long  10b,90b                \n" \
+		".long  11b,90b                \n" \
+		".long  12b,90b                \n" \
+		".long  13b,90b                \n" \
+		".long  14b,90b                \n" \
+		".long  15b,90b                \n" \
+		".long  16b,90b                \n" \
+		".long  17b,90b                \n" \
+		".previous                     \n" \
+		: "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
+
+#define MAC_PDMA_DELAY		32
+
+static inline int mac_pdma_recv(void __iomem *io, unsigned char *start, int n)
+{
+	unsigned char *addr = start;
+	int result = 0;
+
+	if (n >= 1) {
+		MOVE_BYTE("%3@,%0@");
+		if (result)
+			goto out;
+	}
+	if (n >= 1 && ((unsigned long)addr & 1)) {
+		MOVE_BYTE("%3@,%0@");
+		if (result)
+			goto out;
+	}
+	while (n >= 32)
+		MOVE_16_WORDS("%3@,%0@+");
+	while (n >= 2)
+		MOVE_WORD("%3@,%0@+");
+	if (result)
+		return start - addr; /* Negated to indicate uncertain length */
+	if (n == 1)
+		MOVE_BYTE("%3@,%0@");
+out:
+	return addr - start;
+}
+
+static inline int mac_pdma_send(unsigned char *start, void __iomem *io, int n)
+{
+	unsigned char *addr = start;
+	int result = 0;
+
+	if (n >= 1) {
+		MOVE_BYTE("%0@,%3@");
+		if (result)
+			goto out;
+	}
+	if (n >= 1 && ((unsigned long)addr & 1)) {
+		MOVE_BYTE("%0@,%3@");
+		if (result)
+			goto out;
+	}
+	while (n >= 32)
+		MOVE_16_WORDS("%0@+,%3@");
+	while (n >= 2)
+		MOVE_WORD("%0@+,%3@");
+	if (result)
+		return start - addr; /* Negated to indicate uncertain length */
+	if (n == 1)
+		MOVE_BYTE("%0@,%3@");
+out:
+	return addr - start;
+}
+
+#endif /* _ASM_MAC_PDMA_H_ */
drivers/scsi/mac_scsi.c +47 -154

264 lines not on this page · raw message

Signature · 1 line
2.21.0
#8 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Hi Finn,

Quoted 13 lines · Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Quoted 7 lines
Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")

Thanks for your patch!

Quoted 3 lines
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------

Why have you moved the PDMA implementation to a header file under arch/m68k/? Do you intend to reuse it by other drivers?

If not, please keep it in the driver, so (a) you don't need an ack from me ;-), and (b) your change may be easier to review.

Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#9 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Quoted 25 lines · Geert Uytterhoeven

Hi Finn,

Quoted 13 lines · Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Quoted 7 lines
Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")
Quoted 9 lines

Thanks for your patch!

Quoted 3 lines
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------

Why have you moved the PDMA implementation to a header file under arch/m68k/? Do you intend to reuse it by other drivers?

There are a couple of reasons: the mac_esp driver also uses PDMA and the NuBus PowerMac port also uses mac_scsi.c. OTOH, the NuBus PowerMac port is still out-of-tree, and it is unclear whether the mac_esp driver will ever benefit from this code.

Quoted 3 lines

If not, please keep it in the driver, so (a) you don't need an ack from me ;-), and (b) your change may be easier to review.

I take your wink to mean that you don't want to ask the SCSI maintainers to review m68k asm. Putting aside the code review process for a moment, do you have an opinion on the most logical way to organise this sort of code, from the point-of-view of maintainability, re-usability, readability etc.?

Thanks.

Quoted 7 lines

Thanks!

Gr{oetje,eeting}s,

Geert

#10 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Hi Finn,

Quoted 30 lines · Finn Thain
Quoted 29 lines · Geert Uytterhoeven
Quoted 13 lines · Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Quoted 7 lines
Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")

Thanks for your patch!

Quoted 3 lines
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------
Quoted 8 lines
Quoted 3 lines

Why have you moved the PDMA implementation to a header file under arch/m68k/? Do you intend to reuse it by other drivers?

There are a couple of reasons: the mac_esp driver also uses PDMA and the NuBus PowerMac port also uses mac_scsi.c. OTOH, the NuBus PowerMac port is still out-of-tree, and it is unclear whether the mac_esp driver will ever benefit from this code.

So you do have future sharing in mind...

Quoted 5 lines
Quoted 2 lines

If not, please keep it in the driver, so (a) you don't need an ack from me ;-), and (b) your change may be easier to review.

I take your wink to mean that you don't want to ask the SCSI maintainers to review m68k asm. Putting aside the code review process for a moment, do

I meant that apart from the code containing m68k assembler source, it is not related to arch/m68k/, and thus belongs to the driver. There are several other drivers that contain pieces of assembler code.

Quoted 2 lines

you have an opinion on the most logical way to organise this sort of code, from the point-of-view of maintainability, re-usability, readability etc.?

If the code is used by multiple SCSI drivers, you can move it to a header file under drivers/scsi/.
If the code is shared by drivers belonging to multiple subsystems, you can move it to a header file under include/linux/.

Anyone who has a better solution?
Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#11 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Quoted 44 lines · Geert Uytterhoeven

Hi Finn,

Quoted 30 lines · Finn Thain
Quoted 29 lines · Geert Uytterhoeven
Quoted 13 lines · Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Quoted 7 lines
Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")

Thanks for your patch!

Quoted 3 lines
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------
Quoted 8 lines
Quoted 3 lines

Why have you moved the PDMA implementation to a header file under arch/m68k/? Do you intend to reuse it by other drivers?

There are a couple of reasons: the mac_esp driver also uses PDMA and the NuBus PowerMac port also uses mac_scsi.c. OTOH, the NuBus PowerMac port is still out-of-tree, and it is unclear whether the mac_esp driver will ever benefit from this code.

So you do have future sharing in mind...

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If not, please keep it in the driver, so (a) you don't need an ack from me ;-), and (b) your change may be easier to review.

I take your wink to mean that you don't want to ask the SCSI maintainers to review m68k asm. Putting aside the code review process for a moment, do

I meant that apart from the code containing m68k assembler source, it is not related to arch/m68k/, and thus belongs to the driver.

That criterion seems insufficient. It could describe most of arch/m68k/mac (which has headers in arch/m68k/include).

Quoted 2 lines

There are several other drivers that contain pieces of assembler code.

Does any driver contain assembler code for multiple architectures? I was trying to avoid that -- though admittedly I don't yet have actual code for the PDMA implementation for mac_scsi for Nubus PowerMacs.

However, the existence of that out-of-tree port suggests to me that arch/powerpc/include/mac_scsi.h and arch/m68k/include/mac_scsi.h would be an appropriate layout.

But if there's no clear policy then perhaps we should ignore the whole question until the driver code actually becomes shared code. I don't mind re-working the patch to combine the two files.

Quoted 17 lines
Quoted 3 lines

you have an opinion on the most logical way to organise this sort of code, from the point-of-view of maintainability, re-usability, readability etc.?

If the code is used by multiple SCSI drivers, you can move it to a header file under drivers/scsi/.
If the code is shared by drivers belonging to multiple subsystems, you can move it to a header file under include/linux/.

Anyone who has a better solution?
Thanks!

Gr{oetje,eeting}s,

Geert

#12 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Hi Finn,

Quoted 62 lines · Finn Thain
Quoted 42 lines · Geert Uytterhoeven
Quoted 30 lines · Finn Thain
Quoted 29 lines · Geert Uytterhoeven
Quoted 13 lines · Finn Thain

A system bus error during a PDMA transfer can mess up the calculation of the transfer residual (the PDMA handshaking hardware lacks a byte counter). This results in data corruption.

The algorithm in this patch anticipates a bus error by starting each transfer with a MOVE.B instruction. If a bus error is caught the transfer will be retried. If a bus error is caught later in the transfer (for a MOVE.W instruction) the transfer gets failed and subsequent requests for that target will use PIO instead of PDMA.

This avoids the "!REQ and !ACK" error so the severity level of that message is reduced to KERN_DEBUG.

Quoted 7 lines
Cc Michael Schmitz <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc [email protected] # v4.14+
Fixes 3a0f64bfa907 ("mac_scsi: Fix pseudo DMA implementation")

Thanks for your patch!

Quoted 3 lines
---
 arch/m68k/include/asm/mac_pdma.h | 179 +++++++++++++++++++++++++++
 drivers/scsi/mac_scsi.c          | 201 ++++++++-----------------------
Quoted 8 lines
Quoted 3 lines

Why have you moved the PDMA implementation to a header file under arch/m68k/? Do you intend to reuse it by other drivers?

There are a couple of reasons: the mac_esp driver also uses PDMA and the NuBus PowerMac port also uses mac_scsi.c. OTOH, the NuBus PowerMac port is still out-of-tree, and it is unclear whether the mac_esp driver will ever benefit from this code.

So you do have future sharing in mind...

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If not, please keep it in the driver, so (a) you don't need an ack from me ;-), and (b) your change may be easier to review.

I take your wink to mean that you don't want to ask the SCSI maintainers to review m68k asm. Putting aside the code review process for a moment, do

I meant that apart from the code containing m68k assembler source, it is not related to arch/m68k/, and thus belongs to the driver.

That criterion seems insufficient. It could describe most of arch/m68k/mac (which has headers in arch/m68k/include).

Quoted 2 lines

There are several other drivers that contain pieces of assembler code.

Does any driver contain assembler code for multiple architectures? I was trying to avoid that -- though admittedly I don't yet have actual code for the PDMA implementation for mac_scsi for Nubus PowerMacs.

Quoted 7 lines

However, the existence of that out-of-tree port suggests to me that arch/powerpc/include/mac_scsi.h and arch/m68k/include/mac_scsi.h would be an appropriate layout.

But if there's no clear policy then perhaps we should ignore the whole question until the driver code actually becomes shared code. I don't mind re-working the patch to combine the two files.

Yep, can be handled when the need arises.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
maintainer
#13 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

In reply to Finn Thain

Hi Finn,

Quoted 7 lines · Finn Thain
Quoted 3 lines

There are several other drivers that contain pieces of assembler code.

Does any driver contain assembler code for multiple architectures? I was trying to avoid that -- though admittedly I don't yet have actual code for the PDMA implementation for mac_scsi for Nubus PowerMacs.

I've seen that once, for one of the ESP drivers that were supported on both m68k and ppc (APUS, PPC upgrade to Amiga computers). But that driver was removed long ago (after 2.6?).

In that case, the assembly file did reside in drivers/scsi/. That still appears to be current practice (see drivers/scsi/arm/acornscsi-io.S).

Cheers,

    Michael

author
#14 lore raw

Re: [PATCH 5/7] scsi: mac_scsi: Fix pseudo DMA implementation, take 2

Quoted 10 lines · Michael Schmitz

Hi Finn,

Quoted 7 lines · Finn Thain
Quoted 3 lines

There are several other drivers that contain pieces of assembler code.

Does any driver contain assembler code for multiple architectures? I was trying to avoid that -- though admittedly I don't yet have actual code for the PDMA implementation for mac_scsi for Nubus PowerMacs.

Quoted 7 lines

I've seen that once, for one of the ESP drivers that were supported on both m68k and ppc (APUS, PPC upgrade to Amiga computers). But that driver was removed long ago (after 2.6?).

In that case, the assembly file did reside in drivers/scsi/. That still appears to be current practice (see drivers/scsi/arm/acornscsi-io.S).

The presence of that file would be an argument for adding drivers/scsi/m68k/. This seems to be begging the question.

Since there's no clear policy, I'll combine the two files and avoid the question for now.

Quoted 6 lines

Cheers,

??? Michael

author
#15 lore raw

PATCH 6/7 scsi: mac_scsi: Enable PDMA on Mac IIfx

In reply to Finn Thain

Add support for Apple's custom "SCSI DMA" chip. This patch doesn't make use of its DMA capability. Just the PDMA capability is sufficient to improve sequential read throughput by a factor of 5.

Cc Michael Schmitz <[email protected]>
Cc Joshua Thompson <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
---
 arch/m68k/mac/config.c  | 10 +++++++--
 drivers/scsi/mac_scsi.c | 47 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 47 insertions(+), 10 deletions(-)
arch/m68k/mac/config.c +8 -2
index 39835ca5a474..611f73bfc87c 100644
@@ -911,6 +911,10 @@ static const struct resource mac_scsi_iifx_rsrc[] __initconst = {
 		.flags = IORESOURCE_MEM,
 		.start = 0x50008000,
 		.end   = 0x50009FFF,
+	}, {
+		.flags = IORESOURCE_MEM,
+		.start = 0x50008000,
+		.end   = 0x50009FFF,
 	},
 };
 
@@ -1012,10 +1016,12 @@ int __init mac_platform_init(void)
 	case MAC_SCSI_IIFX:
 		/* Addresses from The Guide to Mac Family Hardware.
 		 * $5000 8000 - $5000 9FFF: SCSI DMA
+		 * $5000 A000 - $5000 BFFF: Alternate SCSI
 		 * $5000 C000 - $5000 DFFF: Alternate SCSI (DMA)
 		 * $5000 E000 - $5000 FFFF: Alternate SCSI (Hsk)
-		 * The SCSI DMA custom IC embeds the 53C80 core. mac_scsi does
-		 * not make use of its DMA or hardware handshaking logic.
+		 * The A/UX header file sys/uconfig.h says $50F0 8000.
+		 * The "SCSI DMA" custom IC embeds the 53C80 core and
+		 * supports Programmed IO, DMA and PDMA (hardware handshake).
 		 */
 		platform_device_register_simple("mac_scsi", 0,
 			mac_scsi_iifx_rsrc, ARRAY_SIZE(mac_scsi_iifx_rsrc));
drivers/scsi/mac_scsi.c +39 -8

128 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer Acked-by on v1 6/7
#16 lore raw

Re: [PATCH 6/7] scsi: mac_scsi: Enable PDMA on Mac IIfx

Hi Finn,

Quoted 9 lines · Finn Thain

Add support for Apple's custom "SCSI DMA" chip. This patch doesn't make use of its DMA capability. Just the PDMA capability is sufficient to improve sequential read throughput by a factor of 5.

Cc Michael Schmitz <[email protected]>
Cc Joshua Thompson <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

Thanks for your patch!

Quoted 2 lines
---
 arch/m68k/mac/config.c  | 10 +++++++--

For the m68k change to go in through the SCSI tree:

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#17 lore raw

PATCH 7/7 scsi: mac_scsi: Treat Last Byte Sent time-out as failure

In reply to Finn Thain

A system bus error during a PDMA send operation can result in bytes being lost. Theoretically that could cause the target to remain in DATA OUT phase and the initiator (expecting a phase change) would time-out waiting for the Last Byte Sent flag. Should that happen, fail the transfer so the core driver will stop using PDMA with this target.

---
 drivers/scsi/mac_scsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/mac_scsi.c +4 -1
index 2e503f06ac99..68d4665112b5 100644
@@ -188,9 +188,12 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
 		if (hostdata->pdma_residual == 0) {
 			if (NCR5380_poll_politely(hostdata, TARGET_COMMAND_REG,
 			                          TCR_LAST_BYTE_SENT,
-			                          TCR_LAST_BYTE_SENT, HZ / 64) < 0)
+			                          TCR_LAST_BYTE_SENT,
+			                          HZ / 64) < 0) {
 				scmd_printk(KERN_ERR, hostdata->connected,
 				            "%s: Last Byte Sent timeout\n", __func__);
+				result = -1;
+			}
 			goto out;
 		}
 
Signature · 1 line
2.21.0