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