if_eg.c revision 1.28 1 1.28 thorpej /* $NetBSD: if_eg.c,v 1.28 1996/08/03 02:23:57 thorpej Exp $ */
2 1.4 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1993 Dean Huxley <dean (at) fsa.ca>
5 1.1 deraadt * All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * Redistribution and use in source and binary forms, with or without
8 1.1 deraadt * modification, are permitted provided that the following conditions
9 1.1 deraadt * are met:
10 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
11 1.1 deraadt * notice, this list of conditions and the following disclaimer.
12 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
14 1.1 deraadt * documentation and/or other materials provided with the distribution.
15 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
16 1.1 deraadt * must display the following acknowledgement:
17 1.1 deraadt * This product includes software developed by Dean Huxley.
18 1.1 deraadt * 4. The name of Dean Huxley may not be used to endorse or promote products
19 1.1 deraadt * derived from this software without specific prior written permission.
20 1.1 deraadt *
21 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 deraadt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 deraadt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 deraadt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 deraadt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 deraadt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 deraadt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 deraadt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 deraadt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 deraadt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.22 hpeyerl */
32 1.22 hpeyerl /*
33 1.22 hpeyerl * Support for 3Com 3c505 Etherlink+ card.
34 1.1 deraadt */
35 1.1 deraadt
36 1.1 deraadt /* To do:
37 1.1 deraadt * - multicast
38 1.1 deraadt * - promiscuous
39 1.27 thorpej * - get rid of isa indirect stuff
40 1.1 deraadt */
41 1.1 deraadt #include "bpfilter.h"
42 1.1 deraadt
43 1.1 deraadt #include <sys/types.h>
44 1.1 deraadt #include <sys/param.h>
45 1.1 deraadt #include <sys/mbuf.h>
46 1.1 deraadt #include <sys/socket.h>
47 1.1 deraadt #include <sys/ioctl.h>
48 1.1 deraadt #include <sys/errno.h>
49 1.1 deraadt #include <sys/syslog.h>
50 1.1 deraadt #include <sys/select.h>
51 1.1 deraadt #include <sys/device.h>
52 1.1 deraadt
53 1.1 deraadt #include <net/if.h>
54 1.1 deraadt #include <net/netisr.h>
55 1.1 deraadt #include <net/if_dl.h>
56 1.1 deraadt #include <net/if_types.h>
57 1.1 deraadt #include <net/netisr.h>
58 1.1 deraadt
59 1.1 deraadt #ifdef INET
60 1.1 deraadt #include <netinet/in.h>
61 1.1 deraadt #include <netinet/in_systm.h>
62 1.1 deraadt #include <netinet/in_var.h>
63 1.1 deraadt #include <netinet/ip.h>
64 1.1 deraadt #include <netinet/if_ether.h>
65 1.1 deraadt #endif
66 1.1 deraadt
67 1.1 deraadt #ifdef NS
68 1.1 deraadt #include <netns/ns.h>
69 1.1 deraadt #include <netns/ns_if.h>
70 1.1 deraadt #endif
71 1.1 deraadt
72 1.1 deraadt #if NBPFILTER > 0
73 1.1 deraadt #include <net/bpf.h>
74 1.1 deraadt #include <net/bpfdesc.h>
75 1.1 deraadt #endif
76 1.1 deraadt
77 1.1 deraadt #include <machine/cpu.h>
78 1.26 mycroft #include <machine/intr.h>
79 1.27 thorpej #include <machine/bus.h>
80 1.1 deraadt
81 1.12 cgd #include <dev/isa/isavar.h>
82 1.10 cgd #include <dev/isa/if_egreg.h>
83 1.10 cgd #include <dev/isa/elink.h>
84 1.1 deraadt
85 1.1 deraadt /* for debugging convenience */
86 1.1 deraadt #ifdef EGDEBUG
87 1.3 deraadt #define dprintf(x) printf x
88 1.1 deraadt #else
89 1.3 deraadt #define dprintf(x)
90 1.1 deraadt #endif
91 1.1 deraadt
92 1.1 deraadt #define ETHER_MIN_LEN 64
93 1.1 deraadt #define ETHER_MAX_LEN 1518
94 1.1 deraadt #define ETHER_ADDR_LEN 6
95 1.1 deraadt
96 1.1 deraadt #define EG_INLEN 10
97 1.1 deraadt #define EG_BUFLEN 0x0670
98 1.1 deraadt
99 1.1 deraadt /*
100 1.1 deraadt * Ethernet software status per interface.
101 1.1 deraadt */
102 1.1 deraadt struct eg_softc {
103 1.1 deraadt struct device sc_dev;
104 1.12 cgd void *sc_ih;
105 1.1 deraadt struct arpcom sc_arpcom; /* Ethernet common part */
106 1.27 thorpej bus_chipset_tag_t sc_bc; /* bus chipset identifier */
107 1.27 thorpej bus_io_handle_t sc_ioh; /* i/o handle */
108 1.27 thorpej u_int8_t eg_rom_major; /* Cards ROM version (major number) */
109 1.27 thorpej u_int8_t eg_rom_minor; /* Cards ROM version (minor number) */
110 1.27 thorpej short eg_ram; /* Amount of RAM on the card */
111 1.27 thorpej u_int8_t eg_pcb[64]; /* Primary Command Block buffer */
112 1.27 thorpej u_int8_t eg_incount; /* Number of buffers currently used */
113 1.27 thorpej caddr_t eg_inbuf; /* Incoming packet buffer */
114 1.27 thorpej caddr_t eg_outbuf; /* Outgoing packet buffer */
115 1.1 deraadt };
116 1.1 deraadt
117 1.6 mycroft int egprobe __P((struct device *, void *, void *));
118 1.6 mycroft void egattach __P((struct device *, struct device *, void *));
119 1.1 deraadt
120 1.23 thorpej struct cfattach eg_ca = {
121 1.23 thorpej sizeof(struct eg_softc), egprobe, egattach
122 1.23 thorpej };
123 1.23 thorpej
124 1.23 thorpej struct cfdriver eg_cd = {
125 1.23 thorpej NULL, "eg", DV_IFNET
126 1.1 deraadt };
127 1.1 deraadt
128 1.12 cgd int egintr __P((void *));
129 1.18 mycroft void eginit __P((struct eg_softc *));
130 1.18 mycroft int egioctl __P((struct ifnet *, u_long, caddr_t));
131 1.19 mycroft void egrecv __P((struct eg_softc *));
132 1.18 mycroft void egstart __P((struct ifnet *));
133 1.25 thorpej void egwatchdog __P((struct ifnet *));
134 1.18 mycroft void egreset __P((struct eg_softc *));
135 1.18 mycroft void egread __P((struct eg_softc *, caddr_t, int));
136 1.18 mycroft struct mbuf *egget __P((struct eg_softc *, caddr_t, int));
137 1.18 mycroft void egstop __P((struct eg_softc *));
138 1.1 deraadt
139 1.1 deraadt /*
140 1.1 deraadt * Support stuff
141 1.1 deraadt */
142 1.1 deraadt
143 1.1 deraadt static inline void
144 1.1 deraadt egprintpcb(sc)
145 1.1 deraadt struct eg_softc *sc;
146 1.1 deraadt {
147 1.1 deraadt int i;
148 1.1 deraadt
149 1.1 deraadt for (i = 0; i < sc->eg_pcb[1] + 2; i++)
150 1.3 deraadt dprintf(("pcb[%2d] = %x\n", i, sc->eg_pcb[i]));
151 1.1 deraadt }
152 1.1 deraadt
153 1.1 deraadt
154 1.1 deraadt static inline void
155 1.1 deraadt egprintstat(b)
156 1.1 deraadt u_char b;
157 1.1 deraadt {
158 1.3 deraadt dprintf(("%s %s %s %s %s %s %s\n",
159 1.1 deraadt (b & EG_STAT_HCRE)?"HCRE":"",
160 1.1 deraadt (b & EG_STAT_ACRF)?"ACRF":"",
161 1.1 deraadt (b & EG_STAT_DIR )?"DIR ":"",
162 1.1 deraadt (b & EG_STAT_DONE)?"DONE":"",
163 1.1 deraadt (b & EG_STAT_ASF3)?"ASF3":"",
164 1.1 deraadt (b & EG_STAT_ASF2)?"ASF2":"",
165 1.1 deraadt (b & EG_STAT_ASF1)?"ASF1":""));
166 1.1 deraadt }
167 1.1 deraadt
168 1.1 deraadt static int
169 1.1 deraadt egoutPCB(sc, b)
170 1.1 deraadt struct eg_softc *sc;
171 1.27 thorpej u_int8_t b;
172 1.1 deraadt {
173 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
174 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
175 1.1 deraadt int i;
176 1.1 deraadt
177 1.1 deraadt for (i=0; i < 4000; i++) {
178 1.27 thorpej if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HCRE) {
179 1.27 thorpej bus_io_write_1(bc, ioh, EG_COMMAND, b);
180 1.1 deraadt return 0;
181 1.1 deraadt }
182 1.1 deraadt delay(10);
183 1.1 deraadt }
184 1.3 deraadt dprintf(("egoutPCB failed\n"));
185 1.1 deraadt return 1;
186 1.1 deraadt }
187 1.1 deraadt
188 1.1 deraadt static int
189 1.1 deraadt egreadPCBstat(sc, statb)
190 1.1 deraadt struct eg_softc *sc;
191 1.27 thorpej u_int8_t statb;
192 1.1 deraadt {
193 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
194 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
195 1.1 deraadt int i;
196 1.1 deraadt
197 1.1 deraadt for (i=0; i < 5000; i++) {
198 1.27 thorpej if ((bus_io_read_1(bc, ioh, EG_STATUS) &
199 1.27 thorpej EG_PCB_STAT) != EG_PCB_NULL)
200 1.1 deraadt break;
201 1.1 deraadt delay(10);
202 1.1 deraadt }
203 1.27 thorpej if ((bus_io_read_1(bc, ioh, EG_STATUS) & EG_PCB_STAT) == statb)
204 1.1 deraadt return 0;
205 1.1 deraadt return 1;
206 1.1 deraadt }
207 1.1 deraadt
208 1.1 deraadt static int
209 1.1 deraadt egreadPCBready(sc)
210 1.1 deraadt struct eg_softc *sc;
211 1.1 deraadt {
212 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
213 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
214 1.1 deraadt int i;
215 1.1 deraadt
216 1.1 deraadt for (i=0; i < 10000; i++) {
217 1.27 thorpej if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_ACRF)
218 1.1 deraadt return 0;
219 1.1 deraadt delay(5);
220 1.1 deraadt }
221 1.3 deraadt dprintf(("PCB read not ready\n"));
222 1.1 deraadt return 1;
223 1.1 deraadt }
224 1.1 deraadt
225 1.1 deraadt static int
226 1.1 deraadt egwritePCB(sc)
227 1.1 deraadt struct eg_softc *sc;
228 1.1 deraadt {
229 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
230 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
231 1.1 deraadt int i;
232 1.27 thorpej u_int8_t len;
233 1.1 deraadt
234 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
235 1.27 thorpej (bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
236 1.1 deraadt
237 1.1 deraadt len = sc->eg_pcb[1] + 2;
238 1.1 deraadt for (i = 0; i < len; i++)
239 1.1 deraadt egoutPCB(sc, sc->eg_pcb[i]);
240 1.27 thorpej
241 1.1 deraadt for (i=0; i < 4000; i++) {
242 1.27 thorpej if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HCRE)
243 1.1 deraadt break;
244 1.1 deraadt delay(10);
245 1.1 deraadt }
246 1.17 mycroft
247 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
248 1.28 thorpej (bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_DONE);
249 1.17 mycroft
250 1.1 deraadt egoutPCB(sc, len);
251 1.1 deraadt
252 1.1 deraadt if (egreadPCBstat(sc, EG_PCB_ACCEPT))
253 1.1 deraadt return 1;
254 1.1 deraadt return 0;
255 1.1 deraadt }
256 1.1 deraadt
257 1.1 deraadt static int
258 1.1 deraadt egreadPCB(sc)
259 1.1 deraadt struct eg_softc *sc;
260 1.1 deraadt {
261 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
262 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
263 1.1 deraadt int i;
264 1.27 thorpej u_int8_t b;
265 1.27 thorpej
266 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
267 1.27 thorpej (bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
268 1.1 deraadt
269 1.1 deraadt bzero(sc->eg_pcb, sizeof(sc->eg_pcb));
270 1.1 deraadt
271 1.1 deraadt if (egreadPCBready(sc))
272 1.1 deraadt return 1;
273 1.1 deraadt
274 1.28 thorpej sc->eg_pcb[0] = bus_io_read_1(bc, ioh, EG_COMMAND);
275 1.27 thorpej
276 1.1 deraadt if (egreadPCBready(sc))
277 1.1 deraadt return 1;
278 1.1 deraadt
279 1.27 thorpej sc->eg_pcb[1] = bus_io_read_1(bc, ioh, EG_COMMAND);
280 1.1 deraadt
281 1.1 deraadt if (sc->eg_pcb[1] > 62) {
282 1.3 deraadt dprintf(("len %d too large\n", sc->eg_pcb[1]));
283 1.1 deraadt return 1;
284 1.1 deraadt }
285 1.27 thorpej
286 1.1 deraadt for (i = 0; i < sc->eg_pcb[1]; i++) {
287 1.1 deraadt if (egreadPCBready(sc))
288 1.1 deraadt return 1;
289 1.27 thorpej sc->eg_pcb[2+i] = bus_io_read_1(bc, ioh, EG_COMMAND);
290 1.1 deraadt }
291 1.1 deraadt if (egreadPCBready(sc))
292 1.1 deraadt return 1;
293 1.1 deraadt if (egreadPCBstat(sc, EG_PCB_DONE))
294 1.1 deraadt return 1;
295 1.27 thorpej if ((b = bus_io_read_1(bc, ioh, EG_COMMAND)) != sc->eg_pcb[1] + 2) {
296 1.7 mycroft dprintf(("%d != %d\n", b, sc->eg_pcb[1] + 2));
297 1.1 deraadt return 1;
298 1.1 deraadt }
299 1.17 mycroft
300 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
301 1.27 thorpej (bus_io_read_1(bc, ioh, EG_CONTROL) &
302 1.27 thorpej ~EG_PCB_STAT) | EG_PCB_ACCEPT);
303 1.17 mycroft
304 1.1 deraadt return 0;
305 1.1 deraadt }
306 1.1 deraadt
307 1.1 deraadt /*
308 1.1 deraadt * Real stuff
309 1.1 deraadt */
310 1.1 deraadt
311 1.1 deraadt int
312 1.6 mycroft egprobe(parent, match, aux)
313 1.6 mycroft struct device *parent;
314 1.6 mycroft void *match, *aux;
315 1.1 deraadt {
316 1.6 mycroft struct eg_softc *sc = match;
317 1.1 deraadt struct isa_attach_args *ia = aux;
318 1.27 thorpej bus_chipset_tag_t bc = ia->ia_bc;
319 1.27 thorpej bus_io_handle_t ioh;
320 1.27 thorpej int i, rval;
321 1.27 thorpej
322 1.27 thorpej rval = 0;
323 1.1 deraadt
324 1.2 mycroft if (ia->ia_iobase & ~0x07f0 != 0) {
325 1.3 deraadt dprintf(("Weird iobase %x\n", ia->ia_iobase));
326 1.1 deraadt return 0;
327 1.1 deraadt }
328 1.27 thorpej
329 1.27 thorpej /* Map i/o space. */
330 1.27 thorpej if (bus_io_map(bc, ia->ia_iobase, 0x08, &ioh)) {
331 1.27 thorpej dprintf(("egprobe: can't map i/o space in probe\n"));
332 1.27 thorpej return 0;
333 1.27 thorpej }
334 1.27 thorpej
335 1.27 thorpej /*
336 1.27 thorpej * XXX Indirect brokenness.
337 1.27 thorpej */
338 1.27 thorpej sc->sc_bc = bc; /* XXX */
339 1.27 thorpej sc->sc_ioh = ioh; /* XXX */
340 1.1 deraadt
341 1.1 deraadt /* hard reset card */
342 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_RESET);
343 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, 0);
344 1.1 deraadt for (i = 0; i < 5000; i++) {
345 1.1 deraadt delay(1000);
346 1.27 thorpej if ((bus_io_read_1(bc, ioh, EG_STATUS) &
347 1.27 thorpej EG_PCB_STAT) == EG_PCB_NULL)
348 1.1 deraadt break;
349 1.1 deraadt }
350 1.27 thorpej if ((bus_io_read_1(bc, ioh, EG_STATUS) & EG_PCB_STAT) != EG_PCB_NULL) {
351 1.27 thorpej dprintf(("egprobe: Reset failed\n"));
352 1.27 thorpej goto out;
353 1.1 deraadt }
354 1.1 deraadt sc->eg_pcb[0] = EG_CMD_GETINFO; /* Get Adapter Info */
355 1.1 deraadt sc->eg_pcb[1] = 0;
356 1.1 deraadt if (egwritePCB(sc) != 0)
357 1.27 thorpej goto out;
358 1.27 thorpej
359 1.1 deraadt if (egreadPCB(sc) != 0) {
360 1.1 deraadt egprintpcb(sc);
361 1.27 thorpej goto out;
362 1.1 deraadt }
363 1.1 deraadt
364 1.1 deraadt if (sc->eg_pcb[0] != EG_RSP_GETINFO || /* Get Adapter Info Response */
365 1.1 deraadt sc->eg_pcb[1] != 0x0a) {
366 1.1 deraadt egprintpcb(sc);
367 1.27 thorpej goto out;
368 1.1 deraadt }
369 1.1 deraadt sc->eg_rom_major = sc->eg_pcb[3];
370 1.1 deraadt sc->eg_rom_minor = sc->eg_pcb[2];
371 1.1 deraadt sc->eg_ram = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
372 1.27 thorpej
373 1.1 deraadt ia->ia_iosize = 0x08;
374 1.1 deraadt ia->ia_msize = 0;
375 1.27 thorpej rval = 1;
376 1.27 thorpej
377 1.27 thorpej out:
378 1.27 thorpej bus_io_unmap(bc, ioh, 0x08);
379 1.27 thorpej return rval;
380 1.1 deraadt }
381 1.1 deraadt
382 1.19 mycroft void
383 1.1 deraadt egattach(parent, self, aux)
384 1.1 deraadt struct device *parent, *self;
385 1.1 deraadt void *aux;
386 1.1 deraadt {
387 1.2 mycroft struct eg_softc *sc = (void *)self;
388 1.2 mycroft struct isa_attach_args *ia = aux;
389 1.27 thorpej bus_chipset_tag_t bc = ia->ia_bc;
390 1.27 thorpej bus_io_handle_t ioh;
391 1.1 deraadt struct ifnet *ifp = &sc->sc_arpcom.ac_if;
392 1.1 deraadt int i;
393 1.27 thorpej
394 1.27 thorpej printf("\n");
395 1.27 thorpej
396 1.27 thorpej /* Map i/o space. */
397 1.27 thorpej if (bus_io_map(bc, ia->ia_iobase, ia->ia_iosize, &ioh)) {
398 1.27 thorpej printf("%s: can't map i/o space\n", self->dv_xname);
399 1.27 thorpej return;
400 1.27 thorpej }
401 1.27 thorpej
402 1.27 thorpej sc->sc_bc = bc;
403 1.27 thorpej sc->sc_ioh = ioh;
404 1.27 thorpej
405 1.2 mycroft egstop(sc);
406 1.1 deraadt
407 1.1 deraadt sc->eg_pcb[0] = EG_CMD_GETEADDR; /* Get Station address */
408 1.1 deraadt sc->eg_pcb[1] = 0;
409 1.1 deraadt if (egwritePCB(sc) != 0) {
410 1.27 thorpej printf("%s: can't send Get Station Address\n", self->dv_xname);
411 1.1 deraadt return;
412 1.1 deraadt }
413 1.1 deraadt if (egreadPCB(sc) != 0) {
414 1.27 thorpej printf("%s: can't read station address\n", self->dv_xname);
415 1.1 deraadt egprintpcb(sc);
416 1.1 deraadt return;
417 1.1 deraadt }
418 1.1 deraadt
419 1.1 deraadt /* check Get station address response */
420 1.1 deraadt if (sc->eg_pcb[0] != EG_RSP_GETEADDR || sc->eg_pcb[1] != 0x06) {
421 1.27 thorpej printf("%s: card responded with garbage (1)\n",
422 1.27 thorpej self->dv_xname);
423 1.1 deraadt egprintpcb(sc);
424 1.1 deraadt return;
425 1.1 deraadt }
426 1.1 deraadt bcopy(&sc->eg_pcb[2], sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN);
427 1.1 deraadt
428 1.27 thorpej printf("%s: ROM v%d.%02d %dk address %s\n", self->dv_xname,
429 1.2 mycroft sc->eg_rom_major, sc->eg_rom_minor, sc->eg_ram,
430 1.2 mycroft ether_sprintf(sc->sc_arpcom.ac_enaddr));
431 1.1 deraadt
432 1.1 deraadt sc->eg_pcb[0] = EG_CMD_SETEADDR; /* Set station address */
433 1.1 deraadt if (egwritePCB(sc) != 0) {
434 1.27 thorpej printf("%s: can't send Set Station Address\n", self->dv_xname);
435 1.1 deraadt return;
436 1.1 deraadt }
437 1.1 deraadt if (egreadPCB(sc) != 0) {
438 1.27 thorpej printf("%s: can't read Set Station Address status\n",
439 1.27 thorpej self->dv_xname);
440 1.1 deraadt egprintpcb(sc);
441 1.1 deraadt return;
442 1.1 deraadt }
443 1.2 mycroft if (sc->eg_pcb[0] != EG_RSP_SETEADDR || sc->eg_pcb[1] != 0x02 ||
444 1.7 mycroft sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0) {
445 1.27 thorpej printf("%s: card responded with garbage (2)\n",
446 1.27 thorpej self->dv_xname);
447 1.1 deraadt egprintpcb(sc);
448 1.1 deraadt return;
449 1.1 deraadt }
450 1.1 deraadt
451 1.2 mycroft /* Initialize ifnet structure. */
452 1.25 thorpej bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
453 1.25 thorpej ifp->if_softc = sc;
454 1.1 deraadt ifp->if_start = egstart;
455 1.1 deraadt ifp->if_ioctl = egioctl;
456 1.1 deraadt ifp->if_watchdog = egwatchdog;
457 1.1 deraadt ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
458 1.1 deraadt
459 1.1 deraadt /* Now we can attach the interface. */
460 1.1 deraadt if_attach(ifp);
461 1.1 deraadt ether_ifattach(ifp);
462 1.1 deraadt
463 1.1 deraadt #if NBPFILTER > 0
464 1.2 mycroft bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
465 1.1 deraadt #endif
466 1.12 cgd
467 1.24 cgd sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
468 1.24 cgd IPL_NET, egintr, sc);
469 1.1 deraadt }
470 1.1 deraadt
471 1.18 mycroft void
472 1.1 deraadt eginit(sc)
473 1.1 deraadt register struct eg_softc *sc;
474 1.1 deraadt {
475 1.1 deraadt register struct ifnet *ifp = &sc->sc_arpcom.ac_if;
476 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
477 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
478 1.1 deraadt
479 1.1 deraadt /* soft reset the board */
480 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_FLSH);
481 1.1 deraadt delay(100);
482 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_ATTN);
483 1.1 deraadt delay(100);
484 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, 0);
485 1.1 deraadt delay(200);
486 1.1 deraadt
487 1.1 deraadt sc->eg_pcb[0] = EG_CMD_CONFIG82586; /* Configure 82586 */
488 1.1 deraadt sc->eg_pcb[1] = 2;
489 1.1 deraadt sc->eg_pcb[2] = 3; /* receive broadcast & multicast */
490 1.1 deraadt sc->eg_pcb[3] = 0;
491 1.1 deraadt if (egwritePCB(sc) != 0)
492 1.27 thorpej printf("%s: can't send Configure 82586\n",
493 1.27 thorpej sc->sc_dev.dv_xname);
494 1.1 deraadt
495 1.1 deraadt if (egreadPCB(sc) != 0) {
496 1.27 thorpej printf("%s: can't read Configure 82586 status\n",
497 1.27 thorpej sc->sc_dev.dv_xname);
498 1.1 deraadt egprintpcb(sc);
499 1.1 deraadt } else if (sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0)
500 1.7 mycroft printf("%s: configure card command failed\n",
501 1.7 mycroft sc->sc_dev.dv_xname);
502 1.1 deraadt
503 1.27 thorpej if (sc->eg_inbuf == NULL) {
504 1.1 deraadt sc->eg_inbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
505 1.27 thorpej if (sc->eg_inbuf == NULL) {
506 1.27 thorpej printf("%s: can't allocate inbuf\n",
507 1.27 thorpej sc->sc_dev.dv_xname);
508 1.27 thorpej panic("eginit");
509 1.27 thorpej }
510 1.27 thorpej }
511 1.1 deraadt sc->eg_incount = 0;
512 1.1 deraadt
513 1.27 thorpej if (sc->eg_outbuf == NULL) {
514 1.1 deraadt sc->eg_outbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
515 1.27 thorpej if (sc->eg_outbuf == NULL) {
516 1.27 thorpej printf("%s: can't allocate outbuf\n",
517 1.27 thorpej sc->sc_dev.dv_xname);
518 1.27 thorpej panic("eginit");
519 1.27 thorpej }
520 1.27 thorpej }
521 1.15 mycroft
522 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_CMDE);
523 1.16 mycroft
524 1.16 mycroft sc->eg_incount = 0;
525 1.16 mycroft egrecv(sc);
526 1.16 mycroft
527 1.16 mycroft /* Interface is now `running', with no output active. */
528 1.1 deraadt ifp->if_flags |= IFF_RUNNING;
529 1.1 deraadt ifp->if_flags &= ~IFF_OACTIVE;
530 1.1 deraadt
531 1.16 mycroft /* Attempt to start output, if any. */
532 1.1 deraadt egstart(ifp);
533 1.1 deraadt }
534 1.1 deraadt
535 1.18 mycroft void
536 1.1 deraadt egrecv(sc)
537 1.1 deraadt struct eg_softc *sc;
538 1.1 deraadt {
539 1.2 mycroft
540 1.1 deraadt while (sc->eg_incount < EG_INLEN) {
541 1.1 deraadt sc->eg_pcb[0] = EG_CMD_RECVPACKET;
542 1.1 deraadt sc->eg_pcb[1] = 0x08;
543 1.1 deraadt sc->eg_pcb[2] = 0; /* address not used.. we send zero */
544 1.1 deraadt sc->eg_pcb[3] = 0;
545 1.1 deraadt sc->eg_pcb[4] = 0;
546 1.1 deraadt sc->eg_pcb[5] = 0;
547 1.25 thorpej sc->eg_pcb[6] = EG_BUFLEN & 0xff; /* our buffer size */
548 1.25 thorpej sc->eg_pcb[7] = (EG_BUFLEN >> 8) & 0xff;
549 1.1 deraadt sc->eg_pcb[8] = 0; /* timeout, 0 == none */
550 1.1 deraadt sc->eg_pcb[9] = 0;
551 1.16 mycroft if (egwritePCB(sc) != 0)
552 1.1 deraadt break;
553 1.16 mycroft sc->eg_incount++;
554 1.1 deraadt }
555 1.1 deraadt }
556 1.1 deraadt
557 1.18 mycroft void
558 1.1 deraadt egstart(ifp)
559 1.1 deraadt struct ifnet *ifp;
560 1.1 deraadt {
561 1.25 thorpej register struct eg_softc *sc = ifp->if_softc;
562 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
563 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
564 1.1 deraadt struct mbuf *m0, *m;
565 1.15 mycroft caddr_t buffer;
566 1.1 deraadt int len;
567 1.27 thorpej u_int16_t *ptr;
568 1.1 deraadt
569 1.1 deraadt /* Don't transmit if interface is busy or not running */
570 1.15 mycroft if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
571 1.14 mycroft return;
572 1.1 deraadt
573 1.15 mycroft loop:
574 1.1 deraadt /* Dequeue the next datagram. */
575 1.15 mycroft IF_DEQUEUE(&ifp->if_snd, m0);
576 1.15 mycroft if (m0 == 0)
577 1.14 mycroft return;
578 1.1 deraadt
579 1.15 mycroft ifp->if_flags |= IFF_OACTIVE;
580 1.15 mycroft
581 1.15 mycroft /* We need to use m->m_pkthdr.len, so require the header */
582 1.27 thorpej if ((m0->m_flags & M_PKTHDR) == 0) {
583 1.27 thorpej printf("%s: no header mbuf\n", sc->sc_dev.dv_xname);
584 1.27 thorpej panic("egstart");
585 1.27 thorpej }
586 1.15 mycroft len = max(m0->m_pkthdr.len, ETHER_MIN_LEN);
587 1.1 deraadt
588 1.1 deraadt #if NBPFILTER > 0
589 1.15 mycroft if (ifp->if_bpf)
590 1.15 mycroft bpf_mtap(ifp->if_bpf, m0);
591 1.1 deraadt #endif
592 1.1 deraadt
593 1.1 deraadt sc->eg_pcb[0] = EG_CMD_SENDPACKET;
594 1.1 deraadt sc->eg_pcb[1] = 0x06;
595 1.1 deraadt sc->eg_pcb[2] = 0; /* address not used, we send zero */
596 1.1 deraadt sc->eg_pcb[3] = 0;
597 1.1 deraadt sc->eg_pcb[4] = 0;
598 1.1 deraadt sc->eg_pcb[5] = 0;
599 1.15 mycroft sc->eg_pcb[6] = len; /* length of packet */
600 1.15 mycroft sc->eg_pcb[7] = len >> 8;
601 1.15 mycroft if (egwritePCB(sc) != 0) {
602 1.27 thorpej printf("%s: can't send Send Packet command\n",
603 1.27 thorpej sc->sc_dev.dv_xname);
604 1.15 mycroft ifp->if_oerrors++;
605 1.15 mycroft ifp->if_flags &= ~IFF_OACTIVE;
606 1.27 thorpej m_freem(m0);
607 1.15 mycroft goto loop;
608 1.15 mycroft }
609 1.15 mycroft
610 1.15 mycroft buffer = sc->eg_outbuf;
611 1.15 mycroft for (m = m0; m != 0; m = m->m_next) {
612 1.15 mycroft bcopy(mtod(m, caddr_t), buffer, m->m_len);
613 1.15 mycroft buffer += m->m_len;
614 1.1 deraadt }
615 1.15 mycroft
616 1.16 mycroft /* set direction bit: host -> adapter */
617 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
618 1.27 thorpej bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_CTL_DIR);
619 1.16 mycroft
620 1.27 thorpej for (ptr = (u_int16_t *) sc->eg_outbuf; len > 0; len -= 2) {
621 1.27 thorpej bus_io_write_2(bc, ioh, EG_DATA, *ptr++);
622 1.27 thorpej while (!(bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HRDY))
623 1.15 mycroft ; /* XXX need timeout here */
624 1.15 mycroft }
625 1.15 mycroft
626 1.15 mycroft m_freem(m0);
627 1.1 deraadt }
628 1.1 deraadt
629 1.1 deraadt int
630 1.12 cgd egintr(arg)
631 1.12 cgd void *arg;
632 1.1 deraadt {
633 1.12 cgd register struct eg_softc *sc = arg;
634 1.27 thorpej bus_chipset_tag_t bc = sc->sc_bc;
635 1.27 thorpej bus_io_handle_t ioh = sc->sc_ioh;
636 1.27 thorpej int i, len, serviced;
637 1.27 thorpej u_int16_t *ptr;
638 1.1 deraadt
639 1.27 thorpej serviced = 0;
640 1.27 thorpej
641 1.27 thorpej while (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_ACRF) {
642 1.1 deraadt egreadPCB(sc);
643 1.2 mycroft switch (sc->eg_pcb[0]) {
644 1.1 deraadt case EG_RSP_RECVPACKET:
645 1.7 mycroft len = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
646 1.16 mycroft
647 1.16 mycroft /* Set direction bit : Adapter -> host */
648 1.27 thorpej bus_io_write_1(bc, ioh, EG_CONTROL,
649 1.27 thorpej bus_io_read_1(bc, ioh, EG_CONTROL) | EG_CTL_DIR);
650 1.16 mycroft
651 1.27 thorpej for (ptr = (u_int16_t *) sc->eg_inbuf;
652 1.27 thorpej len > 0; len -= 2) {
653 1.27 thorpej while (!(bus_io_read_1(bc, ioh, EG_STATUS) &
654 1.27 thorpej EG_STAT_HRDY))
655 1.1 deraadt ;
656 1.27 thorpej *ptr++ = bus_io_read_2(bc, ioh, EG_DATA);
657 1.1 deraadt }
658 1.16 mycroft
659 1.7 mycroft len = sc->eg_pcb[8] | (sc->eg_pcb[9] << 8);
660 1.1 deraadt egread(sc, sc->eg_inbuf, len);
661 1.16 mycroft
662 1.1 deraadt sc->eg_incount--;
663 1.16 mycroft egrecv(sc);
664 1.27 thorpej serviced = 1;
665 1.1 deraadt break;
666 1.1 deraadt
667 1.1 deraadt case EG_RSP_SENDPACKET:
668 1.1 deraadt if (sc->eg_pcb[6] || sc->eg_pcb[7]) {
669 1.27 thorpej dprintf(("%s: packet dropped\n",
670 1.27 thorpej sc->sc_dev.dv_xname));
671 1.1 deraadt sc->sc_arpcom.ac_if.if_oerrors++;
672 1.2 mycroft } else
673 1.2 mycroft sc->sc_arpcom.ac_if.if_opackets++;
674 1.27 thorpej sc->sc_arpcom.ac_if.if_collisions +=
675 1.27 thorpej sc->eg_pcb[8] & 0xf;
676 1.1 deraadt sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
677 1.1 deraadt egstart(&sc->sc_arpcom.ac_if);
678 1.27 thorpej serviced = 1;
679 1.1 deraadt break;
680 1.1 deraadt
681 1.27 thorpej /* XXX byte-order and type-size bugs here... */
682 1.1 deraadt case EG_RSP_GETSTATS:
683 1.27 thorpej dprintf(("%s: Card Statistics\n",
684 1.27 thorpej sc->sc_dev.dv_xname));
685 1.3 deraadt bcopy(&sc->eg_pcb[2], &i, sizeof(i));
686 1.3 deraadt dprintf(("Receive Packets %d\n", i));
687 1.3 deraadt bcopy(&sc->eg_pcb[6], &i, sizeof(i));
688 1.3 deraadt dprintf(("Transmit Packets %d\n", i));
689 1.27 thorpej dprintf(("CRC errors %d\n",
690 1.27 thorpej *(short *) &sc->eg_pcb[10]));
691 1.27 thorpej dprintf(("alignment errors %d\n",
692 1.27 thorpej *(short *) &sc->eg_pcb[12]));
693 1.27 thorpej dprintf(("no resources errors %d\n",
694 1.27 thorpej *(short *) &sc->eg_pcb[14]));
695 1.27 thorpej dprintf(("overrun errors %d\n",
696 1.27 thorpej *(short *) &sc->eg_pcb[16]));
697 1.27 thorpej serviced = 1;
698 1.1 deraadt break;
699 1.1 deraadt
700 1.1 deraadt default:
701 1.27 thorpej printf("%s: egintr: Unknown response %x??\n",
702 1.27 thorpej sc->sc_dev.dv_xname, sc->eg_pcb[0]);
703 1.3 deraadt egprintpcb(sc);
704 1.1 deraadt break;
705 1.1 deraadt }
706 1.1 deraadt }
707 1.1 deraadt
708 1.27 thorpej return serviced;
709 1.1 deraadt }
710 1.1 deraadt
711 1.1 deraadt /*
712 1.1 deraadt * Pass a packet up to the higher levels.
713 1.1 deraadt */
714 1.18 mycroft void
715 1.1 deraadt egread(sc, buf, len)
716 1.1 deraadt struct eg_softc *sc;
717 1.1 deraadt caddr_t buf;
718 1.1 deraadt int len;
719 1.1 deraadt {
720 1.18 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
721 1.1 deraadt struct mbuf *m;
722 1.2 mycroft struct ether_header *eh;
723 1.1 deraadt
724 1.1 deraadt if (len <= sizeof(struct ether_header) ||
725 1.1 deraadt len > ETHER_MAX_LEN) {
726 1.18 mycroft printf("%s: invalid packet size %d; dropping\n",
727 1.20 mycroft sc->sc_dev.dv_xname, len);
728 1.18 mycroft ifp->if_ierrors++;
729 1.1 deraadt return;
730 1.1 deraadt }
731 1.1 deraadt
732 1.2 mycroft /* Pull packet off interface. */
733 1.18 mycroft m = egget(sc, buf, len);
734 1.1 deraadt if (m == 0) {
735 1.18 mycroft ifp->if_ierrors++;
736 1.1 deraadt return;
737 1.1 deraadt }
738 1.1 deraadt
739 1.18 mycroft ifp->if_ipackets++;
740 1.18 mycroft
741 1.2 mycroft /* We assume the header fit entirely in one mbuf. */
742 1.2 mycroft eh = mtod(m, struct ether_header *);
743 1.2 mycroft
744 1.1 deraadt #if NBPFILTER > 0
745 1.1 deraadt /*
746 1.1 deraadt * Check if there's a BPF listener on this interface.
747 1.2 mycroft * If so, hand off the raw packet to BPF.
748 1.1 deraadt */
749 1.2 mycroft if (ifp->if_bpf) {
750 1.2 mycroft bpf_mtap(ifp->if_bpf, m);
751 1.1 deraadt
752 1.1 deraadt /*
753 1.1 deraadt * Note that the interface cannot be in promiscuous mode if
754 1.1 deraadt * there are no BPF listeners. And if we are in promiscuous
755 1.1 deraadt * mode, we have to check if this packet is really ours.
756 1.1 deraadt */
757 1.2 mycroft if ((ifp->if_flags & IFF_PROMISC) &&
758 1.1 deraadt (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
759 1.1 deraadt bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
760 1.1 deraadt sizeof(eh->ether_dhost)) != 0) {
761 1.1 deraadt m_freem(m);
762 1.1 deraadt return;
763 1.1 deraadt }
764 1.1 deraadt }
765 1.1 deraadt #endif
766 1.1 deraadt
767 1.2 mycroft /* We assume the header fit entirely in one mbuf. */
768 1.18 mycroft m_adj(m, sizeof(struct ether_header));
769 1.2 mycroft ether_input(ifp, eh, m);
770 1.1 deraadt }
771 1.1 deraadt
772 1.1 deraadt /*
773 1.1 deraadt * convert buf into mbufs
774 1.1 deraadt */
775 1.18 mycroft struct mbuf *
776 1.18 mycroft egget(sc, buf, totlen)
777 1.18 mycroft struct eg_softc *sc;
778 1.2 mycroft caddr_t buf;
779 1.2 mycroft int totlen;
780 1.2 mycroft {
781 1.18 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
782 1.2 mycroft struct mbuf *top, **mp, *m;
783 1.2 mycroft int len;
784 1.1 deraadt
785 1.2 mycroft MGETHDR(m, M_DONTWAIT, MT_DATA);
786 1.18 mycroft if (m == 0)
787 1.2 mycroft return 0;
788 1.2 mycroft m->m_pkthdr.rcvif = ifp;
789 1.2 mycroft m->m_pkthdr.len = totlen;
790 1.2 mycroft len = MHLEN;
791 1.2 mycroft top = 0;
792 1.2 mycroft mp = ⊤
793 1.2 mycroft
794 1.2 mycroft while (totlen > 0) {
795 1.2 mycroft if (top) {
796 1.2 mycroft MGET(m, M_DONTWAIT, MT_DATA);
797 1.2 mycroft if (m == 0) {
798 1.2 mycroft m_freem(top);
799 1.2 mycroft return 0;
800 1.2 mycroft }
801 1.2 mycroft len = MLEN;
802 1.2 mycroft }
803 1.2 mycroft if (totlen >= MINCLSIZE) {
804 1.2 mycroft MCLGET(m, M_DONTWAIT);
805 1.2 mycroft if (m->m_flags & M_EXT)
806 1.2 mycroft len = MCLBYTES;
807 1.2 mycroft }
808 1.2 mycroft m->m_len = len = min(totlen, len);
809 1.2 mycroft bcopy((caddr_t)buf, mtod(m, caddr_t), len);
810 1.2 mycroft buf += len;
811 1.2 mycroft totlen -= len;
812 1.2 mycroft *mp = m;
813 1.2 mycroft mp = &m->m_next;
814 1.2 mycroft }
815 1.1 deraadt
816 1.2 mycroft return top;
817 1.1 deraadt }
818 1.1 deraadt
819 1.18 mycroft int
820 1.18 mycroft egioctl(ifp, cmd, data)
821 1.1 deraadt register struct ifnet *ifp;
822 1.18 mycroft u_long cmd;
823 1.1 deraadt caddr_t data;
824 1.1 deraadt {
825 1.25 thorpej struct eg_softc *sc = ifp->if_softc;
826 1.18 mycroft struct ifaddr *ifa = (struct ifaddr *)data;
827 1.2 mycroft struct ifreq *ifr = (struct ifreq *)data;
828 1.2 mycroft int s, error = 0;
829 1.2 mycroft
830 1.21 mycroft s = splnet();
831 1.2 mycroft
832 1.18 mycroft switch (cmd) {
833 1.1 deraadt
834 1.1 deraadt case SIOCSIFADDR:
835 1.1 deraadt ifp->if_flags |= IFF_UP;
836 1.2 mycroft
837 1.1 deraadt switch (ifa->ifa_addr->sa_family) {
838 1.1 deraadt #ifdef INET
839 1.1 deraadt case AF_INET:
840 1.11 mycroft eginit(sc);
841 1.11 mycroft arp_ifinit(&sc->sc_arpcom, ifa);
842 1.1 deraadt break;
843 1.1 deraadt #endif
844 1.1 deraadt #ifdef NS
845 1.1 deraadt case AF_NS:
846 1.2 mycroft {
847 1.2 mycroft register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
848 1.1 deraadt
849 1.2 mycroft if (ns_nullhost(*ina))
850 1.2 mycroft ina->x_host =
851 1.27 thorpej *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
852 1.2 mycroft else
853 1.2 mycroft bcopy(ina->x_host.c_host,
854 1.2 mycroft sc->sc_arpcom.ac_enaddr,
855 1.2 mycroft sizeof(sc->sc_arpcom.ac_enaddr));
856 1.2 mycroft /* Set new address. */
857 1.2 mycroft eginit(sc);
858 1.2 mycroft break;
859 1.2 mycroft }
860 1.1 deraadt #endif
861 1.1 deraadt default:
862 1.1 deraadt eginit(sc);
863 1.1 deraadt break;
864 1.1 deraadt }
865 1.1 deraadt break;
866 1.2 mycroft
867 1.1 deraadt case SIOCSIFFLAGS:
868 1.1 deraadt if ((ifp->if_flags & IFF_UP) == 0 &&
869 1.1 deraadt (ifp->if_flags & IFF_RUNNING) != 0) {
870 1.2 mycroft /*
871 1.2 mycroft * If interface is marked down and it is running, then
872 1.2 mycroft * stop it.
873 1.2 mycroft */
874 1.2 mycroft egstop(sc);
875 1.1 deraadt ifp->if_flags &= ~IFF_RUNNING;
876 1.1 deraadt } else if ((ifp->if_flags & IFF_UP) != 0 &&
877 1.1 deraadt (ifp->if_flags & IFF_RUNNING) == 0) {
878 1.2 mycroft /*
879 1.2 mycroft * If interface is marked up and it is stopped, then
880 1.2 mycroft * start it.
881 1.2 mycroft */
882 1.1 deraadt eginit(sc);
883 1.1 deraadt } else {
884 1.3 deraadt sc->eg_pcb[0] = EG_CMD_GETSTATS;
885 1.3 deraadt sc->eg_pcb[1] = 0;
886 1.3 deraadt if (egwritePCB(sc) != 0)
887 1.3 deraadt dprintf(("write error\n"));
888 1.1 deraadt /*
889 1.1 deraadt * XXX deal with flags changes:
890 1.1 deraadt * IFF_MULTICAST, IFF_PROMISC,
891 1.1 deraadt * IFF_LINK0, IFF_LINK1,
892 1.1 deraadt */
893 1.1 deraadt }
894 1.1 deraadt break;
895 1.2 mycroft
896 1.1 deraadt default:
897 1.1 deraadt error = EINVAL;
898 1.18 mycroft break;
899 1.1 deraadt }
900 1.2 mycroft
901 1.2 mycroft splx(s);
902 1.2 mycroft return error;
903 1.1 deraadt }
904 1.1 deraadt
905 1.18 mycroft void
906 1.1 deraadt egreset(sc)
907 1.1 deraadt struct eg_softc *sc;
908 1.1 deraadt {
909 1.2 mycroft int s;
910 1.1 deraadt
911 1.27 thorpej dprintf(("%s: egreset()\n", sc->sc_dev.dv_xname));
912 1.21 mycroft s = splnet();
913 1.2 mycroft egstop(sc);
914 1.2 mycroft eginit(sc);
915 1.2 mycroft splx(s);
916 1.1 deraadt }
917 1.1 deraadt
918 1.18 mycroft void
919 1.25 thorpej egwatchdog(ifp)
920 1.25 thorpej struct ifnet *ifp;
921 1.1 deraadt {
922 1.25 thorpej struct eg_softc *sc = ifp->if_softc;
923 1.1 deraadt
924 1.1 deraadt log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
925 1.1 deraadt sc->sc_arpcom.ac_if.if_oerrors++;
926 1.1 deraadt
927 1.1 deraadt egreset(sc);
928 1.1 deraadt }
929 1.1 deraadt
930 1.18 mycroft void
931 1.1 deraadt egstop(sc)
932 1.1 deraadt register struct eg_softc *sc;
933 1.1 deraadt {
934 1.1 deraadt
935 1.27 thorpej bus_io_write_1(sc->sc_bc, sc->sc_ioh, EG_CONTROL, 0);
936 1.1 deraadt }
937