if_es.c revision 1.11 1 1.11 veego /* $NetBSD: if_es.c,v 1.11 1996/04/21 21:11:46 veego Exp $ */
2 1.1 chopps
3 1.1 chopps /*
4 1.1 chopps * Copyright (c) 1995 Michael L. Hitch
5 1.1 chopps * All rights reserved.
6 1.1 chopps *
7 1.1 chopps * Redistribution and use in source and binary forms, with or without
8 1.1 chopps * modification, are permitted provided that the following conditions
9 1.1 chopps * are met:
10 1.1 chopps * 1. Redistributions of source code must retain the above copyright
11 1.1 chopps * notice, this list of conditions and the following disclaimer.
12 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chopps * notice, this list of conditions and the following disclaimer in the
14 1.1 chopps * documentation and/or other materials provided with the distribution.
15 1.1 chopps * 3. All advertising materials mentioning features or use of this software
16 1.1 chopps * must display the following acknowledgement:
17 1.1 chopps * This product includes software developed by Michael L. Hitch.
18 1.1 chopps * 4. The name of the author may not be used to endorse or promote products
19 1.1 chopps * derived from this software without specific prior written permission
20 1.1 chopps *
21 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 chopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 chopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 chopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 chopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 chopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 chopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 chopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 chopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 chopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 chopps */
32 1.1 chopps
33 1.1 chopps /*
34 1.1 chopps * SMC 91C90 Single-Chip Ethernet Controller
35 1.1 chopps */
36 1.1 chopps
37 1.7 chopps #include "bpfilter.h"
38 1.7 chopps
39 1.1 chopps #include <sys/param.h>
40 1.1 chopps #include <sys/systm.h>
41 1.1 chopps #include <sys/mbuf.h>
42 1.1 chopps #include <sys/buf.h>
43 1.1 chopps #include <sys/protosw.h>
44 1.1 chopps #include <sys/socket.h>
45 1.1 chopps #include <sys/syslog.h>
46 1.1 chopps #include <sys/ioctl.h>
47 1.1 chopps #include <sys/errno.h>
48 1.1 chopps #include <sys/device.h>
49 1.1 chopps
50 1.1 chopps #include <net/if.h>
51 1.1 chopps #include <net/netisr.h>
52 1.1 chopps #include <net/route.h>
53 1.1 chopps
54 1.1 chopps #ifdef INET
55 1.1 chopps #include <netinet/in.h>
56 1.1 chopps #include <netinet/in_systm.h>
57 1.1 chopps #include <netinet/in_var.h>
58 1.1 chopps #include <netinet/ip.h>
59 1.1 chopps #include <netinet/if_ether.h>
60 1.1 chopps #endif
61 1.1 chopps
62 1.1 chopps #ifdef NS
63 1.1 chopps #include <netns/ns.h>
64 1.1 chopps #include <netns/ns_if.h>
65 1.1 chopps #endif
66 1.1 chopps
67 1.1 chopps #include <machine/cpu.h>
68 1.1 chopps #include <machine/mtpr.h>
69 1.1 chopps #include <amiga/amiga/device.h>
70 1.1 chopps #include <amiga/amiga/isr.h>
71 1.1 chopps #include <amiga/dev/zbusvar.h>
72 1.1 chopps #include <amiga/dev/if_esreg.h>
73 1.1 chopps
74 1.1 chopps #define SWAP(x) (((x & 0xff) << 8) | ((x >> 8) & 0xff))
75 1.1 chopps
76 1.1 chopps #define ESDEBUG
77 1.1 chopps #define USEPKTBUF
78 1.1 chopps
79 1.1 chopps /*
80 1.1 chopps * Ethernet software status per interface.
81 1.1 chopps *
82 1.1 chopps * Each interface is referenced by a network interface structure,
83 1.1 chopps * es_if, which the routing code uses to locate the interface.
84 1.1 chopps * This structure contains the output queue for the interface, its address, ...
85 1.1 chopps */
86 1.1 chopps struct es_softc {
87 1.1 chopps struct device sc_dev;
88 1.1 chopps struct isr sc_isr;
89 1.3 mycroft struct arpcom sc_arpcom; /* common Ethernet structures */
90 1.1 chopps void *sc_base; /* base address of board */
91 1.1 chopps short sc_iflags;
92 1.1 chopps unsigned short sc_intctl;
93 1.1 chopps #ifdef ESDEBUG
94 1.1 chopps int sc_debug;
95 1.7 chopps short sc_intbusy;
96 1.7 chopps short sc_smcbusy;
97 1.1 chopps #endif
98 1.1 chopps };
99 1.1 chopps
100 1.1 chopps #if NBPFILTER > 0
101 1.1 chopps #include <net/bpf.h>
102 1.1 chopps #include <net/bpfdesc.h>
103 1.1 chopps #endif
104 1.1 chopps
105 1.1 chopps #ifdef ESDEBUG
106 1.1 chopps /* console error messages */
107 1.1 chopps int esdebug = 0;
108 1.7 chopps int estxints = 0; /* IST_TX with TX enabled */
109 1.7 chopps int estxint2 = 0; /* IST_TX active after IST_TX_EMPTY */
110 1.7 chopps int estxint3 = 0; /* IST_TX interrupt processed */
111 1.7 chopps int estxint4 = 0; /* ~TEMPTY counts */
112 1.7 chopps int estxint5 = 0; /* IST_TX_EMPTY interrupts */
113 1.11 veego void es_dump_smcregs __P((char *, union smcregs *));
114 1.1 chopps #endif
115 1.1 chopps
116 1.11 veego int esintr __P((void *));
117 1.3 mycroft void esstart __P((struct ifnet *));
118 1.3 mycroft void eswatchdog __P((int));
119 1.1 chopps int esioctl __P((struct ifnet *, u_long, caddr_t));
120 1.1 chopps void esrint __P((struct es_softc *));
121 1.1 chopps void estint __P((struct es_softc *));
122 1.1 chopps void esinit __P((struct es_softc *));
123 1.1 chopps void esreset __P((struct es_softc *));
124 1.11 veego void esstop __P((struct es_softc *));
125 1.1 chopps
126 1.3 mycroft int esmatch __P((struct device *, void *, void *));
127 1.1 chopps void esattach __P((struct device *, struct device *, void *));
128 1.1 chopps
129 1.9 thorpej struct cfattach es_ca = {
130 1.10 mhitch sizeof(struct es_softc), esmatch, esattach
131 1.9 thorpej };
132 1.9 thorpej
133 1.9 thorpej struct cfdriver es_cd = {
134 1.9 thorpej NULL, "es", DV_IFNET
135 1.3 mycroft };
136 1.1 chopps
137 1.1 chopps int
138 1.3 mycroft esmatch(parent, match, aux)
139 1.3 mycroft struct device *parent;
140 1.3 mycroft void *match, *aux;
141 1.1 chopps {
142 1.3 mycroft struct zbus_args *zap = aux;
143 1.1 chopps
144 1.1 chopps /* Ameristar A4066 ethernet card */
145 1.3 mycroft if (zap->manid == 1053 && zap->prodid == 10)
146 1.1 chopps return(1);
147 1.1 chopps
148 1.1 chopps return (0);
149 1.1 chopps }
150 1.1 chopps
151 1.1 chopps /*
152 1.1 chopps * Interface exists: make available by filling in network interface
153 1.1 chopps * record. System will initialize the interface when it is ready
154 1.1 chopps * to accept packets.
155 1.1 chopps */
156 1.1 chopps void
157 1.3 mycroft esattach(parent, self, aux)
158 1.3 mycroft struct device *parent, *self;
159 1.3 mycroft void *aux;
160 1.1 chopps {
161 1.3 mycroft struct es_softc *sc = (void *)self;
162 1.3 mycroft struct zbus_args *zap = aux;
163 1.3 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
164 1.1 chopps unsigned long ser;
165 1.1 chopps
166 1.1 chopps sc->sc_base = zap->va;
167 1.7 chopps #ifdef ESDEBUG
168 1.7 chopps /* MLHDEBUG
169 1.7 chopps * MLHDEBUG remove first 4 and last 3 pages of the A4066 memory
170 1.7 chopps * MLHDEBUG and use the 5th page to access the SMC
171 1.7 chopps */
172 1.7 chopps sc->sc_base = zap->va + 0x8000; /* MLHDEBUG */
173 1.7 chopps physunaccess(zap->va, 0x8000); /* MLHDEBUG */
174 1.7 chopps physunaccess(zap->va + 0xa000, 0x6000); /* MLHDEBUG */
175 1.7 chopps #endif
176 1.1 chopps
177 1.1 chopps /*
178 1.1 chopps * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
179 1.1 chopps * (Currently only Ameristar.)
180 1.1 chopps */
181 1.3 mycroft sc->sc_arpcom.ac_enaddr[0] = 0x00;
182 1.3 mycroft sc->sc_arpcom.ac_enaddr[1] = 0x00;
183 1.3 mycroft sc->sc_arpcom.ac_enaddr[2] = 0x9f;
184 1.1 chopps
185 1.1 chopps /*
186 1.1 chopps * Serial number for board contains last 3 bytes.
187 1.1 chopps */
188 1.1 chopps ser = (unsigned long) zap->serno;
189 1.1 chopps
190 1.3 mycroft sc->sc_arpcom.ac_enaddr[3] = (ser >> 16) & 0xff;
191 1.3 mycroft sc->sc_arpcom.ac_enaddr[4] = (ser >> 8) & 0xff;
192 1.3 mycroft sc->sc_arpcom.ac_enaddr[5] = (ser ) & 0xff;
193 1.1 chopps
194 1.3 mycroft /* Initialize ifnet structure. */
195 1.3 mycroft ifp->if_unit = sc->sc_dev.dv_unit;
196 1.9 thorpej ifp->if_name = es_cd.cd_name;
197 1.7 chopps ifp->if_output = ether_output;
198 1.1 chopps ifp->if_ioctl = esioctl;
199 1.1 chopps ifp->if_start = esstart;
200 1.1 chopps ifp->if_watchdog = eswatchdog;
201 1.1 chopps /* XXX IFF_MULTICAST */
202 1.1 chopps ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
203 1.1 chopps
204 1.3 mycroft /* Attach the interface. */
205 1.1 chopps if_attach(ifp);
206 1.1 chopps ether_ifattach(ifp);
207 1.3 mycroft
208 1.3 mycroft /* Print additional info when attached. */
209 1.3 mycroft printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr));
210 1.3 mycroft
211 1.1 chopps #if NBPFILTER > 0
212 1.3 mycroft bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
213 1.1 chopps #endif
214 1.1 chopps
215 1.1 chopps sc->sc_isr.isr_intr = esintr;
216 1.1 chopps sc->sc_isr.isr_arg = sc;
217 1.1 chopps sc->sc_isr.isr_ipl = 2;
218 1.3 mycroft add_isr(&sc->sc_isr);
219 1.1 chopps }
220 1.1 chopps
221 1.7 chopps #ifdef ESDEBUG
222 1.7 chopps void
223 1.7 chopps es_dump_smcregs(where, smc)
224 1.7 chopps char *where;
225 1.7 chopps union smcregs *smc;
226 1.7 chopps {
227 1.7 chopps u_short cur_bank = smc->b0.bsr & 0x0300;
228 1.7 chopps
229 1.11 veego printf("SMC registers %p from %s bank %04x\n", smc, where,
230 1.7 chopps smc->b0.bsr);
231 1.7 chopps smc->b0.bsr = BSR_BANK0;
232 1.7 chopps printf("TCR %04x EPHSR %04x RCR %04x ECR %04x MIR %04x MCR %04x\n",
233 1.7 chopps SWAP(smc->b0.tcr), SWAP(smc->b0.ephsr), SWAP(smc->b0.rcr),
234 1.7 chopps SWAP(smc->b0.ecr), SWAP(smc->b0.mir), SWAP(smc->b0.mcr));
235 1.7 chopps smc->b1.bsr = BSR_BANK1;
236 1.7 chopps printf("CR %04x BAR %04x IAR %04x %04x %04x GPR %04x CTR %04x\n",
237 1.7 chopps SWAP(smc->b1.cr), SWAP(smc->b1.bar), smc->b1.iar[0], smc->b1.iar[1],
238 1.7 chopps smc->b1.iar[2], smc->b1.gpr, SWAP(smc->b1.ctr));
239 1.7 chopps smc->b2.bsr = BSR_BANK2;
240 1.7 chopps printf("MMUCR %04x PNR %02x ARR %02x FIFO %04x PTR %04x",
241 1.7 chopps SWAP(smc->b2.mmucr), smc->b2.pnr, smc->b2.arr, smc->b2.fifo,
242 1.7 chopps SWAP(smc->b2.ptr));
243 1.7 chopps printf(" DATA %04x %04x IST %02x MSK %02x\n", smc->b2.data,
244 1.7 chopps smc->b2.datax, smc->b2.ist, smc->b2.msk);
245 1.7 chopps smc->b3.bsr = BSR_BANK3;
246 1.7 chopps printf("MT %04x %04x %04x %04x\n",
247 1.7 chopps smc->b3.mt[0], smc->b3.mt[1], smc->b3.mt[2], smc->b3.mt[3]);
248 1.7 chopps smc->b3.bsr = cur_bank;
249 1.7 chopps }
250 1.7 chopps #endif
251 1.7 chopps
252 1.1 chopps void
253 1.4 chopps esstop(sc)
254 1.4 chopps struct es_softc* sc;
255 1.4 chopps {
256 1.4 chopps }
257 1.4 chopps
258 1.4 chopps void
259 1.1 chopps esinit(sc)
260 1.1 chopps struct es_softc *sc;
261 1.1 chopps {
262 1.3 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
263 1.1 chopps union smcregs *smc = sc->sc_base;
264 1.1 chopps int s;
265 1.1 chopps
266 1.8 mycroft s = splnet();
267 1.1 chopps
268 1.7 chopps #ifdef ESDEBUG
269 1.7 chopps if (ifp->if_flags & IFF_RUNNING)
270 1.7 chopps es_dump_smcregs("esinit", smc);
271 1.7 chopps #endif
272 1.3 mycroft smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
273 1.1 chopps smc->b0.rcr = RCR_EPH_RST;
274 1.1 chopps smc->b0.rcr = 0;
275 1.3 mycroft smc->b3.bsr = BSR_BANK3; /* Select bank 3 */
276 1.1 chopps smc->b3.mt[0] = 0; /* clear Multicast table */
277 1.1 chopps smc->b3.mt[1] = 0;
278 1.1 chopps smc->b3.mt[2] = 0;
279 1.1 chopps smc->b3.mt[3] = 0;
280 1.1 chopps /* XXX set Multicast table from Multicast list */
281 1.3 mycroft smc->b1.bsr = BSR_BANK1; /* Select bank 1 */
282 1.1 chopps smc->b1.cr = CR_RAM32K | CR_NO_WAIT_ST | CR_SET_SQLCH;
283 1.1 chopps smc->b1.ctr = CTR_AUTO_RLSE;
284 1.3 mycroft smc->b1.iar[0] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[0]);
285 1.3 mycroft smc->b1.iar[1] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[2]);
286 1.3 mycroft smc->b1.iar[2] = *((unsigned short *) &sc->sc_arpcom.ac_enaddr[4]);
287 1.3 mycroft smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
288 1.1 chopps smc->b2.mmucr = MMUCR_RESET;
289 1.3 mycroft smc->b0.bsr = BSR_BANK0; /* Select bank 0 */
290 1.3 mycroft smc->b0.mcr = SWAP(0x0020); /* reserve 8K for transmit buffers */
291 1.11 veego smc->b0.tcr = TCR_PAD_EN | (TCR_TXENA + TCR_MON_CSN);
292 1.1 chopps smc->b0.rcr = RCR_FILT_CAR | RCR_STRIP_CRC | RCR_RXEN;
293 1.1 chopps /* XXX add multicast/promiscuous flags */
294 1.3 mycroft smc->b2.bsr = BSR_BANK2; /* Select bank 2 */
295 1.1 chopps smc->b2.msk = sc->sc_intctl = MSK_RX_OVRN | MSK_RX;
296 1.1 chopps
297 1.1 chopps /* Interface is now 'running', with no output active. */
298 1.1 chopps ifp->if_flags |= IFF_RUNNING;
299 1.1 chopps ifp->if_flags &= ~IFF_OACTIVE;
300 1.1 chopps
301 1.1 chopps /* Attempt to start output, if any. */
302 1.1 chopps esstart(ifp);
303 1.1 chopps
304 1.1 chopps splx(s);
305 1.1 chopps }
306 1.1 chopps
307 1.1 chopps int
308 1.11 veego esintr(arg)
309 1.11 veego void *arg;
310 1.1 chopps {
311 1.11 veego struct es_softc *sc = arg;
312 1.2 chopps u_short intsts, intact;
313 1.1 chopps union smcregs *smc;
314 1.8 mycroft int s = splnet();
315 1.1 chopps
316 1.1 chopps smc = sc->sc_base;
317 1.7 chopps #ifdef ESDEBUG
318 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2 &&
319 1.7 chopps sc->sc_arpcom.ac_if.if_flags & IFF_RUNNING) {
320 1.7 chopps printf("%s: intr BSR not 2: %04x\n", sc->sc_dev.dv_xname,
321 1.7 chopps smc->b2.bsr);
322 1.7 chopps smc->b2.bsr = BSR_BANK2;
323 1.7 chopps }
324 1.7 chopps #endif
325 1.2 chopps intsts = smc->b2.ist;
326 1.2 chopps intact = smc->b2.msk & intsts;
327 1.7 chopps if ((intact) == 0) {
328 1.7 chopps splx(s);
329 1.1 chopps return (0);
330 1.7 chopps }
331 1.1 chopps #ifdef ESDEBUG
332 1.1 chopps if (esdebug)
333 1.1 chopps printf ("%s: esintr ist %02x msk %02x",
334 1.2 chopps sc->sc_dev.dv_xname, intsts, smc->b2.msk);
335 1.7 chopps if (sc->sc_intbusy++) {
336 1.7 chopps printf("%s: esintr re-entered\n", sc->sc_dev.dv_xname);
337 1.7 chopps panic("esintr re-entered");
338 1.7 chopps }
339 1.1 chopps #endif
340 1.1 chopps smc->b2.msk = 0;
341 1.1 chopps #ifdef ESDEBUG
342 1.1 chopps if (esdebug)
343 1.1 chopps printf ("=>%02x%02x pnr %02x arr %02x fifo %04x\n",
344 1.1 chopps smc->b2.ist, smc->b2.ist, smc->b2.pnr, smc->b2.arr,
345 1.1 chopps smc->b2.fifo);
346 1.1 chopps #endif
347 1.2 chopps if (intact & IST_ALLOC) {
348 1.1 chopps sc->sc_intctl &= ~MSK_ALLOC;
349 1.1 chopps #ifdef ESDEBUG
350 1.1 chopps if (esdebug || 1)
351 1.7 chopps printf ("%s: ist %02x", sc->sc_dev.dv_xname,
352 1.2 chopps intsts);
353 1.1 chopps #endif
354 1.1 chopps if ((smc->b2.arr & ARR_FAILED) == 0) {
355 1.7 chopps u_char save_pnr;
356 1.1 chopps #ifdef ESDEBUG
357 1.1 chopps if (esdebug || 1)
358 1.7 chopps printf (" arr %02x\n", smc->b2.arr);
359 1.1 chopps #endif
360 1.7 chopps save_pnr = smc->b2.pnr;
361 1.1 chopps smc->b2.pnr = smc->b2.arr;
362 1.1 chopps smc->b2.mmucr = MMUCR_RLSPKT;
363 1.1 chopps while (smc->b2.mmucr & MMUCR_BUSY)
364 1.1 chopps ;
365 1.7 chopps smc->b2.pnr = save_pnr;
366 1.3 mycroft sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
367 1.1 chopps }
368 1.7 chopps #ifdef ESDEBUG
369 1.7 chopps else if (esdebug || 1)
370 1.7 chopps printf (" IST_ALLOC with ARR_FAILED?\n");
371 1.7 chopps #endif
372 1.7 chopps }
373 1.7 chopps #ifdef ESDEBUG
374 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
375 1.7 chopps printf("%s: intr+ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
376 1.7 chopps smc->b2.bsr);
377 1.7 chopps smc->b2.bsr = BSR_BANK2;
378 1.1 chopps }
379 1.7 chopps #endif
380 1.1 chopps while ((smc->b2.fifo & FIFO_REMPTY) == 0) {
381 1.1 chopps esrint(sc);
382 1.1 chopps }
383 1.7 chopps #ifdef ESDEBUG
384 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
385 1.7 chopps printf("%s: intr++ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
386 1.7 chopps smc->b2.bsr);
387 1.7 chopps smc->b2.bsr = BSR_BANK2;
388 1.7 chopps }
389 1.7 chopps #endif
390 1.2 chopps if (intact & IST_RX_OVRN) {
391 1.1 chopps printf ("%s: Overrun ist %02x", sc->sc_dev.dv_xname,
392 1.2 chopps intsts);
393 1.1 chopps smc->b2.ist = ACK_RX_OVRN;
394 1.1 chopps printf ("->%02x\n", smc->b2.ist);
395 1.3 mycroft sc->sc_arpcom.ac_if.if_ierrors++;
396 1.1 chopps }
397 1.2 chopps if (intact & IST_TX_EMPTY) {
398 1.1 chopps u_short ecr;
399 1.1 chopps #ifdef ESDEBUG
400 1.1 chopps if (esdebug)
401 1.1 chopps printf ("%s: TX EMPTY %02x",
402 1.2 chopps sc->sc_dev.dv_xname, intsts);
403 1.7 chopps ++estxint5; /* count # IST_TX_EMPTY ints */
404 1.1 chopps #endif
405 1.1 chopps smc->b2.ist = ACK_TX_EMPTY;
406 1.7 chopps sc->sc_intctl &= ~(MSK_TX_EMPTY | MSK_TX);
407 1.1 chopps #ifdef ESDEBUG
408 1.1 chopps if (esdebug)
409 1.1 chopps printf ("->%02x intcl %x pnr %02x arr %02x\n",
410 1.1 chopps smc->b2.ist, sc->sc_intctl, smc->b2.pnr,
411 1.1 chopps smc->b2.arr);
412 1.1 chopps #endif
413 1.7 chopps if (smc->b2.ist & IST_TX) {
414 1.7 chopps intact |= IST_TX;
415 1.7 chopps #ifdef ESDEBUG
416 1.7 chopps ++estxint2; /* count # TX after TX_EMPTY */
417 1.7 chopps #endif
418 1.7 chopps } else {
419 1.7 chopps smc->b0.bsr = BSR_BANK0;
420 1.7 chopps ecr = smc->b0.ecr; /* Get error counters */
421 1.7 chopps if (ecr & 0xff00)
422 1.7 chopps sc->sc_arpcom.ac_if.if_collisions += ((ecr >> 8) & 15) +
423 1.7 chopps ((ecr >> 11) & 0x1e);
424 1.7 chopps smc->b2.bsr = BSR_BANK2;
425 1.7 chopps #if 0
426 1.7 chopps smc->b2.mmucr = MMUCR_RESET_TX; /* XXX reset TX FIFO */
427 1.7 chopps #endif
428 1.7 chopps }
429 1.7 chopps }
430 1.7 chopps if (intact & IST_TX) {
431 1.7 chopps u_char tx_pnr, save_pnr;
432 1.7 chopps u_short save_ptr, ephsr, tcr;
433 1.7 chopps int n = 0;
434 1.7 chopps #ifdef ESDEBUG
435 1.7 chopps if (esdebug) {
436 1.7 chopps printf ("%s: TX INT ist %02x",
437 1.7 chopps sc->sc_dev.dv_xname, intsts);
438 1.7 chopps printf ("->%02x\n", smc->b2.ist);
439 1.7 chopps }
440 1.7 chopps ++estxint3; /* count # IST_TX */
441 1.7 chopps #endif
442 1.7 chopps zzzz:
443 1.7 chopps ++estxint4; /* count # ~TEMPTY */
444 1.3 mycroft smc->b0.bsr = BSR_BANK0;
445 1.7 chopps ephsr = smc->b0.ephsr; /* get EPHSR */
446 1.7 chopps tcr = smc->b0.tcr; /* and TCR */
447 1.3 mycroft smc->b2.bsr = BSR_BANK2;
448 1.7 chopps save_ptr = smc->b2.ptr;
449 1.7 chopps save_pnr = smc->b2.pnr;
450 1.7 chopps tx_pnr = smc->b2.fifo >> 8; /* pktno from completion fifo */
451 1.7 chopps smc->b2.pnr = tx_pnr; /* set TX packet number */
452 1.7 chopps smc->b2.ptr = PTR_READ; /* point to status word */
453 1.7 chopps #if 0 /* XXXX */
454 1.7 chopps printf("%s: esintr TXINT IST %02x PNR %02x(%d)",
455 1.7 chopps sc->sc_dev.dv_xname, smc->b2.ist,
456 1.7 chopps tx_pnr, n);
457 1.7 chopps printf(" Status %04x", smc->b2.data);
458 1.7 chopps printf(" EPHSR %04x\n", ephsr);
459 1.7 chopps #endif
460 1.7 chopps if ((smc->b2.data & EPHSR_TX_SUC) == 0 && (tcr & TCR_TXENA) == 0) {
461 1.7 chopps /*
462 1.7 chopps * Transmitter was stopped for some error. Enqueue
463 1.7 chopps * the packet again and restart the transmitter.
464 1.7 chopps * May need some check to limit the number of retries.
465 1.7 chopps */
466 1.7 chopps smc->b2.mmucr = MMUCR_ENQ_TX;
467 1.7 chopps smc->b0.bsr = BSR_BANK0;
468 1.7 chopps smc->b0.tcr |= TCR_TXENA;
469 1.7 chopps smc->b2.bsr = BSR_BANK2;
470 1.7 chopps sc->sc_arpcom.ac_if.if_oerrors++;
471 1.7 chopps sc->sc_intctl |= MSK_TX_EMPTY | MSK_TX;
472 1.7 chopps } else {
473 1.7 chopps /*
474 1.7 chopps * This shouldn't have happened: IST_TX indicates
475 1.7 chopps * the TX completion FIFO is not empty, but the
476 1.7 chopps * status for the packet on the completion FIFO
477 1.7 chopps * shows that the transmit was sucessful. Since
478 1.7 chopps * AutoRelease is being used, a sucessful transmit
479 1.7 chopps * should not result in a packet on the completion
480 1.7 chopps * FIFO. Also, that packet doesn't seem to want
481 1.7 chopps * to be acknowledged. If this occurs, just reset
482 1.7 chopps * the TX FIFOs.
483 1.7 chopps */
484 1.7 chopps #if 1
485 1.7 chopps if (smc->b2.ist & IST_TX_EMPTY) {
486 1.7 chopps smc->b2.mmucr = MMUCR_RESET_TX;
487 1.7 chopps sc->sc_intctl &= ~(MSK_TX_EMPTY | MSK_TX);
488 1.7 chopps }
489 1.7 chopps #endif
490 1.7 chopps #ifdef ESDEBUG
491 1.7 chopps ++estxints; /* count IST_TX with TX enabled */
492 1.7 chopps #endif
493 1.7 chopps }
494 1.7 chopps smc->b2.pnr = save_pnr;
495 1.7 chopps smc->b2.ptr = save_ptr;
496 1.7 chopps smc->b2.ist = ACK_TX;
497 1.7 chopps
498 1.7 chopps if ((smc->b2.fifo & FIFO_TEMPTY) == 0 && n++ < 32) {
499 1.7 chopps #if 0 /* XXXX */
500 1.7 chopps printf("%s: multiple TX int(%2d) pnr %02x ist %02x fifo %04x",
501 1.7 chopps sc->sc_dev.dv_xname, n, tx_pnr, smc->b2.ist, smc->b2.fifo);
502 1.7 chopps smc->w2.istmsk = ACK_TX << 8;
503 1.7 chopps printf(" %04x\n", smc->b2.fifo);
504 1.7 chopps #endif
505 1.7 chopps if (tx_pnr != (smc->b2.fifo >> 8))
506 1.7 chopps goto zzzz;
507 1.7 chopps }
508 1.1 chopps }
509 1.1 chopps /* output packets */
510 1.1 chopps estint(sc);
511 1.7 chopps #ifdef ESDEBUG
512 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
513 1.7 chopps printf("%s: intr+++ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
514 1.7 chopps smc->b2.bsr);
515 1.7 chopps smc->b2.bsr = BSR_BANK2;
516 1.7 chopps }
517 1.7 chopps #endif
518 1.1 chopps smc->b2.msk = sc->sc_intctl;
519 1.7 chopps #ifdef ESDEBUG
520 1.7 chopps if (--sc->sc_intbusy) {
521 1.7 chopps printf("%s: esintr busy on exit\n", sc->sc_dev.dv_xname);
522 1.7 chopps panic("esintr busy on exit");
523 1.7 chopps }
524 1.7 chopps #endif
525 1.7 chopps splx(s);
526 1.1 chopps return (1);
527 1.1 chopps }
528 1.1 chopps
529 1.1 chopps void
530 1.3 mycroft esrint(sc)
531 1.1 chopps struct es_softc *sc;
532 1.1 chopps {
533 1.1 chopps union smcregs *smc = sc->sc_base;
534 1.1 chopps int i;
535 1.1 chopps u_short len;
536 1.1 chopps short cnt;
537 1.1 chopps u_short pktctlw, pktlen, *buf;
538 1.11 veego volatile u_short *data;
539 1.11 veego #if 0
540 1.1 chopps u_long *lbuf;
541 1.1 chopps volatile u_long *ldata;
542 1.11 veego #endif
543 1.1 chopps struct ifnet *ifp;
544 1.1 chopps struct mbuf *top, **mp, *m;
545 1.1 chopps struct ether_header *eh;
546 1.1 chopps #ifdef USEPKTBUF
547 1.1 chopps u_char *b, pktbuf[1530];
548 1.1 chopps #endif
549 1.1 chopps
550 1.1 chopps #ifdef ESDEBUG
551 1.1 chopps if (esdebug)
552 1.1 chopps printf ("%s: esrint fifo %04x", sc->sc_dev.dv_xname,
553 1.1 chopps smc->b2.fifo);
554 1.7 chopps if (sc->sc_smcbusy++) {
555 1.11 veego printf("%s: esrint re-entered\n", sc->sc_dev.dv_xname);
556 1.7 chopps panic("esrint re-entered");
557 1.7 chopps }
558 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
559 1.7 chopps printf("%s: rint BSR not 2: %04x\n", sc->sc_dev.dv_xname,
560 1.7 chopps smc->b2.bsr);
561 1.7 chopps smc->b2.bsr = BSR_BANK2;
562 1.7 chopps }
563 1.1 chopps #endif
564 1.1 chopps data = (u_short *)&smc->b2.data;
565 1.3 mycroft smc->b2.ptr = PTR_RCV | PTR_AUTOINCR | PTR_READ | SWAP(0x0002);
566 1.1 chopps (void) smc->b2.mmucr;
567 1.1 chopps #ifdef ESDEBUG
568 1.1 chopps if (esdebug)
569 1.1 chopps printf ("->%04x", smc->b2.fifo);
570 1.1 chopps #endif
571 1.1 chopps len = *data;
572 1.3 mycroft len = SWAP(len); /* Careful of macro side-effects */
573 1.1 chopps #ifdef ESDEBUG
574 1.1 chopps if (esdebug)
575 1.1 chopps printf (" length %d", len);
576 1.1 chopps #endif
577 1.11 veego smc->b2.ptr = PTR_RCV | (PTR_AUTOINCR + PTR_READ) | SWAP(0x0000);
578 1.1 chopps (void) smc->b2.mmucr;
579 1.1 chopps pktctlw = *data;
580 1.1 chopps pktlen = *data;
581 1.3 mycroft pktctlw = SWAP(pktctlw);
582 1.3 mycroft pktlen = SWAP(pktlen) - 6;
583 1.1 chopps if (pktctlw & RFSW_ODDFRM)
584 1.1 chopps pktlen++;
585 1.7 chopps if (len > 1530) {
586 1.7 chopps printf("%s: Corrupted packet length-sts %04x bytcnt %04x len %04x bank %04x\n",
587 1.7 chopps sc->sc_dev.dv_xname, pktctlw, pktlen, len, smc->b2.bsr);
588 1.7 chopps /* XXX ignore packet, or just truncate? */
589 1.7 chopps #if defined(ESDEBUG) && defined(DDB)
590 1.7 chopps if ((smc->b2.bsr & 0x0300) != BSR_BANK2)
591 1.7 chopps Debugger();
592 1.7 chopps #endif
593 1.7 chopps smc->b2.bsr = BSR_BANK2;
594 1.7 chopps smc->b2.mmucr = MMUCR_REMRLS_RX;
595 1.7 chopps while (smc->b2.mmucr & MMUCR_BUSY)
596 1.7 chopps ;
597 1.7 chopps ++sc->sc_arpcom.ac_if.if_ierrors;
598 1.7 chopps #ifdef ESDEBUG
599 1.7 chopps if (--sc->sc_smcbusy) {
600 1.7 chopps printf("%s: esrintr busy on bad packet exit\n",
601 1.7 chopps sc->sc_dev.dv_xname);
602 1.7 chopps panic("esrintr busy on exit");
603 1.7 chopps }
604 1.7 chopps #endif
605 1.7 chopps return;
606 1.7 chopps }
607 1.1 chopps #ifdef USEPKTBUF
608 1.7 chopps #if 0
609 1.1 chopps lbuf = (u_long *) pktbuf;
610 1.1 chopps ldata = (u_long *)data;
611 1.1 chopps cnt = (len - 4) / 4;
612 1.1 chopps while (cnt--)
613 1.1 chopps *lbuf++ = *ldata;
614 1.1 chopps if ((len - 4) & 2) {
615 1.1 chopps buf = (u_short *) lbuf;
616 1.1 chopps *buf = *data;
617 1.1 chopps }
618 1.1 chopps #else
619 1.1 chopps buf = (u_short *)pktbuf;
620 1.1 chopps cnt = (len - 4) / 2;
621 1.1 chopps while (cnt--)
622 1.1 chopps *buf++ = *data;
623 1.1 chopps #endif
624 1.1 chopps smc->b2.mmucr = MMUCR_REMRLS_RX;
625 1.1 chopps while (smc->b2.mmucr & MMUCR_BUSY)
626 1.1 chopps ;
627 1.1 chopps #ifdef ESDEBUG
628 1.1 chopps if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
629 1.1 chopps printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
630 1.1 chopps /* count input error? */
631 1.1 chopps }
632 1.1 chopps if (esdebug) {
633 1.1 chopps printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
634 1.1 chopps smc->b2.fifo);
635 1.1 chopps for (i = 0; i < pktlen; ++i)
636 1.1 chopps printf ("%02x%s", pktbuf[i], ((i & 31) == 31) ? "\n" :
637 1.1 chopps "");
638 1.1 chopps if (i & 31)
639 1.1 chopps printf ("\n");
640 1.1 chopps }
641 1.1 chopps #endif
642 1.1 chopps #else /* USEPKTBUF */
643 1.7 chopps /* XXX copy directly from controller to mbuf */
644 1.1 chopps #ifdef ESDEBUG
645 1.1 chopps if (pktctlw & (RFSW_ALGNERR | RFSW_BADCRC | RFSW_TOOLNG | RFSW_TOOSHORT)) {
646 1.1 chopps printf ("%s: Packet error %04x\n", sc->sc_dev.dv_xname, pktctlw);
647 1.1 chopps /* count input error? */
648 1.1 chopps }
649 1.1 chopps if (esdebug) {
650 1.1 chopps printf (" pktctlw %04x pktlen %04x fifo %04x\n", pktctlw, pktlen,
651 1.1 chopps smc->b2.fifo);
652 1.1 chopps }
653 1.1 chopps #endif
654 1.1 chopps #endif /* USEPKTBUF */
655 1.3 mycroft ifp = &sc->sc_arpcom.ac_if;
656 1.1 chopps ifp->if_ipackets++;
657 1.1 chopps MGETHDR(m, M_DONTWAIT, MT_DATA);
658 1.1 chopps if (m == NULL)
659 1.1 chopps return;
660 1.1 chopps m->m_pkthdr.rcvif = ifp;
661 1.1 chopps m->m_pkthdr.len = pktlen;
662 1.1 chopps len = MHLEN;
663 1.1 chopps top = NULL;
664 1.1 chopps mp = ⊤
665 1.1 chopps #ifdef USEPKTBUF
666 1.1 chopps b = pktbuf;
667 1.1 chopps #endif
668 1.1 chopps while (pktlen > 0) {
669 1.1 chopps if (top) {
670 1.1 chopps MGET(m, M_DONTWAIT, MT_DATA);
671 1.1 chopps if (m == 0) {
672 1.1 chopps m_freem(top);
673 1.1 chopps return;
674 1.1 chopps }
675 1.1 chopps len = MLEN;
676 1.1 chopps }
677 1.1 chopps if (pktlen >= MINCLSIZE) {
678 1.1 chopps MCLGET(m, M_DONTWAIT);
679 1.1 chopps if (m->m_flags & M_EXT)
680 1.1 chopps len = MCLBYTES;
681 1.1 chopps }
682 1.1 chopps m->m_len = len = min(pktlen, len);
683 1.1 chopps #ifdef USEPKTBUF
684 1.1 chopps bcopy((caddr_t)b, mtod(m, caddr_t), len);
685 1.1 chopps b += len;
686 1.1 chopps #else /* USEPKTBUF */
687 1.1 chopps buf = mtod(m, u_short *);
688 1.1 chopps cnt = len / 2;
689 1.1 chopps while (cnt--)
690 1.1 chopps *buf++ = *data;
691 1.1 chopps if (len & 1)
692 1.1 chopps *buf = *data; /* XXX should be byte store */
693 1.1 chopps #ifdef ESDEBUG
694 1.1 chopps if (esdebug) {
695 1.1 chopps buf = mtod(m, u_short *);
696 1.1 chopps for (i = 0; i < len; ++i)
697 1.1 chopps printf ("%02x%s", ((u_char *)buf)[i],
698 1.1 chopps ((i & 31) == 31) ? "\n" : "");
699 1.1 chopps if (i & 31)
700 1.1 chopps printf ("\n");
701 1.1 chopps }
702 1.1 chopps #endif
703 1.1 chopps #endif /* USEPKTBUF */
704 1.1 chopps pktlen -= len;
705 1.1 chopps *mp = m;
706 1.1 chopps mp = &m->m_next;
707 1.1 chopps }
708 1.1 chopps #ifndef USEPKTBUF
709 1.1 chopps smc->b2.mmucr = MMUCR_REMRLS_RX;
710 1.1 chopps while (smc->b2.mmucr & MMUCR_BUSY)
711 1.1 chopps ;
712 1.1 chopps #endif
713 1.1 chopps eh = mtod(top, struct ether_header *);
714 1.7 chopps #if NBPFILTER > 0
715 1.7 chopps /*
716 1.7 chopps * Check if there's a BPF listener on this interface. If so, hand off
717 1.7 chopps * the raw packet to bpf.
718 1.7 chopps */
719 1.7 chopps if (sc->sc_arpcom.ac_if.if_bpf) {
720 1.7 chopps bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, top);
721 1.7 chopps
722 1.7 chopps /*
723 1.7 chopps * Note that the interface cannot be in promiscuous mode if
724 1.7 chopps * there are no BPF listeners. And if we are in promiscuous
725 1.7 chopps * mode, we have to check if this packet is really ours.
726 1.7 chopps */
727 1.7 chopps if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) &&
728 1.7 chopps (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
729 1.7 chopps bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
730 1.7 chopps sizeof(eh->ether_dhost)) != 0) {
731 1.7 chopps m_freem(top);
732 1.7 chopps return;
733 1.7 chopps }
734 1.7 chopps }
735 1.7 chopps #endif
736 1.1 chopps top->m_pkthdr.len -= sizeof (*eh);
737 1.1 chopps top->m_len -= sizeof (*eh);
738 1.1 chopps top->m_data += sizeof (*eh);
739 1.1 chopps
740 1.1 chopps ether_input(ifp, eh, top);
741 1.7 chopps #ifdef ESDEBUG
742 1.7 chopps if (--sc->sc_smcbusy) {
743 1.7 chopps printf("%s: esintr busy on exit\n", sc->sc_dev.dv_xname);
744 1.7 chopps panic("esintr busy on exit");
745 1.7 chopps }
746 1.7 chopps #endif
747 1.1 chopps }
748 1.1 chopps
749 1.1 chopps void
750 1.3 mycroft estint(sc)
751 1.1 chopps struct es_softc *sc;
752 1.1 chopps {
753 1.3 mycroft
754 1.3 mycroft esstart(&sc->sc_arpcom.ac_if);
755 1.1 chopps }
756 1.1 chopps
757 1.3 mycroft void
758 1.1 chopps esstart(ifp)
759 1.1 chopps struct ifnet *ifp;
760 1.1 chopps {
761 1.9 thorpej struct es_softc *sc = es_cd.cd_devs[ifp->if_unit];
762 1.1 chopps union smcregs *smc = sc->sc_base;
763 1.1 chopps struct mbuf *m0, *m;
764 1.1 chopps #ifdef USEPKTBUF
765 1.3 mycroft u_short pktbuf[ETHERMTU + 2];
766 1.7 chopps #else
767 1.7 chopps u_short oddbyte, needbyte;
768 1.1 chopps #endif
769 1.1 chopps u_short pktctlw, pktlen;
770 1.1 chopps u_short *buf;
771 1.1 chopps volatile u_short *data;
772 1.11 veego #if 0
773 1.1 chopps u_long *lbuf;
774 1.1 chopps volatile u_long *ldata;
775 1.11 veego #endif
776 1.1 chopps short cnt;
777 1.1 chopps int i;
778 1.7 chopps u_char active_pnr;
779 1.1 chopps
780 1.3 mycroft if ((sc->sc_arpcom.ac_if.if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
781 1.1 chopps IFF_RUNNING)
782 1.1 chopps return;
783 1.1 chopps
784 1.7 chopps #ifdef ESDEBUG
785 1.7 chopps if (sc->sc_smcbusy++) {
786 1.7 chopps printf("%s: esstart re-entered\n", sc->sc_dev.dv_xname);
787 1.7 chopps panic("esstart re-entred");
788 1.7 chopps }
789 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
790 1.7 chopps printf("%s: esstart BSR not 2: %04x\n", sc->sc_dev.dv_xname,
791 1.7 chopps smc->b2.bsr);
792 1.7 chopps smc->b2.bsr = BSR_BANK2;
793 1.7 chopps }
794 1.7 chopps #endif
795 1.1 chopps for (;;) {
796 1.7 chopps int xxx;
797 1.1 chopps /*
798 1.1 chopps * Sneak a peek at the next packet to get the length
799 1.1 chopps * and see if the SMC 91C90 can accept it.
800 1.1 chopps */
801 1.3 mycroft m = sc->sc_arpcom.ac_if.if_snd.ifq_head;
802 1.1 chopps if (!m)
803 1.1 chopps break;
804 1.1 chopps #ifdef ESDEBUG
805 1.1 chopps if (esdebug && (m->m_next || m->m_len & 1))
806 1.11 veego printf("%s: esstart m_next %p m_len %d\n", sc->sc_dev.dv_xname,
807 1.1 chopps m->m_next, m->m_len);
808 1.1 chopps #endif
809 1.1 chopps for (m0 = m, pktlen = 0; m0; m0 = m0->m_next)
810 1.1 chopps pktlen += m0->m_len;
811 1.1 chopps pktctlw = 0;
812 1.1 chopps pktlen += 4;
813 1.1 chopps if (pktlen & 1)
814 1.1 chopps ++pktlen; /* control byte after last byte */
815 1.1 chopps else
816 1.1 chopps pktlen += 2; /* control byte after pad byte */
817 1.1 chopps smc->b2.mmucr = MMUCR_ALLOC | (pktlen & 0x0700);
818 1.1 chopps for (i = 0; i <= 5; ++i)
819 1.1 chopps if ((smc->b2.arr & ARR_FAILED) == 0)
820 1.1 chopps break;
821 1.1 chopps if (smc->b2.arr & ARR_FAILED) {
822 1.3 mycroft sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
823 1.2 chopps sc->sc_intctl |= MSK_ALLOC;
824 1.1 chopps break;
825 1.1 chopps }
826 1.7 chopps active_pnr = smc->b2.pnr = smc->b2.arr;
827 1.1 chopps
828 1.7 chopps #ifdef ESDEBUG
829 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
830 1.7 chopps printf("%s: esstart+ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
831 1.7 chopps smc->b2.bsr);
832 1.7 chopps smc->b2.bsr = BSR_BANK2;
833 1.7 chopps }
834 1.7 chopps #endif
835 1.3 mycroft IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m);
836 1.7 chopps xxx = splhigh();
837 1.1 chopps smc->b2.ptr = PTR_AUTOINCR;
838 1.1 chopps (void) smc->b2.mmucr;
839 1.1 chopps data = (u_short *)&smc->b2.data;
840 1.3 mycroft *data = SWAP(pktctlw);
841 1.3 mycroft *data = SWAP(pktlen);
842 1.7 chopps #ifdef ESDEBUG
843 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
844 1.7 chopps printf("%s: esstart++ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
845 1.7 chopps smc->b2.bsr);
846 1.7 chopps smc->b2.bsr = BSR_BANK2;
847 1.7 chopps }
848 1.7 chopps #endif
849 1.1 chopps #ifdef USEPKTBUF
850 1.1 chopps i = 0;
851 1.1 chopps for (m0 = m; m; m = m->m_next) {
852 1.1 chopps bcopy(mtod(m, caddr_t), (char *)pktbuf + i, m->m_len);
853 1.1 chopps i += m->m_len;
854 1.1 chopps }
855 1.1 chopps
856 1.1 chopps if (i & 1) /* Figure out where to put control byte */
857 1.1 chopps pktbuf[i/2] = (pktbuf[i/2] & 0xff00) | CTLB_ODD;
858 1.1 chopps else
859 1.1 chopps pktbuf[i/2] = 0;
860 1.7 chopps pktlen -= 4;
861 1.1 chopps #ifdef ESDEBUG
862 1.7 chopps if (pktlen > sizeof(pktbuf))
863 1.7 chopps printf("%s: esstart packet longer than pktbuf\n",
864 1.7 chopps sc->sc_dev.dv_xname);
865 1.1 chopps #endif
866 1.1 chopps #if 0 /* doesn't quite work? */
867 1.1 chopps lbuf = (u_long *)(pktbuf);
868 1.1 chopps ldata = (u_long *)data;
869 1.1 chopps cnt = pktlen / 4;
870 1.1 chopps while(cnt--)
871 1.1 chopps *ldata = *lbuf++;
872 1.1 chopps if (pktlen & 2) {
873 1.1 chopps buf = (u_short *)lbuf;
874 1.1 chopps *data = *buf;
875 1.1 chopps }
876 1.1 chopps #else
877 1.1 chopps buf = pktbuf;
878 1.1 chopps cnt = pktlen / 2;
879 1.1 chopps while (cnt--)
880 1.1 chopps *data = *buf++;
881 1.1 chopps #endif
882 1.1 chopps #else /* USEPKTBUF */
883 1.1 chopps pktctlw = 0;
884 1.7 chopps oddbyte = needbyte = 0;
885 1.1 chopps for (m0 = m; m; m = m->m_next) {
886 1.1 chopps buf = mtod(m, u_short *);
887 1.1 chopps cnt = m->m_len / 2;
888 1.7 chopps if (needbyte) {
889 1.7 chopps oddbyte |= *buf >> 8;
890 1.7 chopps *data = oddbyte;
891 1.7 chopps }
892 1.1 chopps while (cnt--)
893 1.1 chopps *data = *buf++;
894 1.1 chopps if (m->m_len & 1)
895 1.1 chopps pktctlw = (*buf & 0xff00) | CTLB_ODD;
896 1.7 chopps if (m->m_len & 1 && m->m_next)
897 1.7 chopps printf("%s: esstart odd byte count in mbuf\n",
898 1.7 chopps sc->sc_dev.dv_xname);
899 1.1 chopps }
900 1.1 chopps *data = pktctlw;
901 1.1 chopps #endif /* USEPKTBUF */
902 1.7 chopps splx(xxx);
903 1.1 chopps #ifdef ESDEBUG
904 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
905 1.7 chopps printf("%s: esstart+++ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
906 1.7 chopps smc->b2.bsr);
907 1.7 chopps smc->b2.bsr = BSR_BANK2;
908 1.7 chopps }
909 1.1 chopps #endif
910 1.7 chopps smc->b2.mmucr = MMUCR_ENQ_TX;
911 1.7 chopps if (smc->b2.pnr != active_pnr)
912 1.7 chopps printf("%s: esstart - PNR changed %x->%x\n",
913 1.7 chopps sc->sc_dev.dv_xname, active_pnr, smc->b2.pnr);
914 1.1 chopps #if NBPFILTER > 0
915 1.3 mycroft if (sc->sc_arpcom.ac_if.if_bpf)
916 1.3 mycroft bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m0);
917 1.1 chopps #endif
918 1.1 chopps m_freem(m0);
919 1.3 mycroft sc->sc_arpcom.ac_if.if_opackets++; /* move to interrupt? */
920 1.2 chopps sc->sc_intctl |= MSK_TX_EMPTY | MSK_TX;
921 1.1 chopps }
922 1.1 chopps smc->b2.msk = sc->sc_intctl;
923 1.7 chopps #ifdef ESDEBUG
924 1.7 chopps while ((smc->b2.bsr & 0x0300) != BSR_BANK2) {
925 1.7 chopps printf("%s: esstart++++ BSR not 2: %04x\n", sc->sc_dev.dv_xname,
926 1.7 chopps smc->b2.bsr);
927 1.7 chopps smc->b2.bsr = BSR_BANK2;
928 1.7 chopps }
929 1.7 chopps if (--sc->sc_smcbusy) {
930 1.7 chopps printf("%s: esstart busy on exit\n", sc->sc_dev.dv_xname);
931 1.7 chopps panic("esstart busy on exit");
932 1.7 chopps }
933 1.7 chopps #endif
934 1.1 chopps }
935 1.1 chopps
936 1.1 chopps int
937 1.3 mycroft esioctl(ifp, command, data)
938 1.3 mycroft register struct ifnet *ifp;
939 1.3 mycroft u_long command;
940 1.1 chopps caddr_t data;
941 1.1 chopps {
942 1.9 thorpej struct es_softc *sc = es_cd.cd_devs[ifp->if_unit];
943 1.3 mycroft register struct ifaddr *ifa = (struct ifaddr *)data;
944 1.1 chopps struct ifreq *ifr = (struct ifreq *)data;
945 1.1 chopps int s, error = 0;
946 1.1 chopps
947 1.8 mycroft s = splnet();
948 1.1 chopps
949 1.3 mycroft switch (command) {
950 1.1 chopps
951 1.1 chopps case SIOCSIFADDR:
952 1.1 chopps ifp->if_flags |= IFF_UP;
953 1.1 chopps
954 1.1 chopps switch (ifa->ifa_addr->sa_family) {
955 1.1 chopps #ifdef INET
956 1.1 chopps case AF_INET:
957 1.1 chopps esinit(sc);
958 1.3 mycroft arp_ifinit(&sc->sc_arpcom, ifa);
959 1.1 chopps break;
960 1.1 chopps #endif
961 1.1 chopps #ifdef NS
962 1.1 chopps case AF_NS:
963 1.1 chopps {
964 1.1 chopps register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
965 1.1 chopps
966 1.1 chopps if (ns_nullhost(*ina))
967 1.1 chopps ina->x_host =
968 1.3 mycroft *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
969 1.1 chopps else
970 1.1 chopps bcopy(ina->x_host.c_host,
971 1.3 mycroft sc->sc_arpcom.ac_enaddr,
972 1.3 mycroft sizeof(sc->sc_arpcom.ac_enaddr));
973 1.3 mycroft /* Set new address. */
974 1.1 chopps esinit(sc);
975 1.1 chopps break;
976 1.11 veego }
977 1.1 chopps #endif
978 1.1 chopps default:
979 1.1 chopps esinit(sc);
980 1.1 chopps break;
981 1.1 chopps }
982 1.1 chopps break;
983 1.3 mycroft
984 1.1 chopps case SIOCSIFFLAGS:
985 1.1 chopps /*
986 1.1 chopps * If interface is marked down and it is running, then stop it
987 1.1 chopps */
988 1.1 chopps if ((ifp->if_flags & IFF_UP) == 0 &&
989 1.1 chopps (ifp->if_flags & IFF_RUNNING) != 0) {
990 1.1 chopps /*
991 1.1 chopps * If interface is marked down and it is running, then
992 1.1 chopps * stop it.
993 1.1 chopps */
994 1.3 mycroft esstop(sc);
995 1.1 chopps ifp->if_flags &= ~IFF_RUNNING;
996 1.1 chopps } else if ((ifp->if_flags & IFF_UP) != 0 &&
997 1.1 chopps (ifp->if_flags & IFF_RUNNING) == 0) {
998 1.1 chopps /*
999 1.1 chopps * If interface is marked up and it is stopped, then
1000 1.1 chopps * start it.
1001 1.1 chopps */
1002 1.1 chopps esinit(sc);
1003 1.1 chopps } else {
1004 1.1 chopps /*
1005 1.1 chopps * Reset the interface to pick up changes in any other
1006 1.1 chopps * flags that affect hardware registers.
1007 1.1 chopps */
1008 1.3 mycroft esstop(sc);
1009 1.1 chopps esinit(sc);
1010 1.1 chopps }
1011 1.1 chopps #ifdef ESDEBUG
1012 1.1 chopps if (ifp->if_flags & IFF_DEBUG)
1013 1.1 chopps esdebug = sc->sc_debug = 1;
1014 1.1 chopps else
1015 1.1 chopps esdebug = sc->sc_debug = 0;
1016 1.1 chopps #endif
1017 1.7 chopps break;
1018 1.7 chopps
1019 1.7 chopps case SIOCADDMULTI:
1020 1.7 chopps case SIOCDELMULTI:
1021 1.7 chopps error = (command == SIOCADDMULTI) ?
1022 1.7 chopps ether_addmulti(ifr, &sc->sc_arpcom) :
1023 1.7 chopps ether_delmulti(ifr, &sc->sc_arpcom);
1024 1.7 chopps
1025 1.7 chopps if (error == ENETRESET) {
1026 1.7 chopps /*
1027 1.7 chopps * Multicast list has changed; set the hardware filter
1028 1.7 chopps * accordingly.
1029 1.7 chopps */
1030 1.7 chopps /* XXX */
1031 1.7 chopps error = 0;
1032 1.7 chopps }
1033 1.1 chopps break;
1034 1.1 chopps
1035 1.1 chopps default:
1036 1.1 chopps error = EINVAL;
1037 1.1 chopps }
1038 1.1 chopps
1039 1.1 chopps splx(s);
1040 1.1 chopps return (error);
1041 1.1 chopps }
1042 1.1 chopps
1043 1.1 chopps void
1044 1.1 chopps esreset(sc)
1045 1.1 chopps struct es_softc *sc;
1046 1.1 chopps {
1047 1.1 chopps int s;
1048 1.1 chopps
1049 1.8 mycroft s = splnet();
1050 1.3 mycroft esstop(sc);
1051 1.1 chopps esinit(sc);
1052 1.1 chopps splx(s);
1053 1.1 chopps }
1054 1.1 chopps
1055 1.3 mycroft void
1056 1.1 chopps eswatchdog(unit)
1057 1.1 chopps int unit;
1058 1.1 chopps {
1059 1.9 thorpej struct es_softc *sc = es_cd.cd_devs[unit];
1060 1.1 chopps
1061 1.1 chopps log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
1062 1.3 mycroft ++sc->sc_arpcom.ac_if.if_oerrors;
1063 1.3 mycroft
1064 1.1 chopps esreset(sc);
1065 1.1 chopps }
1066