1995-09-26 23:15:57 +03:00
|
|
|
/* $NetBSD: ncr.c,v 1.20 1995/09/26 20:16:08 phil Exp $ */
|
1994-10-26 11:23:50 +03:00
|
|
|
|
1995-01-19 10:03:35 +03:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* Copyright (c) 1994 Matthias Pfaller.
|
1994-02-23 01:54:42 +03:00
|
|
|
* 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:
|
1995-08-25 11:30:33 +04:00
|
|
|
* This product includes software developed by Matthias Pfaller.
|
1995-06-09 08:36:14 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
1994-02-23 01:54:42 +03:00
|
|
|
*
|
1995-06-09 08:36:14 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
1994-02-23 01:54:42 +03:00
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
1995-06-09 08:36:14 +04:00
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
1994-02-23 01:54:42 +03:00
|
|
|
* 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
|
1995-06-09 08:36:14 +04:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1995-08-25 11:30:33 +04:00
|
|
|
*
|
1995-09-26 23:15:57 +03:00
|
|
|
* $Id: ncr.c,v 1.20 1995/09/26 20:16:08 phil Exp $
|
1994-02-23 01:54:42 +03:00
|
|
|
*/
|
|
|
|
|
1994-05-17 21:29:34 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1995-05-16 11:30:30 +04:00
|
|
|
#include <sys/kernel.h>
|
1994-05-17 21:29:34 +04:00
|
|
|
#include <sys/device.h>
|
1995-06-09 08:36:14 +04:00
|
|
|
#include <sys/buf.h>
|
1995-01-19 10:03:35 +03:00
|
|
|
#include <scsi/scsi_all.h>
|
1995-06-09 08:36:14 +04:00
|
|
|
#include <scsi/scsi_message.h>
|
1995-01-19 10:03:35 +03:00
|
|
|
#include <scsi/scsiconf.h>
|
1995-08-25 11:30:33 +04:00
|
|
|
#include <machine/stdarg.h>
|
1995-01-19 10:03:35 +03:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* Include the driver definitions
|
1995-06-09 08:36:14 +04:00
|
|
|
*/
|
1995-08-25 11:30:33 +04:00
|
|
|
#include "ncr5380reg.h"
|
|
|
|
#include "ncrreg.h"
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* Set the various driver options
|
1995-06-09 08:36:14 +04:00
|
|
|
*/
|
1995-08-25 11:30:33 +04:00
|
|
|
#define NREQ 18 /* Size of issue queue */
|
|
|
|
#define AUTO_SENSE 1 /* Automatically issue a request-sense */
|
1995-06-09 08:36:14 +04:00
|
|
|
|
1995-08-25 11:30:33 +04:00
|
|
|
#define DRNAME ncr /* 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 */
|
|
|
|
#undef DBG_NOSTATIC /* No static functions, all in DDB trace*/
|
|
|
|
#define DBG_PID /* Keep track of driver */
|
|
|
|
#undef REAL_DMA /* Use DMA if sensible */
|
|
|
|
#undef REAL_DMA_POLL 0 /* 1: Poll for end of DMA-transfer */
|
|
|
|
#define USE_PDMA /* Use special pdma-transfer function */
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* Softc of currently active controller (a bit of fake; we only have one)
|
1995-06-09 08:36:14 +04:00
|
|
|
*/
|
1995-08-25 11:30:33 +04:00
|
|
|
static struct ncr_softc *cur_softc;
|
1995-06-09 08:36:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function decls:
|
|
|
|
*/
|
1995-09-26 23:15:57 +03:00
|
|
|
static int transfer_pdma __P((u_char *, u_char *, u_long *));
|
1995-06-09 08:36:14 +04:00
|
|
|
static void ncr_intr __P((void *));
|
1995-08-25 11:30:33 +04:00
|
|
|
static void ncr_soft_intr __P((void *));
|
1995-09-26 23:15:57 +03:00
|
|
|
#define scsi_dmaok(x) 0
|
|
|
|
#define pdma_ready() 0
|
1995-08-25 11:30:33 +04:00
|
|
|
#define fair_to_keep_dma() 1
|
|
|
|
#define claimed_dma() 1
|
|
|
|
#define reconsider_dma()
|
|
|
|
#define ENABLE_NCR5380(sc) do { \
|
|
|
|
scsi_select_ctlr(DP8490); \
|
|
|
|
cur_softc = sc; \
|
|
|
|
} while (0)
|
1995-06-09 08:36:14 +04:00
|
|
|
|
|
|
|
void
|
1995-08-25 11:30:33 +04:00
|
|
|
delay(timeo)
|
|
|
|
int timeo;
|
1994-02-23 01:54:42 +03:00
|
|
|
{
|
1995-06-09 08:36:14 +04:00
|
|
|
int len;
|
1995-08-25 11:30:33 +04:00
|
|
|
for (len=0; len < timeo * 2; len++);
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
|
|
|
|
1995-08-25 11:30:33 +04:00
|
|
|
static int
|
|
|
|
machine_match(pdp, cdp, auxp, cfd)
|
|
|
|
struct device *pdp;
|
|
|
|
struct cfdata *cdp;
|
|
|
|
void *auxp;
|
|
|
|
struct cfdriver *cfd;
|
1995-06-09 08:36:14 +04:00
|
|
|
{
|
|
|
|
if(cdp->cf_unit != 0) /* Only one unit */
|
|
|
|
return(0);
|
|
|
|
return(1);
|
1994-02-23 01:54:42 +03:00
|
|
|
}
|
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
static void
|
1995-08-25 11:30:33 +04:00
|
|
|
scsi_mach_init(sc)
|
|
|
|
struct ncr_softc *sc;
|
1995-06-09 08:36:14 +04:00
|
|
|
{
|
1995-08-25 11:30:33 +04:00
|
|
|
register int i;
|
1995-06-09 08:36:14 +04:00
|
|
|
intr_disable(IR_SCSI1);
|
1995-08-30 02:44:27 +04:00
|
|
|
i = intr_establish(SOFTINT, ncr_soft_intr, sc, sc->sc_dev.dv_xname,
|
|
|
|
IPL_BIO, 0);
|
|
|
|
intr_establish(IR_SCSI1, ncr_intr, (void *)i, sc->sc_dev.dv_xname,
|
|
|
|
IPL_BIO, RISING_EDGE);
|
1995-08-25 11:30:33 +04:00
|
|
|
printf(" addr 0x%x, irq %d", NCR5380, IR_SCSI1);
|
1994-02-23 01:54:42 +03:00
|
|
|
}
|
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* 5380 interrupt.
|
1995-06-09 08:36:14 +04:00
|
|
|
*/
|
|
|
|
static void
|
1995-08-25 11:30:33 +04:00
|
|
|
ncr_intr(softint)
|
|
|
|
void *softint;
|
1994-02-23 01:54:42 +03:00
|
|
|
{
|
1995-08-25 11:30:33 +04:00
|
|
|
int ctrlr;
|
1995-06-09 08:36:14 +04:00
|
|
|
|
|
|
|
ctrlr = scsi_select_ctlr(DP8490);
|
1995-08-25 11:30:33 +04:00
|
|
|
if (NCR5380->ncr_dmstat & SC_IRQ_SET) {
|
1995-06-09 08:36:14 +04:00
|
|
|
intr_disable(IR_SCSI1);
|
|
|
|
softintr((int)softint);
|
|
|
|
}
|
|
|
|
scsi_select_ctlr(ctrlr);
|
1994-02-23 01:54:42 +03:00
|
|
|
}
|
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
static void
|
1995-08-25 11:30:33 +04:00
|
|
|
ncr_soft_intr(sc)
|
|
|
|
void *sc;
|
1994-02-23 01:54:42 +03:00
|
|
|
{
|
1995-08-25 11:30:33 +04:00
|
|
|
int ctrlr = scsi_select_ctlr(DP8490);
|
|
|
|
ncr_ctrl_intr(sc);
|
|
|
|
scsi_select_ctlr(ctrlr);
|
1994-02-23 01:54:42 +03:00
|
|
|
}
|
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
/*
|
1995-08-25 11:30:33 +04:00
|
|
|
* PDMA stuff
|
1995-06-09 08:36:14 +04:00
|
|
|
*/
|
1995-08-25 11:30:33 +04:00
|
|
|
#define movsd(from, to, n) do { \
|
|
|
|
register int r0 __asm ("r0") = n; \
|
|
|
|
register u_char *r1 __asm("r1") = from; \
|
|
|
|
register u_char *r2 __asm("r2") = to; \
|
|
|
|
__asm volatile ("movsd" \
|
|
|
|
: "=r" (r1), "=r" (r2) \
|
|
|
|
: "0" (r1), "1" (r2), "r" (r0) \
|
|
|
|
: "r0", "memory" \
|
|
|
|
); \
|
|
|
|
from = r1; to = r2; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define movsb(from, to, n) do { \
|
|
|
|
register int r0 __asm ("r0") = n; \
|
|
|
|
register u_char *r1 __asm("r1") = from; \
|
|
|
|
register u_char *r2 __asm("r2") = to; \
|
|
|
|
__asm volatile ("movsb" \
|
|
|
|
: "=r" (r1), "=r" (r2) \
|
|
|
|
: "0" (r1), "1" (r2), "r" (r0) \
|
|
|
|
: "r0", "memory" \
|
|
|
|
); \
|
|
|
|
from = r1; to = r2; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define TIMEOUT 1000000
|
|
|
|
#define READY(dataout) do { \
|
|
|
|
for (i = TIMEOUT; i > 0; i --) { \
|
1995-08-30 02:44:27 +04:00
|
|
|
/*if (!(NCR5380->ncr_dmstat & SC_PHS_MTCH)) {*/ \
|
1995-08-25 11:30:33 +04:00
|
|
|
if (NCR5380->ncr_dmstat & SC_IRQ_SET) { \
|
|
|
|
if (dataout) NCR5380->ncr_icom &= ~SC_ADTB; \
|
|
|
|
NCR5380->ncr_mode &= ~SC_M_DMA; \
|
|
|
|
*count = len; \
|
|
|
|
if ((idstat = NCR5380->ncr_idstat) & SC_S_REQ) \
|
|
|
|
*phase = (idstat >> 2) & 7; \
|
|
|
|
else \
|
|
|
|
*phase = NR_PHASE; \
|
1995-09-26 23:15:57 +03:00
|
|
|
return(1); \
|
1994-02-23 01:54:42 +03:00
|
|
|
} \
|
1995-08-25 11:30:33 +04:00
|
|
|
if (NCR5380->ncr_dmstat & SC_DMA_REQ) break; \
|
|
|
|
delay(1); \
|
|
|
|
} \
|
|
|
|
if (i <= 0) panic("ncr0: pdma timeout"); \
|
|
|
|
} while (0)
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
#define byte_data ((volatile u_char *)pdma)
|
|
|
|
#define word_data ((volatile u_short *)pdma)
|
|
|
|
#define long_data ((volatile u_long *)pdma)
|
1995-06-27 03:13:54 +04:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
#define W1(n) *byte_data = *(data + n)
|
|
|
|
#define W2(n) *word_data = *((u_short *)data + n)
|
|
|
|
#define W4(n) *long_data = *((u_long *)data + n)
|
1995-06-27 03:13:54 +04:00
|
|
|
#define R1(n) *(data + n) = *byte_data
|
1995-06-09 08:36:14 +04:00
|
|
|
#define R4(n) *((u_long *)data + n) = *long_data
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-09-26 23:15:57 +03:00
|
|
|
static int
|
1995-08-25 11:30:33 +04:00
|
|
|
transfer_pdma(phase, data, count)
|
|
|
|
u_char *phase;
|
|
|
|
u_char *data;
|
|
|
|
u_long *count;
|
1994-02-23 01:54:42 +03:00
|
|
|
{
|
1995-06-09 08:36:14 +04:00
|
|
|
register volatile u_char *pdma = PDMA_ADDRESS;
|
1995-06-18 11:18:02 +04:00
|
|
|
register int len = *count, i, idstat;
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-06-09 08:36:14 +04:00
|
|
|
if (len < 256) {
|
1995-08-30 02:44:27 +04:00
|
|
|
__asm volatile ("lmr ivar0,%0" : : "g" (data));
|
1995-09-26 23:15:57 +03:00
|
|
|
transfer_pio(phase, data, count, 0);
|
|
|
|
return(1);
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
1995-08-25 11:30:33 +04:00
|
|
|
NCR5380->ncr_tcom = *phase;
|
|
|
|
scsi_clr_ipend();
|
1995-06-09 08:36:14 +04:00
|
|
|
if (PH_IN(*phase)) {
|
1995-08-25 11:30:33 +04:00
|
|
|
NCR5380->ncr_icom = 0;
|
|
|
|
NCR5380->ncr_mode = IMODE_BASE | SC_M_DMA;
|
|
|
|
NCR5380->ncr_ircv = 0;
|
|
|
|
while (len >= 256) {
|
1995-08-30 02:44:27 +04:00
|
|
|
if (!((u_long) data & 0xfff))
|
|
|
|
__asm volatile ("lmr ivar0,%0" : : "g" (data));
|
1995-06-09 08:36:14 +04:00
|
|
|
READY(0);
|
1995-06-18 11:18:02 +04:00
|
|
|
di();
|
1995-08-25 11:30:33 +04:00
|
|
|
movsd((u_char *)pdma, data, 64);
|
|
|
|
len -= 256;
|
1995-08-30 02:44:27 +04:00
|
|
|
ei();
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
1995-08-25 11:30:33 +04:00
|
|
|
if (len) {
|
|
|
|
di();
|
|
|
|
while (len) {
|
|
|
|
READY(0);
|
|
|
|
R1(0);
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
ei();
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
|
|
|
} else {
|
1995-08-25 11:30:33 +04:00
|
|
|
NCR5380->ncr_mode = IMODE_BASE | SC_M_DMA;
|
|
|
|
NCR5380->ncr_icom = SC_ADTB;
|
|
|
|
NCR5380->ncr_dmstat = SC_S_SEND;
|
|
|
|
while (len >= 256) {
|
1995-06-09 08:36:14 +04:00
|
|
|
/* The second ready is to
|
|
|
|
* compensate for DMA-prefetch.
|
|
|
|
* Since we adjust len only at
|
|
|
|
* the end of the block, there
|
|
|
|
* is no need to correct the
|
|
|
|
* residue.
|
|
|
|
*/
|
1995-08-25 11:30:33 +04:00
|
|
|
READY(1);
|
|
|
|
di();
|
|
|
|
W1(0); READY(1); W1(1); W2(1);
|
|
|
|
data += 4;
|
|
|
|
movsd(data, (u_char *)pdma, 63);
|
|
|
|
ei();
|
|
|
|
len -= 256;
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
READY(1);
|
1995-08-25 11:30:33 +04:00
|
|
|
di();
|
1995-06-09 08:36:14 +04:00
|
|
|
while (len) {
|
|
|
|
W1(0);
|
|
|
|
READY(1);
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
1995-08-25 11:30:33 +04:00
|
|
|
ei();
|
1995-06-09 08:36:14 +04:00
|
|
|
}
|
|
|
|
i = TIMEOUT;
|
1995-08-25 11:30:33 +04:00
|
|
|
while (((NCR5380->ncr_dmstat & (SC_DMA_REQ|SC_PHS_MTCH))
|
1995-06-09 08:36:14 +04:00
|
|
|
== SC_PHS_MTCH) && --i);
|
|
|
|
if (!i)
|
|
|
|
printf("ncr0: timeout waiting for SC_DMA_REQ.\n");
|
|
|
|
*byte_data = 0;
|
|
|
|
}
|
1994-02-23 01:54:42 +03:00
|
|
|
|
1995-08-25 11:30:33 +04:00
|
|
|
ncr_timeout_error:
|
|
|
|
NCR5380->ncr_mode &= ~SC_M_DMA;
|
|
|
|
if((idstat = NCR5380->ncr_idstat) & SC_S_REQ)
|
1995-06-09 08:36:14 +04:00
|
|
|
*phase = (idstat >> 2) & 7;
|
|
|
|
else
|
|
|
|
*phase = NR_PHASE;
|
|
|
|
*count = len;
|
1995-09-26 23:15:57 +03:00
|
|
|
return(1);
|
1994-02-23 01:54:42 +03:00
|
|
|
}
|
1995-08-25 11:30:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Last but not least... Include the general driver code
|
|
|
|
*/
|
|
|
|
#include "ncr5380.c"
|