Home | History | Annotate | Line # | Download | only in mba
mba.c revision 1.29
      1  1.29   thorpej /*	$NetBSD: mba.c,v 1.29 2002/10/02 16:02:33 thorpej Exp $ */
      2   1.1     ragge /*
      3   1.3     ragge  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
      4   1.1     ragge  * All rights reserved.
      5   1.1     ragge  *
      6   1.1     ragge  * Redistribution and use in source and binary forms, with or without
      7   1.1     ragge  * modification, are permitted provided that the following conditions
      8   1.1     ragge  * are met:
      9   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     10   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     11   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     13   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     14   1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     15   1.1     ragge  *    must display the following acknowledgement:
     16   1.3     ragge  *      This product includes software developed at Ludd, University of
     17   1.3     ragge  *      Lule}, Sweden and its contributors.
     18   1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     19   1.1     ragge  *    derived from this software without specific prior written permission
     20   1.1     ragge  *
     21   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1     ragge  */
     32   1.1     ragge 
     33   1.3     ragge /*
     34   1.3     ragge  * Simple massbus drive routine.
     35   1.3     ragge  * TODO:
     36   1.3     ragge  *  Autoconfig new devices 'on the fly'.
     37   1.3     ragge  *  More intelligent way to handle different interrupts.
     38   1.3     ragge  */
     39   1.3     ragge 
     40   1.3     ragge #include <sys/param.h>
     41   1.6     ragge #include <sys/systm.h>
     42   1.3     ragge #include <sys/device.h>
     43   1.3     ragge #include <sys/queue.h>
     44   1.3     ragge #include <sys/buf.h>
     45   1.3     ragge #include <sys/proc.h>
     46   1.3     ragge 
     47  1.24       mrg #include <uvm/uvm_extern.h>
     48   1.3     ragge 
     49  1.21     ragge #include <machine/bus.h>
     50   1.3     ragge #include <machine/scb.h>
     51   1.3     ragge #include <machine/nexus.h>
     52   1.3     ragge #include <machine/pte.h>
     53   1.3     ragge #include <machine/pcb.h>
     54   1.4     ragge #include <machine/sid.h>
     55  1.14     ragge #include <machine/cpu.h>
     56   1.1     ragge 
     57   1.3     ragge #include <vax/mba/mbareg.h>
     58   1.3     ragge #include <vax/mba/mbavar.h>
     59   1.1     ragge 
     60  1.21     ragge #include "locators.h"
     61  1.16      matt 
     62   1.3     ragge struct	mbaunit mbaunit[] = {
     63   1.6     ragge 	{MBADT_RP04,	"rp04", MB_RP},
     64   1.6     ragge 	{MBADT_RP05,	"rp05", MB_RP},
     65   1.6     ragge 	{MBADT_RP06,	"rp06", MB_RP},
     66   1.6     ragge 	{MBADT_RP07,	"rp07", MB_RP},
     67   1.6     ragge 	{MBADT_RM02,	"rm02", MB_RP},
     68   1.6     ragge 	{MBADT_RM03,	"rm03", MB_RP},
     69   1.6     ragge 	{MBADT_RM05,	"rm05", MB_RP},
     70   1.6     ragge 	{MBADT_RM80,	"rm80", MB_RP},
     71   1.6     ragge 	{0,		0,	0}
     72   1.3     ragge };
     73   1.3     ragge 
     74  1.21     ragge int	mbamatch(struct device *, struct cfdata *, void *);
     75  1.21     ragge void	mbaattach(struct device *, struct device *, void *);
     76  1.21     ragge void	mbaintr(void *);
     77  1.21     ragge int	mbaprint(void *, const char *);
     78  1.21     ragge void	mbaqueue(struct mba_device *);
     79  1.21     ragge void	mbastart(struct mba_softc *);
     80  1.21     ragge void	mbamapregs(struct mba_softc *);
     81   1.3     ragge 
     82  1.28   thorpej CFATTACH_DECL(mba_cmi, sizeof(struct mba_softc),
     83  1.29   thorpej     mbamatch, mbaattach, NULL, NULL);
     84   1.7     ragge 
     85  1.28   thorpej CFATTACH_DECL(mba_sbi, sizeof(struct mba_softc),
     86  1.29   thorpej     mbamatch, mbaattach, NULL, NULL);
     87  1.11   thorpej 
     88  1.21     ragge #define	MBA_WCSR(reg, val) \
     89  1.21     ragge 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, (reg), (val))
     90  1.21     ragge #define MBA_RCSR(reg) \
     91  1.21     ragge 	bus_space_read_4(sc->sc_iot, sc->sc_ioh, (reg))
     92   1.1     ragge 
     93   1.3     ragge /*
     94   1.3     ragge  * Look if this is a massbuss adapter.
     95   1.3     ragge  */
     96   1.3     ragge int
     97  1.21     ragge mbamatch(struct device *parent, struct cfdata *cf, void *aux)
     98   1.3     ragge {
     99   1.3     ragge 	struct	sbi_attach_args *sa = (struct sbi_attach_args *)aux;
    100   1.1     ragge 
    101  1.21     ragge 	if (vax_cputype == VAX_750) {
    102  1.21     ragge 		if (cf->cf_loc[CMICF_TR] != CMICF_TR_DEFAULT &&
    103  1.21     ragge 		    cf->cf_loc[CMICF_TR] != sa->sa_nexnum)
    104  1.21     ragge 			return 0;
    105  1.21     ragge 	} else {
    106  1.21     ragge 		if (cf->cf_loc[SBICF_TR] != SBICF_TR_DEFAULT &&
    107  1.21     ragge 		    cf->cf_loc[SBICF_TR] != sa->sa_nexnum)
    108  1.21     ragge 			return 0;
    109  1.21     ragge 	}
    110   1.1     ragge 
    111  1.21     ragge 	if (sa->sa_type == NEX_MBA)
    112   1.3     ragge 		return 1;
    113   1.1     ragge 
    114   1.3     ragge 	return 0;
    115   1.3     ragge }
    116   1.1     ragge 
    117   1.3     ragge /*
    118   1.3     ragge  * Attach the found massbuss adapter. Setup its interrupt vectors,
    119   1.3     ragge  * reset it and go searching for drives on it.
    120   1.3     ragge  */
    121   1.3     ragge void
    122  1.21     ragge mbaattach(struct device *parent, struct device *self, void *aux)
    123   1.3     ragge {
    124   1.3     ragge 	struct	mba_softc *sc = (void *)self;
    125   1.3     ragge 	struct	sbi_attach_args *sa = (struct sbi_attach_args *)aux;
    126   1.3     ragge 	struct	mba_attach_args ma;
    127   1.3     ragge 	int	i, j;
    128   1.3     ragge 
    129  1.10  christos 	printf("\n");
    130  1.21     ragge 	sc->sc_iot = sa->sa_iot;
    131  1.21     ragge 	sc->sc_ioh = sa->sa_ioh;
    132   1.3     ragge 	/*
    133   1.3     ragge 	 * Set up interrupt vectors for this MBA.
    134   1.3     ragge 	 */
    135  1.25     ragge 	for (i = 0x14; i < 0x18; i++)
    136  1.21     ragge 		scb_vecalloc(vecnum(0, i, sa->sa_nexnum),
    137  1.21     ragge 		    mbaintr, sc, SCB_ISTACK, &sc->sc_intrcnt);
    138  1.22      matt 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    139  1.22      matt 		self->dv_xname, "intr");
    140   1.3     ragge 
    141   1.3     ragge 	sc->sc_first = 0;
    142   1.3     ragge 	sc->sc_last = (void *)&sc->sc_first;
    143  1.21     ragge 	MBA_WCSR(MBA_CR, MBACR_INIT);	/* Reset adapter */
    144  1.21     ragge 	MBA_WCSR(MBA_CR, MBACR_IE);	/* Enable interrupts */
    145   1.3     ragge 
    146   1.3     ragge 	for (i = 0; i < MAXMBADEV; i++) {
    147   1.3     ragge 		sc->sc_state = SC_AUTOCONF;
    148  1.21     ragge 		if ((MBA_RCSR(MUREG(i, MU_DS)) & MBADS_DPR) == 0)
    149   1.3     ragge 			continue;
    150   1.3     ragge 		/* We have a drive, ok. */
    151  1.21     ragge 		ma.ma_unit = i;
    152  1.21     ragge 		ma.ma_type = MBA_RCSR(MUREG(i, MU_DT)) & 0777;
    153   1.3     ragge 		j = 0;
    154   1.3     ragge 		while (mbaunit[j++].nr)
    155  1.21     ragge 			if (mbaunit[j].nr == ma.ma_type)
    156   1.3     ragge 				break;
    157  1.21     ragge 		ma.ma_devtyp = mbaunit[j].devtyp;
    158  1.21     ragge 		ma.ma_name = mbaunit[j].name;
    159  1.21     ragge 		ma.ma_iot = sc->sc_iot;
    160  1.21     ragge 		ma.ma_ioh = sc->sc_ioh + MUREG(i, 0);
    161   1.3     ragge 		config_found(&sc->sc_dev, (void *)&ma, mbaprint);
    162   1.1     ragge 	}
    163   1.1     ragge }
    164   1.1     ragge 
    165   1.1     ragge /*
    166   1.3     ragge  * We got an interrupt. Check type of interrupt and call the specific
    167   1.3     ragge  * device interrupt handling routine.
    168   1.1     ragge  */
    169   1.3     ragge void
    170  1.21     ragge mbaintr(void *mba)
    171   1.3     ragge {
    172  1.18      matt 	struct	mba_softc *sc = mba;
    173   1.3     ragge 	struct	mba_device *md;
    174   1.3     ragge 	struct	buf *bp;
    175   1.6     ragge 	int	itype, attn, anr;
    176   1.3     ragge 
    177  1.21     ragge 	itype = MBA_RCSR(MBA_SR);
    178  1.21     ragge 	MBA_WCSR(MBA_SR, itype);
    179   1.3     ragge 
    180  1.21     ragge 	attn = MBA_RCSR(MUREG(0, MU_AS)) & 0xff;
    181  1.21     ragge 	MBA_WCSR(MUREG(0, MU_AS), attn);
    182   1.3     ragge 
    183   1.3     ragge 	if (sc->sc_state == SC_AUTOCONF)
    184   1.3     ragge 		return;	/* During autoconfig */
    185   1.3     ragge 
    186   1.3     ragge 	md = sc->sc_first;
    187  1.26   hannken 	bp = BUFQ_PEEK(&md->md_q);
    188   1.3     ragge 	/*
    189   1.3     ragge 	 * A data-transfer interrupt. Current operation is finished,
    190   1.3     ragge 	 * call that device's finish routine to see what to do next.
    191   1.3     ragge 	 */
    192   1.3     ragge 	if (sc->sc_state == SC_ACTIVE) {
    193   1.3     ragge 
    194   1.3     ragge 		sc->sc_state = SC_IDLE;
    195   1.3     ragge 		switch ((*md->md_finish)(md, itype, &attn)) {
    196   1.3     ragge 
    197   1.3     ragge 		case XFER_FINISH:
    198   1.3     ragge 			/*
    199   1.3     ragge 			 * Transfer is finished. Take buffer of drive
    200   1.3     ragge 			 * queue, and take drive of adapter queue.
    201   1.3     ragge 			 * If more to transfer, start the adapter again
    202   1.3     ragge 			 * by calling mbastart().
    203   1.3     ragge 			 */
    204  1.26   hannken 			(void)BUFQ_GET(&md->md_q);
    205   1.3     ragge 			sc->sc_first = md->md_back;
    206   1.3     ragge 			md->md_back = 0;
    207   1.3     ragge 			if (sc->sc_first == 0)
    208   1.3     ragge 				sc->sc_last = (void *)&sc->sc_first;
    209   1.3     ragge 
    210  1.26   hannken 			if (BUFQ_PEEK(&md->md_q) != NULL) {
    211   1.3     ragge 				sc->sc_last->md_back = md;
    212   1.3     ragge 				sc->sc_last = md;
    213   1.3     ragge 			}
    214   1.3     ragge 
    215   1.3     ragge 			bp->b_resid = 0;
    216   1.3     ragge 			biodone(bp);
    217   1.3     ragge 			if (sc->sc_first)
    218   1.3     ragge 				mbastart(sc);
    219   1.3     ragge 			break;
    220   1.3     ragge 
    221   1.3     ragge 		case XFER_RESTART:
    222   1.3     ragge 			/*
    223   1.3     ragge 			 * Something went wrong with the transfer. Try again.
    224   1.3     ragge 			 */
    225   1.3     ragge 			mbastart(sc);
    226   1.3     ragge 			break;
    227   1.3     ragge 		}
    228   1.3     ragge 	}
    229   1.1     ragge 
    230   1.3     ragge 	while (attn) {
    231   1.3     ragge 		anr = ffs(attn) - 1;
    232   1.3     ragge 		attn &= ~(1 << anr);
    233   1.3     ragge 		if (sc->sc_md[anr]->md_attn == 0)
    234   1.3     ragge 			panic("Should check for new MBA device %d", anr);
    235   1.3     ragge 		(*sc->sc_md[anr]->md_attn)(sc->sc_md[anr]);
    236   1.3     ragge 	}
    237   1.3     ragge }
    238   1.3     ragge 
    239   1.3     ragge int
    240  1.21     ragge mbaprint(void *aux, const char *mbaname)
    241   1.3     ragge {
    242   1.3     ragge 	struct  mba_attach_args *ma = aux;
    243   1.3     ragge 
    244   1.3     ragge 	if (mbaname) {
    245  1.21     ragge 		if (ma->ma_name)
    246  1.21     ragge 			printf("%s", ma->ma_name);
    247   1.3     ragge 		else
    248  1.21     ragge 			printf("device type %o", ma->ma_type);
    249  1.10  christos 		printf(" at %s", mbaname);
    250   1.3     ragge 	}
    251  1.21     ragge 	printf(" drive %d", ma->ma_unit);
    252  1.21     ragge 	return (ma->ma_name ? UNCONF : UNSUPP);
    253   1.3     ragge }
    254   1.1     ragge 
    255   1.1     ragge /*
    256   1.3     ragge  * A device calls mbaqueue() when it wants to get on the adapter queue.
    257   1.3     ragge  * Called at splbio(). If the adapter is inactive, start it.
    258   1.1     ragge  */
    259   1.3     ragge void
    260  1.21     ragge mbaqueue(struct mba_device *md)
    261   1.3     ragge {
    262   1.3     ragge 	struct	mba_softc *sc = md->md_mba;
    263   1.3     ragge 	int	i = (int)sc->sc_first;
    264   1.3     ragge 
    265   1.3     ragge 	sc->sc_last->md_back = md;
    266   1.3     ragge 	sc->sc_last = md;
    267   1.3     ragge 
    268   1.3     ragge 	if (i == 0)
    269   1.3     ragge 		mbastart(sc);
    270   1.3     ragge }
    271   1.3     ragge 
    272   1.1     ragge /*
    273   1.3     ragge  * Start activity on (idling) adapter. Calls mbamapregs() to setup
    274   1.3     ragge  * for dma transfer, then the unit-specific start routine.
    275   1.1     ragge  */
    276   1.3     ragge void
    277  1.21     ragge mbastart(struct mba_softc *sc)
    278   1.3     ragge {
    279   1.3     ragge 	struct	mba_device *md = sc->sc_first;
    280  1.26   hannken 	struct	buf *bp = BUFQ_PEEK(&md->md_q);
    281   1.3     ragge 
    282  1.21     ragge 	disk_reallymapin(bp, (void *)(sc->sc_ioh + MAPREG(0)), 0, PG_V);
    283   1.3     ragge 
    284   1.3     ragge 	sc->sc_state = SC_ACTIVE;
    285  1.21     ragge 	MBA_WCSR(MBA_VAR, ((u_int)bp->b_data & VAX_PGOFSET));
    286  1.21     ragge 	MBA_WCSR(MBA_BC, (~bp->b_bcount) + 1);
    287   1.3     ragge 	(*md->md_start)(md);		/* machine-dependent start */
    288   1.3     ragge }
    289