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