From: Finn Thain <fthain@telegraphics.com.au>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Michael Schmitz <schmitzmic@gmail.com>,
<linux-m68k@vger.kernel.org>, <linux-scsi@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: Ondrej Zary <linux@rainbow-software.org>, Sam Creasey <sammy@sammy.net>
Subject: [PATCH v3 12/23] sun3_scsi: Adopt NCR5380.c core driver
Date: Mon, 21 Mar 2016 13:32:01 +1100 [thread overview]
Message-ID: <20160321023152.803971245@telegraphics.com.au> (raw)
In-Reply-To: 20160321023149.604138431@telegraphics.com.au
[-- Attachment #1: sun3_scsi-adopt-NCR5380-c --]
[-- Type: text/plain, Size: 8492 bytes --]
Add support for the custom Sun 3 DMA logic to the NCR5380.c core driver.
This code is copied from atari_NCR5380.c.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Tested-by: Michael Schmitz <schmitzmic@gmail.com>
---
The Sun 3 DMA code is still configured by macros. I have simplified things
slightly but I have avoided more ambitious refactoring. It's not clear to
me what that should look like and I can't test sun3_scsi anyway. At least
this permits the removal of atari_NCR5380.c.
---
drivers/scsi/NCR5380.c | 131 +++++++++++++++++++++++++++++++++++++++++++----
drivers/scsi/sun3_scsi.c | 8 +-
2 files changed, 124 insertions(+), 15 deletions(-)
Index: linux/drivers/scsi/sun3_scsi.c
===================================================================
--- linux.orig/drivers/scsi/sun3_scsi.c 2016-03-21 13:31:13.000000000 +1100
+++ linux/drivers/scsi/sun3_scsi.c 2016-03-21 13:31:32.000000000 +1100
@@ -54,10 +54,8 @@
#define NCR5380_abort sun3scsi_abort
#define NCR5380_info sun3scsi_info
-#define NCR5380_dma_read_setup(instance, data, count) \
- sun3scsi_dma_setup(instance, data, count, 0)
-#define NCR5380_dma_write_setup(instance, data, count) \
- sun3scsi_dma_setup(instance, data, count, 1)
+#define NCR5380_dma_recv_setup(instance, data, count) (count)
+#define NCR5380_dma_send_setup(instance, data, count) (count)
#define NCR5380_dma_residual(instance) \
sun3scsi_dma_residual(instance)
#define NCR5380_dma_xfer_len(instance, cmd, phase) \
@@ -406,7 +404,7 @@ static int sun3scsi_dma_finish(int write
}
-#include "atari_NCR5380.c"
+#include "NCR5380.c"
#ifdef SUN3_SCSI_VME
#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
Index: linux/drivers/scsi/NCR5380.c
===================================================================
--- linux.orig/drivers/scsi/NCR5380.c 2016-03-21 13:31:31.000000000 +1100
+++ linux/drivers/scsi/NCR5380.c 2016-03-21 13:31:32.000000000 +1100
@@ -31,6 +31,8 @@
/* Ported to Atari by Roman Hodek and others. */
+/* Adapted for the Sun 3 by Sam Creasey. */
+
/*
* Further development / testing that should be done :
*
@@ -858,6 +860,23 @@ static void NCR5380_dma_complete(struct
}
}
+#ifdef CONFIG_SUN3
+ if ((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) {
+ pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n",
+ instance->host_no);
+ BUG();
+ }
+
+ if ((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH | BASR_ACK)) ==
+ (BASR_PHASE_MATCH | BASR_ACK)) {
+ pr_err("scsi%d: BASR %02x\n", instance->host_no,
+ NCR5380_read(BUS_AND_STATUS_REG));
+ pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n",
+ instance->host_no);
+ BUG();
+ }
+#endif
+
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
@@ -981,10 +1000,16 @@ static irqreturn_t NCR5380_intr(int irq,
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
dsprintk(NDEBUG_INTR, instance, "unknown interrupt\n");
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_DMA_ENABLE;
+#endif
}
handled = 1;
} else {
shost_printk(KERN_NOTICE, instance, "interrupt without IRQ bit\n");
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_DMA_ENABLE;
+#endif
}
spin_unlock_irqrestore(&hostdata->lock, flags);
@@ -1274,6 +1299,10 @@ static struct scsi_cmnd *NCR5380_select(
hostdata->connected = cmd;
hostdata->busy[cmd->device->id] |= 1 << cmd->device->lun;
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_INTR;
+#endif
+
initialize_SCp(cmd);
cmd = NULL;
@@ -1557,6 +1586,11 @@ static int NCR5380_transfer_dma(struct S
dsprintk(NDEBUG_DMA, instance, "initializing DMA %s: length %d, address %p\n",
(p & SR_IO) ? "receive" : "send", c, d);
+#ifdef CONFIG_SUN3
+ /* send start chain */
+ sun3scsi_dma_start(c, *data);
+#endif
+
NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY |
MR_ENABLE_EOP_INTR);
@@ -1577,6 +1611,7 @@ static int NCR5380_transfer_dma(struct S
*/
if (p & SR_IO) {
+ NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_io_delay(1);
NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
} else {
@@ -1587,6 +1622,13 @@ static int NCR5380_transfer_dma(struct S
NCR5380_io_delay(1);
}
+#ifdef CONFIG_SUN3
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_DMA_ENABLE;
+#endif
+ sun3_dma_active = 1;
+#endif
+
if (hostdata->flags & FLAG_LATE_DMA_SETUP) {
/* On the Falcon, the DMA setup must be done after the last
* NCR access, else the DMA setup gets trashed!
@@ -1718,6 +1760,10 @@ static void NCR5380_information_transfer
unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
struct scsi_cmnd *cmd;
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_INTR;
+#endif
+
while ((cmd = hostdata->connected)) {
struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
@@ -1729,6 +1775,31 @@ static void NCR5380_information_transfer
old_phase = phase;
NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
}
+#ifdef CONFIG_SUN3
+ if (phase == PHASE_CMDOUT) {
+ void *d;
+ unsigned long count;
+
+ if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
+ count = cmd->SCp.buffer->length;
+ d = sg_virt(cmd->SCp.buffer);
+ } else {
+ count = cmd->SCp.this_residual;
+ d = cmd->SCp.ptr;
+ }
+
+ if (sun3_dma_setup_done != cmd &&
+ sun3scsi_dma_xfer_len(count, cmd) > 0) {
+ sun3scsi_dma_setup(instance, d, count,
+ rq_data_dir(cmd->request));
+ sun3_dma_setup_done = cmd;
+ }
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_INTR;
+#endif
+ }
+#endif /* CONFIG_SUN3 */
+
if (sink && (phase != PHASE_MSGOUT)) {
NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
@@ -1811,6 +1882,10 @@ static void NCR5380_information_transfer
(unsigned char **)&cmd->SCp.ptr);
cmd->SCp.this_residual -= transfersize - len;
}
+#ifdef CONFIG_SUN3
+ if (sun3_dma_setup_done == cmd)
+ sun3_dma_setup_done = NULL;
+#endif
return;
case PHASE_MSGIN:
len = 1;
@@ -1889,6 +1964,9 @@ static void NCR5380_information_transfer
/* Enable reselect interrupts */
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
+#ifdef SUN3_SCSI_VME
+ dregs->csr |= CSR_DMA_ENABLE;
+#endif
return;
/*
* The SCSI data pointer is *IMPLICITLY* saved on a disconnect
@@ -2040,10 +2118,8 @@ static void NCR5380_reselect(struct Scsi
{
struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char target_mask;
- unsigned char lun, phase;
- int len;
+ unsigned char lun;
unsigned char msg[3];
- unsigned char *data;
struct NCR5380_cmd *ncmd;
struct scsi_cmnd *tmp;
@@ -2085,15 +2161,26 @@ static void NCR5380_reselect(struct Scsi
return;
}
- len = 1;
- data = msg;
- phase = PHASE_MSGIN;
- NCR5380_transfer_pio(instance, &phase, &len, &data);
+#ifdef CONFIG_SUN3
+ /* acknowledge toggle to MSGIN */
+ NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN));
+
+ /* peek at the byte without really hitting the bus */
+ msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG);
+#else
+ {
+ int len = 1;
+ unsigned char *data = msg;
+ unsigned char phase = PHASE_MSGIN;
- if (len) {
- do_abort(instance);
- return;
+ NCR5380_transfer_pio(instance, &phase, &len, &data);
+
+ if (len) {
+ do_abort(instance);
+ return;
+ }
}
+#endif /* CONFIG_SUN3 */
if (!(msg[0] & 0x80)) {
shost_printk(KERN_ERR, instance, "expecting IDENTIFY message, got ");
@@ -2141,6 +2228,30 @@ static void NCR5380_reselect(struct Scsi
return;
}
+#ifdef CONFIG_SUN3
+ {
+ void *d;
+ unsigned long count;
+
+ if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
+ count = tmp->SCp.buffer->length;
+ d = sg_virt(tmp->SCp.buffer);
+ } else {
+ count = tmp->SCp.this_residual;
+ d = tmp->SCp.ptr;
+ }
+
+ if (sun3_dma_setup_done != tmp &&
+ sun3scsi_dma_xfer_len(count, tmp) > 0) {
+ sun3scsi_dma_setup(instance, d, count,
+ rq_data_dir(tmp->request));
+ sun3_dma_setup_done = tmp;
+ }
+ }
+
+ NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
+#endif /* CONFIG_SUN3 */
+
/* Accept message by clearing ACK */
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
next prev parent reply other threads:[~2016-03-21 4:09 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-21 2:31 [PATCH v3 00/23] ncr5380: Eliminate macros, reduce code duplication, fix bugs etc Finn Thain
2016-03-21 2:31 ` [PATCH v3 01/23] g_ncr5380: Remove CONFIG_SCSI_GENERIC_NCR53C400 Finn Thain
2016-03-21 2:31 ` [PATCH v3 02/23] ncr5380: Remove FLAG_NO_PSEUDO_DMA where possible Finn Thain
2016-03-21 2:31 ` [PATCH v3 03/23] ncr5380: Remove REAL_DMA and REAL_DMA_POLL macros Finn Thain
2016-03-21 2:31 ` [PATCH v3 04/23] atari_NCR5380: Remove DMA_MIN_SIZE macro Finn Thain
2016-03-23 7:27 ` Hannes Reinecke
2016-03-21 2:31 ` [PATCH v3 05/23] ncr5380: Disable the DMA errata workaround flag by default Finn Thain
2016-03-21 2:31 ` [PATCH v3 06/23] ncr5380: Remove PSEUDO_DMA macro Finn Thain
2016-03-21 2:31 ` [PATCH v3 07/23] ncr5380: Remove BOARD_REQUIRES_NO_DELAY macro Finn Thain
2016-03-21 2:31 ` [PATCH v3 08/23] ncr5380: Use DMA hooks for PDMA Finn Thain
2016-03-21 2:31 ` [PATCH v3 09/23] ncr5380: Adopt uniform DMA setup convention Finn Thain
2016-03-21 2:31 ` [PATCH v3 10/23] ncr5380: Merge DMA implementation from atari_NCR5380 core driver Finn Thain
2016-03-21 2:32 ` [PATCH v3 11/23] atari_scsi: Adopt NCR5380.c " Finn Thain
2016-03-21 2:32 ` Finn Thain [this message]
2016-03-21 2:32 ` [PATCH v3 13/23] ncr5380: Remove disused atari_NCR5380.c " Finn Thain
2016-03-21 2:32 ` [PATCH v3 14/23] ncr5380: Reduce max_lun limit Finn Thain
2016-03-23 7:28 ` Hannes Reinecke
2016-03-21 2:32 ` [PATCH v3 15/23] dmx3191d: Drop max_sectors limit Finn Thain
2016-03-21 2:32 ` [PATCH v3 16/23] ncr5380: Fix register decoding for debugging Finn Thain
2016-03-21 2:32 ` [PATCH v3 17/23] ncr5380: Remove remaining register storage qualifiers Finn Thain
2016-03-21 2:32 ` [PATCH v3 18/23] ncr5380: Remove DONT_USE_INTR and AUTOPROBE_IRQ macros Finn Thain
2016-03-21 2:32 ` [PATCH v3 19/23] ncr5380: Update usage documentation Finn Thain
2016-03-21 2:32 ` [PATCH v3 20/23] atari_scsi: Set a reasonable default for cmd_per_lun Finn Thain
2016-03-23 7:28 ` Hannes Reinecke
2016-03-21 2:32 ` [PATCH v3 21/23] atari_scsi: Allow can_queue to be increased for Falcon Finn Thain
2016-03-21 2:32 ` [PATCH v3 22/23] mac_scsi: Fix pseudo DMA implementation Finn Thain
2016-03-21 2:32 ` [PATCH v3 23/23] ncr5380: Call complete_cmd() for disconnected commands on bus reset Finn Thain
2016-03-23 7:29 ` Hannes Reinecke
2016-03-22 22:24 ` [PATCH v3 00/23] ncr5380: Eliminate macros, reduce code duplication, fix bugs etc Ondrej Zary
2016-03-23 1:35 ` Finn Thain
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=20160321023152.803971245@telegraphics.com.au \
--to=fthain@telegraphics.com.au \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux@rainbow-software.org \
--cc=martin.petersen@oracle.com \
--cc=sammy@sammy.net \
--cc=schmitzmic@gmail.com \
/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