1997-04-15 07:22:50 +04:00
|
|
|
/* $NetBSD: mac68k5380.c,v 1.30 1997/04/15 03:22:50 briggs Exp $ */
|
1995-09-01 07:43:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Allen Briggs
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Allen Briggs
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Derived from atari5380.c for the mac68k port of NetBSD.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
1995-09-23 05:11:42 +04:00
|
|
|
#include <sys/dkstat.h>
|
1995-09-01 07:43:49 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsi_message.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include the driver definitions
|
|
|
|
*/
|
1996-05-05 10:15:56 +04:00
|
|
|
#include "ncr5380reg.h"
|
1995-09-01 07:43:49 +04:00
|
|
|
|
|
|
|
#include <machine/stdarg.h>
|
1996-03-29 05:06:04 +03:00
|
|
|
#include <machine/viareg.h>
|
1995-09-01 07:43:49 +04:00
|
|
|
|
1996-05-05 10:15:56 +04:00
|
|
|
#include "ncr5380var.h"
|
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
/*
|
|
|
|
* Set the various driver options
|
|
|
|
*/
|
|
|
|
#define NREQ 18 /* Size of issue queue */
|
|
|
|
#define AUTO_SENSE 1 /* Automatically issue a request-sense */
|
|
|
|
|
|
|
|
#define DRNAME ncrscsi /* used in various prints */
|
|
|
|
#undef DBG_SEL /* Show the selection process */
|
|
|
|
#undef DBG_REQ /* Show enqueued/ready requests */
|
|
|
|
#undef DBG_NOWRITE /* Do not allow writes to the targets */
|
|
|
|
#undef DBG_PIO /* Show the polled-I/O process */
|
|
|
|
#undef DBG_INF /* Show information transfer process */
|
|
|
|
#define DBG_NOSTATIC /* No static functions, all in DDB trace*/
|
1996-02-04 02:17:53 +03:00
|
|
|
#define DBG_PID 25 /* Keep track of driver */
|
|
|
|
#ifdef DBG_NOSTATIC
|
|
|
|
# define static
|
|
|
|
#endif
|
|
|
|
#ifdef DBG_SEL
|
1996-10-13 07:21:13 +04:00
|
|
|
# define DBG_SELPRINT(a,b) printf(a,b)
|
1996-02-04 02:17:53 +03:00
|
|
|
#else
|
|
|
|
# define DBG_SELPRINT(a,b)
|
|
|
|
#endif
|
|
|
|
#ifdef DBG_PIO
|
1996-10-13 07:21:13 +04:00
|
|
|
# define DBG_PIOPRINT(a,b,c) printf(a,b,c)
|
1996-02-04 02:17:53 +03:00
|
|
|
#else
|
|
|
|
# define DBG_PIOPRINT(a,b,c)
|
|
|
|
#endif
|
|
|
|
#ifdef DBG_INF
|
|
|
|
# define DBG_INFPRINT(a,b,c) a(b,c)
|
|
|
|
#else
|
|
|
|
# define DBG_INFPRINT(a,b,c)
|
|
|
|
#endif
|
|
|
|
#ifdef DBG_PID
|
|
|
|
/* static char *last_hit = NULL, *olast_hit = NULL; */
|
|
|
|
static char *last_hit[DBG_PID];
|
|
|
|
# define PID(a) \
|
|
|
|
{ int i; \
|
|
|
|
for (i=0; i< DBG_PID-1; i++) \
|
|
|
|
last_hit[i] = last_hit[i+1]; \
|
|
|
|
last_hit[DBG_PID-1] = a; }
|
|
|
|
#else
|
|
|
|
# define PID(a)
|
|
|
|
#endif
|
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
#undef REAL_DMA /* Use DMA if sensible */
|
1996-02-19 05:51:03 +03:00
|
|
|
#define scsi_ipending() (GET_5380_REG(NCR5380_DMSTAT) & SC_IRQ_SET)
|
1995-09-01 07:43:49 +04:00
|
|
|
#define fair_to_keep_dma() 1
|
|
|
|
#define claimed_dma() 1
|
|
|
|
#define reconsider_dma()
|
|
|
|
#define USE_PDMA 1 /* Use special pdma-transfer function */
|
1995-09-23 05:11:42 +04:00
|
|
|
#define MIN_PHYS 0x2000 /* pdma space w/ /DSACK is only 0x2000 */
|
1995-09-01 07:43:49 +04:00
|
|
|
|
|
|
|
#define ENABLE_NCR5380(sc) cur_softc = sc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* softc of currently active controller (well, we only have one for now).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct ncr_softc *cur_softc;
|
|
|
|
|
|
|
|
struct scsi_5380 {
|
|
|
|
volatile u_char scsi_5380[8*16]; /* 8 regs, 1 every 16th byte. */
|
|
|
|
};
|
|
|
|
|
|
|
|
extern vm_offset_t SCSIBase;
|
|
|
|
static volatile u_char *ncr = (volatile u_char *) 0x10000;
|
|
|
|
static volatile u_char *ncr_5380_with_drq = (volatile u_char *) 0x6000;
|
|
|
|
static volatile u_char *ncr_5380_without_drq = (volatile u_char *) 0x12000;
|
|
|
|
|
|
|
|
#define SCSI_5380 ((struct scsi_5380 *) ncr)
|
|
|
|
#define GET_5380_REG(rnum) SCSI_5380->scsi_5380[((rnum)<<4)]
|
|
|
|
#define SET_5380_REG(rnum,val) (SCSI_5380->scsi_5380[((rnum)<<4)] = (val))
|
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
static void ncr5380_irq_intr(void *);
|
|
|
|
static void ncr5380_drq_intr(void *);
|
|
|
|
static void do_ncr5380_drq_intr __P((void *));
|
1995-09-02 23:29:42 +04:00
|
|
|
|
1996-05-05 10:15:56 +04:00
|
|
|
static __inline__ void scsi_clr_ipend __P((void));
|
|
|
|
static void scsi_mach_init __P((struct ncr_softc *sc));
|
1996-12-20 00:48:17 +03:00
|
|
|
static int machine_match __P((struct device *parent,
|
|
|
|
struct cfdata *cf, void *aux,
|
|
|
|
struct cfdriver *cd));
|
1996-05-05 10:15:56 +04:00
|
|
|
static __inline__ int pdma_ready __P((void));
|
|
|
|
static int transfer_pdma __P((u_char *phasep, u_char *data,
|
|
|
|
u_long *count));
|
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
static __inline__ void
|
|
|
|
scsi_clr_ipend()
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
tmp = GET_5380_REG(NCR5380_IRCV);
|
1996-05-25 20:42:24 +04:00
|
|
|
scsi_clear_irq();
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scsi_mach_init(sc)
|
|
|
|
struct ncr_softc *sc;
|
|
|
|
{
|
|
|
|
static int initted = 0;
|
|
|
|
|
|
|
|
if (initted++)
|
|
|
|
panic("scsi_mach_init called again.\n");
|
|
|
|
|
|
|
|
ncr = (volatile u_char *)
|
|
|
|
(SCSIBase + (u_long) ncr);
|
|
|
|
ncr_5380_with_drq = (volatile u_char *)
|
|
|
|
(SCSIBase + (u_int) ncr_5380_with_drq);
|
|
|
|
ncr_5380_without_drq = (volatile u_char *)
|
|
|
|
(SCSIBase + (u_int) ncr_5380_without_drq);
|
1995-09-02 23:29:42 +04:00
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
if (VIA2 == VIA2OFF) {
|
1995-09-02 23:29:42 +04:00
|
|
|
scsi_enable = Via1Base + VIA2 * 0x2000 + vIER;
|
1996-05-25 20:42:24 +04:00
|
|
|
scsi_flag = Via1Base + VIA2 * 0x2000 + vIFR;
|
|
|
|
} else {
|
1995-09-02 23:29:42 +04:00
|
|
|
scsi_enable = Via1Base + VIA2 * 0x2000 + rIER;
|
1996-05-25 20:42:24 +04:00
|
|
|
scsi_flag = Via1Base + VIA2 * 0x2000 + rIFR;
|
|
|
|
}
|
1995-09-02 23:29:42 +04:00
|
|
|
|
1997-02-28 18:50:50 +03:00
|
|
|
via2_register_irq(VIA2_SCSIIRQ, ncr5380_irq_intr, sc);
|
|
|
|
via2_register_irq(VIA2_SCSIDRQ, ncr5380_drq_intr, sc);
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1996-12-20 00:48:17 +03:00
|
|
|
machine_match(parent, cf, aux, cd)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
struct cfdriver *cd;
|
1995-09-01 07:43:49 +04:00
|
|
|
{
|
|
|
|
if (!mac68k_machine.scsi80)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_PDMA
|
1995-09-02 23:29:42 +04:00
|
|
|
int pdma_5380_dir = 0;
|
1995-09-01 07:43:49 +04:00
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
u_char *pending_5380_data;
|
|
|
|
u_long pending_5380_count;
|
1995-09-01 07:43:49 +04:00
|
|
|
|
1996-01-24 09:02:06 +03:00
|
|
|
#define NCR5380_PDMA_DEBUG 1 /* Maybe we try with this off eventually. */
|
1995-09-23 05:11:42 +04:00
|
|
|
|
1996-01-24 09:02:06 +03:00
|
|
|
#if NCR5380_PDMA_DEBUG
|
1995-09-01 07:43:49 +04:00
|
|
|
int pdma_5380_sends = 0;
|
1995-09-02 07:19:37 +04:00
|
|
|
int pdma_5380_bytes = 0;
|
1995-09-01 07:43:49 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
pdma_stat()
|
|
|
|
{
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("PDMA SCSI: %d xfers completed for %d bytes.\n",
|
1995-09-02 23:29:42 +04:00
|
|
|
pdma_5380_sends, pdma_5380_bytes);
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("pdma_5380_dir = %d\t",
|
1995-09-02 23:29:42 +04:00
|
|
|
pdma_5380_dir);
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("datap = %p, remainder = %ld.\n",
|
1995-09-01 07:43:49 +04:00
|
|
|
pending_5380_data, pending_5380_count);
|
1996-01-24 09:02:06 +03:00
|
|
|
scsi_show();
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
void
|
|
|
|
pdma_cleanup(void)
|
|
|
|
{
|
|
|
|
SC_REQ *reqp = connected;
|
1996-05-05 10:15:56 +04:00
|
|
|
int s;
|
1995-09-02 07:19:37 +04:00
|
|
|
|
|
|
|
s = splbio();
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("pdma_cleanup0");
|
1995-09-02 07:19:37 +04:00
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
pdma_5380_dir = 0;
|
1995-09-02 07:19:37 +04:00
|
|
|
|
1996-01-24 09:02:06 +03:00
|
|
|
#if NCR5380_PDMA_DEBUG
|
1995-09-02 07:19:37 +04:00
|
|
|
pdma_5380_sends++;
|
|
|
|
pdma_5380_bytes+=(reqp->xdata_len - pending_5380_count);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update pointers.
|
|
|
|
*/
|
|
|
|
reqp->xdata_ptr += reqp->xdata_len - pending_5380_count;
|
|
|
|
reqp->xdata_len = pending_5380_count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset DMA mode.
|
|
|
|
*/
|
|
|
|
SET_5380_REG(NCR5380_MODE, GET_5380_REG(NCR5380_MODE) & ~SC_M_DMA);
|
|
|
|
|
1995-09-23 05:11:42 +04:00
|
|
|
/*
|
|
|
|
* Clear any pending interrupts.
|
|
|
|
*/
|
|
|
|
scsi_clr_ipend();
|
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
/*
|
|
|
|
* Tell interrupt functions that DMA has ended.
|
|
|
|
*/
|
|
|
|
reqp->dr_flag &= ~DRIVER_IN_DMA;
|
|
|
|
|
|
|
|
SET_5380_REG(NCR5380_MODE, IMODE_BASE);
|
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Back for more punishment.
|
|
|
|
*/
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("pdma_cleanup1");
|
1995-09-02 07:19:37 +04:00
|
|
|
run_main(cur_softc);
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("pdma_cleanup2");
|
1995-09-02 07:19:37 +04:00
|
|
|
}
|
1995-09-27 06:38:57 +03:00
|
|
|
#endif
|
1995-09-02 07:19:37 +04:00
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
static __inline__ int
|
1995-09-16 15:45:18 +04:00
|
|
|
pdma_ready()
|
1995-09-01 07:43:49 +04:00
|
|
|
{
|
1995-09-27 06:38:57 +03:00
|
|
|
#if USE_PDMA
|
|
|
|
SC_REQ *reqp = connected;
|
|
|
|
int dmstat, idstat;
|
|
|
|
extern u_char ncr5380_no_parchk;
|
|
|
|
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("pdma_ready0");
|
1995-09-02 23:29:42 +04:00
|
|
|
if (pdma_5380_dir) {
|
1996-06-07 05:45:43 +04:00
|
|
|
PID("pdma_ready1.");
|
1995-09-01 07:43:49 +04:00
|
|
|
/*
|
|
|
|
* For a phase mis-match, ATN is a "don't care," IRQ is 1 and
|
|
|
|
* all other bits in the Bus & Status Register are 0. Also,
|
|
|
|
* the current SCSI Bus Status Register has a 1 for BSY and
|
|
|
|
* REQ. Since we're just checking that this interrupt isn't a
|
|
|
|
* reselection or a reset, we just check for either.
|
|
|
|
*/
|
1996-05-25 20:42:24 +04:00
|
|
|
dmstat = GET_5380_REG(NCR5380_DMSTAT);
|
1995-09-27 06:38:57 +03:00
|
|
|
idstat = GET_5380_REG(NCR5380_IDSTAT);
|
|
|
|
if ( ((dmstat & (0xff & ~SC_ATN_STAT)) == SC_IRQ_SET)
|
|
|
|
&& ((idstat & (SC_S_BSY|SC_S_REQ))
|
|
|
|
== (SC_S_BSY | SC_S_REQ)) ) {
|
1996-05-25 20:42:24 +04:00
|
|
|
PID("pdma_ready2");
|
1995-09-27 06:38:57 +03:00
|
|
|
pdma_cleanup();
|
|
|
|
return 1;
|
|
|
|
} else if (PH_IN(reqp->phase) && (dmstat & SC_PAR_ERR)) {
|
|
|
|
if (!(ncr5380_no_parchk & (1 << reqp->targ_id)))
|
|
|
|
/* XXX: Should be parity error ???? */
|
|
|
|
reqp->xs->error = XS_DRIVER_STUFFUP;
|
1996-05-25 20:42:24 +04:00
|
|
|
PID("pdma_ready3");
|
1995-09-27 06:38:57 +03:00
|
|
|
/* XXX: is this the right reaction? */
|
|
|
|
pdma_cleanup();
|
|
|
|
return 1;
|
|
|
|
} else if ( !(idstat & SC_S_REQ)
|
|
|
|
|| (((idstat>>2) & 7) != reqp->phase)) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* XXX: is this the right reaction? Can this happen? */
|
|
|
|
scsi_show();
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("Unexpected phase change.\n");
|
1995-09-27 06:38:57 +03:00
|
|
|
#endif
|
|
|
|
reqp->xs->error = XS_DRIVER_STUFFUP;
|
1995-09-02 07:19:37 +04:00
|
|
|
pdma_cleanup();
|
1995-09-02 09:35:59 +04:00
|
|
|
return 1;
|
1995-09-02 07:19:37 +04:00
|
|
|
} else {
|
|
|
|
scsi_show();
|
|
|
|
panic("Spurious interrupt during PDMA xfer.\n");
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
1996-02-04 02:17:53 +03:00
|
|
|
} else
|
1996-05-25 20:42:24 +04:00
|
|
|
PID("pdma_ready4");
|
1995-09-27 06:38:57 +03:00
|
|
|
#endif
|
1995-09-02 09:35:59 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
static void
|
1995-09-04 09:07:16 +04:00
|
|
|
ncr5380_irq_intr(p)
|
|
|
|
void *p;
|
1995-09-02 09:35:59 +04:00
|
|
|
{
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("irq");
|
1996-05-25 20:42:24 +04:00
|
|
|
|
1995-09-27 06:38:57 +03:00
|
|
|
#if USE_PDMA
|
1995-09-16 15:45:18 +04:00
|
|
|
if (pdma_ready()) {
|
1995-09-02 09:35:59 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-09-27 06:38:57 +03:00
|
|
|
#endif
|
1996-05-25 20:42:24 +04:00
|
|
|
scsi_idisable();
|
|
|
|
ncr_ctrl_intr(cur_softc);
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
/*
|
1995-09-23 05:11:42 +04:00
|
|
|
* This is the meat of the PDMA transfer.
|
|
|
|
* When we get here, we shove data as fast as the mac can take it.
|
|
|
|
* We depend on several things:
|
|
|
|
* * All macs after the Mac Plus that have a 5380 chip should have a general
|
|
|
|
* logic IC that handshakes data for blind transfers.
|
|
|
|
* * If the SCSI controller finishes sending/receiving data before we do,
|
|
|
|
* the same general logic IC will generate a /BERR for us in short order.
|
|
|
|
* * The fault address for said /BERR minus the base address for the
|
|
|
|
* transfer will be the amount of data that was actually written.
|
|
|
|
*
|
|
|
|
* We use the nofault flag and the setjmp/longjmp in locore.s so we can
|
|
|
|
* detect and handle the bus error for early termination of a command.
|
|
|
|
* This is usually caused by a disconnecting target.
|
1995-09-02 23:29:42 +04:00
|
|
|
*/
|
1996-05-25 20:42:24 +04:00
|
|
|
static void
|
|
|
|
do_ncr5380_drq_intr(p)
|
1995-09-04 09:07:16 +04:00
|
|
|
void *p;
|
1995-09-01 07:43:49 +04:00
|
|
|
{
|
|
|
|
#if USE_PDMA
|
1995-09-23 05:11:42 +04:00
|
|
|
extern int *nofault, mac68k_buserr_addr;
|
|
|
|
label_t faultbuf;
|
|
|
|
register int count;
|
|
|
|
volatile u_int32_t *long_drq;
|
|
|
|
u_int32_t *long_data;
|
1996-05-25 20:42:24 +04:00
|
|
|
volatile u_int8_t *drq, tmp_data;
|
1995-09-23 05:11:42 +04:00
|
|
|
u_int8_t *data;
|
|
|
|
|
1996-02-04 02:17:53 +03:00
|
|
|
#if DBG_PID
|
|
|
|
if (pdma_5380_dir == 2) {
|
|
|
|
PID("drq (in)");
|
|
|
|
} else {
|
|
|
|
PID("drq (out)");
|
|
|
|
}
|
1995-09-01 07:43:49 +04:00
|
|
|
#endif
|
1995-09-23 05:11:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup for a possible bus error caused by SCSI controller
|
|
|
|
* switching out of DATA-IN/OUT before we're done with the
|
|
|
|
* current transfer.
|
|
|
|
*/
|
|
|
|
nofault = (int *) &faultbuf;
|
|
|
|
|
|
|
|
if (setjmp((label_t *) nofault)) {
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("drq berr");
|
1995-09-23 05:11:42 +04:00
|
|
|
nofault = (int *) 0;
|
|
|
|
count = ( (u_long) mac68k_buserr_addr
|
|
|
|
- (u_long) ncr_5380_with_drq);
|
|
|
|
if ((count < 0) || (count > pending_5380_count)) {
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("pdma %s: cnt = %d (0x%x) (pending cnt %ld)\n",
|
1995-11-01 07:59:03 +03:00
|
|
|
(pdma_5380_dir == 2) ? "in" : "out",
|
|
|
|
count, count, pending_5380_count);
|
1995-09-23 05:11:42 +04:00
|
|
|
panic("something is wrong");
|
|
|
|
}
|
|
|
|
|
|
|
|
pending_5380_data += count;
|
|
|
|
pending_5380_count -= count;
|
|
|
|
|
|
|
|
mac68k_buserr_addr = 0;
|
1996-05-25 20:42:24 +04:00
|
|
|
|
|
|
|
PID("end drq early");
|
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
return;
|
1995-09-23 05:11:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdma_5380_dir == 2) { /* Data In */
|
|
|
|
int resid;
|
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
/*
|
1995-09-23 05:11:42 +04:00
|
|
|
* Get the dest address aligned.
|
1995-09-02 23:29:42 +04:00
|
|
|
*/
|
1996-01-24 09:02:06 +03:00
|
|
|
resid = count = min(pending_5380_count,
|
|
|
|
4 - (((int) pending_5380_data) & 0x3));
|
|
|
|
if (count && (count < 4)) {
|
1995-09-23 05:11:42 +04:00
|
|
|
data = (u_int8_t *) pending_5380_data;
|
|
|
|
drq = (u_int8_t *) ncr_5380_with_drq;
|
|
|
|
while (count) {
|
|
|
|
#define R1 *data++ = *drq++
|
|
|
|
R1; count--;
|
|
|
|
#undef R1
|
|
|
|
}
|
|
|
|
pending_5380_data += resid;
|
|
|
|
pending_5380_count -= resid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get ready to start the transfer.
|
|
|
|
*/
|
1995-09-27 06:38:57 +03:00
|
|
|
while (pending_5380_count) {
|
|
|
|
int dcount;
|
|
|
|
|
|
|
|
dcount = count = min(pending_5380_count, MIN_PHYS);
|
1995-09-23 05:11:42 +04:00
|
|
|
long_drq = (volatile u_int32_t *) ncr_5380_with_drq;
|
1995-10-01 00:34:54 +03:00
|
|
|
long_data = (u_int32_t *) pending_5380_data;
|
1995-09-23 05:11:42 +04:00
|
|
|
|
|
|
|
#define R4 *long_data++ = *long_drq++
|
1997-04-15 07:22:50 +04:00
|
|
|
while ( count > 64 ) {
|
1995-09-23 05:11:42 +04:00
|
|
|
R4; R4; R4; R4; R4; R4; R4; R4;
|
|
|
|
R4; R4; R4; R4; R4; R4; R4; R4; /* 64 */
|
1996-05-25 20:42:24 +04:00
|
|
|
count -= 64;
|
1995-09-23 05:11:42 +04:00
|
|
|
}
|
1997-04-15 07:22:50 +04:00
|
|
|
while (count > 8) {
|
|
|
|
R4; R4; count -= 8;
|
1995-09-23 05:11:42 +04:00
|
|
|
}
|
|
|
|
#undef R4
|
|
|
|
data = (u_int8_t *) long_data;
|
|
|
|
drq = (u_int8_t *) long_drq;
|
|
|
|
while (count) {
|
|
|
|
#define R1 *data++ = *drq++
|
|
|
|
R1; count--;
|
|
|
|
#undef R1
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
1995-09-27 06:38:57 +03:00
|
|
|
pending_5380_count -= dcount;
|
1995-10-01 00:34:54 +03:00
|
|
|
pending_5380_data += dcount;
|
1995-09-27 06:38:57 +03:00
|
|
|
}
|
1997-04-15 07:22:50 +04:00
|
|
|
/*
|
|
|
|
* OK. No bus error occurred above. Clear the nofault flag
|
|
|
|
* so we no longer short-circuit bus errors.
|
|
|
|
*/
|
|
|
|
nofault = (int *) 0;
|
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
} else {
|
1995-09-23 05:11:42 +04:00
|
|
|
int resid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the source address aligned.
|
|
|
|
*/
|
1996-01-24 09:02:06 +03:00
|
|
|
resid = count = min(pending_5380_count,
|
|
|
|
4 - (((int) pending_5380_data) & 0x3));
|
|
|
|
if (count && (count < 4)) {
|
1995-09-23 05:11:42 +04:00
|
|
|
data = (u_int8_t *) pending_5380_data;
|
|
|
|
drq = (u_int8_t *) ncr_5380_with_drq;
|
|
|
|
while (count) {
|
|
|
|
#define W1 *drq++ = *data++
|
|
|
|
W1; count--;
|
|
|
|
#undef W1
|
|
|
|
}
|
|
|
|
pending_5380_data += resid;
|
|
|
|
pending_5380_count -= resid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get ready to start the transfer.
|
|
|
|
*/
|
1995-09-27 06:38:57 +03:00
|
|
|
while (pending_5380_count) {
|
|
|
|
int dcount;
|
|
|
|
|
|
|
|
dcount = count = min(pending_5380_count, MIN_PHYS);
|
1995-09-23 05:11:42 +04:00
|
|
|
long_drq = (volatile u_int32_t *) ncr_5380_with_drq;
|
1995-10-01 00:34:54 +03:00
|
|
|
long_data = (u_int32_t *) pending_5380_data;
|
1995-09-23 05:11:42 +04:00
|
|
|
|
|
|
|
#define W4 *long_drq++ = *long_data++
|
1997-04-15 07:22:50 +04:00
|
|
|
while ( count > 64 ) {
|
1995-09-23 05:11:42 +04:00
|
|
|
W4; W4; W4; W4; W4; W4; W4; W4;
|
1995-09-27 06:38:57 +03:00
|
|
|
W4; W4; W4; W4; W4; W4; W4; W4; /* 64 */
|
1995-09-23 05:11:42 +04:00
|
|
|
count -= 64;
|
|
|
|
}
|
1997-04-15 07:22:50 +04:00
|
|
|
while ( count > 8 ) {
|
|
|
|
W4; W4;
|
|
|
|
count -= 8;
|
1995-09-23 05:11:42 +04:00
|
|
|
}
|
|
|
|
#undef W4
|
|
|
|
data = (u_int8_t *) long_data;
|
|
|
|
drq = (u_int8_t *) long_drq;
|
|
|
|
while (count) {
|
|
|
|
#define W1 *drq++ = *data++
|
|
|
|
W1; count--;
|
|
|
|
#undef W1
|
1995-09-27 06:38:57 +03:00
|
|
|
}
|
|
|
|
pending_5380_count -= dcount;
|
1995-10-01 00:34:54 +03:00
|
|
|
pending_5380_data += dcount;
|
1995-09-27 06:38:57 +03:00
|
|
|
}
|
1997-04-15 07:22:50 +04:00
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
PID("write complete");
|
|
|
|
|
1997-04-15 07:22:50 +04:00
|
|
|
/*
|
|
|
|
* OK. No bus error occurred above. Clear the nofault flag
|
|
|
|
* so we no longer short-circuit bus errors.
|
|
|
|
*/
|
|
|
|
nofault = (int *) 0;
|
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
drq = (volatile u_int8_t *) ncr_5380_with_drq;
|
|
|
|
tmp_data = *drq;
|
|
|
|
|
1997-04-15 07:22:50 +04:00
|
|
|
PID("read a byte to force a phase change");
|
1995-09-02 23:29:42 +04:00
|
|
|
}
|
1995-09-23 05:11:42 +04:00
|
|
|
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("end drq");
|
1996-05-25 20:42:24 +04:00
|
|
|
return;
|
|
|
|
#else
|
|
|
|
return;
|
1995-09-02 23:29:42 +04:00
|
|
|
#endif /* if USE_PDMA */
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
1996-05-25 20:42:24 +04:00
|
|
|
static void
|
|
|
|
ncr5380_drq_intr(p)
|
|
|
|
void *p;
|
|
|
|
{
|
|
|
|
while (GET_5380_REG(NCR5380_DMSTAT) & SC_DMA_REQ) {
|
|
|
|
do_ncr5380_drq_intr(p);
|
|
|
|
scsi_clear_drq();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
#if USE_PDMA
|
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
#define SCSI_TIMEOUT_VAL 10000000
|
|
|
|
|
|
|
|
static int
|
|
|
|
transfer_pdma(phasep, data, count)
|
|
|
|
u_char *phasep;
|
|
|
|
u_char *data;
|
|
|
|
u_long *count;
|
|
|
|
{
|
|
|
|
SC_REQ *reqp = connected;
|
1996-05-05 10:15:56 +04:00
|
|
|
int len = *count, s, scsi_timeout = SCSI_TIMEOUT_VAL;
|
1995-09-01 07:43:49 +04:00
|
|
|
|
1995-09-02 23:29:42 +04:00
|
|
|
if (pdma_5380_dir) {
|
1995-09-01 07:43:49 +04:00
|
|
|
panic("ncrscsi: transfer_pdma called when operation already "
|
|
|
|
"pending.\n");
|
|
|
|
}
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("transfer_pdma0")
|
1995-09-01 07:43:49 +04:00
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
/*
|
1995-09-23 05:11:42 +04:00
|
|
|
* Don't bother with PDMA if we can't sleep or for small transfers.
|
1995-09-02 07:19:37 +04:00
|
|
|
*/
|
1995-09-16 22:22:33 +04:00
|
|
|
if (reqp->dr_flag & DRIVER_NOINT) {
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("pdma, falling back to transfer_pio.")
|
1995-09-13 02:31:45 +04:00
|
|
|
transfer_pio(phasep, data, count, 0);
|
1995-09-02 07:19:37 +04:00
|
|
|
return -1;
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
/*
|
|
|
|
* We are probably already at spl2(), so this is likely a no-op.
|
|
|
|
* Paranoia.
|
|
|
|
*/
|
|
|
|
s = splbio();
|
|
|
|
|
1995-09-23 05:11:42 +04:00
|
|
|
scsi_idisable();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Match phases with target.
|
|
|
|
*/
|
|
|
|
SET_5380_REG(NCR5380_TCOM, *phasep);
|
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
/*
|
|
|
|
* Clear pending interrupts.
|
|
|
|
*/
|
1995-09-01 07:43:49 +04:00
|
|
|
scsi_clr_ipend();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until target asserts BSY.
|
|
|
|
*/
|
1995-09-23 05:11:42 +04:00
|
|
|
while ( ((GET_5380_REG(NCR5380_IDSTAT) & SC_S_BSY) == 0)
|
|
|
|
&& (--scsi_timeout) );
|
1995-09-01 07:43:49 +04:00
|
|
|
if (!scsi_timeout) {
|
|
|
|
#if DIAGNOSTIC
|
1996-10-13 07:21:13 +04:00
|
|
|
printf("scsi timeout: waiting for BSY in %s.\n",
|
1995-09-23 05:11:42 +04:00
|
|
|
(*phasep == PH_DATAOUT) ? "pdma_out" : "pdma_in");
|
1995-09-01 07:43:49 +04:00
|
|
|
#endif
|
|
|
|
goto scsi_timeout_error;
|
|
|
|
}
|
|
|
|
|
1995-09-02 07:19:37 +04:00
|
|
|
/*
|
|
|
|
* Tell the driver that we're in DMA mode.
|
|
|
|
*/
|
|
|
|
reqp->dr_flag |= DRIVER_IN_DMA;
|
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
/*
|
1995-09-02 23:29:42 +04:00
|
|
|
* Load transfer values for DRQ interrupt handlers.
|
1995-09-01 07:43:49 +04:00
|
|
|
*/
|
1995-09-02 23:29:42 +04:00
|
|
|
pending_5380_data = data;
|
1995-09-01 07:43:49 +04:00
|
|
|
pending_5380_count = len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the transfer function to be called on DRQ interrupts.
|
1995-09-02 07:19:37 +04:00
|
|
|
* And note that we're waiting.
|
1995-09-01 07:43:49 +04:00
|
|
|
*/
|
1995-09-02 23:29:42 +04:00
|
|
|
switch (*phasep) {
|
|
|
|
default:
|
|
|
|
panic("Unexpected phase in transfer_pdma.\n");
|
|
|
|
case PH_DATAOUT:
|
|
|
|
pdma_5380_dir = 1;
|
1996-01-24 09:02:06 +03:00
|
|
|
SET_5380_REG(NCR5380_ICOM, GET_5380_REG(NCR5380_ICOM)|SC_ADTB);
|
|
|
|
SET_5380_REG(NCR5380_MODE, GET_5380_REG(NCR5380_MODE)|SC_M_DMA);
|
1995-09-23 05:11:42 +04:00
|
|
|
SET_5380_REG(NCR5380_DMSTAT, 0);
|
1995-09-02 23:29:42 +04:00
|
|
|
break;
|
|
|
|
case PH_DATAIN:
|
|
|
|
pdma_5380_dir = 2;
|
1996-01-24 09:02:06 +03:00
|
|
|
SET_5380_REG(NCR5380_ICOM, 0);
|
|
|
|
SET_5380_REG(NCR5380_MODE, GET_5380_REG(NCR5380_MODE)|SC_M_DMA);
|
1995-09-01 07:43:49 +04:00
|
|
|
SET_5380_REG(NCR5380_IRCV, 0);
|
1995-09-23 05:11:42 +04:00
|
|
|
break;
|
1995-09-01 07:43:49 +04:00
|
|
|
}
|
|
|
|
|
1996-02-04 02:17:53 +03:00
|
|
|
PID("waiting for interrupt.")
|
1996-01-24 09:02:06 +03:00
|
|
|
|
1995-09-01 07:43:49 +04:00
|
|
|
/*
|
|
|
|
* Now that we're set up, enable interrupts and drop processor
|
1995-09-02 07:19:37 +04:00
|
|
|
* priority back down.
|
1995-09-01 07:43:49 +04:00
|
|
|
*/
|
|
|
|
scsi_ienable();
|
|
|
|
splx(s);
|
1995-09-02 07:19:37 +04:00
|
|
|
return 0;
|
1995-09-01 07:43:49 +04:00
|
|
|
|
|
|
|
scsi_timeout_error:
|
|
|
|
/*
|
|
|
|
* Clear the DMA mode.
|
|
|
|
*/
|
|
|
|
SET_5380_REG(NCR5380_MODE, GET_5380_REG(NCR5380_MODE) & ~SC_M_DMA);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* if USE_PDMA */
|
|
|
|
|
|
|
|
/* Include general routines. */
|
1995-09-03 07:36:35 +04:00
|
|
|
#include <mac68k/dev/ncr5380.c>
|