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