Home | History | Annotate | Line # | Download | only in uba
uba_sbi.c revision 1.20
      1 /*	$NetBSD: uba_sbi.c,v 1.20 2003/07/15 02:15:02 lukem Exp $	   */
      2 /*
      3  * Copyright (c) 1996 Jonathan Stone.
      4  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
      5  * Copyright (c) 1982, 1986 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
     37  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: uba_sbi.c,v 1.20 2003/07/15 02:15:02 lukem Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/device.h>
     45 #include <sys/systm.h>
     46 #include <sys/kernel.h>
     47 
     48 #define _VAX_BUS_DMA_PRIVATE
     49 #include <machine/bus.h>
     50 #include <machine/mtpr.h>
     51 #include <machine/nexus.h>
     52 #include <machine/cpu.h>
     53 #include <machine/sgmap.h>
     54 #include <machine/scb.h>
     55 
     56 #include <dev/qbus/ubavar.h>
     57 
     58 #include <vax/uba/uba_common.h>
     59 
     60 #include "locators.h"
     61 #include "ioconf.h"
     62 
     63 /* Some SBI-specific defines */
     64 #define UBASIZE		(UBAPAGES * VAX_NBPG)
     65 #define UMEMA8600(i)   	(0x20100000+(i)*0x40000)
     66 #define	UMEMB8600(i)	(0x22100000+(i)*0x40000)
     67 
     68 /*
     69  * Some status registers.
     70  */
     71 #define UBACNFGR_UBIC  0x00010000      /* unibus init complete */
     72 #define UBACNFGR_BITS \
     73 "\40\40PARFLT\37WSQFLT\36URDFLT\35ISQFLT\34MXTFLT\33XMTFLT\30ADPDN\27ADPUP\23UBINIT\22UBPDN\21UBIC"
     74 
     75 #define UBACR_IFS      0x00000040      /* interrupt field switch */
     76 #define UBACR_BRIE     0x00000020      /* BR interrupt enable */
     77 #define UBACR_USEFIE   0x00000010      /* UNIBUS to SBI error field IE */
     78 #define UBACR_SUEFIE   0x00000008      /* SBI to UNIBUS error field IE */
     79 #define UBACR_ADINIT   0x00000001      /* adapter init */
     80 
     81 #define UBADPR_BNE     0x80000000      /* buffer not empty - purge */
     82 
     83 #define UBABRRVR_DIV    0x0000ffff      /* device interrupt vector field */
     84 
     85 #define UBASR_BITS \
     86 "\20\13RDTO\12RDS\11CRD\10CXTER\7CXTMO\6DPPE\5IVMR\4MRPF\3LEB\2UBSTO\1UBSSYNTO"
     87 
     88 char    ubasr_bits[] = UBASR_BITS;
     89 
     90 /*
     91  * The DW780 are directly connected to the SBI on 11/780 and 8600.
     92  */
     93 static	int	dw780_match(struct device *, struct cfdata *, void *);
     94 static	void	dw780_attach(struct device *, struct device *, void *);
     95 static	void	dw780_init(struct uba_softc*);
     96 static	void    dw780_beforescan(struct uba_softc *);
     97 static	void    dw780_afterscan(struct uba_softc *);
     98 static	int     dw780_errchk(struct uba_softc *);
     99 static	void    uba_dw780int(void *);
    100 static  void	ubaerror(struct uba_softc *, int *, int *);
    101 #ifdef notyet
    102 static	void	dw780_purge(struct uba_softc *, int);
    103 #endif
    104 
    105 CFATTACH_DECL(uba_sbi, sizeof(struct uba_vsoftc),
    106     dw780_match, dw780_attach, NULL, NULL);
    107 
    108 static struct evcnt strayint = EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "uba","stray intr");
    109 static int strayinit = 0;
    110 
    111 extern	struct vax_bus_space vax_mem_bus_space;
    112 
    113 int
    114 dw780_match(struct device *parent, struct cfdata *cf, void *aux)
    115 {
    116 	struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
    117 
    118 	if (cf->cf_loc[SBICF_TR] != sa->sa_nexnum &&
    119 	    cf->cf_loc[SBICF_TR] != SBICF_TR_DEFAULT)
    120 		return 0;
    121 	/*
    122 	 * The uba type is actually only telling where the uba
    123 	 * space is in nexus space.
    124 	 */
    125 	if ((sa->sa_type & ~3) != NEX_UBA0)
    126 		return 0;
    127 
    128 	return 1;
    129 }
    130 
    131 void
    132 dw780_attach(struct device *parent, struct device *self, void *aux)
    133 {
    134 	struct uba_vsoftc *sc = (void *)self;
    135 	struct sbi_attach_args *sa = aux;
    136 	int ubaddr = sa->sa_type & 3;
    137 	int i;
    138 
    139 	printf(": DW780\n");
    140 	/*
    141 	 * Fill in bus specific data.
    142 	 */
    143 	sc->uv_sc.uh_ubainit = dw780_init;
    144 #ifdef notyet
    145 	sc->uv_sc.uh_ubapurge = dw780_purge;
    146 #endif
    147 	sc->uv_sc.uh_beforescan = dw780_beforescan;
    148 	sc->uv_sc.uh_afterscan = dw780_afterscan;
    149 	sc->uv_sc.uh_errchk = dw780_errchk;
    150 	sc->uv_sc.uh_iot = &vax_mem_bus_space;
    151 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
    152 	sc->uv_sc.uh_nr = ubaddr;
    153 	sc->uv_uba = (void *)sa->sa_ioh;
    154 	sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
    155 	sc->uv_sc.uh_type = UBA_UBA;
    156 
    157 	if (strayinit++ == 0) evcnt_attach_static(&strayint); /* Setup stray
    158 							         interrupt
    159 							         counter. */
    160 
    161 	/*
    162 	 * Set up dispatch vectors for DW780.
    163 	 */
    164 	for (i = 0x14; i < 0x18; i++)
    165 		scb_vecalloc(vecnum(0, i, sa->sa_nexnum), uba_dw780int,
    166 		    sc, SCB_ISTACK, &sc->uv_sc.uh_intrcnt);
    167 	evcnt_attach_dynamic(&sc->uv_sc.uh_intrcnt, EVCNT_TYPE_INTR, NULL,
    168 		sc->uv_sc.uh_dev.dv_xname, "intr");
    169 
    170 	/*
    171 	 * Fill in variables used by the sgmap system.
    172 	 */
    173 	sc->uv_size = UBASIZE;		/* Size in bytes of Unibus space */
    174 
    175 	uba_dma_init(sc);
    176 	uba_attach(&sc->uv_sc, (sa->sa_sbinum ? UMEMB8600(ubaddr) :
    177 	    UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
    178 }
    179 
    180 void
    181 dw780_beforescan(struct uba_softc *sc)
    182 {
    183 	struct uba_vsoftc *vc = (void *)sc;
    184 	volatile int *hej = &vc->uv_uba->uba_sr;
    185 
    186 	*hej = *hej;
    187 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
    188 }
    189 
    190 void
    191 dw780_afterscan(struct uba_softc *sc)
    192 {
    193 	struct uba_vsoftc *vc = (void *)sc;
    194 
    195 	vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
    196 	    UBACR_USEFIE | UBACR_SUEFIE |
    197 	    (vc->uv_uba->uba_cr & 0x7c000000);
    198 }
    199 
    200 
    201 int
    202 dw780_errchk(struct uba_softc *sc)
    203 {
    204 	struct uba_vsoftc *vc = (void *)sc;
    205 	volatile int *hej = &vc->uv_uba->uba_sr;
    206 
    207 	if (*hej) {
    208 		*hej = *hej;
    209 		return 1;
    210 	}
    211 	return 0;
    212 }
    213 
    214 void
    215 uba_dw780int(void *arg)
    216 {
    217 	extern	void scb_stray(void *);
    218 	struct	uba_vsoftc *vc = arg;
    219 	struct	uba_regs *ur = vc->uv_uba;
    220 	struct	ivec_dsp *ivec;
    221 	struct  evcnt *uvec;
    222 	int	br, vec;
    223 
    224 	br = mfpr(PR_IPL);
    225 	uvec = &vc->uv_sc.uh_intrcnt;
    226 	vec = ur->uba_brrvr[br - 0x14];
    227 	if (vec <= 0) {
    228 		ubaerror(&vc->uv_sc, &br, &vec);
    229 		if (vec == 0)
    230 			return;
    231 	}
    232 
    233 	uvec->ev_count--;	/* This interrupt should not be counted against
    234 				   the uba. */
    235 	ivec = &scb_vec[(vc->uh_ibase + vec)/4];
    236 	if (cold && *ivec->hoppaddr == scb_stray) {
    237 		scb_fake(vec + vc->uh_ibase, br);
    238 	} else {
    239 		if (*ivec->hoppaddr == scb_stray)
    240 			strayint.ev_count++; /* Count against stray int */
    241 		else
    242 			ivec->ev->ev_count++; /* Count against device */
    243 		(*ivec->hoppaddr)(ivec->pushlarg);
    244 	}
    245 }
    246 
    247 void
    248 dw780_init(struct uba_softc *sc)
    249 {
    250 	struct uba_vsoftc *vc = (void *)sc;
    251 
    252 	vc->uv_uba->uba_cr = UBACR_ADINIT;
    253 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
    254 	while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
    255 		;
    256 }
    257 
    258 #ifdef notyet
    259 void
    260 dw780_purge(sc, bdp)
    261 	struct uba_softc *sc;
    262 	int bdp;
    263 {
    264 	struct uba_vsoftc *vc = (void *)sc;
    265 
    266 	vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
    267 }
    268 #endif
    269 
    270 int	ubawedgecnt = 10;
    271 int	ubacrazy = 500;
    272 int	zvcnt_max = 5000;	/* in 8 sec */
    273 int	ubaerrcnt;
    274 /*
    275  * This routine is called by the locore code to process a UBA
    276  * error on an 11/780 or 8600.	The arguments are passed
    277  * on the stack, and value-result (through some trickery).
    278  * In particular, the uvec argument is used for further
    279  * uba processing so the result aspect of it is very important.
    280  */
    281 /*ARGSUSED*/
    282 void
    283 ubaerror(struct uba_softc *uh, int *ipl, int *uvec)
    284 {
    285 	struct uba_vsoftc *vc = (void *)uh;
    286 	struct	uba_regs *uba = vc->uv_uba;
    287 	int sr, s;
    288 	char sbuf[256], sbuf2[256];
    289 
    290 	if (*uvec == 0) {
    291 		/*
    292 		 * Declare dt as unsigned so that negative values
    293 		 * are handled as >8 below, in case time was set back.
    294 		 */
    295 		u_long	dt = time.tv_sec - vc->uh_zvtime;
    296 
    297 		vc->uh_zvtotal++;
    298 		if (dt > 8) {
    299 			vc->uh_zvtime = time.tv_sec;
    300 			vc->uh_zvcnt = 0;
    301 		}
    302 		if (++vc->uh_zvcnt > zvcnt_max) {
    303 			printf("%s: too many zero vectors (%d in <%d sec)\n",
    304 				vc->uv_sc.uh_dev.dv_xname, vc->uh_zvcnt, (int)dt + 1);
    305 
    306 			bitmask_snprintf(uba->uba_cnfgr&(~0xff), UBACNFGR_BITS,
    307 					 sbuf, sizeof(sbuf));
    308 			printf("\tIPL 0x%x\n\tcnfgr: %s	 Adapter Code: 0x%x\n",
    309 				*ipl, sbuf, uba->uba_cnfgr&0xff);
    310 
    311 			bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    312 			printf("\tsr: %s\n\tdcr: %x (MIC %sOK)\n",
    313 				sbuf, uba->uba_dcr,
    314 				(uba->uba_dcr&0x8000000)?"":"NOT ");
    315 
    316 			ubareset(&vc->uv_sc);
    317 		}
    318 		return;
    319 	}
    320 	if (uba->uba_cnfgr & NEX_CFGFLT) {
    321 		bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    322 		bitmask_snprintf(uba->uba_cnfgr, NEXFLT_BITS, sbuf2, sizeof(sbuf2));
    323 		printf("%s: sbi fault sr=%s cnfgr=%s\n",
    324 		    vc->uv_sc.uh_dev.dv_xname, sbuf, sbuf2);
    325 		ubareset(&vc->uv_sc);
    326 		*uvec = 0;
    327 		return;
    328 	}
    329 	sr = uba->uba_sr;
    330 	s = spluba();
    331 	bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    332 	printf("%s: uba error sr=%s fmer=%x fubar=%o\n", vc->uv_sc.uh_dev.dv_xname,
    333 	    sbuf, uba->uba_fmer, 4*uba->uba_fubar);
    334 	splx(s);
    335 	uba->uba_sr = sr;
    336 	*uvec &= UBABRRVR_DIV;
    337 	if (++ubaerrcnt % ubawedgecnt == 0) {
    338 		if (ubaerrcnt > ubacrazy)
    339 			panic("uba crazy");
    340 		printf("ERROR LIMIT ");
    341 		ubareset(&vc->uv_sc);
    342 		*uvec = 0;
    343 	}
    344 }
    345