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