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