1999-01-02 00:43:17 +03:00
|
|
|
/* $NetBSD: mba.c,v 1.15 1999/01/01 21:43:18 ragge Exp $ */
|
1995-02-13 03:43:59 +03:00
|
|
|
/*
|
1996-02-11 16:19:33 +03:00
|
|
|
* Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
|
1995-02-13 03:43:59 +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:
|
1996-02-11 16:19:33 +03:00
|
|
|
* This product includes software developed at Ludd, University of
|
|
|
|
* Lule}, Sweden and its contributors.
|
1995-02-13 03:43:59 +03: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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
/*
|
|
|
|
* Simple massbus drive routine.
|
|
|
|
* TODO:
|
|
|
|
* Autoconfig new devices 'on the fly'.
|
|
|
|
* More intelligent way to handle different interrupts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-04-08 22:32:26 +04:00
|
|
|
#include <sys/systm.h>
|
1996-02-11 16:19:33 +03:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
#include <machine/trap.h>
|
|
|
|
#include <machine/scb.h>
|
|
|
|
#include <machine/nexus.h>
|
|
|
|
#include <machine/pte.h>
|
|
|
|
#include <machine/pcb.h>
|
1996-02-25 00:22:54 +03:00
|
|
|
#include <machine/sid.h>
|
1998-05-21 17:16:14 +04:00
|
|
|
#include <machine/cpu.h>
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-02 21:05:36 +03:00
|
|
|
#include <vax/mba/mbareg.h>
|
1996-02-11 16:19:33 +03:00
|
|
|
#include <vax/mba/mbavar.h>
|
|
|
|
|
|
|
|
struct mbaunit mbaunit[] = {
|
1996-04-08 22:32:26 +04:00
|
|
|
{MBADT_RP04, "rp04", MB_RP},
|
|
|
|
{MBADT_RP05, "rp05", MB_RP},
|
|
|
|
{MBADT_RP06, "rp06", MB_RP},
|
|
|
|
{MBADT_RP07, "rp07", MB_RP},
|
|
|
|
{MBADT_RM02, "rm02", MB_RP},
|
|
|
|
{MBADT_RM03, "rm03", MB_RP},
|
|
|
|
{MBADT_RM05, "rm05", MB_RP},
|
|
|
|
{MBADT_RM80, "rm80", MB_RP},
|
|
|
|
{0, 0, 0}
|
1996-02-11 16:19:33 +03:00
|
|
|
};
|
|
|
|
|
1998-01-24 17:16:11 +03:00
|
|
|
int mbamatch __P((struct device *, struct cfdata *, void *));
|
1996-02-11 16:19:33 +03:00
|
|
|
void mbaattach __P((struct device *, struct device *, void *));
|
|
|
|
void mbaintr __P((int));
|
1996-08-28 01:53:46 +04:00
|
|
|
int mbaprint __P((void *, const char *));
|
1996-02-11 16:19:33 +03:00
|
|
|
void mbaqueue __P((struct mba_device *));
|
|
|
|
void mbastart __P((struct mba_softc *));
|
|
|
|
void mbamapregs __P((struct mba_softc *));
|
|
|
|
|
1996-08-20 18:15:04 +04:00
|
|
|
struct cfattach mba_cmi_ca = {
|
|
|
|
sizeof(struct mba_softc), mbamatch, mbaattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfattach mba_sbi_ca = {
|
1996-03-18 01:56:15 +03:00
|
|
|
sizeof(struct mba_softc), mbamatch, mbaattach
|
1996-02-11 16:19:33 +03:00
|
|
|
};
|
|
|
|
|
1998-01-19 01:09:13 +03:00
|
|
|
extern struct cfdriver mba_cd;
|
1998-01-12 23:52:29 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
/*
|
|
|
|
* Look if this is a massbuss adapter.
|
|
|
|
*/
|
|
|
|
int
|
1998-01-24 17:16:11 +03:00
|
|
|
mbamatch(parent, cf, aux)
|
1996-02-11 16:19:33 +03:00
|
|
|
struct device *parent;
|
1998-01-24 17:16:11 +03:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-02-11 16:19:33 +03:00
|
|
|
{
|
|
|
|
struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
if ((cf->cf_loc[0] != sa->nexnum) && (cf->cf_loc[0] > -1 ))
|
|
|
|
return 0;
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
if (sa->type == NEX_MBA)
|
|
|
|
return 1;
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the found massbuss adapter. Setup its interrupt vectors,
|
|
|
|
* reset it and go searching for drives on it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mbaattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct mba_softc *sc = (void *)self;
|
|
|
|
struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
|
|
|
|
volatile struct mba_regs *mbar = (struct mba_regs *)sa->nexaddr;
|
|
|
|
struct mba_attach_args ma;
|
|
|
|
extern struct ivec_dsp idsptch;
|
|
|
|
int i, j;
|
|
|
|
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1996-02-11 16:19:33 +03:00
|
|
|
/*
|
|
|
|
* Set up interrupt vectors for this MBA.
|
|
|
|
*/
|
|
|
|
bcopy(&idsptch, &sc->sc_dsp, sizeof(struct ivec_dsp));
|
|
|
|
scb->scb_nexvec[0][sa->nexnum] = scb->scb_nexvec[1][sa->nexnum] =
|
|
|
|
scb->scb_nexvec[2][sa->nexnum] = scb->scb_nexvec[3][sa->nexnum] =
|
|
|
|
&sc->sc_dsp;
|
|
|
|
sc->sc_dsp.pushlarg = sc->sc_dev.dv_unit;
|
|
|
|
sc->sc_dsp.hoppaddr = mbaintr;
|
|
|
|
|
1996-02-25 00:22:54 +03:00
|
|
|
sc->sc_physnr = sa->nexnum - 8; /* MBA's have TR between 8 - 11... */
|
|
|
|
#ifdef VAX750
|
1996-08-20 18:15:04 +04:00
|
|
|
if (vax_cputype == VAX_750)
|
1996-02-25 00:22:54 +03:00
|
|
|
sc->sc_physnr += 4; /* ...but not on 11/750 */
|
|
|
|
#endif
|
1996-02-11 16:19:33 +03:00
|
|
|
sc->sc_first = 0;
|
|
|
|
sc->sc_last = (void *)&sc->sc_first;
|
|
|
|
sc->sc_mbareg = (struct mba_regs *)mbar;
|
|
|
|
mbar->mba_cr = MBACR_INIT; /* Reset adapter */
|
|
|
|
mbar->mba_cr = MBACR_IE; /* Enable interrupts */
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
for (i = 0; i < MAXMBADEV; i++) {
|
|
|
|
sc->sc_state = SC_AUTOCONF;
|
|
|
|
if ((mbar->mba_md[i].md_ds & MBADS_DPR) == 0)
|
|
|
|
continue;
|
|
|
|
/* We have a drive, ok. */
|
|
|
|
ma.unit = i;
|
|
|
|
ma.type = mbar->mba_md[i].md_dt & 0777;
|
|
|
|
j = 0;
|
|
|
|
while (mbaunit[j++].nr)
|
|
|
|
if (mbaunit[j].nr == ma.type)
|
|
|
|
break;
|
|
|
|
ma.devtyp = mbaunit[j].devtyp;
|
|
|
|
ma.name = mbaunit[j].name;
|
|
|
|
config_found(&sc->sc_dev, (void *)&ma, mbaprint);
|
1995-02-13 03:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-02-11 16:19:33 +03:00
|
|
|
* We got an interrupt. Check type of interrupt and call the specific
|
|
|
|
* device interrupt handling routine.
|
1995-02-13 03:43:59 +03:00
|
|
|
*/
|
1996-02-11 16:19:33 +03:00
|
|
|
void
|
|
|
|
mbaintr(mba)
|
|
|
|
int mba;
|
|
|
|
{
|
1996-03-18 01:56:15 +03:00
|
|
|
struct mba_softc *sc = mba_cd.cd_devs[mba];
|
1996-02-11 16:19:33 +03:00
|
|
|
volatile struct mba_regs *mr = sc->sc_mbareg;
|
|
|
|
struct mba_device *md;
|
|
|
|
struct buf *bp;
|
1996-04-08 22:32:26 +04:00
|
|
|
int itype, attn, anr;
|
1996-02-11 16:19:33 +03:00
|
|
|
|
|
|
|
itype = mr->mba_sr;
|
|
|
|
mr->mba_sr = itype; /* Write back to clear bits */
|
|
|
|
|
|
|
|
attn = mr->mba_md[0].md_as & 0xff;
|
|
|
|
mr->mba_md[0].md_as = attn;
|
|
|
|
|
|
|
|
if (sc->sc_state == SC_AUTOCONF)
|
|
|
|
return; /* During autoconfig */
|
|
|
|
|
|
|
|
md = sc->sc_first;
|
|
|
|
bp = md->md_q.b_actf;
|
|
|
|
/*
|
|
|
|
* A data-transfer interrupt. Current operation is finished,
|
|
|
|
* call that device's finish routine to see what to do next.
|
|
|
|
*/
|
|
|
|
if (sc->sc_state == SC_ACTIVE) {
|
|
|
|
|
|
|
|
sc->sc_state = SC_IDLE;
|
|
|
|
switch ((*md->md_finish)(md, itype, &attn)) {
|
|
|
|
|
|
|
|
case XFER_FINISH:
|
|
|
|
/*
|
|
|
|
* Transfer is finished. Take buffer of drive
|
|
|
|
* queue, and take drive of adapter queue.
|
|
|
|
* If more to transfer, start the adapter again
|
|
|
|
* by calling mbastart().
|
|
|
|
*/
|
|
|
|
md->md_q.b_actf = bp->b_actf;
|
|
|
|
sc->sc_first = md->md_back;
|
|
|
|
md->md_back = 0;
|
|
|
|
if (sc->sc_first == 0)
|
|
|
|
sc->sc_last = (void *)&sc->sc_first;
|
1995-02-13 03:43:59 +03:00
|
|
|
|
1996-02-11 16:19:33 +03:00
|
|
|
if (md->md_q.b_actf) {
|
|
|
|
sc->sc_last->md_back = md;
|
|
|
|
sc->sc_last = md;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp->b_resid = 0;
|
|
|
|
biodone(bp);
|
|
|
|
if (sc->sc_first)
|
|
|
|
mbastart(sc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XFER_RESTART:
|
|
|
|
/*
|
|
|
|
* Something went wrong with the transfer. Try again.
|
|
|
|
*/
|
|
|
|
mbastart(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (attn) {
|
|
|
|
anr = ffs(attn) - 1;
|
|
|
|
attn &= ~(1 << anr);
|
|
|
|
if (sc->sc_md[anr]->md_attn == 0)
|
|
|
|
panic("Should check for new MBA device %d", anr);
|
|
|
|
(*sc->sc_md[anr]->md_attn)(sc->sc_md[anr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mbaprint(aux, mbaname)
|
|
|
|
void *aux;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *mbaname;
|
1996-02-11 16:19:33 +03:00
|
|
|
{
|
|
|
|
struct mba_attach_args *ma = aux;
|
|
|
|
|
|
|
|
if (mbaname) {
|
|
|
|
if (ma->name)
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("%s", ma->name);
|
1996-02-11 16:19:33 +03:00
|
|
|
else
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("device type %o", ma->type);
|
|
|
|
printf(" at %s", mbaname);
|
1996-02-11 16:19:33 +03:00
|
|
|
}
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(" drive %d", ma->unit);
|
1996-02-11 16:19:33 +03:00
|
|
|
return (ma->name ? UNCONF : UNSUPP);
|
|
|
|
}
|
1995-02-13 03:43:59 +03:00
|
|
|
|
|
|
|
/*
|
1996-02-11 16:19:33 +03:00
|
|
|
* A device calls mbaqueue() when it wants to get on the adapter queue.
|
|
|
|
* Called at splbio(). If the adapter is inactive, start it.
|
1995-02-13 03:43:59 +03:00
|
|
|
*/
|
1996-02-11 16:19:33 +03:00
|
|
|
void
|
|
|
|
mbaqueue(md)
|
|
|
|
struct mba_device *md;
|
|
|
|
{
|
|
|
|
struct mba_softc *sc = md->md_mba;
|
|
|
|
int i = (int)sc->sc_first;
|
|
|
|
|
|
|
|
sc->sc_last->md_back = md;
|
|
|
|
sc->sc_last = md;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
mbastart(sc);
|
|
|
|
}
|
|
|
|
|
1995-02-13 03:43:59 +03:00
|
|
|
/*
|
1996-02-11 16:19:33 +03:00
|
|
|
* Start activity on (idling) adapter. Calls mbamapregs() to setup
|
|
|
|
* for dma transfer, then the unit-specific start routine.
|
1995-02-13 03:43:59 +03:00
|
|
|
*/
|
1996-02-11 16:19:33 +03:00
|
|
|
void
|
|
|
|
mbastart(sc)
|
|
|
|
struct mba_softc *sc;
|
|
|
|
{
|
|
|
|
struct mba_device *md = sc->sc_first;
|
|
|
|
volatile struct mba_regs *mr = sc->sc_mbareg;
|
|
|
|
struct buf *bp = md->md_q.b_actf;
|
|
|
|
|
1996-08-20 18:15:04 +04:00
|
|
|
disk_reallymapin(md->md_q.b_actf, sc->sc_mbareg->mba_map, 0, PG_V);
|
1996-02-11 16:19:33 +03:00
|
|
|
|
|
|
|
sc->sc_state = SC_ACTIVE;
|
1999-01-02 00:43:17 +03:00
|
|
|
mr->mba_var = ((u_int)bp->b_un.b_addr & VAX_PGOFSET);
|
1996-02-11 16:19:33 +03:00
|
|
|
mr->mba_bc = (~bp->b_bcount) + 1;
|
|
|
|
(*md->md_start)(md); /* machine-dependent start */
|
|
|
|
}
|