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