xref: /netbsd/sys/dev/qbus/if_de.c (revision bf9ec67e)
1 /*	$NetBSD: if_de.c,v 1.11 2001/11/13 07:11:24 lukem Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
5  * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
6  * All rights reserved.
7  *
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)if_de.c	7.12 (Berkeley) 12/16/90
38  */
39 
40 /*
41  * DEC DEUNA interface
42  *
43  *	Lou Salkind
44  *	New York University
45  *
46  *	Rewritten by Ragge 30 April 2000 to match new world.
47  *
48  * TODO:
49  *	timeout routine (get statistics)
50  */
51 
52 #include <sys/cdefs.h>
53 __KERNEL_RCSID(0, "$NetBSD: if_de.c,v 1.11 2001/11/13 07:11:24 lukem Exp $");
54 
55 #include "opt_inet.h"
56 #include "bpfilter.h"
57 
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/mbuf.h>
61 #include <sys/buf.h>
62 #include <sys/protosw.h>
63 #include <sys/socket.h>
64 #include <sys/ioctl.h>
65 #include <sys/errno.h>
66 #include <sys/syslog.h>
67 #include <sys/device.h>
68 
69 #include <net/if.h>
70 #include <net/if_ether.h>
71 #include <net/if_dl.h>
72 
73 #ifdef INET
74 #include <netinet/in.h>
75 #include <netinet/if_inarp.h>
76 #endif
77 
78 #if NBPFILTER > 0
79 #include <net/bpf.h>
80 #include <net/bpfdesc.h>
81 #endif
82 
83 #include <machine/bus.h>
84 
85 #include <dev/qbus/ubavar.h>
86 #include <dev/qbus/if_dereg.h>
87 #include <dev/qbus/if_uba.h>
88 
89 #include "ioconf.h"
90 
91 /*
92  * Be careful with transmit/receive buffers, each entry steals 4 map
93  * registers, and there is only 496 on one unibus...
94  */
95 #define NRCV	7	/* number of receive buffers (must be > 1) */
96 #define NXMT	3	/* number of transmit buffers */
97 
98 /*
99  * Structure containing the elements that must be in DMA-safe memory.
100  */
101 struct	de_cdata {
102 	/* the following structures are always mapped in */
103 	struct	de_pcbb dc_pcbb;	/* port control block */
104 	struct	de_ring dc_xrent[NXMT]; /* transmit ring entrys */
105 	struct	de_ring dc_rrent[NRCV]; /* receive ring entrys */
106 	struct	de_udbbuf dc_udbbuf;	/* UNIBUS data buffer */
107 	/* end mapped area */
108 };
109 
110 /*
111  * Ethernet software status per interface.
112  *
113  * Each interface is referenced by a network interface structure,
114  * ds_if, which the routing code uses to locate the interface.
115  * This structure contains the output queue for the interface, its address, ...
116  * We also have, for each interface, a UBA interface structure, which
117  * contains information about the UNIBUS resources held by the interface:
118  * map registers, buffered data paths, etc.  Information is cached in this
119  * structure for use by the if_uba.c routines in running the interface
120  * efficiently.
121  */
122 struct	de_softc {
123 	struct	device sc_dev;		/* Configuration common part */
124 	struct	evcnt sc_intrcnt;	/* Interrupt counting */
125 	struct	ethercom sc_ec;		/* Ethernet common part */
126 #define sc_if	sc_ec.ec_if		/* network-visible interface */
127 	bus_space_tag_t sc_iot;
128 	bus_addr_t sc_ioh;
129 	bus_dma_tag_t sc_dmat;
130 	int	sc_flags;
131 #define	DSF_MAPPED	1
132 	struct ubinfo sc_ui;
133 	struct de_cdata *sc_dedata;	/* Control structure */
134 	struct de_cdata *sc_pdedata;	/* Bus-mapped control structure */
135 	struct	ifubinfo sc_ifuba;      /* UNIBUS resources */
136 	struct	ifrw sc_ifr[NRCV];      /* UNIBUS receive buffer maps */
137 	struct	ifxmt sc_ifw[NXMT];     /* UNIBUS receive buffer maps */
138 
139 	int	sc_xindex;		/* UNA index into transmit chain */
140 	int	sc_rindex;		/* UNA index into receive chain */
141 	int	sc_xfree;		/* index for next transmit buffer */
142 	int	sc_nxmit;		/* # of transmits in progress */
143 	void *sc_sh;			/* shutdownhook cookie */
144 };
145 
146 static	int dematch(struct device *, struct cfdata *, void *);
147 static	void deattach(struct device *, struct device *, void *);
148 static	void dewait(struct de_softc *, char *);
149 static	int deinit(struct ifnet *);
150 static	int deioctl(struct ifnet *, u_long, caddr_t);
151 static	void dereset(struct device *);
152 static	void destop(struct ifnet *, int);
153 static	void destart(struct ifnet *);
154 static	void derecv(struct de_softc *);
155 static	void deintr(void *);
156 static	void deshutdown(void *);
157 
158 struct	cfattach de_ca = {
159 	sizeof(struct de_softc), dematch, deattach
160 };
161 
162 #define DE_WCSR(csr, val) \
163 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
164 #define DE_WLOW(val) \
165 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, DE_PCSR0, val)
166 #define DE_WHIGH(val) \
167 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, DE_PCSR0 + 1, val)
168 #define DE_RCSR(csr) \
169 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
170 
171 #define LOWORD(x)	((int)(x) & 0xffff)
172 #define HIWORD(x)	(((int)(x) >> 16) & 0x3)
173 /*
174  * Interface exists: make available by filling in network interface
175  * record.  System will initialize the interface when it is ready
176  * to accept packets.  We get the ethernet address here.
177  */
178 void
179 deattach(struct device *parent, struct device *self, void *aux)
180 {
181 	struct uba_attach_args *ua = aux;
182 	struct de_softc *sc = (struct de_softc *)self;
183 	struct ifnet *ifp = &sc->sc_if;
184 	u_int8_t myaddr[ETHER_ADDR_LEN];
185 	int csr1, error;
186 	char *c;
187 
188 	sc->sc_iot = ua->ua_iot;
189 	sc->sc_ioh = ua->ua_ioh;
190 	sc->sc_dmat = ua->ua_dmat;
191 
192 	/*
193 	 * What kind of a board is this?
194 	 * The error bits 4-6 in pcsr1 are a device id as long as
195 	 * the high byte is zero.
196 	 */
197 	csr1 = DE_RCSR(DE_PCSR1);
198 	if (csr1 & 0xff60)
199 		c = "broken";
200 	else if (csr1 & 0x10)
201 		c = "delua";
202 	else
203 		c = "deuna";
204 
205 	/*
206 	 * Reset the board and temporarily map
207 	 * the pcbb buffer onto the Unibus.
208 	 */
209 	DE_WCSR(DE_PCSR0, 0);		/* reset INTE */
210 	DELAY(100);
211 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
212 	dewait(sc, "reset");
213 
214 	sc->sc_ui.ui_size = sizeof(struct de_cdata);
215 	if ((error = ubmemalloc((struct uba_softc *)parent, &sc->sc_ui, 0)))
216 		return printf(": failed ubmemalloc(), error = %d\n", error);
217 	sc->sc_dedata = (struct de_cdata *)sc->sc_ui.ui_vaddr;
218 
219 	/*
220 	 * Tell the DEUNA about our PCB
221 	 */
222 	DE_WCSR(DE_PCSR2, LOWORD(sc->sc_ui.ui_baddr));
223 	DE_WCSR(DE_PCSR3, HIWORD(sc->sc_ui.ui_baddr));
224 	DE_WLOW(CMD_GETPCBB);
225 	dewait(sc, "pcbb");
226 
227 	sc->sc_dedata->dc_pcbb.pcbb0 = FC_RDPHYAD;
228 	DE_WLOW(CMD_GETCMD);
229 	dewait(sc, "read addr ");
230 
231 	bcopy((caddr_t)&sc->sc_dedata->dc_pcbb.pcbb2, myaddr, sizeof (myaddr));
232 	printf("\n%s: %s, hardware address %s\n", sc->sc_dev.dv_xname, c,
233 		ether_sprintf(myaddr));
234 
235 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec, deintr, sc,
236 	    &sc->sc_intrcnt);
237 	uba_reset_establish(dereset, &sc->sc_dev);
238 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
239 	    sc->sc_dev.dv_xname, "intr");
240 
241 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
242 	ifp->if_softc = sc;
243 	ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI;
244 	ifp->if_ioctl = deioctl;
245 	ifp->if_start = destart;
246 	ifp->if_init = deinit;
247 	ifp->if_stop = destop;
248 	IFQ_SET_READY(&ifp->if_snd);
249 
250 	if_attach(ifp);
251 	ether_ifattach(ifp, myaddr);
252 	ubmemfree((struct uba_softc *)parent, &sc->sc_ui);
253 
254 	sc->sc_sh = shutdownhook_establish(deshutdown, sc);
255 }
256 
257 void
258 destop(struct ifnet *ifp, int a)
259 {
260 	struct de_softc *sc = ifp->if_softc;
261 
262 	DE_WLOW(0);
263 	DELAY(5000);
264 	DE_WLOW(PCSR0_RSET);
265 }
266 
267 
268 /*
269  * Reset of interface after UNIBUS reset.
270  */
271 void
272 dereset(struct device *dev)
273 {
274 	struct de_softc *sc = (void *)dev;
275 
276 	sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
277 	sc->sc_flags &= ~DSF_MAPPED;
278 	sc->sc_pdedata = NULL;	/* All mappings lost */
279 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
280 	dewait(sc, "reset");
281 	deinit(&sc->sc_if);
282 }
283 
284 /*
285  * Initialization of interface; clear recorded pending
286  * operations, and reinitialize UNIBUS usage.
287  */
288 int
289 deinit(struct ifnet *ifp)
290 {
291 	struct de_softc *sc = ifp->if_softc;
292 	struct de_cdata *dc, *pdc;
293 	struct ifrw *ifrw;
294 	struct ifxmt *ifxp;
295 	struct de_ring *rp;
296 	int s, error;
297 
298 	if (ifp->if_flags & IFF_RUNNING)
299 		return 0;
300 	if ((sc->sc_flags & DSF_MAPPED) == 0) {
301 		if (if_ubaminit(&sc->sc_ifuba, (void *)sc->sc_dev.dv_parent,
302 		    MCLBYTES, sc->sc_ifr, NRCV, sc->sc_ifw, NXMT)) {
303 			printf("%s: can't initialize\n", sc->sc_dev.dv_xname);
304 			ifp->if_flags &= ~IFF_UP;
305 			return 0;
306 		}
307 		sc->sc_ui.ui_size = sizeof(struct de_cdata);
308 		if ((error = ubmemalloc((void *)sc->sc_dev.dv_parent,
309 		    &sc->sc_ui, 0))) {
310 			printf(": unable to ubmemalloc(), error = %d\n", error);
311 			return 0;
312 		}
313 		sc->sc_pdedata = (struct de_cdata *)sc->sc_ui.ui_baddr;
314 		sc->sc_dedata = (struct de_cdata *)sc->sc_ui.ui_vaddr;
315 		sc->sc_flags |= DSF_MAPPED;
316 	}
317 
318 	/*
319 	 * Tell the DEUNA about our PCB
320 	 */
321 	DE_WCSR(DE_PCSR2, LOWORD(sc->sc_pdedata));
322 	DE_WCSR(DE_PCSR3, HIWORD(sc->sc_pdedata));
323 	DE_WLOW(0);		/* reset INTE */
324 	DELAY(500);
325 	DE_WLOW(CMD_GETPCBB);
326 	dewait(sc, "pcbb");
327 
328 	dc = sc->sc_dedata;
329 	pdc = sc->sc_pdedata;
330 	/* set the transmit and receive ring header addresses */
331 	dc->dc_pcbb.pcbb0 = FC_WTRING;
332 	dc->dc_pcbb.pcbb2 = LOWORD(&pdc->dc_udbbuf);
333 	dc->dc_pcbb.pcbb4 = HIWORD(&pdc->dc_udbbuf);
334 
335 	dc->dc_udbbuf.b_tdrbl = LOWORD(&pdc->dc_xrent[0]);
336 	dc->dc_udbbuf.b_tdrbh = HIWORD(&pdc->dc_xrent[0]);
337 	dc->dc_udbbuf.b_telen = sizeof (struct de_ring) / sizeof(u_int16_t);
338 	dc->dc_udbbuf.b_trlen = NXMT;
339 	dc->dc_udbbuf.b_rdrbl = LOWORD(&pdc->dc_rrent[0]);
340 	dc->dc_udbbuf.b_rdrbh = HIWORD(&pdc->dc_rrent[0]);
341 	dc->dc_udbbuf.b_relen = sizeof (struct de_ring) / sizeof(u_int16_t);
342 	dc->dc_udbbuf.b_rrlen = NRCV;
343 
344 	DE_WLOW(CMD_GETCMD);
345 	dewait(sc, "wtring");
346 
347 	sc->sc_dedata->dc_pcbb.pcbb0 = FC_WTMODE;
348 	sc->sc_dedata->dc_pcbb.pcbb2 = MOD_TPAD|MOD_HDX|MOD_DRDC|MOD_ENAL;
349 	DE_WLOW(CMD_GETCMD);
350 	dewait(sc, "wtmode");
351 
352 	/* set up the receive and transmit ring entries */
353 	ifxp = &sc->sc_ifw[0];
354 	for (rp = &dc->dc_xrent[0]; rp < &dc->dc_xrent[NXMT]; rp++) {
355 		rp->r_segbl = LOWORD(ifxp->ifw_info);
356 		rp->r_segbh = HIWORD(ifxp->ifw_info);
357 		rp->r_flags = 0;
358 		ifxp++;
359 	}
360 	ifrw = &sc->sc_ifr[0];
361 	for (rp = &dc->dc_rrent[0]; rp < &dc->dc_rrent[NRCV]; rp++) {
362 		rp->r_slen = MCLBYTES - 2;
363 		rp->r_segbl = LOWORD(ifrw->ifrw_info);
364 		rp->r_segbh = HIWORD(ifrw->ifrw_info);
365 		rp->r_flags = RFLG_OWN;
366 		ifrw++;
367 	}
368 
369 	/* start up the board (rah rah) */
370 	s = splnet();
371 	sc->sc_rindex = sc->sc_xindex = sc->sc_xfree = sc->sc_nxmit = 0;
372 	sc->sc_if.if_flags |= IFF_RUNNING;
373 	DE_WLOW(PCSR0_INTE);			/* avoid interlock */
374 	destart(&sc->sc_if);		/* queue output packets */
375 	DE_WLOW(CMD_START|PCSR0_INTE);
376 	splx(s);
377 	return 0;
378 }
379 
380 /*
381  * Setup output on interface.
382  * Get another datagram to send off of the interface queue,
383  * and map it to the interface before starting the output.
384  * Must be called from ipl >= our interrupt level.
385  */
386 void
387 destart(struct ifnet *ifp)
388 {
389 	struct de_softc *sc = ifp->if_softc;
390 	struct de_cdata *dc;
391 	struct de_ring *rp;
392 	struct mbuf *m;
393 	int nxmit, len;
394 
395 	/*
396 	 * the following test is necessary, since
397 	 * the code is not reentrant and we have
398 	 * multiple transmission buffers.
399 	 */
400 	if (sc->sc_if.if_flags & IFF_OACTIVE)
401 		return;
402 	dc = sc->sc_dedata;
403 	for (nxmit = sc->sc_nxmit; nxmit < NXMT; nxmit++) {
404 		IFQ_DEQUEUE(&ifp->if_snd, m);
405 		if (m == 0)
406 			break;
407 
408 		rp = &dc->dc_xrent[sc->sc_xfree];
409 		if (rp->r_flags & XFLG_OWN)
410 			panic("deuna xmit in progress");
411 #if NBPFILTER > 0
412 		if (ifp->if_bpf)
413 			bpf_mtap(ifp->if_bpf, m);
414 #endif
415 
416 		len = if_ubaput(&sc->sc_ifuba, &sc->sc_ifw[sc->sc_xfree], m);
417 		rp->r_slen = len;
418 		rp->r_tdrerr = 0;
419 		rp->r_flags = XFLG_STP|XFLG_ENP|XFLG_OWN;
420 
421 		sc->sc_xfree++;
422 		if (sc->sc_xfree == NXMT)
423 			sc->sc_xfree = 0;
424 	}
425 	if (sc->sc_nxmit != nxmit) {
426 		sc->sc_nxmit = nxmit;
427 		if (ifp->if_flags & IFF_RUNNING)
428 			DE_WLOW(PCSR0_INTE|CMD_PDMD);
429 	}
430 }
431 
432 /*
433  * Command done interrupt.
434  */
435 void
436 deintr(void *arg)
437 {
438 	struct ifxmt *ifxp;
439 	struct de_cdata *dc;
440 	struct de_softc *sc = arg;
441 	struct de_ring *rp;
442 	short csr0;
443 
444 	/* save flags right away - clear out interrupt bits */
445 	csr0 = DE_RCSR(DE_PCSR0);
446 	DE_WHIGH(csr0 >> 8);
447 
448 
449 	sc->sc_if.if_flags |= IFF_OACTIVE;	/* prevent entering destart */
450 	/*
451 	 * if receive, put receive buffer on mbuf
452 	 * and hang the request again
453 	 */
454 	derecv(sc);
455 
456 	/*
457 	 * Poll transmit ring and check status.
458 	 * Be careful about loopback requests.
459 	 * Then free buffer space and check for
460 	 * more transmit requests.
461 	 */
462 	dc = sc->sc_dedata;
463 	for ( ; sc->sc_nxmit > 0; sc->sc_nxmit--) {
464 		rp = &dc->dc_xrent[sc->sc_xindex];
465 		if (rp->r_flags & XFLG_OWN)
466 			break;
467 
468 		sc->sc_if.if_opackets++;
469 		ifxp = &sc->sc_ifw[sc->sc_xindex];
470 		/* check for unusual conditions */
471 		if (rp->r_flags & (XFLG_ERRS|XFLG_MTCH|XFLG_ONE|XFLG_MORE)) {
472 			if (rp->r_flags & XFLG_ERRS) {
473 				/* output error */
474 				sc->sc_if.if_oerrors++;
475 			} else if (rp->r_flags & XFLG_ONE) {
476 				/* one collision */
477 				sc->sc_if.if_collisions++;
478 			} else if (rp->r_flags & XFLG_MORE) {
479 				/* more than one collision */
480 				sc->sc_if.if_collisions += 2;	/* guess */
481 			}
482 		}
483 		if_ubaend(&sc->sc_ifuba, ifxp);
484 		/* check if next transmit buffer also finished */
485 		sc->sc_xindex++;
486 		if (sc->sc_xindex == NXMT)
487 			sc->sc_xindex = 0;
488 	}
489 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
490 	destart(&sc->sc_if);
491 
492 	if (csr0 & PCSR0_RCBI) {
493 		DE_WLOW(PCSR0_INTE|CMD_PDMD);
494 	}
495 }
496 
497 /*
498  * Ethernet interface receiver interface.
499  * If input error just drop packet.
500  * Otherwise purge input buffered data path and examine
501  * packet to determine type.  If can't determine length
502  * from type, then have to drop packet.	 Othewise decapsulate
503  * packet based on type and pass to type specific higher-level
504  * input routine.
505  */
506 void
507 derecv(struct de_softc *sc)
508 {
509 	struct ifnet *ifp = &sc->sc_if;
510 	struct de_ring *rp;
511 	struct de_cdata *dc;
512 	struct mbuf *m;
513 	int len;
514 
515 	dc = sc->sc_dedata;
516 	rp = &dc->dc_rrent[sc->sc_rindex];
517 	while ((rp->r_flags & RFLG_OWN) == 0) {
518 		sc->sc_if.if_ipackets++;
519 		len = (rp->r_lenerr&RERR_MLEN) - ETHER_CRC_LEN;
520 		/* check for errors */
521 		if ((rp->r_flags & (RFLG_ERRS|RFLG_FRAM|RFLG_OFLO|RFLG_CRC)) ||
522 		    (rp->r_lenerr & (RERR_BUFL|RERR_UBTO))) {
523 			sc->sc_if.if_ierrors++;
524 			goto next;
525 		}
526 		m = if_ubaget(&sc->sc_ifuba, &sc->sc_ifr[sc->sc_rindex],
527 		    ifp, len);
528 		if (m == 0) {
529 			sc->sc_if.if_ierrors++;
530 			goto next;
531 		}
532 #if NBPFILTER > 0
533 		if (ifp->if_bpf)
534 			bpf_mtap(ifp->if_bpf, m);
535 #endif
536 
537 		(*ifp->if_input)(ifp, m);
538 
539 		/* hang the receive buffer again */
540 next:		rp->r_lenerr = 0;
541 		rp->r_flags = RFLG_OWN;
542 
543 		/* check next receive buffer */
544 		sc->sc_rindex++;
545 		if (sc->sc_rindex == NRCV)
546 			sc->sc_rindex = 0;
547 		rp = &dc->dc_rrent[sc->sc_rindex];
548 	}
549 }
550 
551 /*
552  * Process an ioctl request.
553  */
554 int
555 deioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
556 {
557 	int s, error = 0;
558 
559 	s = splnet();
560 
561 	error = ether_ioctl(ifp, cmd, data);
562 	if (error == ENETRESET)
563 		error = 0;
564 
565 	splx(s);
566 	return (error);
567 }
568 
569 /*
570  * Await completion of the named function
571  * and check for errors.
572  */
573 void
574 dewait(struct de_softc *sc, char *fn)
575 {
576 	int csr0;
577 
578 	while ((DE_RCSR(DE_PCSR0) & PCSR0_INTR) == 0)
579 		;
580 	csr0 = DE_RCSR(DE_PCSR0);
581 	DE_WHIGH(csr0 >> 8);
582 	if (csr0 & PCSR0_PCEI) {
583 		char bits[64];
584 		printf("%s: %s failed, csr0=%s ", sc->sc_dev.dv_xname, fn,
585 		    bitmask_snprintf(csr0, PCSR0_BITS, bits, sizeof(bits)));
586 		printf("csr1=%s\n", bitmask_snprintf(DE_RCSR(DE_PCSR1),
587 		    PCSR1_BITS, bits, sizeof(bits)));
588 	}
589 }
590 
591 int
592 dematch(struct device *parent, struct cfdata *cf, void *aux)
593 {
594 	struct uba_attach_args *ua = aux;
595 	struct de_softc ssc;
596 	struct de_softc *sc = &ssc;
597 	int i;
598 
599 	sc->sc_iot = ua->ua_iot;
600 	sc->sc_ioh = ua->ua_ioh;
601 	/*
602 	 * Make sure self-test is finished before we screw with the board.
603 	 * Self-test on a DELUA can take 15 seconds (argh).
604 	 */
605 	for (i = 0;
606 	    (i < 160) &&
607 	    (DE_RCSR(DE_PCSR0) & PCSR0_FATI) == 0 &&
608 	    (DE_RCSR(DE_PCSR1) & PCSR1_STMASK) == STAT_RESET;
609 	    ++i)
610 		DELAY(50000);
611 	if (((DE_RCSR(DE_PCSR0) & PCSR0_FATI) != 0) ||
612 	    (((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_READY) &&
613 	    ((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_RUN)))
614 		return(0);
615 
616 	DE_WCSR(DE_PCSR0, 0);
617 	DELAY(5000);
618 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
619 	while ((DE_RCSR(DE_PCSR0) & PCSR0_INTR) == 0)
620 		;
621 	/* make board interrupt by executing a GETPCBB command */
622 	DE_WCSR(DE_PCSR0, PCSR0_INTE);
623 	DE_WCSR(DE_PCSR2, 0);
624 	DE_WCSR(DE_PCSR3, 0);
625 	DE_WCSR(DE_PCSR0, PCSR0_INTE|CMD_GETPCBB);
626 	DELAY(50000);
627 
628 	return 1;
629 }
630 
631 void
632 deshutdown(void *arg)
633 {
634 	struct de_softc *sc = arg;
635 
636 	DE_WCSR(DE_PCSR0, 0);
637 	DELAY(1000);
638 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
639 	dewait(sc, "shutdown");
640 }
641