if_es.c revision 1.6 1 /* $NetBSD: if_es.c,v 1.6 1995/07/02 00:16:04 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1995 Michael L. Hitch
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Michael L. Hitch.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * SMC 91C90 Single-Chip Ethernet Controller
35 */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/buf.h>
41 #include <sys/protosw.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
44 #include <sys/ioctl.h>
45 #include <sys/errno.h>
46 #include <sys/device.h>
47
48 #include <net/if.h>
49 #include <net/netisr.h>
50 #include <net/route.h>
51
52 #ifdef INET
53 #include <netinet/in.h>
54 #include <netinet/in_systm.h>
55 #include <netinet/in_var.h>
56 #include <netinet/ip.h>
57 #include <netinet/if_ether.h>
58 #endif
59
60 #ifdef NS
61 #include <netns/ns.h>
62 #include <netns/ns_if.h>
63 #endif
64
65 #include <machine/cpu.h>
66 #include <machine/mtpr.h>
67 #include <amiga/amiga/device.h>
68 #include <amiga/amiga/isr.h>
69 #include <amiga/dev/zbusvar.h>
70 #include <amiga/dev/if_esreg.h>
71
72 #define SWAP(x) (((x & 0xff) << 8) | ((x >> 8) & 0xff))
73
74 #define ESDEBUG
75 #define USEPKTBUF
76
77 /*
78 * Ethernet software status per interface.
79 *
80 * Each interface is referenced by a network interface structure,
81 * es_if, which the routing code uses to locate the interface.
82 * This structure contains the output queue for the interface, its address, ...
83 */
84 struct es_softc {
85 struct device sc_dev;
86 struct isr sc_isr;
87 struct arpcom sc_arpcom; /* common Ethernet structures */
88 void *sc_base; /* base address of board */
89 short sc_iflags;
90 unsigned short sc_intctl;
91 #ifdef ESDEBUG
92 int sc_debug;
93 #endif
94 };
95
96 #if NBPFILTER > 0
97 #include <net/bpf.h>
98 #include <net/bpfdesc.h>
99 #endif
100
101 #ifdef ESDEBUG
102 /* console error messages */
103 int esdebug = 0;
104 #endif
105
106 int esintr __P((struct es_softc *));
107 void esstart __P((struct ifnet *));
108 void eswatchdog __P((int));
109 int esioctl __P((struct ifnet *, u_long, caddr_t));
110 void esrint __P((struct es_softc *));
111 void estint __P((struct es_softc *));
112 void esinit __P((struct es_softc *));
113 void esreset __P((struct es_softc *));
114
115 int esmatch __P((struct device *, void *, void *));
116 void esattach __P((struct device *, struct device *, void *));
117
118 struct cfdriver escd = {
119 NULL, "es", esmatch, esattach, DV_IFNET, sizeof(struct es_softc)
120 };
121
122 int
123 esmatch(parent, match, aux)
124 struct device *parent;
125 void *match, *aux;
126 {
127 struct zbus_args *zap = aux;
128
129 /* Ameristar A4066 ethernet card */
130 if (zap->manid == 1053 && zap->prodid == 10)
131 return(1);
132
133 return (0);
134 }
135
136 /*
137 * Interface exists: make available by filling in network interface
138 * record. System will initialize the interface when it is ready
139 * to accept packets.
140 */
141 void
142 esattach(parent, self, aux)
143 struct device *parent, *self;
144 void *aux;
145 {
146 struct es_softc *sc = (void *)self;
147 struct zbus_args *zap = aux;
148 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
149 unsigned long ser;
150
151 sc->sc_base = zap->va;
152
153 /*
154 * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
155 * (Currently only Ameristar.)
156 */
157 sc->sc_arpcom.ac_enaddr[0] = 0x00;
158 sc->sc_arpcom.ac_enaddr[1] = 0x00;
159 sc->sc_arpcom.ac_enaddr[2] = 0x9f;
160
161 /*
162 * Serial number for board contains last 3 bytes.
163 */
164 ser = (unsigned long) zap->serno;
165
166 sc->sc_arpcom.ac_enaddr[3] = (ser >> 16) & 0xff;
167 sc->sc_arpcom.ac_enaddr[4] = (ser >> 8) & 0xff;
168 sc->sc_arpcom.ac_enaddr[5] = (ser ) & 0xff;
169
170 /* Initialize ifnet structure. */
171 ifp->if_unit = sc->sc_dev.dv_unit;
172 ifp->if_name = escd.cd_name;
173 ifp->if_ioctl = esioctl;
174 ifp->if_start = esstart;
175 ifp->if_watchdog = eswatchdog;
176 /* XXX IFF_MULTICAST */
177 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
178
179 /* Attach the interface. */
180 if_attach(ifp);
181 ether_ifattach(ifp);
182
183 /* Print additional info when attached. */
184 printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr));
185
186 #if NBPFILTER > 0
187 bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
188 #endif
189
190 sc->sc_isr.isr_intr = esintr;
191 sc->sc_isr.isr_arg = sc;
192 sc->sc_isr.isr_ipl = 2;
193 add_isr(&sc->sc_isr);
194 }
195
196 void
197 esstop(sc)
198 struct es_softc* sc;
199 {
200 }
201
202 void
203 esinit(sc)
204 struct es_softc *sc;
205 {
206 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
207 union smcregs *smc = sc->sc_base;
208 int s;
209
210 s = splimp();
211
212 smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
213 smc->b0.rcr = RCR_EPH_RST;
214 smc->b0.rcr = 0;
215 smc->b3.bsr = BSR_BANK3; /* Select bank 3 */
216 smc->b3.mt[0] = 0; /* clear Multicast table */
217 smc->b3.mt[1] = 0;
218 smc->b3.mt[2] = 0;
219 smc->b3.mt[3] = 0;
220 /* XXX set Multicast table from Multicast list */
221 smc->b1.bsr = BSR_BANK1; /* Select bank 1 */
222 smc->b1.cr = CR_RAM32K | CR_NO_WAIT_ST | CR_SET_SQLCH;
223 smc->b1.ctr = CTR_AUTO_RLSE;
224 smc->b1.iar[0] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[0]);
225 smc->b1.iar[1] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[2]);
226 smc->b1.iar[2] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[4]);
227 smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
228 smc->b2.mmucr = MMUCR_RESET;
229 smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
230 smc->b0.mcr = SWAP(0x0020); /* reserve 8K for transmit buffers */
231 smc->b0.tcr = TCR_PAD_EN | TCR_TXENA + TCR_MON_CSN;
232 smc->b0.rcr = RCR_FILT_CAR | RCR_STRIP_CRC | RCR_RXEN;
233 /* XXX add multicast/promiscuous flags */
234 smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
235 smc->b2.msk = sc->sc_intctl = MSK_RX_OVRN | MSK_RX;
236
237 /* Interface is now 'running', with no output active. */
238 ifp->if_flags |= IFF_RUNNING;
239 ifp->if_flags &= ~IFF_OACTIVE;
240
241 /* Attempt to start output, if any. */
242 esstart(ifp);
243
244 splx(s);
245 }
246
247 int
248 esintr(sc)
249 struct es_softc *sc;
250 {
251 int i;
252 u_short intsts, intact;
253 int done = 0;
254 union smcregs *smc;
255
256 smc = sc->sc_base;
257 intsts = smc->b2.ist;
258 intact = smc->b2.msk & intsts;
259 if ((intact) == 0)
260 return (0);
261 #ifdef ESDEBUG
262 if (esdebug)
263 printf ("%s: esintr ist %02x msk %02x",
264 sc->sc_dev.dv_xname, intsts, smc->b2.msk);
265 #endif
266 smc->b2.msk = 0;
267 #ifdef ESDEBUG
268 if (esdebug)
269 printf ("=>%02x%02x pnr %02x arr %02x fifo %04x\n",
270 smc->b2.ist, smc->b2.ist, smc->b2.pnr, smc->b2.arr,
271 smc->b2.fifo);
272 #endif
273 if (intact & IST_ALLOC) {
274 sc->sc_intctl &= ~MSK_ALLOC;
275 #ifdef ESDEBUG
276 if (esdebug || 1)
277 printf ("%s: ist %02x\n", sc->sc_dev.dv_xname,
278 intsts);
279 #endif
280 if ((smc->b2.arr & ARR_FAILED) == 0) {
281 #ifdef ESDEBUG
282 if (esdebug || 1)
283 printf ("%s: arr %02x\n", sc->sc_dev.dv_xname,
284 smc->b2.arr);
285 #endif
286 smc->b2.pnr = smc->b2.arr;
287 smc->b2.mmucr = MMUCR_RLSPKT;
288 while (smc->b2.mmucr & MMUCR_BUSY)
289 ;
290 sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
291 }
292 }
293 while ((smc->b2.fifo & FIFO_REMPTY) == 0) {
294 esrint(sc);
295 }
296 if (intact & IST_RX_OVRN) {
297 printf ("%s: Overrun ist %02x", sc->sc_dev.dv_xname,
298 intsts);
299 smc->b2.ist = ACK_RX_OVRN;
300 printf ("->%02x\n", smc->b2.ist);
301 sc->sc_arpcom.ac_if.if_ierrors++;
302 }
303 if (intact & IST_TX) {
304 #ifdef ESDEBUG
305 if (esdebug)
306 printf ("%s: TX INT ist %02x",
307 sc->sc_dev.dv_xname, intsts);
308 #endif
309 smc->b2.ist = ACK_TX;
310 #ifdef ESDEBUG
311 if (esdebug)
312 printf ("->%02x\n", smc->b2.ist);
313 #endif
314 smc->b0.bsr = BSR_BANK0;
315 if ((smc->b0.tcr & TCR_TXENA) == 0) {
316 printf("%s: IST %02x masked %02x EPH status %04x tcr %04x\n",
317 sc->sc_dev.dv_xname, intsts, intact, smc->b0.ephsr,
318 smc->b0.tcr);
319 if ((smc->b0.ephsr & EPHSR_TX_SUC) == 0) {
320 smc->b0.tcr |= TCR_TXENA;
321 sc->sc_arpcom.ac_if.if_oerrors++;
322 }
323 }
324 /*
325 * else - got a TX interrupt, but TCR_TXENA is still set??
326 */
327 #if 0
328 else if ((intact & IST_TX_EMPTY) == 0) {
329 printf("%s: unexpected TX interrupt %02x %02x\n",
330 sc->sc_dev.dv_xname, intsts, intact);
331 smc->b2.bsr = 0x0200;
332 printf (" %02x\n", smc->b2.ist);
333 }
334 #endif
335 smc->b2.bsr = BSR_BANK2;
336 }
337 if (intact & IST_TX_EMPTY) {
338 u_short ecr;
339 #ifdef ESDEBUG
340 if (esdebug)
341 printf ("%s: TX EMPTY %02x",
342 sc->sc_dev.dv_xname, intsts);
343 #endif
344 smc->b2.ist = ACK_TX_EMPTY;
345 #ifdef ESDEBUG
346 if (esdebug)
347 printf ("->%02x intcl %x pnr %02x arr %02x\n",
348 smc->b2.ist, sc->sc_intctl, smc->b2.pnr,
349 smc->b2.arr);
350 #endif
351 sc->sc_intctl &= ~(MSK_TX_EMPTY | MSK_TX);
352 smc->b0.bsr = BSR_BANK0;
353 ecr = smc->b0.ecr; /* Get error counters */
354 if (ecr & 0xff00)
355 sc->sc_arpcom.ac_if.if_collisions += ((ecr >> 8) & 15) +
356 ((ecr >> 11) & 0x1e);
357 smc->b2.bsr = BSR_BANK2;
358 }
359 /* output packets */
360 estint(sc);
361 smc->b2.msk = sc->sc_intctl;
362 return (1);
363 }
364
365 void
366 esrint(sc)
367 struct es_softc *sc;
368 {
369 union smcregs *smc = sc->sc_base;
370 int i;
371 u_short len;
372 short cnt;
373 u_short pktctlw, pktlen, *buf;
374 u_long *lbuf;
375 volatile u_short *data;
376 volatile u_long *ldata;
377 struct ifnet *ifp;
378 struct mbuf *top, **mp, *m;
379 struct ether_header *eh;
380 #ifdef USEPKTBUF
381 u_char *b, pktbuf[1530];
382 #endif
383
384 #ifdef ESDEBUG
385 if (esdebug)
386 printf ("%s: esrint fifo %04x", sc->sc_dev.dv_xname,
387 smc->b2.fifo);
388 #endif
389 data = (u_short *)&smc->b2.data;
390 smc->b2.ptr = PTR_RCV | PTR_AUTOINCR | PTR_READ | SWAP(0x0002);
391 (void) smc->b2.mmucr;
392 #ifdef ESDEBUG
393 if (esdebug)
394 printf ("->%04x", smc->b2.fifo);
395 #endif
396 len = *data;
397 len = SWAP(len); /* Careful of macro side-effects */
398 #ifdef ESDEBUG
399 if (esdebug)
400 printf (" length %d", len);
401 #endif
402 smc->b2.ptr = PTR_RCV | PTR_AUTOINCR + PTR_READ | SWAP(0x0000);
403 (void) smc->b2.mmucr;
404 pktctlw = *data;
405 pktlen = *data;
406 pktctlw = SWAP(pktctlw);
407 pktlen = SWAP(pktlen) - 6;
408 if (pktctlw & RFSW_ODDFRM)
409 pktlen++;
410 /* XXX copy directly from controller to mbuf */
411 #ifdef USEPKTBUF
412 #if 1
413 lbuf = (u_long *) pktbuf;
414 ldata = (u_long *)data;
415 cnt = (len - 4) / 4;
416 while (cnt--)
417 *lbuf++ = *ldata;
418 if ((len - 4) & 2) {
419 buf = (u_short *) lbuf;
420 *buf = *data;
421 }
422 #else
423 buf = (u_short *)pktbuf;
424 cnt = (len - 4) / 2;
425 while (cnt--)
426 *buf++ = *data;
427 #endif
428 smc->b2.mmucr = MMUCR_REMRLS_RX;
429 while (smc->b2.mmucr & MMUCR_BUSY)
430 ;
431 #ifdef ESDEBUG
432 if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
433 printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
434 /* count input error? */
435 }
436 if (esdebug) {
437 printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
438 smc->b2.fifo);
439 for (i = 0; i < pktlen; ++i)
440 printf ("%02x%s", pktbuf[i], ((i & 31) == 31) ? "\n" :
441 "");
442 if (i & 31)
443 printf ("\n");
444 }
445 #endif
446 #else /* USEPKTBUF */
447 #ifdef ESDEBUG
448 if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
449 printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
450 /* count input error? */
451 }
452 if (esdebug) {
453 printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
454 smc->b2.fifo);
455 }
456 #endif
457 #endif /* USEPKTBUF */
458 ifp = &sc->sc_arpcom.ac_if;
459 ifp->if_ipackets++;
460 MGETHDR(m, M_DONTWAIT, MT_DATA);
461 if (m == NULL)
462 return;
463 m->m_pkthdr.rcvif = ifp;
464 m->m_pkthdr.len = pktlen;
465 len = MHLEN;
466 top = NULL;
467 mp = ⊤
468 #ifdef USEPKTBUF
469 b = pktbuf;
470 #endif
471 while (pktlen > 0) {
472 if (top) {
473 MGET(m, M_DONTWAIT, MT_DATA);
474 if (m == 0) {
475 m_freem(top);
476 return;
477 }
478 len = MLEN;
479 }
480 if (pktlen >= MINCLSIZE) {
481 MCLGET(m, M_DONTWAIT);
482 if (m->m_flags & M_EXT)
483 len = MCLBYTES;
484 }
485 m->m_len = len = min(pktlen, len);
486 #ifdef USEPKTBUF
487 bcopy((caddr_t)b, mtod(m, caddr_t), len);
488 b += len;
489 #else /* USEPKTBUF */
490 buf = mtod(m, u_short *);
491 cnt = len / 2;
492 while (cnt--)
493 *buf++ = *data;
494 if (len & 1)
495 *buf = *data; /* XXX should be byte store */
496 #ifdef ESDEBUG
497 if (esdebug) {
498 buf = mtod(m, u_short *);
499 for (i = 0; i < len; ++i)
500 printf ("%02x%s", ((u_char *)buf)[i],
501 ((i & 31) == 31) ? "\n" : "");
502 if (i & 31)
503 printf ("\n");
504 }
505 #endif
506 #endif /* USEPKTBUF */
507 pktlen -= len;
508 *mp = m;
509 mp = &m->m_next;
510 }
511 #ifndef USEPKTBUF
512 smc->b2.mmucr = MMUCR_REMRLS_RX;
513 while (smc->b2.mmucr & MMUCR_BUSY)
514 ;
515 #endif
516 eh = mtod(top, struct ether_header *);
517 top->m_pkthdr.len -= sizeof (*eh);
518 top->m_len -= sizeof (*eh);
519 top->m_data += sizeof (*eh);
520
521 ether_input(ifp, eh, top);
522 }
523
524 void
525 estint(sc)
526 struct es_softc *sc;
527 {
528
529 esstart(&sc->sc_arpcom.ac_if);
530 }
531
532 void
533 esstart(ifp)
534 struct ifnet *ifp;
535 {
536 struct es_softc *sc = escd.cd_devs[ifp->if_unit];
537 union smcregs *smc = sc->sc_base;
538 struct mbuf *m0, *m;
539 #ifdef USEPKTBUF
540 u_short pktbuf[ETHERMTU + 2];
541 #endif
542 u_short pktctlw, pktlen;
543 u_short *buf;
544 volatile u_short *data;
545 u_long *lbuf;
546 volatile u_long *ldata;
547 short cnt;
548 int i;
549
550 if ((sc->sc_arpcom.ac_if.if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
551 IFF_RUNNING)
552 return;
553
554 for (;;) {
555 /*
556 * Sneak a peek at the next packet to get the length
557 * and see if the SMC 91C90 can accept it.
558 */
559 m = sc->sc_arpcom.ac_if.if_snd.ifq_head;
560 if (!m)
561 break;
562 #ifdef ESDEBUG
563 if (esdebug && (m->m_next || m->m_len & 1))
564 printf("%s: esstart m_next %x m_len %d\n", sc->sc_dev.dv_xname,
565 m->m_next, m->m_len);
566 #endif
567 for (m0 = m, pktlen = 0; m0; m0 = m0->m_next)
568 pktlen += m0->m_len;
569 #ifdef ESDEBUG
570 if (esdebug)
571 printf("%s: esstart r1 %x len %d", sc->sc_dev.dv_xname, smc->b2.pnr, pktlen);
572 #endif
573 pktctlw = 0;
574 pktlen += 4;
575 if (pktlen & 1)
576 ++pktlen; /* control byte after last byte */
577 else
578 pktlen += 2; /* control byte after pad byte */
579 smc->b2.mmucr = MMUCR_ALLOC | (pktlen & 0x0700);
580 for (i = 0; i <= 5; ++i)
581 if ((smc->b2.arr & ARR_FAILED) == 0)
582 break;
583 if (smc->b2.arr & ARR_FAILED) {
584 sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
585 #ifdef ESDEBUG
586 if (esdebug)
587 printf("-no xmit bufs r1 %x\n", smc->b2.pnr);
588 #endif
589 sc->sc_intctl |= MSK_ALLOC;
590 break;
591 }
592 smc->b2.pnr = smc->b2.arr;
593
594 IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m);
595 smc->b2.ptr = PTR_AUTOINCR;
596 (void) smc->b2.mmucr;
597 data = (u_short *)&smc->b2.data;
598 *data = SWAP(pktctlw);
599 *data = SWAP(pktlen);
600 #ifdef USEPKTBUF
601 i = 0;
602 for (m0 = m; m; m = m->m_next) {
603 bcopy(mtod(m, caddr_t), (char *)pktbuf + i, m->m_len);
604 i += m->m_len;
605 }
606
607 if (i & 1) /* Figure out where to put control byte */
608 pktbuf[i/2] = (pktbuf[i/2] & 0xff00) | CTLB_ODD;
609 else
610 pktbuf[i/2] = 0;
611 #ifdef ESDEBUG
612 if (esdebug) {
613 int j;
614 printf("-sending len %d pktlen %d r1 %04x\n", i, pktlen, smc->b2.pnr);
615 for (j = 0; j < pktlen - 4; ++j)
616 printf("%02x%s", ((u_char *)pktbuf)[j], ((j & 31) == 31) ? "\n" : "");
617 if (j & 31)
618 printf("\n");
619 }
620 #endif
621 #if 0 /* doesn't quite work? */
622 lbuf = (u_long *)(pktbuf);
623 ldata = (u_long *)data;
624 cnt = pktlen / 4;
625 while(cnt--)
626 *ldata = *lbuf++;
627 if (pktlen & 2) {
628 buf = (u_short *)lbuf;
629 *data = *buf;
630 }
631 #else
632 buf = pktbuf;
633 cnt = pktlen / 2;
634 while (cnt--)
635 *data = *buf++;
636 #endif
637 #else /* USEPKTBUF */
638 #ifdef ESDEBUG
639 if (esdebug)
640 printf("-sending pktlen %d r1 %04x\n", pktlen, smc->b2.pnr);
641 #endif
642 pktctlw = 0;
643 for (m0 = m; m; m = m->m_next) {
644 buf = mtod(m, u_short *);
645 #ifdef ESDEBUG
646 if (esdebug) {
647 printf(" m->m_len %d\n", m->m_len);
648 for (i = 0; i < m->m_len; ++i)
649 printf("%02x%s", ((u_char *)buf)[i], ((i & 31) == 31) ? "\n" : "");
650 if (i & 31)
651 printf("\n");
652 }
653 #endif
654 cnt = m->m_len / 2;
655 while (cnt--)
656 *data = *buf++;
657 if (m->m_len & 1)
658 pktctlw = (*buf & 0xff00) | CTLB_ODD;
659 }
660 *data = pktctlw;
661 #endif /* USEPKTBUF */
662 smc->b2.mmucr = MMUCR_ENQ_TX;
663 #ifdef ESDEBUG
664 if (esdebug)
665 printf("%s: esstart packet sent r1 %x\n", sc->sc_dev.dv_xname, smc->b2.pnr);
666 #endif
667 #if NBPFILTER > 0
668 if (sc->sc_arpcom.ac_if.if_bpf)
669 bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m0);
670 #endif
671 m_freem(m0);
672 sc->sc_arpcom.ac_if.if_opackets++; /* move to interrupt? */
673 sc->sc_intctl |= MSK_TX_EMPTY | MSK_TX;
674 }
675 smc->b2.msk = sc->sc_intctl;
676 }
677
678 int
679 esioctl(ifp, command, data)
680 register struct ifnet *ifp;
681 u_long command;
682 caddr_t data;
683 {
684 struct es_softc *sc = escd.cd_devs[ifp->if_unit];
685 register struct ifaddr *ifa = (struct ifaddr *)data;
686 struct ifreq *ifr = (struct ifreq *)data;
687 int s, error = 0;
688
689 s = splimp();
690
691 switch (command) {
692
693 case SIOCSIFADDR:
694 ifp->if_flags |= IFF_UP;
695
696 switch (ifa->ifa_addr->sa_family) {
697 #ifdef INET
698 case AF_INET:
699 esinit(sc);
700 arp_ifinit(&sc->sc_arpcom, ifa);
701 break;
702 #endif
703 #ifdef NS
704 case AF_NS:
705 {
706 register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
707
708 if (ns_nullhost(*ina))
709 ina->x_host =
710 *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
711 else
712 bcopy(ina->x_host.c_host,
713 sc->sc_arpcom.ac_enaddr,
714 sizeof(sc->sc_arpcom.ac_enaddr));
715 /* Set new address. */
716 esinit(sc);
717 break;
718 #endif
719 default:
720 esinit(sc);
721 break;
722 }
723 break;
724
725 case SIOCSIFFLAGS:
726 /*
727 * If interface is marked down and it is running, then stop it
728 */
729 if ((ifp->if_flags & IFF_UP) == 0 &&
730 (ifp->if_flags & IFF_RUNNING) != 0) {
731 /*
732 * If interface is marked down and it is running, then
733 * stop it.
734 */
735 esstop(sc);
736 ifp->if_flags &= ~IFF_RUNNING;
737 } else if ((ifp->if_flags & IFF_UP) != 0 &&
738 (ifp->if_flags & IFF_RUNNING) == 0) {
739 /*
740 * If interface is marked up and it is stopped, then
741 * start it.
742 */
743 esinit(sc);
744 } else {
745 /*
746 * Reset the interface to pick up changes in any other
747 * flags that affect hardware registers.
748 */
749 esstop(sc);
750 esinit(sc);
751 }
752 #ifdef ESDEBUG
753 if (ifp->if_flags & IFF_DEBUG)
754 esdebug = sc->sc_debug = 1;
755 else
756 esdebug = sc->sc_debug = 0;
757 #endif
758 break;
759
760 default:
761 error = EINVAL;
762 }
763
764 splx(s);
765 return (error);
766 }
767
768 void
769 esreset(sc)
770 struct es_softc *sc;
771 {
772 int s;
773
774 s = splimp();
775 esstop(sc);
776 esinit(sc);
777 splx(s);
778 }
779
780 void
781 eswatchdog(unit)
782 int unit;
783 {
784 struct es_softc *sc = escd.cd_devs[unit];
785
786 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
787 ++sc->sc_arpcom.ac_if.if_oerrors;
788
789 esreset(sc);
790 }
791