2 /* $NecBSD: dp83932.c,v 1.5 1999/07/29 05:08:44 kmatsuda Exp $ */
3 /* $NetBSD: if_snc.c,v 1.18 1998/04/25 21:27:40 scottr Exp $ */
6 * Copyright (c) 1997, 1998, 1999
7 * Kouichi Matsuda. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kouichi Matsuda for
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Modified for FreeBSD(98) 4.0 from NetBSD/pc98 1.4.2 by Motomichi Matsuzaki.
41 * Modified for NetBSD/pc98 1.2G from NetBSD/mac68k 1.2G by Kouichi Matsuda.
42 * Make adapted for NEC PC-9801-83, 84, PC-9801-103, 104, PC-9801N-25 and
43 * PC-9801N-J02, J02R, which uses National Semiconductor DP83934AVQB as
44 * Ethernet Controller and National Semiconductor NS46C46 as
45 * (64 * 16 bits) Microwire Serial EEPROM.
49 * National Semiconductor DP8393X SONIC Driver
50 * Copyright (c) 1991 Algorithmics Ltd (http://www.algor.co.uk)
51 * You may use, copy, and modify this program so long as you retain the
54 * This driver has been substantially modified since Algorithmics donated
57 * Denton Gentry <denny1@home.com>
59 * Yanagisawa Takeshi <yanagisw@aa.ap.titech.ac.jp>
60 * did the work to get this running on the Macintosh.
65 #include <sys/param.h>
66 #include <sys/kernel.h>
67 #include <sys/systm.h>
68 #include <sys/sockio.h>
70 #include <sys/protosw.h>
71 #include <sys/socket.h>
72 #include <sys/syslog.h>
73 #include <sys/errno.h>
75 #include <net/ethernet.h>
77 #include <net/if_arp.h>
78 #include <net/if_dl.h>
79 #include <net/if_media.h>
80 #include <net/if_types.h>
85 #include <machine/bus.h>
86 #include <dev/snc/dp83932reg.h>
87 #include <dev/snc/dp83932var.h>
89 static void sncwatchdog(void *);
90 static void sncinit(void *);
91 static void sncinit_locked(struct snc_softc *);
92 static int sncstop(struct snc_softc *sc);
93 static int sncioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
94 static void sncstart(struct ifnet *ifp);
95 static void sncstart_locked(struct ifnet *ifp);
96 static void sncreset(struct snc_softc *sc);
98 static void caminitialise(struct snc_softc *);
99 static void camentry(struct snc_softc *, int, u_char *ea);
100 static void camprogram(struct snc_softc *);
101 static void initialise_tda(struct snc_softc *);
102 static void initialise_rda(struct snc_softc *);
103 static void initialise_rra(struct snc_softc *);
105 static void camdump(struct snc_softc *sc);
108 static void sonictxint(struct snc_softc *);
109 static void sonicrxint(struct snc_softc *);
111 static u_int sonicput(struct snc_softc *sc, struct mbuf *m0, int mtd_next);
112 static int sonic_read(struct snc_softc *, u_int32_t, int);
113 static struct mbuf *sonic_get(struct snc_softc *, u_int32_t, int);
115 int snc_enable(struct snc_softc *);
116 void snc_disable(struct snc_softc *);
118 int snc_mediachange(struct ifnet *);
119 void snc_mediastatus(struct ifnet *, struct ifmediareq *);
125 #define assert(e) ((void)0)
126 #define _assert(e) ((void)0)
128 #define _assert(e) assert(e)
130 #define assert(e) ((e) ? (void)0 : __assert("snc ", __FILE__, __LINE__, #e))
132 #define assert(e) ((e) ? (void)0 : __assert("snc "__FILE__, __LINE__, "e"))
137 #define SNC_SHOWTXHDR 0x01 /* show tx ether_header */
138 #define SNC_SHOWRXHDR 0x02 /* show rx ether_header */
139 #define SNC_SHOWCAMENT 0x04 /* show CAM entry */
140 #endif /* SNCDEBUG */
145 sncconfig(sc, media, nmedia, defmedia, myea)
146 struct snc_softc *sc;
147 int *media, nmedia, defmedia;
154 if ((sncdebug & SNC_SHOWCAMENT) != 0) {
159 ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
161 device_printf(sc->sc_dev, "can not if_alloc()\n");
166 device_printf(sc->sc_dev,
167 "buffers: rra=0x%x cda=0x%x rda=0x%x tda=0x%x\n",
168 sc->v_rra[0], sc->v_cda,
169 sc->v_rda, sc->mtda[0].mtd_vtxp);
173 if_initname(ifp, device_get_name(sc->sc_dev),
174 device_get_unit(sc->sc_dev));
175 ifp->if_ioctl = sncioctl;
176 ifp->if_start = sncstart;
177 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
178 ifp->if_init = sncinit;
179 ifp->if_mtu = ETHERMTU;
180 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
182 /* Initialize media goo. */
183 ifmedia_init(&sc->sc_media, 0, snc_mediachange,
186 for (i = 0; i < nmedia; i++)
187 ifmedia_add(&sc->sc_media, media[i], 0, NULL);
188 ifmedia_set(&sc->sc_media, defmedia);
190 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
191 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
194 ether_ifattach(ifp, myea);
202 struct snc_softc *sc = arg;
204 SNC_ASSERT_LOCKED(sc);
209 * Media change callback.
215 struct snc_softc *sc = ifp->if_softc;
219 if (sc->sc_mediachange)
220 error = (*sc->sc_mediachange)(sc);
228 * Media status callback.
231 snc_mediastatus(ifp, ifmr)
233 struct ifmediareq *ifmr;
235 struct snc_softc *sc = ifp->if_softc;
238 if (sc->sc_enabled == 0) {
239 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
240 ifmr->ifm_status = 0;
245 if (sc->sc_mediastatus)
246 (*sc->sc_mediastatus)(sc, ifmr);
252 sncioctl(ifp, cmd, data)
258 struct snc_softc *sc = ifp->if_softc;
265 if ((ifp->if_flags & IFF_UP) == 0 &&
266 (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
268 * If interface is marked down and it is running,
273 } else if ((ifp->if_flags & IFF_UP) != 0 &&
274 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
276 * If interface is marked up and it is stopped,
279 if ((err = snc_enable(sc)) != 0)
282 } else if (sc->sc_enabled) {
284 * reset the interface to pick up any other changes
288 sncstart_locked(ifp);
296 if (sc->sc_enabled == 0) {
307 ifr = (struct ifreq *) data;
308 err = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
311 err = ether_ioctl(ifp, cmd, data);
318 * Encapsulate a packet of type family for the local net.
324 struct snc_softc *sc = ifp->if_softc;
327 sncstart_locked(ifp);
335 struct snc_softc *sc = ifp->if_softc;
339 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
344 /* Check for room in the xmit buffer. */
345 if ((mtd_next = (sc->mtd_free + 1)) == NTDA)
348 if (mtd_next == sc->mtd_hw) {
349 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
353 IF_DEQUEUE(&ifp->if_snd, m);
357 /* We need the header for m_pkthdr.len. */
361 * If there is nothing in the o/p queue, and there is room in
362 * the Tx ring, then send the packet directly. Otherwise append
363 * it to the o/p queue.
365 if ((sonicput(sc, m, mtd_next)) == 0) {
366 IF_PREPEND(&ifp->if_snd, m);
371 * If bpf is listening on this interface, let it see the packet
372 * before we commit it to the wire, but only if we are really
373 * committed to send it.
375 * XXX: Locking must protect m against premature m_freem() in
380 sc->mtd_prev = sc->mtd_free;
381 sc->mtd_free = mtd_next;
383 ifp->if_opackets++; /* # of pkts */
385 /* Jump back for possibly more punishment. */
390 * reset and restart the SONIC. Called in case of fatal
391 * hardware/software errors.
395 struct snc_softc *sc;
405 struct snc_softc *sc = xsc;
413 sncinit_locked(struct snc_softc *sc)
417 if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
418 /* already running */
421 NIC_PUT(sc, SNCR_CR, CR_RST); /* DCR only accessable in reset mode! */
424 NIC_PUT(sc, SNCR_DCR, (sc->sncr_dcr |
425 (sc->bitmode ? DCR_DW32 : DCR_DW16)));
426 NIC_PUT(sc, SNCR_DCR2, sc->sncr_dcr2);
428 s_rcr = RCR_BRD | RCR_LBNONE;
429 if (sc->sc_ifp->if_flags & IFF_PROMISC)
431 if (sc->sc_ifp->if_flags & IFF_ALLMULTI)
433 NIC_PUT(sc, SNCR_RCR, s_rcr);
435 NIC_PUT(sc, SNCR_IMR, (IMR_PRXEN | IMR_PTXEN | IMR_TXEREN | IMR_LCDEN));
437 /* clear pending interrupts */
438 NIC_PUT(sc, SNCR_ISR, ISR_ALL);
440 /* clear tally counters */
441 NIC_PUT(sc, SNCR_CRCT, -1);
442 NIC_PUT(sc, SNCR_FAET, -1);
443 NIC_PUT(sc, SNCR_MPT, -1);
449 /* enable the chip */
450 NIC_PUT(sc, SNCR_CR, 0);
453 /* program the CAM */
456 /* get it to read resource descriptors */
457 NIC_PUT(sc, SNCR_CR, CR_RRRA);
459 while ((NIC_GET(sc, SNCR_CR)) & CR_RRRA)
463 NIC_PUT(sc, SNCR_CR, CR_RXEN);
466 /* flag interface as "running" */
467 sc->sc_ifp->if_drv_flags |= IFF_DRV_RUNNING;
468 sc->sc_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
469 callout_reset(&sc->sc_timer, hz, sncwatchdog, sc);
475 * close down an interface and free its buffers
476 * Called on final close of device, or if sncinit() fails
481 struct snc_softc *sc;
485 SNC_ASSERT_LOCKED(sc);
487 /* stick chip in reset */
488 NIC_PUT(sc, SNCR_CR, CR_RST);
491 /* free all receive buffers (currently static so nothing to do) */
493 /* free all pending transmit mbufs */
494 while (sc->mtd_hw != sc->mtd_free) {
495 mtd = &sc->mtda[sc->mtd_hw];
497 m_freem(mtd->mtd_mbuf);
498 if (++sc->mtd_hw == NTDA) sc->mtd_hw = 0;
501 callout_stop(&sc->sc_timer);
502 sc->sc_tx_timeout = 0;
503 sc->sc_ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
509 * Called if any Tx packets remain unsent after 5 seconds,
510 * In all cases we just reset the chip, and any retransmission
511 * will be handled by higher level protocol timeouts.
514 sncwatchdog(void *arg)
516 struct snc_softc *sc = arg;
519 SNC_ASSERT_LOCKED(sc);
520 if (sc->sc_tx_timeout && --sc->sc_tx_timeout == 0) {
521 if (sc->mtd_hw != sc->mtd_free) {
522 /* something still pending for transmit */
523 mtd = &sc->mtda[sc->mtd_hw];
524 if (SRO(sc, mtd->mtd_vtxp, TXP_STATUS) == 0)
525 log(LOG_ERR, "%s: Tx - timeout\n",
526 device_get_nameunit(sc->sc_dev));
528 log(LOG_ERR, "%s: Tx - lost interrupt\n",
529 device_get_nameunit(sc->sc_dev));
533 callout_reset(&sc->sc_timer, hz, sncwatchdog, sc);
537 * stuff packet into sonic
540 sonicput(sc, m0, mtd_next)
541 struct snc_softc *sc;
552 #ifdef whyonearthwouldyoudothis
553 if (NIC_GET(sc, SNCR_CR) & CR_TXP)
557 /* grab the replacement mtd */
558 mtdp = &sc->mtda[sc->mtd_free];
560 buff = mtdp->mtd_vbuf;
562 /* this packet goes to mtdnext fill in the TDA */
564 txp = mtdp->mtd_vtxp;
566 /* Write to the config word. Every (NTDA/2)+1 packets we set an intr */
567 if (sc->mtd_pint == 0) {
568 sc->mtd_pint = NTDA/2;
569 SWO(sc, txp, TXP_CONFIG, TCR_PINT);
572 SWO(sc, txp, TXP_CONFIG, 0);
575 for (m = m0; m; m = m->m_next) {
578 (*sc->sc_copytobuf)(sc, mtod(m, caddr_t), buff, len);
581 if (totlen >= TXBSIZE) {
582 panic("%s: sonicput: packet overflow",
583 device_get_nameunit(sc->sc_dev));
586 SWO(sc, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FPTRLO,
587 LOWER(mtdp->mtd_vbuf));
588 SWO(sc, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FPTRHI,
589 UPPER(mtdp->mtd_vbuf));
591 if (totlen < ETHERMIN + sizeof(struct ether_header)) {
592 int pad = ETHERMIN + sizeof(struct ether_header) - totlen;
593 (*sc->sc_zerobuf)(sc, mtdp->mtd_vbuf + totlen, pad);
594 totlen = ETHERMIN + sizeof(struct ether_header);
597 SWO(sc, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FSIZE,
599 SWO(sc, txp, TXP_FRAGCNT, 1);
600 SWO(sc, txp, TXP_PKTSIZE, totlen);
602 /* link onto the next mtd that will be used */
603 SWO(sc, txp, TXP_FRAGOFF + (1 * TXP_FRAGSIZE) + TXP_FPTRLO,
604 LOWER(sc->mtda[mtd_next].mtd_vtxp) | EOL);
607 * The previous txp.tlink currently contains a pointer to
608 * our txp | EOL. Want to clear the EOL, so write our
609 * pointer to the previous txp.
611 SWO(sc, sc->mtda[sc->mtd_prev].mtd_vtxp, sc->mtd_tlinko,
612 LOWER(mtdp->mtd_vtxp));
614 /* make sure chip is running */
616 NIC_PUT(sc, SNCR_CR, CR_TXP);
619 /* 5 seconds to watch for failing to transmit */
620 sc->sc_tx_timeout = 5;
626 * These are called from sonicioctl() when /etc/ifconfig is run to set
627 * the address or switch the i/f on.
634 struct snc_softc *sc;
636 u_int32_t v_cda = sc->v_cda;
640 for (i = 0; i < MAXCAM; i++) {
641 camoffset = i * CDA_CAMDESC;
642 SWO(sc, v_cda, (camoffset + CDA_CAMEP), i);
643 SWO(sc, v_cda, (camoffset + CDA_CAMAP2), 0);
644 SWO(sc, v_cda, (camoffset + CDA_CAMAP1), 0);
645 SWO(sc, v_cda, (camoffset + CDA_CAMAP0), 0);
647 SWO(sc, v_cda, CDA_ENABLE, 0);
650 if ((sncdebug & SNC_SHOWCAMENT) != 0) {
657 camentry(sc, entry, ea)
660 struct snc_softc *sc;
662 u_int32_t v_cda = sc->v_cda;
663 int camoffset = entry * CDA_CAMDESC;
665 SWO(sc, v_cda, camoffset + CDA_CAMEP, entry);
666 SWO(sc, v_cda, camoffset + CDA_CAMAP2, (ea[5] << 8) | ea[4]);
667 SWO(sc, v_cda, camoffset + CDA_CAMAP1, (ea[3] << 8) | ea[2]);
668 SWO(sc, v_cda, camoffset + CDA_CAMAP0, (ea[1] << 8) | ea[0]);
669 SWO(sc, v_cda, CDA_ENABLE,
670 (SRO(sc, v_cda, CDA_ENABLE) | (1 << entry)));
675 struct snc_softc *sc;
677 struct ifmultiaddr *ifma;
686 /* Always load our own address first. */
687 camentry (sc, mcount, IF_LLADDR(sc->sc_ifp));
690 /* Assume we won't need allmulti bit. */
691 ifp->if_flags &= ~IFF_ALLMULTI;
693 /* Loop through multicast addresses */
695 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
696 if (ifma->ifma_addr->sa_family != AF_LINK)
698 if (mcount == MAXCAM) {
699 ifp->if_flags |= IFF_ALLMULTI;
703 /* program the CAM with the specified entry */
705 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
708 if_maddr_runlock(ifp);
710 NIC_PUT(sc, SNCR_CDP, LOWER(sc->v_cda));
711 NIC_PUT(sc, SNCR_CDC, MAXCAM);
712 NIC_PUT(sc, SNCR_CR, CR_LCAM);
716 while ((NIC_GET(sc, SNCR_CR) & CR_LCAM) && timeout--)
720 panic("%s: CAM initialisation failed\n",
721 device_get_nameunit(sc->sc_dev));
724 while (((NIC_GET(sc, SNCR_ISR) & ISR_LCD) == 0) && timeout--)
727 if (NIC_GET(sc, SNCR_ISR) & ISR_LCD)
728 NIC_PUT(sc, SNCR_ISR, ISR_LCD);
730 device_printf(sc->sc_dev,
731 "CAM initialisation without interrupt\n");
737 struct snc_softc *sc;
741 printf("CAM entries:\n");
742 NIC_PUT(sc, SNCR_CR, CR_RST);
745 for (i = 0; i < 16; i++) {
746 u_short ap2, ap1, ap0;
747 NIC_PUT(sc, SNCR_CEP, i);
749 ap2 = NIC_GET(sc, SNCR_CAP2);
750 ap1 = NIC_GET(sc, SNCR_CAP1);
751 ap0 = NIC_GET(sc, SNCR_CAP0);
752 printf("%d: ap2=0x%x ap1=0x%x ap0=0x%x\n", i, ap2, ap1, ap0);
754 printf("CAM enable 0x%x\n", NIC_GET(sc, SNCR_CEP));
756 NIC_PUT(sc, SNCR_CR, 0);
763 struct snc_softc *sc;
768 for (i = 0; i < NTDA; i++) {
774 sc->mtd_prev = NTDA - 1;
776 sc->mtd_tlinko = TXP_FRAGOFF + 1*TXP_FRAGSIZE + TXP_FPTRLO;
777 sc->mtd_pint = NTDA/2;
779 NIC_PUT(sc, SNCR_UTDA, UPPER(sc->mtda[0].mtd_vtxp));
780 NIC_PUT(sc, SNCR_CTDA, LOWER(sc->mtda[0].mtd_vtxp));
785 struct snc_softc *sc;
788 u_int32_t vv_rda = 0;
791 /* link the RDA's together into a circular list */
792 for (i = 0; i < (sc->sc_nrda - 1); i++) {
793 v_rda = sc->v_rda + (i * RXPKT_SIZE(sc));
794 vv_rda = sc->v_rda + ((i+1) * RXPKT_SIZE(sc));
795 SWO(sc, v_rda, RXPKT_RLINK, LOWER(vv_rda));
796 SWO(sc, v_rda, RXPKT_INUSE, 1);
798 v_rda = sc->v_rda + ((sc->sc_nrda - 1) * RXPKT_SIZE(sc));
799 SWO(sc, v_rda, RXPKT_RLINK, LOWER(sc->v_rda) | EOL);
800 SWO(sc, v_rda, RXPKT_INUSE, 1);
802 /* mark end of receive descriptor list */
803 sc->sc_rdamark = sc->sc_nrda - 1;
807 NIC_PUT(sc, SNCR_URDA, UPPER(sc->v_rda));
808 NIC_PUT(sc, SNCR_CRDA, LOWER(sc->v_rda));
814 struct snc_softc *sc;
818 int bitmode = sc->bitmode;
821 NIC_PUT(sc, SNCR_EOBC, RBASIZE(sc) / 2 - 2);
823 NIC_PUT(sc, SNCR_EOBC, RBASIZE(sc) / 2 - 1);
825 NIC_PUT(sc, SNCR_URRA, UPPER(sc->v_rra[0]));
826 NIC_PUT(sc, SNCR_RSA, LOWER(sc->v_rra[0]));
827 /* rea must point just past the end of the rra space */
828 NIC_PUT(sc, SNCR_REA, LOWER(sc->v_rea));
829 NIC_PUT(sc, SNCR_RRP, LOWER(sc->v_rra[0]));
830 NIC_PUT(sc, SNCR_RSC, 0);
832 /* fill up SOME of the rra with buffers */
833 for (i = 0; i < NRBA; i++) {
834 v = SONIC_GETDMA(sc->rbuf[i]);
835 SWO(sc, sc->v_rra[i], RXRSRC_PTRHI, UPPER(v));
836 SWO(sc, sc->v_rra[i], RXRSRC_PTRLO, LOWER(v));
837 SWO(sc, sc->v_rra[i], RXRSRC_WCHI, UPPER(PAGE_SIZE/2));
838 SWO(sc, sc->v_rra[i], RXRSRC_WCLO, LOWER(PAGE_SIZE/2));
840 sc->sc_rramark = NRBA;
841 NIC_PUT(sc, SNCR_RWP, LOWER(sc->v_rra[sc->sc_rramark]));
849 struct snc_softc *sc = (struct snc_softc *)arg;
852 if (sc->sc_enabled == 0)
856 while ((isr = (NIC_GET(sc, SNCR_ISR) & ISR_ALL)) != 0) {
857 /* scrub the interrupts that we are going to service */
858 NIC_PUT(sc, SNCR_ISR, isr);
861 if (isr & (ISR_BR | ISR_LCD | ISR_TC))
862 device_printf(sc->sc_dev,
863 "unexpected interrupt status 0x%x\n",
866 if (isr & (ISR_TXDN | ISR_TXER | ISR_PINT))
872 if (isr & (ISR_HBL | ISR_RDE | ISR_RBE | ISR_RBAE | ISR_RFO)) {
875 * The repeater is not providing a heartbeat.
876 * In itself this isn't harmful, lots of the
877 * cheap repeater hubs don't supply a heartbeat.
878 * So ignore the lack of heartbeat. Its only
879 * if we can't detect a carrier that we have a
884 device_printf(sc->sc_dev,
885 "receive descriptors exhausted\n");
887 device_printf(sc->sc_dev,
888 "receive buffers exhausted\n");
890 device_printf(sc->sc_dev,
891 "receive buffer area exhausted\n");
893 device_printf(sc->sc_dev,
894 "receive FIFO overrun\n");
896 if (isr & (ISR_CRC | ISR_FAE | ISR_MP)) {
906 sncstart_locked(sc->sc_ifp);
913 * Transmit interrupt routine
917 struct snc_softc *sc;
921 unsigned short txp_status;
923 struct ifnet *ifp = sc->sc_ifp;
927 if (mtd_hw == sc->mtd_free)
930 while (mtd_hw != sc->mtd_free) {
931 mtd = &sc->mtda[mtd_hw];
935 if (SRO(sc, txp, TXP_STATUS) == 0) {
936 break; /* it hasn't really gone yet */
940 if ((sncdebug & SNC_SHOWTXHDR) != 0)
942 struct ether_header eh;
944 (*sc->sc_copyfrombuf)(sc, &eh, mtd->mtd_vbuf, sizeof(eh));
945 device_printf(sc->sc_dev,
946 "xmit status=0x%x len=%d type=0x%x from %6D",
947 SRO(sc, txp, TXP_STATUS),
948 SRO(sc, txp, TXP_PKTSIZE),
949 htons(eh.ether_type),
950 eh.ether_shost, ":");
951 printf(" (to %6D)\n", eh.ether_dhost, ":");
953 #endif /* SNCDEBUG */
955 sc->sc_tx_timeout = 0;
956 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
958 if (mtd->mtd_mbuf != 0) {
959 m_freem(mtd->mtd_mbuf);
962 if (++mtd_hw == NTDA) mtd_hw = 0;
964 txp_status = SRO(sc, txp, TXP_STATUS);
966 ifp->if_collisions += (txp_status & TCR_EXC) ? 16 :
967 ((txp_status & TCR_NC) >> 12);
969 if ((txp_status & TCR_PTX) == 0) {
971 device_printf(sc->sc_dev, "Tx packet status=0x%x\n",
974 /* XXX - DG This looks bogus */
975 if (mtd_hw != sc->mtd_free) {
976 printf("resubmitting remaining packets\n");
977 mtd = &sc->mtda[mtd_hw];
978 NIC_PUT(sc, SNCR_CTDA, LOWER(mtd->mtd_vtxp));
979 NIC_PUT(sc, SNCR_CR, CR_TXP);
991 * Receive interrupt routine
995 struct snc_softc *sc;
1002 u_int16_t rxpkt_ptr;
1004 rda = sc->v_rda + (sc->sc_rxmark * RXPKT_SIZE(sc));
1006 while (SRO(sc, rda, RXPKT_INUSE) == 0) {
1007 u_int status = SRO(sc, rda, RXPKT_STATUS);
1009 orra = RBASEQ(SRO(sc, rda, RXPKT_SEQNO)) & RRAMASK;
1010 rxpkt_ptr = SRO(sc, rda, RXPKT_PTRLO);
1012 * Do not trunc ether_header length.
1013 * Our sonic_read() and sonic_get() require it.
1015 len = SRO(sc, rda, RXPKT_BYTEC) - FCSSIZE;
1016 if (status & RCR_PRX) {
1017 /* XXX: Does PAGE_MASK require? */
1019 sc->rbuf[orra & RBAMASK] + (rxpkt_ptr & PAGE_MASK);
1020 if (sonic_read(sc, pkt, len))
1021 sc->sc_ifp->if_ipackets++;
1023 sc->sc_ifp->if_ierrors++;
1025 sc->sc_ifp->if_ierrors++;
1028 * give receive buffer area back to chip.
1030 * If this was the last packet in the RRA, give the RRA to
1032 * If sonic read didnt copy it out then we would have to
1034 * (dont bother add it back in again straight away)
1036 * Really, we're doing v_rra[rramark] = v_rra[orra] but
1037 * we have to use the macros because SONIC might be in
1038 * 16 or 32 bit mode.
1040 if (status & RCR_LPKT) {
1041 u_int32_t tmp1, tmp2;
1043 rramark = sc->sc_rramark;
1044 tmp1 = sc->v_rra[rramark];
1045 tmp2 = sc->v_rra[orra];
1046 SWO(sc, tmp1, RXRSRC_PTRLO,
1047 SRO(sc, tmp2, RXRSRC_PTRLO));
1048 SWO(sc, tmp1, RXRSRC_PTRHI,
1049 SRO(sc, tmp2, RXRSRC_PTRHI));
1050 SWO(sc, tmp1, RXRSRC_WCLO,
1051 SRO(sc, tmp2, RXRSRC_WCLO));
1052 SWO(sc, tmp1, RXRSRC_WCHI,
1053 SRO(sc, tmp2, RXRSRC_WCHI));
1055 /* zap old rra for fun */
1056 SWO(sc, tmp2, RXRSRC_WCHI, 0);
1057 SWO(sc, tmp2, RXRSRC_WCLO, 0);
1059 sc->sc_rramark = (++rramark) & RRAMASK;
1060 NIC_PUT(sc, SNCR_RWP, LOWER(sc->v_rra[rramark]));
1065 * give receive descriptor back to chip simple
1068 rdamark = sc->sc_rdamark;
1069 SWO(sc, rda, RXPKT_INUSE, 1);
1070 SWO(sc, rda, RXPKT_RLINK,
1071 SRO(sc, rda, RXPKT_RLINK) | EOL);
1072 SWO(sc, (sc->v_rda + (rdamark * RXPKT_SIZE(sc))), RXPKT_RLINK,
1073 SRO(sc, (sc->v_rda + (rdamark * RXPKT_SIZE(sc))),
1074 RXPKT_RLINK) & ~EOL);
1075 sc->sc_rdamark = sc->sc_rxmark;
1077 if (++sc->sc_rxmark >= sc->sc_nrda)
1079 rda = sc->v_rda + (sc->sc_rxmark * RXPKT_SIZE(sc));
1084 * sonic_read -- pull packet off interface and forward to
1085 * appropriate protocol handler
1088 sonic_read(sc, pkt, len)
1089 struct snc_softc *sc;
1093 struct ifnet *ifp = sc->sc_ifp;
1094 struct ether_header *et;
1097 if (len <= sizeof(struct ether_header) ||
1098 len > ETHERMTU + sizeof(struct ether_header)) {
1099 device_printf(sc->sc_dev,
1100 "invalid packet length %d bytes\n", len);
1104 /* Pull packet off interface. */
1105 m = sonic_get(sc, pkt, len);
1110 /* We assume that the header fit entirely in one mbuf. */
1111 et = mtod(m, struct ether_header *);
1114 if ((sncdebug & SNC_SHOWRXHDR) != 0)
1116 device_printf(sc->sc_dev, "rcvd 0x%x len=%d type=0x%x from %6D",
1117 pkt, len, htons(et->ether_type),
1118 et->ether_shost, ":");
1119 printf(" (to %6D)\n", et->ether_dhost, ":");
1121 #endif /* SNCDEBUG */
1123 /* Pass the packet up. */
1125 (*ifp->if_input)(ifp, m);
1132 * munge the received packet into an mbuf chain
1134 static struct mbuf *
1135 sonic_get(sc, pkt, datalen)
1136 struct snc_softc *sc;
1140 struct mbuf *m, *top, **mp;
1143 * Do not trunc ether_header length.
1144 * Our sonic_read() and sonic_get() require it.
1147 MGETHDR(m, M_DONTWAIT, MT_DATA);
1150 m->m_pkthdr.rcvif = sc->sc_ifp;
1151 m->m_pkthdr.len = datalen;
1156 while (datalen > 0) {
1158 MGET(m, M_DONTWAIT, MT_DATA);
1165 if (datalen >= MINCLSIZE) {
1166 MCLGET(m, M_DONTWAIT);
1167 if ((m->m_flags & M_EXT) == 0) {
1168 if (top) m_freem(top);
1177 ALIGN(sizeof(struct ether_header)) -
1178 sizeof(struct ether_header);
1183 m->m_len = len = min(datalen, len);
1185 (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), pkt, len);
1195 * Enable power on the interface.
1199 struct snc_softc *sc;
1203 device_printf(sc->sc_dev, "snc_enable()\n");
1204 #endif /* SNCDEBUG */
1206 if (sc->sc_enabled == 0 && sc->sc_enable != NULL) {
1207 if ((*sc->sc_enable)(sc) != 0) {
1208 device_printf(sc->sc_dev, "device enable failed\n");
1218 * Disable power on the interface.
1222 struct snc_softc *sc;
1226 device_printf(sc->sc_dev, "snc_disable()\n");
1227 #endif /* SNCDEBUG */
1229 if (sc->sc_enabled != 0 && sc->sc_disable != NULL) {
1230 (*sc->sc_disable)(sc);