if_es.c revision 1.3 1 /* $NetBSD: if_es.c,v 1.3 1995/04/11 05:58:58 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 esinit(sc)
198 struct es_softc *sc;
199 {
200 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
201 union smcregs *smc = sc->sc_base;
202 int s;
203
204 if (ifp->if_addrlist == 0)
205 return;
206
207 s = splimp();
208
209 smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
210 smc->b0.rcr = RCR_EPH_RST;
211 smc->b0.rcr = 0;
212 smc->b3.bsr = BSR_BANK3; /* Select bank 3 */
213 smc->b3.mt[0] = 0; /* clear Multicast table */
214 smc->b3.mt[1] = 0;
215 smc->b3.mt[2] = 0;
216 smc->b3.mt[3] = 0;
217 /* XXX set Multicast table from Multicast list */
218 smc->b1.bsr = BSR_BANK1; /* Select bank 1 */
219 smc->b1.cr = CR_RAM32K | CR_NO_WAIT_ST | CR_SET_SQLCH;
220 smc->b1.ctr = CTR_AUTO_RLSE;
221 smc->b1.iar[0] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[0]);
222 smc->b1.iar[1] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[2]);
223 smc->b1.iar[2] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[4]);
224 smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
225 smc->b2.mmucr = MMUCR_RESET;
226 smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
227 smc->b0.mcr = SWAP(0x0020); /* reserve 8K for transmit buffers */
228 smc->b0.tcr = TCR_PAD_EN | TCR_TXENA + TCR_MON_CSN;
229 smc->b0.rcr = RCR_FILT_CAR | RCR_STRIP_CRC | RCR_RXEN;
230 /* XXX add multicast/promiscuous flags */
231 smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
232 smc->b2.msk = sc->sc_intctl = MSK_RX_OVRN | MSK_RX;
233
234 /* Interface is now 'running', with no output active. */
235 ifp->if_flags |= IFF_RUNNING;
236 ifp->if_flags &= ~IFF_OACTIVE;
237
238 /* Attempt to start output, if any. */
239 esstart(ifp);
240
241 splx(s);
242 }
243
244 int
245 esintr(sc)
246 struct es_softc *sc;
247 {
248 int i;
249 u_short intsts, intact;
250 int done = 0;
251 union smcregs *smc;
252
253 smc = sc->sc_base;
254 intsts = smc->b2.ist;
255 intact = smc->b2.msk & intsts;
256 if ((intact) == 0)
257 return (0);
258 #ifdef ESDEBUG
259 if (esdebug)
260 printf ("%s: esintr ist %02x msk %02x",
261 sc->sc_dev.dv_xname, intsts, smc->b2.msk);
262 #endif
263 smc->b2.msk = 0;
264 #ifdef ESDEBUG
265 if (esdebug)
266 printf ("=>%02x%02x pnr %02x arr %02x fifo %04x\n",
267 smc->b2.ist, smc->b2.ist, smc->b2.pnr, smc->b2.arr,
268 smc->b2.fifo);
269 #endif
270 if (intact & IST_ALLOC) {
271 sc->sc_intctl &= ~MSK_ALLOC;
272 #ifdef ESDEBUG
273 if (esdebug || 1)
274 printf ("%s: ist %02x\n", sc->sc_dev.dv_xname,
275 intsts);
276 #endif
277 if ((smc->b2.arr & ARR_FAILED) == 0) {
278 #ifdef ESDEBUG
279 if (esdebug || 1)
280 printf ("%s: arr %02x\n", sc->sc_dev.dv_xname,
281 smc->b2.arr);
282 #endif
283 smc->b2.pnr = smc->b2.arr;
284 smc->b2.mmucr = MMUCR_RLSPKT;
285 while (smc->b2.mmucr & MMUCR_BUSY)
286 ;
287 sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
288 }
289 }
290 while ((smc->b2.fifo & FIFO_REMPTY) == 0) {
291 esrint(sc);
292 }
293 if (intact & IST_RX_OVRN) {
294 printf ("%s: Overrun ist %02x", sc->sc_dev.dv_xname,
295 intsts);
296 smc->b2.ist = ACK_RX_OVRN;
297 printf ("->%02x\n", smc->b2.ist);
298 sc->sc_arpcom.ac_if.if_ierrors++;
299 }
300 if (intact & IST_TX) {
301 #ifdef ESDEBUG
302 if (esdebug)
303 printf ("%s: TX INT ist %02x",
304 sc->sc_dev.dv_xname, intsts);
305 #endif
306 smc->b2.ist = ACK_TX;
307 #ifdef ESDEBUG
308 if (esdebug)
309 printf ("->%02x\n", smc->b2.ist);
310 #endif
311 smc->b0.bsr = BSR_BANK0;
312 if ((smc->b0.tcr & TCR_TXENA) == 0) {
313 printf("%s: IST %02x masked %02x EPH status %04x tcr %04x\n",
314 sc->sc_dev.dv_xname, intsts, intact, smc->b0.ephsr,
315 smc->b0.tcr);
316 if ((smc->b0.ephsr & EPHSR_TX_SUC) == 0) {
317 smc->b0.tcr |= TCR_TXENA;
318 sc->sc_arpcom.ac_if.if_oerrors++;
319 }
320 }
321 /*
322 * else - got a TX interrupt, but TCR_TXENA is still set??
323 */
324 #if 0
325 else if ((intact & IST_TX_EMPTY) == 0) {
326 printf("%s: unexpected TX interrupt %02x %02x\n",
327 sc->sc_dev.dv_xname, intsts, intact);
328 smc->b2.bsr = 0x0200;
329 printf (" %02x\n", smc->b2.ist);
330 }
331 #endif
332 smc->b2.bsr = BSR_BANK2;
333 }
334 if (intact & IST_TX_EMPTY) {
335 u_short ecr;
336 #ifdef ESDEBUG
337 if (esdebug)
338 printf ("%s: TX EMPTY %02x",
339 sc->sc_dev.dv_xname, intsts);
340 #endif
341 smc->b2.ist = ACK_TX_EMPTY;
342 #ifdef ESDEBUG
343 if (esdebug)
344 printf ("->%02x intcl %x pnr %02x arr %02x\n",
345 smc->b2.ist, sc->sc_intctl, smc->b2.pnr,
346 smc->b2.arr);
347 #endif
348 sc->sc_intctl &= ~(MSK_TX_EMPTY | MSK_TX);
349 smc->b0.bsr = BSR_BANK0;
350 ecr = smc->b0.ecr; /* Get error counters */
351 if (ecr & 0xff00)
352 sc->sc_arpcom.ac_if.if_collisions += ((ecr >> 8) & 15) +
353 ((ecr >> 11) & 0x1e);
354 smc->b2.bsr = BSR_BANK2;
355 }
356 /* output packets */
357 estint(sc);
358 smc->b2.msk = sc->sc_intctl;
359 return (1);
360 }
361
362 void
363 esrint(sc)
364 struct es_softc *sc;
365 {
366 union smcregs *smc = sc->sc_base;
367 int i;
368 u_short len;
369 short cnt;
370 u_short pktctlw, pktlen, *buf;
371 u_long *lbuf;
372 volatile u_short *data;
373 volatile u_long *ldata;
374 struct ifnet *ifp;
375 struct mbuf *top, **mp, *m;
376 struct ether_header *eh;
377 #ifdef USEPKTBUF
378 u_char *b, pktbuf[1530];
379 #endif
380
381 #ifdef ESDEBUG
382 if (esdebug)
383 printf ("%s: esrint fifo %04x", sc->sc_dev.dv_xname,
384 smc->b2.fifo);
385 #endif
386 data = (u_short *)&smc->b2.data;
387 smc->b2.ptr = PTR_RCV | PTR_AUTOINCR | PTR_READ | SWAP(0x0002);
388 (void) smc->b2.mmucr;
389 #ifdef ESDEBUG
390 if (esdebug)
391 printf ("->%04x", smc->b2.fifo);
392 #endif
393 len = *data;
394 len = SWAP(len); /* Careful of macro side-effects */
395 #ifdef ESDEBUG
396 if (esdebug)
397 printf (" length %d", len);
398 #endif
399 smc->b2.ptr = PTR_RCV | PTR_AUTOINCR + PTR_READ | SWAP(0x0000);
400 (void) smc->b2.mmucr;
401 pktctlw = *data;
402 pktlen = *data;
403 pktctlw = SWAP(pktctlw);
404 pktlen = SWAP(pktlen) - 6;
405 if (pktctlw & RFSW_ODDFRM)
406 pktlen++;
407 /* XXX copy directly from controller to mbuf */
408 #ifdef USEPKTBUF
409 #if 1
410 lbuf = (u_long *) pktbuf;
411 ldata = (u_long *)data;
412 cnt = (len - 4) / 4;
413 while (cnt--)
414 *lbuf++ = *ldata;
415 if ((len - 4) & 2) {
416 buf = (u_short *) lbuf;
417 *buf = *data;
418 }
419 #else
420 buf = (u_short *)pktbuf;
421 cnt = (len - 4) / 2;
422 while (cnt--)
423 *buf++ = *data;
424 #endif
425 smc->b2.mmucr = MMUCR_REMRLS_RX;
426 while (smc->b2.mmucr & MMUCR_BUSY)
427 ;
428 #ifdef ESDEBUG
429 if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
430 printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
431 /* count input error? */
432 }
433 if (esdebug) {
434 printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
435 smc->b2.fifo);
436 for (i = 0; i < pktlen; ++i)
437 printf ("%02x%s", pktbuf[i], ((i & 31) == 31) ? "\n" :
438 "");
439 if (i & 31)
440 printf ("\n");
441 }
442 #endif
443 #else /* USEPKTBUF */
444 #ifdef ESDEBUG
445 if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
446 printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
447 /* count input error? */
448 }
449 if (esdebug) {
450 printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
451 smc->b2.fifo);
452 }
453 #endif
454 #endif /* USEPKTBUF */
455 ifp = &sc->sc_arpcom.ac_if;
456 ifp->if_ipackets++;
457 MGETHDR(m, M_DONTWAIT, MT_DATA);
458 if (m == NULL)
459 return;
460 m->m_pkthdr.rcvif = ifp;
461 m->m_pkthdr.len = pktlen;
462 len = MHLEN;
463 top = NULL;
464 mp = ⊤
465 #ifdef USEPKTBUF
466 b = pktbuf;
467 #endif
468 while (pktlen > 0) {
469 if (top) {
470 MGET(m, M_DONTWAIT, MT_DATA);
471 if (m == 0) {
472 m_freem(top);
473 return;
474 }
475 len = MLEN;
476 }
477 if (pktlen >= MINCLSIZE) {
478 MCLGET(m, M_DONTWAIT);
479 if (m->m_flags & M_EXT)
480 len = MCLBYTES;
481 }
482 m->m_len = len = min(pktlen, len);
483 #ifdef USEPKTBUF
484 bcopy((caddr_t)b, mtod(m, caddr_t), len);
485 b += len;
486 #else /* USEPKTBUF */
487 buf = mtod(m, u_short *);
488 cnt = len / 2;
489 while (cnt--)
490 *buf++ = *data;
491 if (len & 1)
492 *buf = *data; /* XXX should be byte store */
493 #ifdef ESDEBUG
494 if (esdebug) {
495 buf = mtod(m, u_short *);
496 for (i = 0; i < len; ++i)
497 printf ("%02x%s", ((u_char *)buf)[i],
498 ((i & 31) == 31) ? "\n" : "");
499 if (i & 31)
500 printf ("\n");
501 }
502 #endif
503 #endif /* USEPKTBUF */
504 pktlen -= len;
505 *mp = m;
506 mp = &m->m_next;
507 }
508 #ifndef USEPKTBUF
509 smc->b2.mmucr = MMUCR_REMRLS_RX;
510 while (smc->b2.mmucr & MMUCR_BUSY)
511 ;
512 #endif
513 eh = mtod(top, struct ether_header *);
514 top->m_pkthdr.len -= sizeof (*eh);
515 top->m_len -= sizeof (*eh);
516 top->m_data += sizeof (*eh);
517
518 ether_input(ifp, eh, top);
519 }
520
521 void
522 estint(sc)
523 struct es_softc *sc;
524 {
525
526 esstart(&sc->sc_arpcom.ac_if);
527 }
528
529 void
530 esstart(ifp)
531 struct ifnet *ifp;
532 {
533 struct es_softc *sc = escd.cd_devs[ifp->if_unit];
534 union smcregs *smc = sc->sc_base;
535 struct mbuf *m0, *m;
536 #ifdef USEPKTBUF
537 u_short pktbuf[ETHERMTU + 2];
538 #endif
539 u_short pktctlw, pktlen;
540 u_short *buf;
541 volatile u_short *data;
542 u_long *lbuf;
543 volatile u_long *ldata;
544 short cnt;
545 int i;
546
547 if ((sc->sc_arpcom.ac_if.if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
548 IFF_RUNNING)
549 return;
550
551 for (;;) {
552 /*
553 * Sneak a peek at the next packet to get the length
554 * and see if the SMC 91C90 can accept it.
555 */
556 m = sc->sc_arpcom.ac_if.if_snd.ifq_head;
557 if (!m)
558 break;
559 #ifdef ESDEBUG
560 if (esdebug && (m->m_next || m->m_len & 1))
561 printf("%s: esstart m_next %x m_len %d\n", sc->sc_dev.dv_xname,
562 m->m_next, m->m_len);
563 #endif
564 for (m0 = m, pktlen = 0; m0; m0 = m0->m_next)
565 pktlen += m0->m_len;
566 #ifdef ESDEBUG
567 if (esdebug)
568 printf("%s: esstart r1 %x len %d", sc->sc_dev.dv_xname, smc->b2.pnr, pktlen);
569 #endif
570 pktctlw = 0;
571 pktlen += 4;
572 if (pktlen & 1)
573 ++pktlen; /* control byte after last byte */
574 else
575 pktlen += 2; /* control byte after pad byte */
576 smc->b2.mmucr = MMUCR_ALLOC | (pktlen & 0x0700);
577 for (i = 0; i <= 5; ++i)
578 if ((smc->b2.arr & ARR_FAILED) == 0)
579 break;
580 if (smc->b2.arr & ARR_FAILED) {
581 sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
582 #ifdef ESDEBUG
583 if (esdebug)
584 printf("-no xmit bufs r1 %x\n", smc->b2.pnr);
585 #endif
586 sc->sc_intctl |= MSK_ALLOC;
587 break;
588 }
589 smc->b2.pnr = smc->b2.arr;
590
591 IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m);
592 smc->b2.ptr = PTR_AUTOINCR;
593 (void) smc->b2.mmucr;
594 data = (u_short *)&smc->b2.data;
595 *data = SWAP(pktctlw);
596 *data = SWAP(pktlen);
597 #ifdef USEPKTBUF
598 i = 0;
599 for (m0 = m; m; m = m->m_next) {
600 bcopy(mtod(m, caddr_t), (char *)pktbuf + i, m->m_len);
601 i += m->m_len;
602 }
603
604 if (i & 1) /* Figure out where to put control byte */
605 pktbuf[i/2] = (pktbuf[i/2] & 0xff00) | CTLB_ODD;
606 else
607 pktbuf[i/2] = 0;
608 #ifdef ESDEBUG
609 if (esdebug) {
610 int j;
611 printf("-sending len %d pktlen %d r1 %04x\n", i, pktlen, smc->b2.pnr);
612 for (j = 0; j < pktlen - 4; ++j)
613 printf("%02x%s", ((u_char *)pktbuf)[j], ((j & 31) == 31) ? "\n" : "");
614 if (j & 31)
615 printf("\n");
616 }
617 #endif
618 #if 0 /* doesn't quite work? */
619 lbuf = (u_long *)(pktbuf);
620 ldata = (u_long *)data;
621 cnt = pktlen / 4;
622 while(cnt--)
623 *ldata = *lbuf++;
624 if (pktlen & 2) {
625 buf = (u_short *)lbuf;
626 *data = *buf;
627 }
628 #else
629 buf = pktbuf;
630 cnt = pktlen / 2;
631 while (cnt--)
632 *data = *buf++;
633 #endif
634 #else /* USEPKTBUF */
635 #ifdef ESDEBUG
636 if (esdebug)
637 printf("-sending pktlen %d r1 %04x\n", pktlen, smc->b2.pnr);
638 #endif
639 pktctlw = 0;
640 for (m0 = m; m; m = m->m_next) {
641 buf = mtod(m, u_short *);
642 #ifdef ESDEBUG
643 if (esdebug) {
644 printf(" m->m_len %d\n", m->m_len);
645 for (i = 0; i < m->m_len; ++i)
646 printf("%02x%s", ((u_char *)buf)[i], ((i & 31) == 31) ? "\n" : "");
647 if (i & 31)
648 printf("\n");
649 }
650 #endif
651 cnt = m->m_len / 2;
652 while (cnt--)
653 *data = *buf++;
654 if (m->m_len & 1)
655 pktctlw = (*buf & 0xff00) | CTLB_ODD;
656 }
657 *data = pktctlw;
658 #endif /* USEPKTBUF */
659 smc->b2.mmucr = MMUCR_ENQ_TX;
660 #ifdef ESDEBUG
661 if (esdebug)
662 printf("%s: esstart packet sent r1 %x\n", sc->sc_dev.dv_xname, smc->b2.pnr);
663 #endif
664 #if NBPFILTER > 0
665 if (sc->sc_arpcom.ac_if.if_bpf)
666 bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m0);
667 #endif
668 m_freem(m0);
669 sc->sc_arpcom.ac_if.if_opackets++; /* move to interrupt? */
670 sc->sc_intctl |= MSK_TX_EMPTY | MSK_TX;
671 }
672 smc->b2.msk = sc->sc_intctl;
673 return 0;
674 }
675
676 int
677 esioctl(ifp, command, data)
678 register struct ifnet *ifp;
679 u_long command;
680 caddr_t data;
681 {
682 struct es_softc *sc = escd.cd_devs[ifp->if_unit];
683 register struct ifaddr *ifa = (struct ifaddr *)data;
684 struct ifreq *ifr = (struct ifreq *)data;
685 int s, error = 0;
686
687 s = splimp();
688
689 switch (command) {
690
691 case SIOCSIFADDR:
692 ifp->if_flags |= IFF_UP;
693
694 switch (ifa->ifa_addr->sa_family) {
695 #ifdef INET
696 case AF_INET:
697 esinit(sc);
698 arp_ifinit(&sc->sc_arpcom, ifa);
699 break;
700 #endif
701 #ifdef NS
702 case AF_NS:
703 {
704 register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
705
706 if (ns_nullhost(*ina))
707 ina->x_host =
708 *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
709 else
710 bcopy(ina->x_host.c_host,
711 sc->sc_arpcom.ac_enaddr,
712 sizeof(sc->sc_arpcom.ac_enaddr));
713 /* Set new address. */
714 esinit(sc);
715 break;
716 #endif
717 default:
718 esinit(sc);
719 break;
720 }
721 break;
722
723 case SIOCSIFFLAGS:
724 /*
725 * If interface is marked down and it is running, then stop it
726 */
727 if ((ifp->if_flags & IFF_UP) == 0 &&
728 (ifp->if_flags & IFF_RUNNING) != 0) {
729 /*
730 * If interface is marked down and it is running, then
731 * stop it.
732 */
733 esstop(sc);
734 ifp->if_flags &= ~IFF_RUNNING;
735 } else if ((ifp->if_flags & IFF_UP) != 0 &&
736 (ifp->if_flags & IFF_RUNNING) == 0) {
737 /*
738 * If interface is marked up and it is stopped, then
739 * start it.
740 */
741 esinit(sc);
742 } else {
743 /*
744 * Reset the interface to pick up changes in any other
745 * flags that affect hardware registers.
746 */
747 esstop(sc);
748 esinit(sc);
749 }
750 #ifdef ESDEBUG
751 if (ifp->if_flags & IFF_DEBUG)
752 esdebug = sc->sc_debug = 1;
753 else
754 esdebug = sc->sc_debug = 0;
755 #endif
756 break;
757
758 default:
759 error = EINVAL;
760 }
761
762 splx(s);
763 return (error);
764 }
765
766 void
767 esreset(sc)
768 struct es_softc *sc;
769 {
770 int s;
771
772 s = splimp();
773 esstop(sc);
774 esinit(sc);
775 splx(s);
776 }
777
778 void
779 eswatchdog(unit)
780 int unit;
781 {
782 struct es_softc *sc = escd.cd_devs[unit];
783
784 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
785 ++sc->sc_arpcom.ac_if.if_oerrors;
786
787 esreset(sc);
788 }
789