smc90cx6.c revision 1.17 1 1.17 thorpej /* $NetBSD: smc90cx6.c,v 1.17 1996/05/07 01:43:18 thorpej Exp $ */
2 1.2 chopps
3 1.1 chopps /*
4 1.1 chopps * Copyright (c) 1994, 1995 Ignatios Souvatzis
5 1.1 chopps * All rights reserved.
6 1.1 chopps *
7 1.1 chopps * Redistribution and use in source and binary forms, with or without
8 1.1 chopps * modification, are permitted provided that the following conditions
9 1.1 chopps * are met:
10 1.1 chopps * 1. Redistributions of source code must retain the above copyright
11 1.1 chopps * notice, this list of conditions and the following disclaimer.
12 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chopps * notice, this list of conditions and the following disclaimer in the
14 1.1 chopps * documentation and/or other materials provided with the distribution.
15 1.1 chopps * 3. All advertising materials mentioning features or use of this software
16 1.1 chopps * must display the following acknowledgement:
17 1.6 chopps * This product includes software developed by Ignatios Souvatzis
18 1.7 cgd * for the NetBSD Project.
19 1.1 chopps * 4. The name of the author may not be used to endorse or promote products
20 1.1 chopps * derived from this software without specific prior written permission
21 1.1 chopps *
22 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 chopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 chopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 chopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 chopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 chopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 chopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 chopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 chopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 chopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 chopps */
33 1.1 chopps
34 1.1 chopps /*
35 1.7 cgd * Driver for the Commodore Busines Machines ARCnet card.
36 1.1 chopps */
37 1.1 chopps
38 1.1 chopps #define BAHASMCOPY /**/
39 1.1 chopps #define BAHSOFTCOPY /**/
40 1.14 chopps #define BAHRETRANSMIT /**/
41 1.14 chopps /* #define BAHTIMINGS */
42 1.14 chopps /* #define BAH_DEBUG 3 */
43 1.1 chopps
44 1.16 is /* zeroth version of M68060 support */
45 1.16 is
46 1.16 is #if defined(M68060) && defined(BAHASMCOPY)
47 1.16 is #undef BAHASMCOPY
48 1.16 is #endif
49 1.16 is
50 1.1 chopps #include "bpfilter.h"
51 1.1 chopps
52 1.1 chopps #include <sys/param.h>
53 1.1 chopps #include <sys/systm.h>
54 1.1 chopps #include <sys/mbuf.h>
55 1.1 chopps #include <sys/buf.h>
56 1.1 chopps #include <sys/device.h>
57 1.1 chopps #include <sys/protosw.h>
58 1.1 chopps #include <sys/socket.h>
59 1.1 chopps #include <sys/syslog.h>
60 1.1 chopps #include <sys/ioctl.h>
61 1.1 chopps #include <sys/errno.h>
62 1.1 chopps
63 1.1 chopps #include <net/if.h>
64 1.1 chopps #include <net/if_dl.h>
65 1.1 chopps #include <net/if_types.h>
66 1.1 chopps #include <net/netisr.h>
67 1.1 chopps
68 1.1 chopps #ifdef INET
69 1.1 chopps #include <netinet/in.h>
70 1.1 chopps #include <netinet/in_systm.h>
71 1.1 chopps #include <netinet/in_var.h>
72 1.1 chopps #include <netinet/ip.h>
73 1.1 chopps #include <netinet/if_ether.h>
74 1.1 chopps #include <netinet/if_arc.h>
75 1.1 chopps #endif
76 1.1 chopps
77 1.1 chopps #if NBPFILTER > 0
78 1.1 chopps #include <net/bpf.h>
79 1.1 chopps #include <net/bpfdesc.h>
80 1.1 chopps #endif
81 1.1 chopps
82 1.1 chopps #include <sys/kernel.h>
83 1.1 chopps #include <machine/cpu.h>
84 1.1 chopps #include <machine/mtpr.h>
85 1.1 chopps
86 1.1 chopps #include <amiga/amiga/device.h>
87 1.1 chopps #include <amiga/amiga/isr.h>
88 1.1 chopps #include <amiga/dev/zbusvar.h>
89 1.1 chopps #include <amiga/dev/if_bahreg.h>
90 1.1 chopps
91 1.1 chopps /* these should be elsewhere */
92 1.1 chopps
93 1.1 chopps #define ARC_MIN_LEN 1
94 1.1 chopps #define ARC_MIN_FORBID_LEN 254
95 1.1 chopps #define ARC_MAX_FORBID_LEN 256
96 1.1 chopps #define ARC_MAX_LEN 508
97 1.1 chopps #define ARC_ADDR_LEN 1
98 1.1 chopps
99 1.6 chopps /* for watchdog timer. This should be more than enough. */
100 1.6 chopps #define ARCTIMEOUT (5*IFNET_SLOWHZ)
101 1.6 chopps
102 1.1 chopps /*
103 1.1 chopps * This currently uses 2 bufs for tx, 2 for rx
104 1.1 chopps *
105 1.1 chopps * New rx protocol:
106 1.1 chopps *
107 1.1 chopps * rx has a fillcount variable. If fillcount > (NRXBUF-1),
108 1.1 chopps * rx can be switched off from rx hard int.
109 1.1 chopps * Else rx is restarted on the other receiver.
110 1.1 chopps * rx soft int counts down. if it is == (NRXBUF-1), it restarts
111 1.1 chopps * the receiver.
112 1.1 chopps * To ensure packet ordering (we need that for 1201 later), we have a counter
113 1.1 chopps * which is incremented modulo 256 on each receive and a per buffer
114 1.1 chopps * variable, which is set to the counter on filling. The soft int can
115 1.1 chopps * compare both values to determine the older packet.
116 1.1 chopps *
117 1.1 chopps * Transmit direction:
118 1.1 chopps *
119 1.1 chopps * bah_start checks tx_fillcount
120 1.1 chopps * case 2: return
121 1.1 chopps *
122 1.1 chopps * else fill tx_act ^ 1 && inc tx_fillcount
123 1.1 chopps *
124 1.1 chopps * check tx_fillcount again.
125 1.1 chopps * case 2: set IFF_OACTIVE to stop arc_output from filling us.
126 1.1 chopps * case 1: start tx
127 1.1 chopps *
128 1.1 chopps * tint clears IFF_OCATIVE, decrements and checks tx_fillcount
129 1.1 chopps * case 1: start tx on tx_act ^ 1, softcall bah_start
130 1.1 chopps * case 0: softcall bah_start
131 1.1 chopps *
132 1.1 chopps * #define fill(i) get mbuf && copy mbuf to chip(i)
133 1.1 chopps */
134 1.1 chopps
135 1.7 cgd #ifdef BAHTIMINGS
136 1.7 cgd /*
137 1.7 cgd * ARCnet stats; per interface.
138 1.7 cgd */
139 1.7 cgd struct bah_stats {
140 1.7 cgd u_long mincopyin;
141 1.7 cgd u_long maxcopyin; /* divided by byte count */
142 1.7 cgd u_long mincopyout;
143 1.7 cgd u_long maxcopyout;
144 1.7 cgd u_long minsend;
145 1.7 cgd u_long maxsend;
146 1.7 cgd u_long lasttxstart_mics;
147 1.7 cgd struct timeval lasttxstart_tv;
148 1.7 cgd };
149 1.7 cgd
150 1.7 cgd #error BAHTIMINGS CODE IS BROKEN; use of clkread() is bogus
151 1.7 cgd #endif
152 1.7 cgd
153 1.1 chopps /*
154 1.1 chopps * Arcnet software status per interface
155 1.1 chopps */
156 1.1 chopps struct bah_softc {
157 1.3 chopps struct device sc_dev;
158 1.3 chopps struct arccom sc_arccom; /* Common arcnet structures */
159 1.3 chopps struct isr sc_isr;
160 1.3 chopps struct a2060 *sc_base;
161 1.1 chopps u_long sc_recontime; /* seconds only, I'm lazy */
162 1.1 chopps u_long sc_reconcount; /* for the above */
163 1.1 chopps u_long sc_reconcount_excessive; /* for the above */
164 1.1 chopps #define ARC_EXCESSIVE_RECONS 20
165 1.1 chopps #define ARC_EXCESSIVE_RECONS_REWARN 400
166 1.1 chopps u_char sc_intmask;
167 1.3 chopps u_char sc_rx_act; /* 2..3 */
168 1.3 chopps u_char sc_tx_act; /* 0..1 */
169 1.3 chopps u_char sc_rx_fillcount;
170 1.3 chopps u_char sc_tx_fillcount;
171 1.1 chopps u_char sc_broadcast[2]; /* is it a broadcast packet? */
172 1.1 chopps u_char sc_retransmits[2]; /* unused at the moment */
173 1.1 chopps #ifdef BAHTIMINGS
174 1.7 cgd struct bah_stats sc_stats;
175 1.1 chopps #endif
176 1.1 chopps };
177 1.1 chopps
178 1.15 thorpej int bah_zbus_match __P((struct device *, void *, void *));
179 1.15 thorpej void bah_zbus_attach __P((struct device *, struct device *, void *));
180 1.8 cgd void bah_init __P((struct bah_softc *));
181 1.7 cgd void bah_reset __P((struct bah_softc *));
182 1.7 cgd void bah_stop __P((struct bah_softc *));
183 1.7 cgd void bah_start __P((struct ifnet *));
184 1.7 cgd int bahintr __P((struct bah_softc *sc));
185 1.7 cgd int bah_ioctl __P((struct ifnet *, unsigned long, caddr_t));
186 1.17 thorpej void bah_watchdog __P((struct ifnet *));
187 1.7 cgd void movepout __P((u_char *from, u_char __volatile *to, int len));
188 1.7 cgd void movepin __P((u_char __volatile *from, u_char *to, int len));
189 1.14 chopps void bah_srint __P((void *vsc, void *dummy));
190 1.14 chopps void callstart __P((void *vsc, void *dummy));
191 1.1 chopps
192 1.1 chopps #ifdef BAHTIMINGS
193 1.7 cgd int clkread();
194 1.1 chopps #endif
195 1.1 chopps
196 1.15 thorpej struct cfattach bah_zbus_ca = {
197 1.15 thorpej sizeof(struct bah_softc), bah_zbus_match, bah_zbus_attach
198 1.15 thorpej };
199 1.15 thorpej
200 1.15 thorpej struct cfdriver bah_cd = {
201 1.15 thorpej NULL, "bah", DV_IFNET
202 1.1 chopps };
203 1.1 chopps
204 1.1 chopps int
205 1.15 thorpej bah_zbus_match(parent, match, aux)
206 1.4 mycroft struct device *parent;
207 1.4 mycroft void *match, *aux;
208 1.1 chopps {
209 1.4 mycroft struct zbus_args *zap = aux;
210 1.1 chopps
211 1.1 chopps if ((zap->manid == 514 || zap->manid == 1053) && zap->prodid == 9)
212 1.1 chopps return (1);
213 1.4 mycroft
214 1.1 chopps return (0);
215 1.1 chopps }
216 1.1 chopps
217 1.1 chopps void
218 1.15 thorpej bah_zbus_attach(parent, self, aux)
219 1.4 mycroft struct device *parent, *self;
220 1.4 mycroft void *aux;
221 1.1 chopps {
222 1.4 mycroft struct bah_softc *sc = (void *)self;
223 1.4 mycroft struct zbus_args *zap = aux;
224 1.4 mycroft struct ifnet *ifp = &sc->sc_arccom.ac_if;
225 1.14 chopps int s, linkaddress;
226 1.1 chopps
227 1.1 chopps #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2))
228 1.4 mycroft printf("\n%s: attach(0x%x, 0x%x, 0x%x)\n",
229 1.4 mycroft sc->sc_dev.dv_xname, parent, self, aux);
230 1.1 chopps #endif
231 1.1 chopps s = splhigh();
232 1.1 chopps sc->sc_base = zap->va;
233 1.1 chopps
234 1.1 chopps /*
235 1.1 chopps * read the arcnet address from the board
236 1.1 chopps */
237 1.1 chopps
238 1.1 chopps sc->sc_base->kick1 = 0x0;
239 1.1 chopps sc->sc_base->kick2 = 0x0;
240 1.14 chopps DELAY(200);
241 1.1 chopps
242 1.1 chopps sc->sc_base->kick1 = 0xFF;
243 1.1 chopps sc->sc_base->kick2 = 0xFF;
244 1.1 chopps do {
245 1.14 chopps DELAY(200);
246 1.1 chopps } while (!(sc->sc_base->status & ARC_POR));
247 1.1 chopps
248 1.1 chopps linkaddress = sc->sc_base->dipswitches;
249 1.1 chopps
250 1.1 chopps #ifdef BAHTIMINGS
251 1.1 chopps printf(": link addr 0x%02x(%ld), with timer\n",
252 1.1 chopps linkaddress, linkaddress);
253 1.1 chopps #else
254 1.1 chopps printf(": link addr 0x%02x(%ld)\n", linkaddress, linkaddress);
255 1.1 chopps #endif
256 1.1 chopps
257 1.6 chopps sc->sc_arccom.ac_anaddr = linkaddress;
258 1.1 chopps
259 1.1 chopps /* clear the int mask... */
260 1.1 chopps
261 1.3 chopps sc->sc_base->status = sc->sc_intmask = 0;
262 1.1 chopps
263 1.1 chopps sc->sc_base->command = ARC_CONF(CONF_LONG);
264 1.1 chopps sc->sc_base->command = ARC_CLR(CLR_POR|CLR_RECONFIG);
265 1.3 chopps sc->sc_recontime = sc->sc_reconcount = 0;
266 1.1 chopps
267 1.1 chopps /* and reenable kernel int level */
268 1.1 chopps splx(s);
269 1.1 chopps
270 1.1 chopps /*
271 1.1 chopps * set interface to stopped condition (reset)
272 1.1 chopps */
273 1.1 chopps bah_stop(sc);
274 1.1 chopps
275 1.17 thorpej bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
276 1.17 thorpej ifp->if_softc = sc;
277 1.1 chopps ifp->if_output = arc_output;
278 1.1 chopps ifp->if_start = bah_start;
279 1.1 chopps ifp->if_ioctl = bah_ioctl;
280 1.6 chopps ifp->if_timer = 0;
281 1.6 chopps ifp->if_watchdog = bah_watchdog;
282 1.6 chopps
283 1.6 chopps ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX |
284 1.6 chopps IFF_NOTRAILERS | IFF_NOARP;
285 1.6 chopps
286 1.6 chopps ifp->if_mtu = ARCMTU;
287 1.1 chopps
288 1.4 mycroft if_attach(ifp);
289 1.4 mycroft arc_ifattach(ifp);
290 1.1 chopps
291 1.1 chopps #if NBPFILTER > 0
292 1.4 mycroft bpfattach(&ifp->if_bpf, ifp, DLT_ARCNET, ARC_HDRLEN);
293 1.1 chopps #endif
294 1.11 chopps /* under heavy load we need four of them: */
295 1.11 chopps alloc_sicallback();
296 1.11 chopps alloc_sicallback();
297 1.11 chopps alloc_sicallback();
298 1.11 chopps alloc_sicallback();
299 1.11 chopps
300 1.1 chopps sc->sc_isr.isr_intr = bahintr;
301 1.1 chopps sc->sc_isr.isr_arg = sc;
302 1.1 chopps sc->sc_isr.isr_ipl = 2;
303 1.1 chopps add_isr(&sc->sc_isr);
304 1.1 chopps }
305 1.1 chopps
306 1.1 chopps /*
307 1.1 chopps * Initialize device
308 1.1 chopps *
309 1.1 chopps */
310 1.1 chopps void
311 1.1 chopps bah_init(sc)
312 1.1 chopps struct bah_softc *sc;
313 1.1 chopps {
314 1.3 chopps struct ifnet *ifp;
315 1.1 chopps int s;
316 1.3 chopps
317 1.3 chopps ifp = &sc->sc_arccom.ac_if;
318 1.1 chopps
319 1.1 chopps if ((ifp->if_flags & IFF_RUNNING) == 0) {
320 1.13 mycroft s = splnet();
321 1.1 chopps ifp->if_flags |= IFF_RUNNING;
322 1.1 chopps bah_reset(sc);
323 1.4 mycroft bah_start(ifp);
324 1.1 chopps splx(s);
325 1.1 chopps }
326 1.1 chopps }
327 1.1 chopps
328 1.1 chopps /*
329 1.1 chopps * Reset the interface...
330 1.1 chopps *
331 1.1 chopps * this assumes that it is called inside a critical section...
332 1.1 chopps *
333 1.1 chopps */
334 1.1 chopps void
335 1.1 chopps bah_reset(sc)
336 1.1 chopps struct bah_softc *sc;
337 1.1 chopps {
338 1.3 chopps struct ifnet *ifp;
339 1.14 chopps int linkaddress;
340 1.1 chopps
341 1.1 chopps ifp = &sc->sc_arccom.ac_if;
342 1.1 chopps
343 1.1 chopps #ifdef BAH_DEBUG
344 1.4 mycroft printf("%s: reset\n", sc->sc_dev.dv_xname);
345 1.1 chopps #endif
346 1.1 chopps /* stop hardware in case it still runs */
347 1.1 chopps
348 1.1 chopps sc->sc_base->kick1 = 0;
349 1.1 chopps sc->sc_base->kick2 = 0;
350 1.14 chopps DELAY(200);
351 1.1 chopps
352 1.1 chopps /* and restart it */
353 1.1 chopps sc->sc_base->kick1 = 0xFF;
354 1.1 chopps sc->sc_base->kick2 = 0xFF;
355 1.1 chopps
356 1.1 chopps do {
357 1.14 chopps DELAY(200);
358 1.1 chopps } while (!(sc->sc_base->status & ARC_POR));
359 1.1 chopps
360 1.6 chopps linkaddress = sc->sc_base->dipswitches;
361 1.6 chopps
362 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
363 1.17 thorpej printf("%s: reset: card reset, link addr = 0x%02x (%ld)\n",
364 1.17 thorpej sc->sc_dev.dv_xname, linkaddress, linkaddress);
365 1.1 chopps #endif
366 1.6 chopps sc->sc_arccom.ac_anaddr = linkaddress;
367 1.6 chopps
368 1.6 chopps /* tell the routing level about the (possibly changed) link address */
369 1.6 chopps arc_ifattach(ifp);
370 1.6 chopps
371 1.1 chopps /* POR is NMI, but we need it below: */
372 1.1 chopps sc->sc_intmask = ARC_RECON|ARC_POR;
373 1.1 chopps sc->sc_base->status = sc->sc_intmask;
374 1.1 chopps sc->sc_base->command = ARC_CONF(CONF_LONG);
375 1.1 chopps
376 1.1 chopps #ifdef BAH_DEBUG
377 1.4 mycroft printf("%s: reset: chip configured, status=0x%02x\n",
378 1.4 mycroft sc->sc_dev.dv_xname, sc->sc_base->status);
379 1.1 chopps #endif
380 1.1 chopps
381 1.1 chopps sc->sc_base->command = ARC_CLR(CLR_POR|CLR_RECONFIG);
382 1.1 chopps
383 1.1 chopps #ifdef BAH_DEBUG
384 1.4 mycroft printf("%s: reset: bits cleared, status=0x%02x\n",
385 1.4 mycroft sc->sc_dev.dv_xname, sc->sc_base->status);
386 1.1 chopps #endif
387 1.1 chopps
388 1.1 chopps sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS;
389 1.1 chopps
390 1.1 chopps /* start receiver */
391 1.1 chopps
392 1.1 chopps sc->sc_intmask |= ARC_RI;
393 1.14 chopps sc->sc_rx_fillcount = 0;
394 1.1 chopps sc->sc_rx_act = 2;
395 1.1 chopps
396 1.1 chopps sc->sc_base->command = ARC_RXBC(2);
397 1.1 chopps sc->sc_base->status = sc->sc_intmask;
398 1.1 chopps
399 1.1 chopps #ifdef BAH_DEBUG
400 1.4 mycroft printf("%s: reset: started receiver, status=0x%02x\n",
401 1.4 mycroft sc->sc_dev.dv_xname, sc->sc_base->status);
402 1.1 chopps #endif
403 1.1 chopps
404 1.1 chopps /* and init transmitter status */
405 1.1 chopps sc->sc_tx_act = 0;
406 1.1 chopps sc->sc_tx_fillcount = 0;
407 1.1 chopps
408 1.1 chopps ifp->if_flags |= IFF_RUNNING;
409 1.1 chopps ifp->if_flags &= ~IFF_OACTIVE;
410 1.1 chopps
411 1.1 chopps #ifdef BAHTIMINGS
412 1.7 cgd bzero((caddr_t)&(sc->sc_stats), sizeof(sc->sc_stats));
413 1.1 chopps sc->sc_stats.mincopyin =
414 1.1 chopps sc->sc_stats.mincopyout =
415 1.7 cgd sc->sc_stats.minsend = ULONG_MAX;
416 1.1 chopps #endif
417 1.1 chopps
418 1.1 chopps bah_start(ifp);
419 1.1 chopps }
420 1.1 chopps
421 1.1 chopps /*
422 1.1 chopps * Take interface offline
423 1.1 chopps */
424 1.1 chopps void
425 1.1 chopps bah_stop(sc)
426 1.1 chopps struct bah_softc *sc;
427 1.1 chopps {
428 1.1 chopps /* Stop the interrupts */
429 1.1 chopps sc->sc_base->status = 0;
430 1.1 chopps
431 1.1 chopps /* Stop the interface */
432 1.1 chopps sc->sc_base->kick1 = 0;
433 1.1 chopps sc->sc_base->kick2 = 0;
434 1.1 chopps
435 1.6 chopps /* Stop watchdog timer */
436 1.6 chopps sc->sc_arccom.ac_if.if_timer = 0;
437 1.6 chopps
438 1.1 chopps #ifdef BAHTIMINGS
439 1.7 cgd log(LOG_DEBUG,"%s: to board: %6lu .. %6lu ns/byte\n",
440 1.4 mycroft sc->sc_dev.dv_xname,
441 1.7 cgd sc->sc_stats.mincopyout, sc->sc_stats.maxcopyout);
442 1.7 cgd
443 1.7 cgd log(LOG_DEBUG,"%s: from board: %6lu .. %6lu ns/byte\n",
444 1.7 cgd sc->sc_dev.dv_xname,
445 1.7 cgd sc->sc_stats.mincopyin, sc->sc_stats.maxcopyin);
446 1.7 cgd
447 1.7 cgd log(LOG_DEBUG,"%s: send time: %6lu .. %6lu mics/byte\n",
448 1.7 cgd sc->sc_dev.dv_xname,
449 1.7 cgd sc->sc_stats.minsend, sc->sc_stats.maxsend);
450 1.1 chopps
451 1.1 chopps sc->sc_stats.minsend =
452 1.1 chopps sc->sc_stats.mincopyout =
453 1.7 cgd sc->sc_stats.mincopyin = ULONG_MAX;
454 1.1 chopps sc->sc_stats.maxsend =
455 1.1 chopps sc->sc_stats.maxcopyout =
456 1.7 cgd sc->sc_stats.maxcopyin = 0;
457 1.1 chopps #endif
458 1.1 chopps }
459 1.1 chopps
460 1.7 cgd __inline void
461 1.7 cgd movepout(from, to, len)
462 1.1 chopps u_char *from;
463 1.7 cgd __volatile u_char *to;
464 1.1 chopps int len;
465 1.1 chopps {
466 1.1 chopps #ifdef BAHASMCOPY
467 1.1 chopps u_short shortd;
468 1.7 cgd u_long longd, longd1, longd2, longd3, longd4;
469 1.1 chopps
470 1.7 cgd if ((len > 3) && ((long)from) & 3) {
471 1.7 cgd switch (((long)from) & 3) {
472 1.1 chopps case 3:
473 1.1 chopps *to = *from++;
474 1.7 cgd to += 2; --len;
475 1.1 chopps break;
476 1.1 chopps case 1:
477 1.1 chopps *to = *from++;
478 1.1 chopps to += 2; --len;
479 1.1 chopps case 2:
480 1.1 chopps shortd = *((u_short *)from)++;
481 1.1 chopps asm("movepw %0,%1@(0)" : : "d"(shortd), "a"(to));
482 1.1 chopps to += 4; len -= 2;
483 1.1 chopps break;
484 1.1 chopps default:
485 1.1 chopps }
486 1.1 chopps
487 1.7 cgd while (len >= 32) {
488 1.1 chopps longd1 = *((u_long *)from)++;
489 1.1 chopps longd2 = *((u_long *)from)++;
490 1.1 chopps longd3 = *((u_long *)from)++;
491 1.1 chopps longd4 = *((u_long *)from)++;
492 1.1 chopps asm("movepl %0,%1@(0)" : : "d"(longd1), "a"(to));
493 1.1 chopps asm("movepl %0,%1@(8)" : : "d"(longd2), "a"(to));
494 1.1 chopps asm("movepl %0,%1@(16)" : : "d"(longd3), "a"(to));
495 1.1 chopps asm("movepl %0,%1@(24)" : : "d"(longd4), "a"(to));
496 1.1 chopps
497 1.1 chopps longd1 = *((u_long *)from)++;
498 1.1 chopps longd2 = *((u_long *)from)++;
499 1.1 chopps longd3 = *((u_long *)from)++;
500 1.1 chopps longd4 = *((u_long *)from)++;
501 1.1 chopps asm("movepl %0,%1@(32)" : : "d"(longd1), "a"(to));
502 1.1 chopps asm("movepl %0,%1@(40)" : : "d"(longd2), "a"(to));
503 1.1 chopps asm("movepl %0,%1@(48)" : : "d"(longd3), "a"(to));
504 1.1 chopps asm("movepl %0,%1@(56)" : : "d"(longd4), "a"(to));
505 1.1 chopps
506 1.1 chopps to += 64; len -= 32;
507 1.1 chopps }
508 1.7 cgd while (len > 0) {
509 1.1 chopps longd = *((u_long *)from)++;
510 1.1 chopps asm("movepl %0,%1@(0)" : : "d"(longd), "a"(to));
511 1.1 chopps to += 8; len -= 4;
512 1.1 chopps }
513 1.1 chopps }
514 1.1 chopps #endif
515 1.7 cgd while (len > 0) {
516 1.1 chopps *to = *from++;
517 1.7 cgd to += 2;
518 1.1 chopps --len;
519 1.1 chopps }
520 1.1 chopps }
521 1.1 chopps
522 1.1 chopps /*
523 1.1 chopps * Start output on interface. Get another datagram to send
524 1.1 chopps * off the interface queue, and copy it to the
525 1.1 chopps * interface becore starting the output
526 1.1 chopps *
527 1.1 chopps * this assumes that it is called inside a critical section...
528 1.1 chopps * XXX hm... does it still?
529 1.1 chopps *
530 1.1 chopps */
531 1.4 mycroft void
532 1.1 chopps bah_start(ifp)
533 1.1 chopps struct ifnet *ifp;
534 1.1 chopps {
535 1.1 chopps struct bah_softc *sc;
536 1.1 chopps struct mbuf *m,*mp;
537 1.7 cgd __volatile u_char *bah_ram_ptr;
538 1.14 chopps int len, tlen, offset, s, buffer;
539 1.1 chopps #ifdef BAHTIMINGS
540 1.7 cgd u_long copystart, lencopy, perbyte;
541 1.1 chopps #endif
542 1.1 chopps
543 1.17 thorpej sc = ifp->if_softc;
544 1.1 chopps
545 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 3)
546 1.4 mycroft printf("%s: start(0x%x)\n", sc->sc_dev.dv_xname, ifp);
547 1.1 chopps #endif
548 1.1 chopps
549 1.4 mycroft if ((ifp->if_flags & IFF_RUNNING) == 0)
550 1.5 chopps return;
551 1.1 chopps
552 1.13 mycroft s = splnet();
553 1.1 chopps
554 1.1 chopps if (sc->sc_tx_fillcount >= 2) {
555 1.1 chopps splx(s);
556 1.5 chopps return;
557 1.1 chopps }
558 1.1 chopps
559 1.1 chopps IF_DEQUEUE(&ifp->if_snd, m);
560 1.1 chopps buffer = sc->sc_tx_act ^ 1;
561 1.1 chopps
562 1.1 chopps splx(s);
563 1.1 chopps
564 1.1 chopps if (m == 0)
565 1.5 chopps return;
566 1.1 chopps
567 1.1 chopps #if NBPFILTER > 0
568 1.1 chopps /*
569 1.1 chopps * If bpf is listening on this interface, let it
570 1.1 chopps * see the packet before we commit it to the wire
571 1.1 chopps *
572 1.1 chopps * (can't give the copy in A2060 card RAM to bpf, because
573 1.1 chopps * that RAM is just accessed as on every other byte)
574 1.1 chopps */
575 1.4 mycroft if (ifp->if_bpf)
576 1.4 mycroft bpf_mtap(ifp->if_bpf, m);
577 1.4 mycroft #endif
578 1.1 chopps
579 1.1 chopps #ifdef BAH_DEBUG
580 1.1 chopps m = m_pullup(m,3); /* gcc does structure padding */
581 1.4 mycroft printf("%s: start: filling %ld from %ld to %ld type %ld\n",
582 1.7 cgd sc->sc_dev.dv_xname, buffer, mtod(m, u_char *)[0],
583 1.7 cgd mtod(m, u_char *)[1], mtod(m, u_char *)[2]);
584 1.1 chopps #else
585 1.7 cgd m = m_pullup(m, 2);
586 1.1 chopps #endif
587 1.1 chopps bah_ram_ptr = sc->sc_base->buffers + buffer*512*2;
588 1.1 chopps
589 1.1 chopps /* write the addresses to RAM and throw them away */
590 1.1 chopps
591 1.1 chopps /*
592 1.1 chopps * Hardware does this: Yet Another Microsecond Saved.
593 1.1 chopps * (btw, timing code says usually 2 microseconds)
594 1.1 chopps * bah_ram_ptr[0*2] = mtod(m, u_char *)[0];
595 1.1 chopps */
596 1.7 cgd bah_ram_ptr[1 * 2] = mtod(m, u_char *)[1];
597 1.4 mycroft m_adj(m, 2);
598 1.1 chopps
599 1.14 chopps /* get total length left at this point */
600 1.14 chopps tlen = m->m_pkthdr.len;
601 1.3 chopps if (tlen < ARC_MIN_FORBID_LEN) {
602 1.7 cgd offset = 256 - tlen;
603 1.7 cgd bah_ram_ptr[2 * 2] = offset;
604 1.3 chopps } else {
605 1.14 chopps bah_ram_ptr[2 * 2] = 0;
606 1.14 chopps if (tlen <= ARC_MAX_FORBID_LEN)
607 1.14 chopps offset = 255; /* !!! */
608 1.1 chopps else {
609 1.1 chopps if (tlen > ARC_MAX_LEN)
610 1.1 chopps tlen = ARC_MAX_LEN;
611 1.7 cgd offset = 512 - tlen;
612 1.1 chopps }
613 1.14 chopps bah_ram_ptr[3 * 2] = offset;
614 1.1 chopps
615 1.1 chopps }
616 1.7 cgd bah_ram_ptr += offset * 2;
617 1.1 chopps
618 1.14 chopps /* lets loop through the mbuf chain */
619 1.1 chopps
620 1.7 cgd for (mp = m; mp; mp = mp->m_next) {
621 1.14 chopps if ((len = mp->m_len)) { /* YAMS */
622 1.1 chopps #ifdef BAHTIMINGS
623 1.1 chopps lencopy = len;
624 1.1 chopps copystart = clkread();
625 1.1 chopps #endif
626 1.7 cgd movepout(mtod(mp, caddr_t), bah_ram_ptr, len);
627 1.1 chopps
628 1.1 chopps #ifdef BAHTIMINGS
629 1.7 cgd perbyte = 1000 * (clkread() - copystart) / lencopy;
630 1.1 chopps sc->sc_stats.mincopyout =
631 1.7 cgd ulmin(sc->sc_stats.mincopyout, perbyte);
632 1.1 chopps sc->sc_stats.maxcopyout =
633 1.7 cgd ulmax(sc->sc_stats.maxcopyout, perbyte);
634 1.1 chopps #endif
635 1.1 chopps bah_ram_ptr += len*2;
636 1.1 chopps }
637 1.1 chopps }
638 1.1 chopps
639 1.1 chopps sc->sc_broadcast[buffer] = (m->m_flags & M_BCAST) != 0;
640 1.4 mycroft sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5;
641 1.1 chopps
642 1.1 chopps /* actually transmit the packet */
643 1.13 mycroft s = splnet();
644 1.1 chopps
645 1.3 chopps if (++sc->sc_tx_fillcount > 1) {
646 1.3 chopps /*
647 1.3 chopps * We are filled up to the rim. No more bufs for the moment,
648 1.3 chopps * please.
649 1.3 chopps */
650 1.3 chopps ifp->if_flags |= IFF_OACTIVE;
651 1.3 chopps } else {
652 1.1 chopps #ifdef BAH_DEBUG
653 1.4 mycroft printf("%s: start: starting transmitter on buffer %d\n",
654 1.4 mycroft sc->sc_dev.dv_xname, buffer);
655 1.1 chopps #endif
656 1.1 chopps /* Transmitter was off, start it */
657 1.1 chopps sc->sc_tx_act = buffer;
658 1.1 chopps
659 1.1 chopps /*
660 1.1 chopps * We still can accept another buf, so don't:
661 1.1 chopps * ifp->if_flags |= IFF_OACTIVE;
662 1.1 chopps */
663 1.1 chopps sc->sc_intmask |= ARC_TA;
664 1.1 chopps sc->sc_base->command = ARC_TX(buffer);
665 1.1 chopps sc->sc_base->status = sc->sc_intmask;
666 1.1 chopps
667 1.6 chopps sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT;
668 1.1 chopps #ifdef BAHTIMINGS
669 1.1 chopps bcopy((caddr_t)&time,
670 1.1 chopps (caddr_t)&(sc->sc_stats.lasttxstart_tv),
671 1.1 chopps sizeof(struct timeval));
672 1.1 chopps
673 1.1 chopps sc->sc_stats.lasttxstart_mics = clkread();
674 1.1 chopps #endif
675 1.1 chopps }
676 1.1 chopps splx(s);
677 1.1 chopps m_freem(m);
678 1.1 chopps
679 1.1 chopps /*
680 1.6 chopps * After 10 times reading the docs, I realized
681 1.6 chopps * that in the case the receiver NAKs the buffer request,
682 1.1 chopps * the hardware retries till shutdown.
683 1.6 chopps * This is integrated now in the code above.
684 1.1 chopps */
685 1.6 chopps
686 1.6 chopps return;
687 1.1 chopps }
688 1.1 chopps
689 1.1 chopps void
690 1.14 chopps callstart(vsc, dummy)
691 1.14 chopps void *vsc, *dummy;
692 1.14 chopps {
693 1.1 chopps struct bah_softc *sc;
694 1.4 mycroft
695 1.14 chopps sc = (struct bah_softc *)vsc;
696 1.4 mycroft bah_start(&sc->sc_arccom.ac_if);
697 1.1 chopps }
698 1.1 chopps
699 1.7 cgd __inline void
700 1.7 cgd movepin(from, to, len)
701 1.7 cgd __volatile u_char *from;
702 1.1 chopps u_char *to;
703 1.1 chopps int len;
704 1.1 chopps {
705 1.1 chopps #ifdef BAHASMCOPY
706 1.1 chopps unsigned long longd, longd1, longd2, longd3, longd4;
707 1.1 chopps ushort shortd;
708 1.1 chopps
709 1.7 cgd if ((len > 3) && (((long)to) & 3)) {
710 1.7 cgd switch (((long)to) & 3) {
711 1.1 chopps case 3: *to++ = *from;
712 1.7 cgd from += 2; --len;
713 1.1 chopps break;
714 1.1 chopps case 1: *to++ = *from;
715 1.7 cgd from += 2; --len;
716 1.1 chopps case 2: asm ("movepw %1@(0),%0": "=d" (shortd) : "a" (from));
717 1.1 chopps *((ushort *)to)++ = shortd;
718 1.1 chopps from += 4; len -= 2;
719 1.1 chopps break;
720 1.1 chopps default:
721 1.1 chopps }
722 1.1 chopps
723 1.7 cgd while (len >= 32) {
724 1.1 chopps asm("movepl %1@(0),%0" : "=d"(longd1) : "a" (from));
725 1.1 chopps asm("movepl %1@(8),%0" : "=d"(longd2) : "a" (from));
726 1.1 chopps asm("movepl %1@(16),%0" : "=d"(longd3) : "a" (from));
727 1.1 chopps asm("movepl %1@(24),%0" : "=d"(longd4) : "a" (from));
728 1.1 chopps *((unsigned long *)to)++ = longd1;
729 1.1 chopps *((unsigned long *)to)++ = longd2;
730 1.1 chopps *((unsigned long *)to)++ = longd3;
731 1.1 chopps *((unsigned long *)to)++ = longd4;
732 1.1 chopps
733 1.1 chopps asm("movepl %1@(32),%0" : "=d"(longd1) : "a" (from));
734 1.1 chopps asm("movepl %1@(40),%0" : "=d"(longd2) : "a" (from));
735 1.1 chopps asm("movepl %1@(48),%0" : "=d"(longd3) : "a" (from));
736 1.1 chopps asm("movepl %1@(56),%0" : "=d"(longd4) : "a" (from));
737 1.1 chopps *((unsigned long *)to)++ = longd1;
738 1.1 chopps *((unsigned long *)to)++ = longd2;
739 1.1 chopps *((unsigned long *)to)++ = longd3;
740 1.1 chopps *((unsigned long *)to)++ = longd4;
741 1.1 chopps
742 1.1 chopps from += 64; len -= 32;
743 1.1 chopps }
744 1.7 cgd while (len > 0) {
745 1.1 chopps asm("movepl %1@(0),%0" : "=d"(longd) : "a" (from));
746 1.1 chopps *((unsigned long *)to)++ = longd;
747 1.1 chopps from += 8; len -= 4;
748 1.1 chopps }
749 1.1 chopps
750 1.1 chopps }
751 1.1 chopps #endif /* BAHASMCOPY */
752 1.7 cgd while (len > 0) {
753 1.1 chopps *to++ = *from;
754 1.7 cgd from += 2;
755 1.1 chopps --len;
756 1.1 chopps }
757 1.1 chopps
758 1.1 chopps }
759 1.1 chopps
760 1.1 chopps /*
761 1.1 chopps * Arcnet interface receiver soft interrupt:
762 1.1 chopps * get the stuff out of any filled buffer we find.
763 1.1 chopps */
764 1.1 chopps void
765 1.14 chopps bah_srint(vsc, dummy)
766 1.14 chopps void *vsc, *dummy;
767 1.14 chopps {
768 1.1 chopps struct bah_softc *sc;
769 1.14 chopps int buffer, len, len1, amount, offset, s, i, type;
770 1.7 cgd u_char __volatile *bah_ram_ptr;
771 1.3 chopps struct mbuf *m, *dst, *head;
772 1.3 chopps struct arc_header *ah;
773 1.5 chopps struct ifnet *ifp;
774 1.7 cgd #ifdef BAHTIMINGS
775 1.7 cgd u_long copystart, lencopy, perbyte;
776 1.7 cgd #endif
777 1.14 chopps sc = (struct bah_softc *)vsc;
778 1.14 chopps ifp = &sc->sc_arccom.ac_if;
779 1.3 chopps head = 0;
780 1.1 chopps
781 1.13 mycroft s = splnet();
782 1.14 chopps buffer = sc->sc_rx_act ^ 1;
783 1.1 chopps splx(s);
784 1.1 chopps
785 1.1 chopps /* Allocate header mbuf */
786 1.1 chopps MGETHDR(m, M_DONTWAIT, MT_DATA);
787 1.1 chopps
788 1.1 chopps if (m == 0) {
789 1.1 chopps /*
790 1.1 chopps * in case s.th. goes wrong with mem, drop it
791 1.1 chopps * to make sure the receiver can be started again
792 1.1 chopps * count it as input error (we dont have any other
793 1.1 chopps * detectable)
794 1.1 chopps */
795 1.5 chopps ifp->if_ierrors++;
796 1.1 chopps goto cleanup;
797 1.1 chopps }
798 1.1 chopps
799 1.5 chopps m->m_pkthdr.rcvif = ifp;
800 1.1 chopps
801 1.1 chopps /*
802 1.1 chopps * Align so that IP packet will be longword aligned. Here we
803 1.1 chopps * assume that m_data of new packet is longword aligned.
804 1.8 cgd * When implementing PHDS, we might have to change it to 2,
805 1.8 cgd * (2*sizeof(ulong) - ARC_HDRNEWLEN)), packet type dependent.
806 1.1 chopps */
807 1.1 chopps
808 1.1 chopps bah_ram_ptr = sc->sc_base->buffers + buffer*512*2;
809 1.1 chopps offset = bah_ram_ptr[2*2];
810 1.3 chopps if (offset)
811 1.1 chopps len = 256 - offset;
812 1.3 chopps else {
813 1.1 chopps offset = bah_ram_ptr[3*2];
814 1.1 chopps len = 512 - offset;
815 1.1 chopps }
816 1.8 cgd type = bah_ram_ptr[offset*2];
817 1.8 cgd m->m_data += 1 + arc_isphds(type);
818 1.8 cgd
819 1.8 cgd head = m;
820 1.8 cgd ah = mtod(head, struct arc_header *);
821 1.8 cgd
822 1.8 cgd ah->arc_shost = bah_ram_ptr[0*2];
823 1.8 cgd ah->arc_dhost = bah_ram_ptr[1*2];
824 1.8 cgd
825 1.8 cgd m->m_pkthdr.len = len+2; /* whole packet length */
826 1.8 cgd m->m_len = 2; /* mbuf filled with ARCnet addresses */
827 1.8 cgd bah_ram_ptr += offset*2; /* ram buffer continues there */
828 1.1 chopps
829 1.1 chopps while (len > 0) {
830 1.1 chopps
831 1.1 chopps len1 = len;
832 1.1 chopps amount = M_TRAILINGSPACE(m);
833 1.1 chopps
834 1.1 chopps if (amount == 0) {
835 1.1 chopps dst = m;
836 1.1 chopps MGET(m, M_DONTWAIT, MT_DATA);
837 1.1 chopps
838 1.1 chopps if (m == 0) {
839 1.5 chopps ifp->if_ierrors++;
840 1.1 chopps goto cleanup;
841 1.1 chopps }
842 1.1 chopps
843 1.1 chopps if (len1 >= MINCLSIZE)
844 1.1 chopps MCLGET(m, M_DONTWAIT);
845 1.1 chopps
846 1.1 chopps m->m_len = 0;
847 1.1 chopps dst->m_next = m;
848 1.1 chopps amount = M_TRAILINGSPACE(m);
849 1.1 chopps }
850 1.1 chopps
851 1.1 chopps if (amount < len1)
852 1.1 chopps len1 = amount;
853 1.1 chopps
854 1.1 chopps #ifdef BAHTIMINGS
855 1.1 chopps lencopy = len;
856 1.1 chopps copystart = clkread();
857 1.1 chopps #endif
858 1.1 chopps
859 1.7 cgd movepin(bah_ram_ptr, mtod(m, u_char *) + m->m_len, len1);
860 1.1 chopps
861 1.1 chopps #ifdef BAHTIMINGS
862 1.7 cgd perbyte = 1000 * (clkread() - copystart) / lencopy;
863 1.7 cgd sc->sc_stats.mincopyin =
864 1.7 cgd ulmin(sc->sc_stats.mincopyin, perbyte);
865 1.7 cgd sc->sc_stats.maxcopyin =
866 1.7 cgd ulmax(sc->sc_stats.maxcopyin, perbyte);
867 1.1 chopps #endif
868 1.1 chopps
869 1.1 chopps m->m_len += len1;
870 1.1 chopps bah_ram_ptr += len1*2;
871 1.1 chopps len -= len1;
872 1.1 chopps }
873 1.1 chopps
874 1.1 chopps #if NBPFILTER > 0
875 1.4 mycroft if (ifp->if_bpf)
876 1.4 mycroft bpf_mtap(ifp->if_bpf, head);
877 1.1 chopps #endif
878 1.1 chopps
879 1.6 chopps arc_input(&sc->sc_arccom.ac_if, head);
880 1.1 chopps
881 1.1 chopps /* arc_input has freed it, we dont need to... */
882 1.1 chopps
883 1.1 chopps head = NULL;
884 1.5 chopps ifp->if_ipackets++;
885 1.1 chopps
886 1.1 chopps cleanup:
887 1.1 chopps
888 1.14 chopps if (head != NULL)
889 1.1 chopps m_freem(head);
890 1.1 chopps
891 1.16 is /* mark buffer as invalid by source id 0 */
892 1.16 is sc->sc_base->buffers[buffer*512*2] = 0;
893 1.13 mycroft s = splnet();
894 1.1 chopps
895 1.14 chopps if (--sc->sc_rx_fillcount == 2 - 1) {
896 1.1 chopps
897 1.1 chopps /* was off, restart it on buffer just emptied */
898 1.1 chopps sc->sc_rx_act = buffer;
899 1.1 chopps sc->sc_intmask |= ARC_RI;
900 1.1 chopps
901 1.1 chopps /* this also clears the RI flag interupt: */
902 1.1 chopps sc->sc_base->command = ARC_RXBC(buffer);
903 1.1 chopps sc->sc_base->status = sc->sc_intmask;
904 1.1 chopps
905 1.1 chopps #ifdef BAH_DEBUG
906 1.4 mycroft printf("%s: srint: restarted rx on buf %ld\n",
907 1.4 mycroft sc->sc_dev.dv_xname, buffer);
908 1.1 chopps #endif
909 1.1 chopps }
910 1.1 chopps splx(s);
911 1.1 chopps }
912 1.1 chopps
913 1.7 cgd __inline static void
914 1.14 chopps bah_tint(sc, isr)
915 1.1 chopps struct bah_softc *sc;
916 1.14 chopps int isr;
917 1.1 chopps {
918 1.14 chopps struct ifnet *ifp;
919 1.14 chopps
920 1.1 chopps int buffer;
921 1.14 chopps #ifdef BAHTIMINGS
922 1.1 chopps int clknow;
923 1.14 chopps #endif
924 1.1 chopps
925 1.14 chopps ifp = &(sc->sc_arccom.ac_if);
926 1.1 chopps buffer = sc->sc_tx_act;
927 1.1 chopps
928 1.6 chopps /*
929 1.14 chopps * retransmit code:
930 1.14 chopps * Normal situtations first for fast path:
931 1.14 chopps * If acknowledgement received ok or broadcast, we're ok.
932 1.14 chopps * else if
933 1.6 chopps */
934 1.1 chopps
935 1.14 chopps if (isr & ARC_TMA || sc->sc_broadcast[buffer])
936 1.14 chopps sc->sc_arccom.ac_if.if_opackets++;
937 1.14 chopps #ifdef BAHRETRANSMIT
938 1.14 chopps else if (ifp->if_flags & IFF_LINK2 && ifp->if_timer > 0
939 1.14 chopps && --sc->sc_retransmits[buffer] > 0) {
940 1.14 chopps /* retransmit same buffer */
941 1.14 chopps sc->sc_base->command = ARC_TX(buffer);
942 1.14 chopps return;
943 1.14 chopps }
944 1.14 chopps #endif
945 1.3 chopps else
946 1.14 chopps ifp->if_oerrors++;
947 1.14 chopps
948 1.14 chopps
949 1.1 chopps #ifdef BAHTIMINGS
950 1.1 chopps clknow = clkread();
951 1.1 chopps
952 1.7 cgd sc->sc_stats.minsend = ulmin(sc->sc_stats.minsend,
953 1.1 chopps clknow - sc->sc_stats.lasttxstart_mics);
954 1.1 chopps
955 1.7 cgd sc->sc_stats.maxsend = ulmax(sc->sc_stats.maxsend,
956 1.1 chopps clknow - sc->sc_stats.lasttxstart_mics);
957 1.1 chopps #endif
958 1.1 chopps
959 1.1 chopps /* We know we can accept another buffer at this point. */
960 1.14 chopps ifp->if_flags &= ~IFF_OACTIVE;
961 1.1 chopps
962 1.1 chopps if (--sc->sc_tx_fillcount > 0) {
963 1.1 chopps
964 1.1 chopps /*
965 1.1 chopps * start tx on other buffer.
966 1.1 chopps * This also clears the int flag
967 1.1 chopps */
968 1.1 chopps buffer ^= 1;
969 1.1 chopps sc->sc_tx_act = buffer;
970 1.1 chopps
971 1.1 chopps /*
972 1.1 chopps * already given:
973 1.1 chopps * sc->sc_intmask |= ARC_TA;
974 1.1 chopps * sc->sc_base->status = sc->sc_intmask;
975 1.1 chopps */
976 1.1 chopps sc->sc_base->command = ARC_TX(buffer);
977 1.6 chopps /* init watchdog timer */
978 1.14 chopps ifp->if_timer = ARCTIMEOUT;
979 1.1 chopps
980 1.1 chopps #ifdef BAHTIMINGS
981 1.1 chopps bcopy((caddr_t)&time,
982 1.1 chopps (caddr_t)&(sc->sc_stats.lasttxstart_tv),
983 1.1 chopps sizeof(struct timeval));
984 1.1 chopps
985 1.1 chopps sc->sc_stats.lasttxstart_mics = clkread();
986 1.1 chopps #endif
987 1.1 chopps
988 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
989 1.4 mycroft printf("%s: tint: starting tx on buffer %d, status 0x%02x\n",
990 1.4 mycroft sc->sc_dev.dv_xname, buffer, sc->sc_base->status);
991 1.1 chopps #endif
992 1.1 chopps } else {
993 1.1 chopps /* have to disable TX interrupt */
994 1.1 chopps sc->sc_intmask &= ~ARC_TA;
995 1.1 chopps sc->sc_base->status = sc->sc_intmask;
996 1.6 chopps /* ... and watchdog timer */
997 1.14 chopps ifp->if_timer = 0;
998 1.1 chopps
999 1.1 chopps #ifdef BAH_DEBUG
1000 1.4 mycroft printf("%s: tint: no more buffers to send, status 0x%02x\n",
1001 1.4 mycroft sc->sc_dev.dv_xname, sc->sc_base->status);
1002 1.1 chopps #endif
1003 1.1 chopps }
1004 1.1 chopps
1005 1.1 chopps #ifdef BAHSOFTCOPY
1006 1.1 chopps /* schedule soft int to fill a new buffer for us */
1007 1.12 chopps add_sicallback((sifunc_t)callstart, sc, NULL);
1008 1.1 chopps #else
1009 1.1 chopps /* call it directly */
1010 1.1 chopps callstart(sc, NULL);
1011 1.1 chopps #endif
1012 1.1 chopps }
1013 1.1 chopps
1014 1.1 chopps /*
1015 1.1 chopps * Our interrupt routine
1016 1.1 chopps */
1017 1.1 chopps int
1018 1.1 chopps bahintr(sc)
1019 1.1 chopps struct bah_softc *sc;
1020 1.1 chopps {
1021 1.11 chopps u_char isr, maskedisr;
1022 1.1 chopps int buffer;
1023 1.1 chopps u_long newsec;
1024 1.1 chopps
1025 1.1 chopps isr = sc->sc_base->status;
1026 1.11 chopps maskedisr = isr & sc->sc_intmask;
1027 1.11 chopps if (!maskedisr)
1028 1.3 chopps return (0);
1029 1.1 chopps
1030 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG>1)
1031 1.4 mycroft printf("%s: intr: status 0x%02x, intmask 0x%02x\n",
1032 1.4 mycroft sc->sc_dev.dv_xname, isr, sc->sc_intmask);
1033 1.1 chopps #endif
1034 1.1 chopps
1035 1.11 chopps if (maskedisr & ARC_POR) {
1036 1.1 chopps sc->sc_arccom.ac_anaddr = sc->sc_base->dipswitches;
1037 1.1 chopps sc->sc_base->command = ARC_CLR(CLR_POR);
1038 1.4 mycroft log(LOG_WARNING, "%s: intr: got spurious power on reset int\n",
1039 1.4 mycroft sc->sc_dev.dv_xname);
1040 1.1 chopps }
1041 1.1 chopps
1042 1.11 chopps if (maskedisr & ARC_RECON) {
1043 1.1 chopps /*
1044 1.1 chopps * we dont need to:
1045 1.1 chopps * sc->sc_base->command = ARC_CONF(CONF_LONG);
1046 1.1 chopps */
1047 1.1 chopps sc->sc_base->command = ARC_CLR(CLR_RECONFIG);
1048 1.1 chopps sc->sc_arccom.ac_if.if_collisions++;
1049 1.7 cgd
1050 1.7 cgd /*
1051 1.7 cgd * If more than 2 seconds per reconfig:
1052 1.7 cgd * Reset time and counter.
1053 1.7 cgd * else:
1054 1.7 cgd * If more than ARC_EXCESSIVE_RECONFIGS reconfigs
1055 1.7 cgd * since last burst, complain and set treshold for
1056 1.7 cgd * warnings to ARC_EXCESSIVE_RECONS_REWARN.
1057 1.7 cgd *
1058 1.7 cgd * This allows for, e.g., new stations on the cable, or
1059 1.7 cgd * cable switching as long as it is over after (normally)
1060 1.7 cgd * 16 seconds.
1061 1.7 cgd *
1062 1.7 cgd * XXX TODO: check timeout bits in status word and double
1063 1.7 cgd * time if necessary.
1064 1.7 cgd */
1065 1.1 chopps
1066 1.1 chopps newsec = time.tv_sec;
1067 1.7 cgd if (newsec - sc->sc_recontime > 2 * sc->sc_reconcount) {
1068 1.1 chopps sc->sc_recontime = newsec;
1069 1.1 chopps sc->sc_reconcount = 0;
1070 1.1 chopps sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS;
1071 1.3 chopps } else if (++sc->sc_reconcount > sc->sc_reconcount_excessive) {
1072 1.3 chopps sc->sc_reconcount_excessive =
1073 1.3 chopps ARC_EXCESSIVE_RECONS_REWARN;
1074 1.3 chopps log(LOG_WARNING,
1075 1.4 mycroft "%s: excessive token losses, cable problem?\n",
1076 1.4 mycroft sc->sc_dev.dv_xname);
1077 1.3 chopps sc->sc_recontime = newsec;
1078 1.3 chopps sc->sc_reconcount = 0;
1079 1.1 chopps }
1080 1.1 chopps }
1081 1.1 chopps
1082 1.11 chopps if (maskedisr & ARC_RI) {
1083 1.1 chopps
1084 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
1085 1.16 is printf("%s: intr: hard rint, act %ld\n",
1086 1.16 is sc->sc_dev.dv_xname, sc->sc_rx_act);
1087 1.1 chopps #endif
1088 1.1 chopps
1089 1.1 chopps buffer = sc->sc_rx_act;
1090 1.16 is /* look if buffer is marked invalid: */
1091 1.16 is if (sc->sc_base->buffers[buffer*512*2] == 0) {
1092 1.16 is /* invalid marked buffer (or illegally configured sender) */
1093 1.16 is log(LOG_WARNING,
1094 1.16 is "%s: spurious RX interrupt or sender 0 (ignored)\n",
1095 1.16 is sc->sc_dev.dv_xname);
1096 1.16 is /*
1097 1.16 is * restart receiver on same buffer.
1098 1.16 is */
1099 1.16 is sc->sc_base->command = ARC_RXBC(buffer);
1100 1.16 is
1101 1.16 is } else if (++sc->sc_rx_fillcount > 1) {
1102 1.1 chopps sc->sc_intmask &= ~ARC_RI;
1103 1.1 chopps sc->sc_base->status = sc->sc_intmask;
1104 1.1 chopps } else {
1105 1.1 chopps
1106 1.1 chopps buffer ^= 1;
1107 1.1 chopps sc->sc_rx_act = buffer;
1108 1.1 chopps
1109 1.1 chopps /*
1110 1.1 chopps * Start receiver on other receive buffer.
1111 1.1 chopps * This also clears the RI interupt flag.
1112 1.1 chopps */
1113 1.1 chopps sc->sc_base->command = ARC_RXBC(buffer);
1114 1.1 chopps /* we are in the RX intr, so mask is ok for RX */
1115 1.1 chopps
1116 1.1 chopps #ifdef BAH_DEBUG
1117 1.4 mycroft printf("%s: started rx for buffer %ld, status 0x%02x\n",
1118 1.4 mycroft sc->sc_dev.dv_xname, sc->sc_rx_act,
1119 1.1 chopps sc->sc_base->status);
1120 1.1 chopps #endif
1121 1.1 chopps }
1122 1.1 chopps
1123 1.1 chopps #ifdef BAHSOFTCOPY
1124 1.1 chopps /* this one starts a soft int to copy out of the hw */
1125 1.12 chopps add_sicallback((sifunc_t)bah_srint, sc,NULL);
1126 1.1 chopps #else
1127 1.1 chopps /* this one does the copy here */
1128 1.1 chopps bah_srint(sc,NULL);
1129 1.1 chopps #endif
1130 1.1 chopps }
1131 1.1 chopps
1132 1.11 chopps if (maskedisr & ARC_TA)
1133 1.14 chopps bah_tint(sc, isr);
1134 1.1 chopps
1135 1.3 chopps return (1);
1136 1.1 chopps }
1137 1.1 chopps
1138 1.1 chopps /*
1139 1.1 chopps * Process an ioctl request.
1140 1.1 chopps * This code needs some work - it looks pretty ugly.
1141 1.1 chopps */
1142 1.1 chopps int
1143 1.1 chopps bah_ioctl(ifp, command, data)
1144 1.1 chopps register struct ifnet *ifp;
1145 1.7 cgd u_long command;
1146 1.1 chopps caddr_t data;
1147 1.1 chopps {
1148 1.1 chopps struct bah_softc *sc;
1149 1.1 chopps register struct ifaddr *ifa;
1150 1.3 chopps int s, error;
1151 1.1 chopps
1152 1.3 chopps error = 0;
1153 1.17 thorpej sc = ifp->if_softc;
1154 1.1 chopps ifa = (struct ifaddr *)data;
1155 1.13 mycroft s = splnet();
1156 1.1 chopps
1157 1.1 chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
1158 1.4 mycroft printf("%s: ioctl() called, cmd = 0x%x\n",
1159 1.4 mycroft sc->sc_dev.dv_xname, command);
1160 1.1 chopps #endif
1161 1.1 chopps
1162 1.4 mycroft switch (command) {
1163 1.1 chopps case SIOCSIFADDR:
1164 1.1 chopps ifp->if_flags |= IFF_UP;
1165 1.4 mycroft switch (ifa->ifa_addr->sa_family) {
1166 1.1 chopps #ifdef INET
1167 1.1 chopps case AF_INET:
1168 1.4 mycroft bah_init(sc);
1169 1.1 chopps break;
1170 1.1 chopps #endif
1171 1.1 chopps default:
1172 1.1 chopps bah_init(sc);
1173 1.1 chopps break;
1174 1.1 chopps }
1175 1.1 chopps
1176 1.1 chopps case SIOCSIFFLAGS:
1177 1.1 chopps if ((ifp->if_flags & IFF_UP) == 0 &&
1178 1.1 chopps (ifp->if_flags & IFF_RUNNING) != 0) {
1179 1.1 chopps /*
1180 1.1 chopps * If interface is marked down and it is running,
1181 1.1 chopps * then stop it.
1182 1.1 chopps */
1183 1.1 chopps bah_stop(sc);
1184 1.1 chopps ifp->if_flags &= ~IFF_RUNNING;
1185 1.4 mycroft } else if ((ifp->if_flags & IFF_UP) != 0 &&
1186 1.4 mycroft (ifp->if_flags & IFF_RUNNING) == 0) {
1187 1.1 chopps /*
1188 1.1 chopps * If interface is marked up and it is stopped, then
1189 1.1 chopps * start it.
1190 1.1 chopps */
1191 1.1 chopps bah_init(sc);
1192 1.1 chopps }
1193 1.1 chopps break;
1194 1.1 chopps
1195 1.1 chopps /* Multicast not supported */
1196 1.4 mycroft
1197 1.1 chopps default:
1198 1.1 chopps error = EINVAL;
1199 1.1 chopps }
1200 1.1 chopps
1201 1.4 mycroft splx(s);
1202 1.3 chopps return (error);
1203 1.6 chopps }
1204 1.6 chopps
1205 1.6 chopps /*
1206 1.6 chopps * watchdog routine for transmitter.
1207 1.6 chopps *
1208 1.6 chopps * We need this, because else a receiver whose hardware is alive, but whose
1209 1.6 chopps * software has not enabled the Receiver, would make our hardware wait forever
1210 1.6 chopps * Discovered this after 20 times reading the docs.
1211 1.6 chopps *
1212 1.6 chopps * Only thing we do is disable transmitter. We'll get an transmit timeout,
1213 1.6 chopps * and the int handler will have to decide not to retransmit (in case
1214 1.6 chopps * retransmission is implemented).
1215 1.6 chopps *
1216 1.16 is * This one assumes being called inside splnet(), and that net >= ipl2
1217 1.6 chopps */
1218 1.6 chopps
1219 1.6 chopps void
1220 1.17 thorpej bah_watchdog(ifp)
1221 1.17 thorpej struct ifnet *ifp;
1222 1.6 chopps {
1223 1.17 thorpej struct bah_softc *sc = ifp->if_softc;
1224 1.6 chopps
1225 1.6 chopps sc->sc_base->command = ARC_TXDIS;
1226 1.6 chopps return;
1227 1.1 chopps }
1228