2003-07-15 06:54:31 +04:00
|
|
|
/* $NetBSD: sii_ds.c,v 1.21 2003/07/15 02:54:39 lukem Exp $ */
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1996 The Board of Trustees of The Leland Stanford
|
|
|
|
* Junior University. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies. Stanford University
|
|
|
|
* makes no representations about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without
|
|
|
|
* express or implied warranty.
|
|
|
|
*
|
|
|
|
* this driver contributed by Jonathan Stone
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sii_ds.c,v 1.21 2003/07/15 02:54:39 lukem Exp $");
|
|
|
|
|
2000-06-03 00:20:29 +04:00
|
|
|
#include "sii.h"
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
2000-06-03 00:20:29 +04:00
|
|
|
#include <sys/buf.h>
|
1999-03-22 16:08:51 +03:00
|
|
|
|
2000-01-09 06:55:28 +03:00
|
|
|
#include <machine/locore.h>
|
1998-04-19 05:27:02 +04:00
|
|
|
|
2000-06-03 00:20:29 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
#include <dev/scsipi/scsi_message.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
1996-10-13 07:02:39 +04:00
|
|
|
#include <pmax/dev/siireg.h>
|
|
|
|
#include <pmax/dev/siivar.h>
|
|
|
|
|
1998-04-19 05:27:02 +04:00
|
|
|
#include <pmax/ibus/ibusvar.h> /* interrupt etablish */
|
2000-01-10 06:24:31 +03:00
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
#include <pmax/pmax/kn01.h> /* kn01 (ds3100) address constants */
|
1998-04-19 05:27:02 +04:00
|
|
|
#include <pmax/pmax/pmaxtype.h>
|
1996-10-13 07:02:39 +04:00
|
|
|
|
2000-01-09 06:55:28 +03:00
|
|
|
|
|
|
|
static void kn230_copytobuf __P((u_short *src, /* NB: must be short aligned */
|
|
|
|
volatile u_short *dst, int length));
|
|
|
|
static void kn230_copyfrombuf __P((volatile u_short *src, char *dst,
|
|
|
|
int length));
|
|
|
|
|
|
|
|
static void kn01_copytobuf __P((u_short *src, /* NB: must be short aligned */
|
|
|
|
volatile u_short *dst, int length));
|
|
|
|
static void kn01_copyfrombuf __P((volatile u_short *src, char *dst,
|
|
|
|
int length));
|
|
|
|
|
1996-10-13 07:02:39 +04:00
|
|
|
/*
|
|
|
|
* Autoconfig definition of driver front-end
|
|
|
|
*/
|
2000-01-09 06:55:28 +03:00
|
|
|
static int sii_ds_match __P((struct device* parent, struct cfdata *match,
|
|
|
|
void *aux));
|
|
|
|
static void sii_ds_attach __P((struct device *parent, struct device *self,
|
|
|
|
void *aux));
|
1996-10-13 07:02:39 +04:00
|
|
|
|
2002-10-02 08:06:36 +04:00
|
|
|
CFATTACH_DECL(sii_ds, sizeof(struct siisoftc),
|
|
|
|
sii_ds_match, sii_ds_attach, NULL, NULL);
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
/* define a safe address in the SCSI buffer for doing status & message DMA */
|
1997-06-22 11:42:25 +04:00
|
|
|
#define SII_BUF_ADDR (MIPS_PHYS_TO_KSEG1(KN01_SYS_SII_B_START) \
|
1996-10-13 07:02:39 +04:00
|
|
|
+ SII_MAX_DMA_XFER_LENGTH * 14)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Match driver on Decstation (2100, 3100, 5100) based on name and probe.
|
|
|
|
*/
|
2000-01-09 06:55:28 +03:00
|
|
|
static int
|
1996-10-13 07:02:39 +04:00
|
|
|
sii_ds_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-07-21 09:39:02 +04:00
|
|
|
struct cfdata *match;
|
1996-10-13 07:02:39 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
1998-04-19 05:27:02 +04:00
|
|
|
struct ibus_attach_args *ia = aux;
|
1999-04-24 12:01:01 +04:00
|
|
|
void * siiaddr;
|
1996-10-13 07:02:39 +04:00
|
|
|
|
1998-04-19 05:27:02 +04:00
|
|
|
if (strcmp(ia->ia_name, "sii") != 0)
|
1996-10-13 07:02:39 +04:00
|
|
|
return (0);
|
1998-04-19 05:27:02 +04:00
|
|
|
siiaddr = (void *)ia->ia_addr;
|
1996-10-13 07:02:39 +04:00
|
|
|
if (badaddr(siiaddr, 4))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2000-01-09 06:55:28 +03:00
|
|
|
static void
|
1996-10-13 07:02:39 +04:00
|
|
|
sii_ds_attach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct ibus_attach_args *ia = aux;
|
|
|
|
struct siisoftc *sc = (struct siisoftc *) self;
|
1996-10-13 07:02:39 +04:00
|
|
|
|
1998-04-19 05:27:02 +04:00
|
|
|
sc->sc_regs = (SIIRegs *)MIPS_PHYS_TO_KSEG1(ia->ia_addr);
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
/* set up scsi buffer. XXX Why statically allocated? */
|
1997-06-22 11:42:25 +04:00
|
|
|
sc->sc_buf = (void*)(MIPS_PHYS_TO_KSEG1(KN01_SYS_SII_B_START));
|
1996-10-13 07:02:39 +04:00
|
|
|
|
1998-04-19 05:27:02 +04:00
|
|
|
if (systype == DS_PMAX) {
|
|
|
|
#if 0
|
|
|
|
sc->sii_copytobuf = CopyToBuffer;
|
|
|
|
sc->sii_copyfrombuf = CopyFromBuffer;
|
|
|
|
#else
|
|
|
|
sc->sii_copytobuf = kn01_copytobuf;
|
|
|
|
sc->sii_copyfrombuf = kn01_copyfrombuf;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
sc->sii_copytobuf = kn230_copytobuf;
|
|
|
|
sc->sii_copyfrombuf = kn230_copyfrombuf;
|
|
|
|
}
|
1999-04-24 12:01:01 +04:00
|
|
|
|
2000-06-03 00:20:29 +04:00
|
|
|
/* Do the common parts of attachment. */
|
2001-04-25 21:53:04 +04:00
|
|
|
sc->sc_adapter.adapt_request = sii_scsi_request;
|
|
|
|
sc->sc_adapter.adapt_minphys = minphys;
|
|
|
|
siiattach(sc);
|
1996-10-13 07:02:39 +04:00
|
|
|
|
|
|
|
/* tie pseudo-slot to device */
|
1999-11-15 12:54:41 +03:00
|
|
|
ibus_intr_establish(parent, (void*)ia->ia_cookie, IPL_BIO, siiintr, sc);
|
1996-10-13 07:02:39 +04:00
|
|
|
}
|
1998-04-19 05:27:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Padded DMA copy functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX assumes src is always 32-bit aligned.
|
|
|
|
* currently safe on sii driver, but API and casts should be changed.
|
|
|
|
*/
|
2000-01-09 06:55:28 +03:00
|
|
|
static void
|
1998-04-19 05:27:02 +04:00
|
|
|
kn230_copytobuf(src, dst, len)
|
|
|
|
u_short *src;
|
|
|
|
volatile u_short *dst;
|
|
|
|
int len;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
u_int *wsrc = (u_int *)src;
|
2000-03-30 18:45:04 +04:00
|
|
|
volatile u_int *wdst = (volatile u_int *)dst;
|
1999-04-24 12:01:01 +04:00
|
|
|
int i, n;
|
1998-04-19 05:27:02 +04:00
|
|
|
|
|
|
|
#if defined(DIAGNOSTIC) || defined(DEBUG)
|
|
|
|
if ((u_int)(src) & 0x3) {
|
|
|
|
printf("kn230: copytobuf, src %p misaligned\n", src);
|
|
|
|
}
|
|
|
|
if ((u_int)(dst) & 0x3) {
|
|
|
|
printf("kn230: copytobuf, dst %p misaligned\n", dst);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* DMA buffer is allocated in 32-bit words, so just copy words. */
|
|
|
|
n = len / 4;
|
1999-04-24 12:01:01 +04:00
|
|
|
if (len & 0x3)
|
1998-04-19 05:27:02 +04:00
|
|
|
n++;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
*wdst = *wsrc;
|
|
|
|
wsrc++;
|
|
|
|
wdst+= 2;
|
|
|
|
}
|
1999-04-24 12:01:01 +04:00
|
|
|
|
1998-04-19 05:27:02 +04:00
|
|
|
wbflush(); /* XXX not necessary? */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX assumes dst is always 32-bit aligned.
|
|
|
|
* currently safe on sii driver, but API and casts should be changed.
|
|
|
|
*/
|
2000-01-09 06:55:28 +03:00
|
|
|
static void
|
1999-04-24 12:01:01 +04:00
|
|
|
kn230_copyfrombuf(src, dst, len)
|
1998-04-19 05:27:02 +04:00
|
|
|
volatile u_short *src;
|
|
|
|
char *dst; /* XXX assume 32-bit aligned? */
|
|
|
|
int len;
|
|
|
|
{
|
2000-03-30 18:45:04 +04:00
|
|
|
volatile u_int *wsrc = (volatile u_int *)src;
|
1999-04-24 12:01:01 +04:00
|
|
|
u_int *wdst = (u_int *)dst;
|
|
|
|
int i, n;
|
1998-04-19 05:27:02 +04:00
|
|
|
|
|
|
|
#if defined(DIAGNOSTIC) || defined(DEBUG)
|
|
|
|
if ((u_int)(src) & 0x3) {
|
|
|
|
printf("kn230: copyfrombuf, src %p misaligned\n", src);
|
|
|
|
}
|
|
|
|
if ((u_int)(dst) & 0x3) {
|
|
|
|
printf("kn230: copyfrombuf, dst %p misaligned\n", dst);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
n = len / 4;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
*wdst = *wsrc;
|
|
|
|
wsrc += 2;
|
|
|
|
wdst++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len & 0x3) {
|
1999-04-24 12:01:01 +04:00
|
|
|
u_int lastword = *wsrc;
|
1998-04-19 05:27:02 +04:00
|
|
|
|
|
|
|
if (len & 0x2)
|
|
|
|
*((u_short*)(wdst)) = (u_short) (lastword);
|
|
|
|
|
|
|
|
if (len & 0x1)
|
|
|
|
((u_char*)(wdst))[2] = (u_char) (lastword >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
wbflush(); /* XXX not necessary? */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-09 06:55:28 +03:00
|
|
|
static void
|
1998-04-19 05:27:02 +04:00
|
|
|
kn01_copytobuf(src, dst, len)
|
|
|
|
u_short *src;
|
|
|
|
volatile u_short *dst;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
#if defined(DIAGNOSTIC) || defined(DEBUG)
|
|
|
|
if ((u_int)(src) & 0x3) {
|
|
|
|
printf("kn01: copytobuf, src %p misaligned\n", src);
|
|
|
|
}
|
|
|
|
if ((u_int)(dst) & 0x3) {
|
|
|
|
printf("kn01: copytobuf, dst %p misaligned\n", dst);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CopyToBuffer(src, dst, len);
|
|
|
|
}
|
|
|
|
|
2000-01-09 06:55:28 +03:00
|
|
|
static void
|
1999-04-24 12:01:01 +04:00
|
|
|
kn01_copyfrombuf(src, dst, len)
|
1998-04-19 05:27:02 +04:00
|
|
|
volatile u_short *src;
|
|
|
|
char *dst; /* XXX assume 32-bit aligned? */
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
#if defined(DIAGNOSTIC) || defined(DEBUG)
|
|
|
|
if ((u_int)(src) & 0x3) {
|
|
|
|
printf("kn01: copyfrombuf, src %p misaligned\n", src);
|
|
|
|
}
|
|
|
|
if ((u_int)(dst) & 0x3) {
|
|
|
|
printf("kn01: copyfrombuf, dst %p misaligned\n", dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
CopyFromBuffer(src, dst, len);
|
|
|
|
|
|
|
|
}
|