smc90cx6.c revision 1.33.2.2 1 /* $NetBSD: smc90cx6.c,v 1.33.2.2 2000/12/13 15:50:06 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Chip core driver for the SMC90c26 / SMC90c56 (and SMC90c66 in '56
41 * compatibility mode) boards
42 */
43
44 /* #define BAHSOFTCOPY */
45 #define BAHRETRANSMIT /**/
46
47 #include "opt_inet.h"
48 #include "bpfilter.h"
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
53 #include <sys/buf.h>
54 #include <sys/device.h>
55 #include <sys/protosw.h>
56 #include <sys/socket.h>
57 #include <sys/syslog.h>
58 #include <sys/ioctl.h>
59 #include <sys/errno.h>
60
61 #include <net/if.h>
62 #include <net/if_dl.h>
63 #include <net/if_types.h>
64 #include <net/if_arc.h>
65
66 #ifdef INET
67 #include <netinet/in.h>
68 #include <netinet/in_systm.h>
69 #include <netinet/in_var.h>
70 #include <netinet/ip.h>
71 #include <netinet/if_inarp.h>
72 #endif
73
74 #if NBPFILTER > 0
75 #include <net/bpf.h>
76 #include <net/bpfdesc.h>
77 #endif
78
79 #include <sys/kernel.h>
80 #include <machine/bus.h>
81 #include <machine/cpu.h>
82 #include <machine/intr.h>
83 #include <machine/mtpr.h>
84
85 #include <dev/ic/smc90cx6reg.h>
86 #include <dev/ic/smc90cx6var.h>
87
88 /* these should be elsewhere */
89
90 #define ARC_MIN_LEN 1
91 #define ARC_MIN_FORBID_LEN 254
92 #define ARC_MAX_FORBID_LEN 256
93 #define ARC_MAX_LEN 508
94 #define ARC_ADDR_LEN 1
95
96 /* for watchdog timer. This should be more than enough. */
97 #define ARCTIMEOUT (5*IFNET_SLOWHZ)
98
99 /*
100 * This currently uses 2 bufs for tx, 2 for rx
101 *
102 * New rx protocol:
103 *
104 * rx has a fillcount variable. If fillcount > (NRXBUF-1),
105 * rx can be switched off from rx hard int.
106 * Else rx is restarted on the other receiver.
107 * rx soft int counts down. if it is == (NRXBUF-1), it restarts
108 * the receiver.
109 * To ensure packet ordering (we need that for 1201 later), we have a counter
110 * which is incremented modulo 256 on each receive and a per buffer
111 * variable, which is set to the counter on filling. The soft int can
112 * compare both values to determine the older packet.
113 *
114 * Transmit direction:
115 *
116 * bah_start checks tx_fillcount
117 * case 2: return
118 *
119 * else fill tx_act ^ 1 && inc tx_fillcount
120 *
121 * check tx_fillcount again.
122 * case 2: set IFF_OACTIVE to stop arc_output from filling us.
123 * case 1: start tx
124 *
125 * tint clears IFF_OCATIVE, decrements and checks tx_fillcount
126 * case 1: start tx on tx_act ^ 1, softcall bah_start
127 * case 0: softcall bah_start
128 *
129 * #define fill(i) get mbuf && copy mbuf to chip(i)
130 */
131
132 void bah_init __P((struct bah_softc *));
133 void bah_reset __P((struct bah_softc *));
134 void bah_stop __P((struct bah_softc *));
135 void bah_start __P((struct ifnet *));
136 int bahintr __P((void *));
137 int bah_ioctl __P((struct ifnet *, unsigned long, caddr_t));
138 void bah_watchdog __P((struct ifnet *));
139 void bah_srint __P((void *vsc));
140 static void bah_tint __P((struct bah_softc *, int));
141 void bah_reconwatch(void *);
142
143 /* short notation */
144
145 #define GETREG(off) bus_space_read_1(bst_r, regs, (off))
146 #define PUTREG(off, v) bus_space_write_1(bst_r, regs, (off), (v))
147 #define GETMEM(off) bus_space_read_1(bst_m, mem, (off))
148 #define PUTMEM(off, v) bus_space_write_1(bst_m, mem, (off), (v))
149
150 void
151 bah_attach_subr(sc)
152 struct bah_softc *sc;
153 {
154 struct ifnet *ifp = &sc->sc_arccom.ac_if;
155 int s;
156 u_int8_t linkaddress;
157
158 bus_space_tag_t bst_r = sc->sc_bst_r;
159 bus_space_tag_t bst_m = sc->sc_bst_m;
160 bus_space_handle_t regs = sc->sc_regs;
161 bus_space_handle_t mem = sc->sc_mem;
162
163 #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2))
164 printf("\n%s: attach(0x%x, 0x%x, 0x%x)\n",
165 sc->sc_dev.dv_xname, parent, self, aux);
166 #endif
167 s = splhigh();
168
169 /*
170 * read the arcnet address from the board
171 */
172
173 (*sc->sc_reset)(sc, 1);
174
175 do {
176 delay(200);
177 } while (!(GETREG(BAHSTAT) & BAH_POR));
178
179 linkaddress = GETMEM(BAHMACOFF);
180
181 printf(": link addr 0x%02x(%d)\n", linkaddress, linkaddress);
182
183 /* clear the int mask... */
184
185 sc->sc_intmask = 0;
186 PUTREG(BAHSTAT, 0);
187
188 PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
189 PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG));
190 sc->sc_recontime = sc->sc_reconcount = 0;
191
192 /* and reenable kernel int level */
193 splx(s);
194
195 /*
196 * set interface to stopped condition (reset)
197 */
198 bah_stop(sc);
199
200 bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
201 ifp->if_softc = sc;
202 ifp->if_start = bah_start;
203 ifp->if_ioctl = bah_ioctl;
204 ifp->if_timer = 0;
205 ifp->if_watchdog = bah_watchdog;
206
207 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
208
209 ifp->if_mtu = ARCMTU;
210
211 arc_ifattach(ifp, linkaddress);
212
213 #ifdef BAHSOFTCOPY
214 sc->sc_rxcookie = softintr_establish(IPL_SOFTNET, bah_srint, sc);
215 sc->sc_txcookie = softintr_establish(IPL_SOFTNET,
216 (void (*) __P((void *)))bah_start, ifp);
217 #endif
218
219 callout_init(&sc->sc_recon_ch);
220 }
221
222 /*
223 * Initialize device
224 *
225 */
226 void
227 bah_init(sc)
228 struct bah_softc *sc;
229 {
230 struct ifnet *ifp;
231 int s;
232
233 ifp = &sc->sc_arccom.ac_if;
234
235 if ((ifp->if_flags & IFF_RUNNING) == 0) {
236 s = splnet();
237 ifp->if_flags |= IFF_RUNNING;
238 bah_reset(sc);
239 bah_start(ifp);
240 splx(s);
241 }
242 }
243
244 /*
245 * Reset the interface...
246 *
247 * this assumes that it is called inside a critical section...
248 *
249 */
250 void
251 bah_reset(sc)
252 struct bah_softc *sc;
253 {
254 struct ifnet *ifp;
255 int linkaddress;
256
257 bus_space_tag_t bst_r = sc->sc_bst_r;
258 bus_space_tag_t bst_m = sc->sc_bst_m;
259 bus_space_handle_t regs = sc->sc_regs;
260 bus_space_handle_t mem = sc->sc_mem;
261
262 ifp = &sc->sc_arccom.ac_if;
263
264 #ifdef BAH_DEBUG
265 printf("%s: reset\n", sc->sc_dev.dv_xname);
266 #endif
267 /* stop and restart hardware */
268
269 (*sc->sc_reset)(sc, 1);
270 do {
271 DELAY(200);
272 } while (!(GETREG(BAHSTAT) & BAH_POR));
273
274 linkaddress = GETMEM(BAHMACOFF);
275
276 #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
277 printf("%s: reset: card reset, link addr = 0x%02x (%ld)\n",
278 sc->sc_dev.dv_xname, linkaddress, linkaddress);
279 #endif
280
281 /* tell the routing level about the (possibly changed) link address */
282 arc_storelladdr(ifp, linkaddress);
283
284 /* POR is NMI, but we need it below: */
285 sc->sc_intmask = BAH_RECON|BAH_POR;
286 PUTREG(BAHSTAT, sc->sc_intmask);
287 PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
288
289 #ifdef BAH_DEBUG
290 printf("%s: reset: chip configured, status=0x%02x\n",
291 sc->sc_dev.dv_xname, GETREG(BAHSTAT));
292 #endif
293 PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG));
294
295 #ifdef BAH_DEBUG
296 printf("%s: reset: bits cleared, status=0x%02x\n",
297 sc->sc_dev.dv_xname, GETREG(BAHSTAT);
298 #endif
299
300 sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS;
301
302 /* start receiver */
303
304 sc->sc_intmask |= BAH_RI;
305 sc->sc_rx_fillcount = 0;
306 sc->sc_rx_act = 2;
307
308 PUTREG(BAHCMD, BAH_RXBC(2));
309 PUTREG(BAHSTAT, sc->sc_intmask);
310
311 #ifdef BAH_DEBUG
312 printf("%s: reset: started receiver, status=0x%02x\n",
313 sc->sc_dev.dv_xname, GETREG(BAHSTAT);
314 #endif
315
316 /* and init transmitter status */
317 sc->sc_tx_act = 0;
318 sc->sc_tx_fillcount = 0;
319
320 ifp->if_flags |= IFF_RUNNING;
321 ifp->if_flags &= ~IFF_OACTIVE;
322
323 bah_start(ifp);
324 }
325
326 /*
327 * Take interface offline
328 */
329 void
330 bah_stop(sc)
331 struct bah_softc *sc;
332 {
333 bus_space_tag_t bst_r = sc->sc_bst_r;
334 bus_space_handle_t regs = sc->sc_regs;
335
336 /* Stop the interrupts */
337 PUTREG(BAHSTAT, 0);
338
339 /* Stop the interface */
340 (*sc->sc_reset)(sc, 0);
341
342 /* Stop watchdog timer */
343 sc->sc_arccom.ac_if.if_timer = 0;
344 }
345
346 /*
347 * Start output on interface. Get another datagram to send
348 * off the interface queue, and copy it to the
349 * interface becore starting the output
350 *
351 * this assumes that it is called inside a critical section...
352 * XXX hm... does it still?
353 *
354 */
355 void
356 bah_start(ifp)
357 struct ifnet *ifp;
358 {
359 struct bah_softc *sc = ifp->if_softc;
360 struct mbuf *m,*mp;
361
362 bus_space_tag_t bst_r = sc->sc_bst_r;
363 bus_space_handle_t regs = sc->sc_regs;
364 bus_space_tag_t bst_m = sc->sc_bst_m;
365 bus_space_handle_t mem = sc->sc_mem;
366
367 int bah_ram_ptr;
368 int len, tlen, offset, s, buffer;
369 #ifdef BAHTIMINGS
370 u_long copystart, lencopy, perbyte;
371 #endif
372
373 #if defined(BAH_DEBUG) && (BAH_DEBUG > 3)
374 printf("%s: start(0x%x)\n", sc->sc_dev.dv_xname, ifp);
375 #endif
376
377 if ((ifp->if_flags & IFF_RUNNING) == 0)
378 return;
379
380 s = splnet();
381
382 if (sc->sc_tx_fillcount >= 2) {
383 splx(s);
384 return;
385 }
386
387 IF_DEQUEUE(&ifp->if_snd, m);
388 buffer = sc->sc_tx_act ^ 1;
389
390 splx(s);
391
392 if (m == 0)
393 return;
394
395 #if NBPFILTER > 0
396 /*
397 * If bpf is listening on this interface, let it
398 * see the packet before we commit it to the wire
399 *
400 * (can't give the copy in A2060 card RAM to bpf, because
401 * that RAM is just accessed as on every other byte)
402 */
403 if (ifp->if_bpf)
404 bpf_mtap(ifp->if_bpf, m);
405 #endif
406
407 #ifdef BAH_DEBUG
408 if (m->m_len < ARC_HDRLEN)
409 m = m_pullup(m, ARC_HDRLEN);/* gcc does structure padding */
410 printf("%s: start: filling %ld from %ld to %ld type %ld\n",
411 sc->sc_dev.dv_xname, buffer, mtod(m, u_char *)[0],
412 mtod(m, u_char *)[1], mtod(m, u_char *)[2]);
413 #else
414 if (m->m_len < 2)
415 m = m_pullup(m, 2);
416 #endif
417 bah_ram_ptr = buffer*512;
418
419 if (m == 0)
420 return;
421
422 /* write the addresses to RAM and throw them away */
423
424 /*
425 * Hardware does this: Yet Another Microsecond Saved.
426 * (btw, timing code says usually 2 microseconds)
427 * PUTMEM(bah_ram_ptr + 0, mtod(m, u_char *)[0]);
428 */
429
430 PUTMEM(bah_ram_ptr + 1, mtod(m, u_char *)[1]);
431 m_adj(m, 2);
432
433 /* get total length left at this point */
434 tlen = m->m_pkthdr.len;
435 if (tlen < ARC_MIN_FORBID_LEN) {
436 offset = 256 - tlen;
437 PUTMEM(bah_ram_ptr + 2, offset);
438 } else {
439 PUTMEM(bah_ram_ptr + 2, 0);
440 if (tlen <= ARC_MAX_FORBID_LEN)
441 offset = 255; /* !!! */
442 else {
443 if (tlen > ARC_MAX_LEN)
444 tlen = ARC_MAX_LEN;
445 offset = 512 - tlen;
446 }
447 PUTMEM(bah_ram_ptr + 3, offset);
448
449 }
450 bah_ram_ptr += offset;
451
452 /* lets loop through the mbuf chain */
453
454 for (mp = m; mp; mp = mp->m_next) {
455 if ((len = mp->m_len)) { /* YAMS */
456 bus_space_write_region_1(bst_m, mem, bah_ram_ptr,
457 mtod(mp, caddr_t), len);
458
459 bah_ram_ptr += len;
460 }
461 }
462
463 sc->sc_broadcast[buffer] = (m->m_flags & M_BCAST) != 0;
464 sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5;
465
466 /* actually transmit the packet */
467 s = splnet();
468
469 if (++sc->sc_tx_fillcount > 1) {
470 /*
471 * We are filled up to the rim. No more bufs for the moment,
472 * please.
473 */
474 ifp->if_flags |= IFF_OACTIVE;
475 } else {
476 #ifdef BAH_DEBUG
477 printf("%s: start: starting transmitter on buffer %d\n",
478 sc->sc_dev.dv_xname, buffer);
479 #endif
480 /* Transmitter was off, start it */
481 sc->sc_tx_act = buffer;
482
483 /*
484 * We still can accept another buf, so don't:
485 * ifp->if_flags |= IFF_OACTIVE;
486 */
487 sc->sc_intmask |= BAH_TA;
488 PUTREG(BAHCMD, BAH_TX(buffer));
489 PUTREG(BAHSTAT, sc->sc_intmask);
490
491 sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT;
492 }
493 splx(s);
494 m_freem(m);
495
496 /*
497 * After 10 times reading the docs, I realized
498 * that in the case the receiver NAKs the buffer request,
499 * the hardware retries till shutdown.
500 * This is integrated now in the code above.
501 */
502
503 return;
504 }
505
506 /*
507 * Arcnet interface receiver soft interrupt:
508 * get the stuff out of any filled buffer we find.
509 */
510 void
511 bah_srint(vsc)
512 void *vsc;
513 {
514 struct bah_softc *sc = (struct bah_softc *)vsc;
515 int buffer, len, len1, amount, offset, s, type;
516 int bah_ram_ptr;
517 struct mbuf *m, *dst, *head;
518 struct arc_header *ah;
519 struct ifnet *ifp;
520
521 bus_space_tag_t bst_r = sc->sc_bst_r;
522 bus_space_tag_t bst_m = sc->sc_bst_m;
523 bus_space_handle_t regs = sc->sc_regs;
524 bus_space_handle_t mem = sc->sc_mem;
525
526 ifp = &sc->sc_arccom.ac_if;
527 head = 0;
528
529 s = splnet();
530 buffer = sc->sc_rx_act ^ 1;
531 splx(s);
532
533 /* Allocate header mbuf */
534 MGETHDR(m, M_DONTWAIT, MT_DATA);
535
536 if (m == 0) {
537 /*
538 * in case s.th. goes wrong with mem, drop it
539 * to make sure the receiver can be started again
540 * count it as input error (we dont have any other
541 * detectable)
542 */
543 ifp->if_ierrors++;
544 goto cleanup;
545 }
546
547 m->m_pkthdr.rcvif = ifp;
548
549 /*
550 * Align so that IP packet will be longword aligned. Here we
551 * assume that m_data of new packet is longword aligned.
552 * When implementing PHDS, we might have to change it to 2,
553 * (2*sizeof(ulong) - ARC_HDRNEWLEN)), packet type dependent.
554 */
555
556 bah_ram_ptr = buffer*512;
557 offset = GETMEM(bah_ram_ptr + 2);
558 if (offset)
559 len = 256 - offset;
560 else {
561 offset = GETMEM(bah_ram_ptr + 3);
562 len = 512 - offset;
563 }
564 if (len+2 >= MINCLSIZE)
565 MCLGET(m, M_DONTWAIT);
566
567 if (m == 0) {
568 ifp->if_ierrors++;
569 goto cleanup;
570 }
571
572 type = GETMEM(bah_ram_ptr + offset);
573 m->m_data += 1 + arc_isphds(type);
574
575 head = m;
576 ah = mtod(head, struct arc_header *);
577
578 ah->arc_shost = GETMEM(bah_ram_ptr + 0);
579 ah->arc_dhost = GETMEM(bah_ram_ptr + 1);
580
581 m->m_pkthdr.len = len+2; /* whole packet length */
582 m->m_len = 2; /* mbuf filled with ARCnet addresses */
583 bah_ram_ptr += offset; /* ram buffer continues there */
584
585 while (len > 0) {
586
587 len1 = len;
588 amount = M_TRAILINGSPACE(m);
589
590 if (amount == 0) {
591 dst = m;
592 MGET(m, M_DONTWAIT, MT_DATA);
593
594 if (m == 0) {
595 ifp->if_ierrors++;
596 goto cleanup;
597 }
598
599 if (len1 >= MINCLSIZE)
600 MCLGET(m, M_DONTWAIT);
601
602 m->m_len = 0;
603 dst->m_next = m;
604 amount = M_TRAILINGSPACE(m);
605 }
606
607 if (amount < len1)
608 len1 = amount;
609
610 bus_space_read_region_1(bst_m, mem, bah_ram_ptr,
611 mtod(m, u_char *) + m->m_len, len1);
612
613 m->m_len += len1;
614 bah_ram_ptr += len1;
615 len -= len1;
616 }
617
618 #if NBPFILTER > 0
619 if (ifp->if_bpf)
620 bpf_mtap(ifp->if_bpf, head);
621 #endif
622
623 (*sc->sc_arccom.ac_if.if_input)(&sc->sc_arccom.ac_if, head);
624
625 head = NULL;
626 ifp->if_ipackets++;
627
628 cleanup:
629
630 if (head != NULL)
631 m_freem(head);
632
633 /* mark buffer as invalid by source id 0 */
634 bus_space_write_1(bst_m, mem, buffer*512, 0);
635 s = splnet();
636
637 if (--sc->sc_rx_fillcount == 2 - 1) {
638
639 /* was off, restart it on buffer just emptied */
640 sc->sc_rx_act = buffer;
641 sc->sc_intmask |= BAH_RI;
642
643 /* this also clears the RI flag interupt: */
644 PUTREG(BAHCMD, BAH_RXBC(buffer));
645 PUTREG(BAHSTAT, sc->sc_intmask);
646
647 #ifdef BAH_DEBUG
648 printf("%s: srint: restarted rx on buf %ld\n",
649 sc->sc_dev.dv_xname, buffer);
650 #endif
651 }
652 splx(s);
653 }
654
655 __inline static void
656 bah_tint(sc, isr)
657 struct bah_softc *sc;
658 int isr;
659 {
660 struct ifnet *ifp;
661
662 bus_space_tag_t bst_r = sc->sc_bst_r;
663 bus_space_handle_t regs = sc->sc_regs;
664
665
666 int buffer;
667 #ifdef BAHTIMINGS
668 int clknow;
669 #endif
670
671 ifp = &(sc->sc_arccom.ac_if);
672 buffer = sc->sc_tx_act;
673
674 /*
675 * retransmit code:
676 * Normal situtations first for fast path:
677 * If acknowledgement received ok or broadcast, we're ok.
678 * else if
679 */
680
681 if (isr & BAH_TMA || sc->sc_broadcast[buffer])
682 sc->sc_arccom.ac_if.if_opackets++;
683 #ifdef BAHRETRANSMIT
684 else if (ifp->if_flags & IFF_LINK2 && ifp->if_timer > 0
685 && --sc->sc_retransmits[buffer] > 0) {
686 /* retransmit same buffer */
687 PUTREG(BAHCMD, BAH_TX(buffer));
688 return;
689 }
690 #endif
691 else
692 ifp->if_oerrors++;
693
694
695 /* We know we can accept another buffer at this point. */
696 ifp->if_flags &= ~IFF_OACTIVE;
697
698 if (--sc->sc_tx_fillcount > 0) {
699
700 /*
701 * start tx on other buffer.
702 * This also clears the int flag
703 */
704 buffer ^= 1;
705 sc->sc_tx_act = buffer;
706
707 /*
708 * already given:
709 * sc->sc_intmask |= BAH_TA;
710 * PUTREG(BAHSTAT, sc->sc_intmask);
711 */
712 PUTREG(BAHCMD, BAH_TX(buffer));
713 /* init watchdog timer */
714 ifp->if_timer = ARCTIMEOUT;
715
716 #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
717 printf("%s: tint: starting tx on buffer %d, status 0x%02x\n",
718 sc->sc_dev.dv_xname, buffer, GETREG(BAHSTAT));
719 #endif
720 } else {
721 /* have to disable TX interrupt */
722 sc->sc_intmask &= ~BAH_TA;
723 PUTREG(BAHSTAT, sc->sc_intmask);
724 /* ... and watchdog timer */
725 ifp->if_timer = 0;
726
727 #ifdef BAH_DEBUG
728 printf("%s: tint: no more buffers to send, status 0x%02x\n",
729 sc->sc_dev.dv_xname, GETREG(BAHSTAT));
730 #endif
731 }
732
733 /* XXXX TODO */
734 #ifdef BAHSOFTCOPY
735 /* schedule soft int to fill a new buffer for us */
736 softintr_schedule(sc->sc_txcookie);
737 #else
738 /* call it directly */
739 bah_start(ifp);
740 #endif
741 }
742
743 /*
744 * Our interrupt routine
745 */
746 int
747 bahintr(arg)
748 void *arg;
749 {
750 struct bah_softc *sc = arg;
751
752 bus_space_tag_t bst_r = sc->sc_bst_r;
753 bus_space_tag_t bst_m = sc->sc_bst_m;
754 bus_space_handle_t regs = sc->sc_regs;
755 bus_space_handle_t mem = sc->sc_mem;
756
757 u_char isr, maskedisr;
758 int buffer;
759 u_long newsec;
760
761 isr = GETREG(BAHSTAT);
762 maskedisr = isr & sc->sc_intmask;
763 if (!maskedisr)
764 return (0);
765 do {
766
767 #if defined(BAH_DEBUG) && (BAH_DEBUG>1)
768 printf("%s: intr: status 0x%02x, intmask 0x%02x\n",
769 sc->sc_dev.dv_xname, isr, sc->sc_intmask);
770 #endif
771
772 if (maskedisr & BAH_POR) {
773 /*
774 * XXX We should never see this. Don't bother to store
775 * the address.
776 * sc->sc_arccom.ac_anaddr = GETMEM(BAHMACOFF);
777 */
778 PUTREG(BAHCMD, BAH_CLR(CLR_POR));
779 log(LOG_WARNING,
780 "%s: intr: got spurious power on reset int\n",
781 sc->sc_dev.dv_xname);
782 }
783
784 if (maskedisr & BAH_RECON) {
785 /*
786 * we dont need to:
787 * PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
788 */
789 PUTREG(BAHCMD, BAH_CLR(CLR_RECONFIG));
790 sc->sc_arccom.ac_if.if_collisions++;
791
792 /*
793 * If less than 2 seconds per reconfig:
794 * If ARC_EXCESSIVE_RECONFIGS
795 * since last burst, complain and set treshold for
796 * warnings to ARC_EXCESSIVE_RECONS_REWARN.
797 *
798 * This allows for, e.g., new stations on the cable, or
799 * cable switching as long as it is over after
800 * (normally) 16 seconds.
801 *
802 * XXX TODO: check timeout bits in status word and
803 * double time if necessary.
804 */
805
806 callout_stop(&sc->sc_recon_ch);
807 newsec = time.tv_sec;
808 if ((newsec - sc->sc_recontime <= 2) &&
809 (++sc->sc_reconcount == ARC_EXCESSIVE_RECONS)) {
810 log(LOG_WARNING,
811 "%s: excessive token losses, "
812 "cable problem?\n", sc->sc_dev.dv_xname);
813 }
814 sc->sc_recontime = newsec;
815 callout_reset(&sc->sc_recon_ch, 15 * hz,
816 bah_reconwatch, (void *)sc);
817 }
818
819 if (maskedisr & BAH_RI) {
820 #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
821 printf("%s: intr: hard rint, act %ld\n",
822 sc->sc_dev.dv_xname, sc->sc_rx_act);
823 #endif
824
825 buffer = sc->sc_rx_act;
826 /* look if buffer is marked invalid: */
827 if (GETMEM(buffer*512) == 0) {
828 /*
829 * invalid marked buffer (or illegally
830 * configured sender)
831 */
832 log(LOG_WARNING,
833 "%s: spurious RX interupt or sender 0 "
834 " (ignored)\n", sc->sc_dev.dv_xname);
835 /*
836 * restart receiver on same buffer.
837 * XXX maybe better reset interface?
838 */
839 PUTREG(BAHCMD, BAH_RXBC(buffer));
840 } else {
841 if (++sc->sc_rx_fillcount > 1) {
842 sc->sc_intmask &= ~BAH_RI;
843 PUTREG(BAHSTAT, sc->sc_intmask);
844 } else {
845 buffer ^= 1;
846 sc->sc_rx_act = buffer;
847
848 /*
849 * Start receiver on other receive
850 * buffer. This also clears the RI
851 * interupt flag.
852 */
853 PUTREG(BAHCMD, BAH_RXBC(buffer));
854 /* in RX intr, so mask is ok for RX */
855
856 #ifdef BAH_DEBUG
857 printf("%s: strt rx for buf %ld, "
858 "stat 0x%02x\n",
859 sc->sc_dev.dv_xname, sc->sc_rx_act,
860 GETREG(BAHSTAT);
861 #endif
862 }
863
864 #ifdef BAHSOFTCOPY
865 /*
866 * this one starts a soft int to copy out
867 * of the hw
868 */
869 softintr_schedule(sc->sc_rxcookie);
870 #else
871 /* this one does the copy here */
872 bah_srint(sc);
873 #endif
874 }
875 }
876 if (maskedisr & BAH_TA) {
877 bah_tint(sc, isr);
878 }
879 isr = GETREG(BAHSTAT);
880 maskedisr = isr & sc->sc_intmask;
881 } while (maskedisr);
882
883 return (1);
884 }
885
886 void
887 bah_reconwatch(arg)
888 void *arg;
889 {
890 struct bah_softc *sc = arg;
891
892 if (sc->sc_reconcount >= ARC_EXCESSIVE_RECONS) {
893 sc->sc_reconcount = 0;
894 log(LOG_WARNING, "%s: token valid again.\n",
895 sc->sc_dev.dv_xname);
896 }
897 sc->sc_reconcount = 0;
898 }
899
900
901 /*
902 * Process an ioctl request.
903 * This code needs some work - it looks pretty ugly.
904 */
905 int
906 bah_ioctl(ifp, command, data)
907 struct ifnet *ifp;
908 u_long command;
909 caddr_t data;
910 {
911 struct bah_softc *sc;
912 struct ifaddr *ifa;
913 struct ifreq *ifr;
914 int s, error;
915
916 error = 0;
917 sc = ifp->if_softc;
918 ifa = (struct ifaddr *)data;
919 ifr = (struct ifreq *)data;
920 s = splnet();
921
922 #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
923 printf("%s: ioctl() called, cmd = 0x%x\n",
924 sc->sc_dev.dv_xname, command);
925 #endif
926
927 switch (command) {
928 case SIOCSIFADDR:
929 ifp->if_flags |= IFF_UP;
930 switch (ifa->ifa_addr->sa_family) {
931 #ifdef INET
932 case AF_INET:
933 bah_init(sc);
934 arp_ifinit(ifp, ifa);
935 break;
936 #endif
937 default:
938 bah_init(sc);
939 break;
940 }
941
942 case SIOCSIFFLAGS:
943 if ((ifp->if_flags & IFF_UP) == 0 &&
944 (ifp->if_flags & IFF_RUNNING) != 0) {
945 /*
946 * If interface is marked down and it is running,
947 * then stop it.
948 */
949 bah_stop(sc);
950 ifp->if_flags &= ~IFF_RUNNING;
951 } else if ((ifp->if_flags & IFF_UP) != 0 &&
952 (ifp->if_flags & IFF_RUNNING) == 0) {
953 /*
954 * If interface is marked up and it is stopped, then
955 * start it.
956 */
957 bah_init(sc);
958 }
959 break;
960
961 case SIOCADDMULTI:
962 case SIOCDELMULTI:
963 switch (ifr->ifr_addr.sa_family) {
964 case AF_INET:
965 case AF_INET6:
966 error = 0;
967 break;
968 default:
969 error = EAFNOSUPPORT;
970 break;
971 }
972 break;
973
974 default:
975 error = EINVAL;
976 }
977
978 splx(s);
979 return (error);
980 }
981
982 /*
983 * watchdog routine for transmitter.
984 *
985 * We need this, because else a receiver whose hardware is alive, but whose
986 * software has not enabled the Receiver, would make our hardware wait forever
987 * Discovered this after 20 times reading the docs.
988 *
989 * Only thing we do is disable transmitter. We'll get an transmit timeout,
990 * and the int handler will have to decide not to retransmit (in case
991 * retransmission is implemented).
992 *
993 * This one assumes being called inside splnet()
994 */
995
996 void
997 bah_watchdog(ifp)
998 struct ifnet *ifp;
999 {
1000 struct bah_softc *sc = ifp->if_softc;
1001
1002 bus_space_tag_t bst_r = sc->sc_bst_r;
1003 bus_space_handle_t regs = sc->sc_regs;
1004
1005 PUTREG(BAHCMD, BAH_TXDIS);
1006 return;
1007 }
1008
1009