From b8c4a37a40fbc7dd0a9e13c6a19af16489874aa1 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 10 May 1996 12:41:32 +0000 Subject: if_name/if_unit -> if_xname/if_softc --- sys/dev/ic/am7990.c | 308 ++++++++++++++++++++++++++++++------------------ sys/dev/ic/am7990var.h | 133 +++++++++++++++------ sys/dev/ic/elink3.c | 21 ++-- sys/dev/ic/i82595reg.h | 219 ++++++++++++++++++++++++++++++++++ sys/dev/ic/pdq_ifsubr.c | 8 +- sys/dev/ic/pdqvar.h | 16 ++- sys/dev/ic/smc90cx6.c | 26 ++-- 7 files changed, 551 insertions(+), 180 deletions(-) create mode 100644 sys/dev/ic/i82595reg.h (limited to 'sys/dev/ic') diff --git a/sys/dev/ic/am7990.c b/sys/dev/ic/am7990.c index 2b243bd2095..5f89ebb8e63 100644 --- a/sys/dev/ic/am7990.c +++ b/sys/dev/ic/am7990.c @@ -1,5 +1,5 @@ -/* $OpenBSD: am7990.c,v 1.7 1996/05/05 13:39:31 mickey Exp $ */ -/* $NetBSD: am7990.c,v 1.18 1996/04/22 02:40:50 christos Exp $ */ +/* $OpenBSD: am7990.c,v 1.8 1996/05/10 12:41:10 deraadt Exp $ */ +/* $NetBSD: am7990.c,v 1.19 1996/05/07 01:38:35 thorpej Exp $ */ /*- * Copyright (c) 1995 Charles M. Hannum. All rights reserved. @@ -40,10 +40,23 @@ * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */ +#include "bpfilter.h" + +#include +#include +#include +#include +#include +#include +#include #include #include +#include + #ifdef INET +#include +#include #include #include #include @@ -54,31 +67,81 @@ #include #endif +#include +#include + #ifdef LEDEBUG -void recv_print __P((struct le_softc *, int)); -void xmit_print __P((struct le_softc *, int)); +void am7990_recv_print __P((struct am7990_softc *, int)); +void am7990_xmit_print __P((struct am7990_softc *, int)); #endif +integrate void am7990_rint __P((struct am7990_softc *)); +integrate void am7990_tint __P((struct am7990_softc *)); + +integrate int am7990_put __P((struct am7990_softc *, int, struct mbuf *)); +integrate struct mbuf *am7990_get __P((struct am7990_softc *, int, int)); +integrate void am7990_read __P((struct am7990_softc *, int, int)); + +hide void am7990_shutdown __P((void *)); + #define ifp (&sc->sc_arpcom.ac_if) +#if 0 /* XXX what do we do about this?! --thorpej */ +static inline u_int16_t ether_cmp __P((void *, void *)); + +/* + * Compare two Ether/802 addresses for equality, inlined and + * unrolled for speed. I'd love to have an inline assembler + * version of this... XXX: Who wanted that? mycroft? + * I wrote one, but the following is just as efficient. + * This expands to 10 short m68k instructions! -gwr + * Note: use this like bcmp() + */ +static inline u_short +ether_cmp(one, two) + void *one, *two; +{ + register u_int16_t *a = (u_short *) one; + register u_int16_t *b = (u_short *) two; + register u_int16_t diff; + + diff = *a++ - *b++; + diff |= *a++ - *b++; + diff |= *a++ - *b++; + + return (diff); +} + +#define ETHER_CMP ether_cmp +#endif /* XXX */ + #ifndef ETHER_CMP #define ETHER_CMP(a, b) bcmp((a), (b), ETHER_ADDR_LEN) #endif +/* + * am7990 configuration driver. Attachments are provided by + * machine-dependent driver front-ends. + */ +struct cfdriver le_cd = { + NULL, "le", DV_IFNET +}; + void -leconfig(sc) - struct le_softc *sc; +am7990_config(sc) + struct am7990_softc *sc; { int mem; /* Make sure the chip is stopped. */ - lestop(sc); + am7990_stop(sc); /* Initialize ifnet structure. */ - ifp->if_unit = sc->sc_dev.dv_unit; - ifp->if_start = lestart; - ifp->if_ioctl = leioctl; - ifp->if_watchdog = lewatchdog; + bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); + ifp->if_softc = sc; + ifp->if_start = am7990_start; + ifp->if_ioctl = am7990_ioctl; + ifp->if_watchdog = am7990_watchdog; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; #ifdef LANCE_REVC_BUG @@ -111,13 +174,17 @@ leconfig(sc) sc->sc_ntbuf = 8; break; default: - panic("leconfig: weird memory size"); + panic("am7990_config: weird memory size"); } printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); printf("%s: %d receive buffers, %d transmit buffers\n", sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf); + sc->sc_sh = shutdownhook_establish(am7990_shutdown, sc); + if (sc->sc_sh == NULL) + panic("am7990_config: can't establish shutdownhook"); + mem = 0; sc->sc_initaddr = mem; mem += sizeof(struct leinit); @@ -136,34 +203,22 @@ leconfig(sc) } void -lereset(sc) - struct le_softc *sc; +am7990_reset(sc) + struct am7990_softc *sc; { int s; s = splimp(); - leinit(sc); + am7990_init(sc); splx(s); } -void -lewatchdog(unit) - int unit; -{ - struct le_softc *sc = LE_SOFTC(unit); - - log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); - ++ifp->if_oerrors; - - lereset(sc); -} - /* * Set up the initialization block and the descriptor rings. */ void -lememinit(sc) - register struct le_softc *sc; +am7990_meminit(sc) + register struct am7990_softc *sc; { u_long a; int bix; @@ -183,7 +238,7 @@ lememinit(sc) (sc->sc_arpcom.ac_enaddr[3] << 8) | sc->sc_arpcom.ac_enaddr[2]; init.init_padr[2] = (sc->sc_arpcom.ac_enaddr[5] << 8) | sc->sc_arpcom.ac_enaddr[4]; - lesetladrf(&sc->sc_arpcom, init.init_ladrf); + am7990_setladrf(&sc->sc_arpcom, init.init_ladrf); sc->sc_last_rd = 0; sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; @@ -228,11 +283,11 @@ lememinit(sc) } void -lestop(sc) - struct le_softc *sc; +am7990_stop(sc) + struct am7990_softc *sc; { - lewrcsr(sc, LE_CSR0, LE_C0_STOP); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); } /* @@ -240,45 +295,47 @@ lestop(sc) * and transmit/receive descriptor rings. */ void -leinit(sc) - register struct le_softc *sc; +am7990_init(sc) + register struct am7990_softc *sc; { register int timo; u_long a; - lewrcsr(sc, LE_CSR0, LE_C0_STOP); - LE_DELAY(100); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); + DELAY(100); /* Set the correct byte swapping mode, etc. */ - lewrcsr(sc, LE_CSR3, sc->sc_conf3); + (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3); /* Set up LANCE init block. */ - lememinit(sc); + am7990_meminit(sc); /* Give LANCE the physical address of its init block. */ a = sc->sc_addr + LE_INITADDR(sc); - lewrcsr(sc, LE_CSR1, a); - lewrcsr(sc, LE_CSR2, a >> 16); + (*sc->sc_wrcsr)(sc, LE_CSR1, a); + (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16); /* Try to initialize the LANCE. */ - LE_DELAY(100); - lewrcsr(sc, LE_CSR0, LE_C0_INIT); + DELAY(100); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT); /* Wait for initialization to finish. */ for (timo = 100000; timo; timo--) - if (lerdcsr(sc, LE_CSR0) & LE_C0_IDON) + if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) break; - if (lerdcsr(sc, LE_CSR0) & LE_C0_IDON) { + if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) { /* Start the LANCE. */ - lewrcsr(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT | LE_C0_IDON); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT | + LE_C0_IDON); ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; ifp->if_timer = 0; - lestart(ifp); + am7990_start(ifp); } else printf("%s: card failed to initialize\n", sc->sc_dev.dv_xname); - lehwinit(sc); + if (sc->sc_hwinit) + (*sc->sc_hwinit)(sc); } /* @@ -286,8 +343,8 @@ leinit(sc) * network buffer memory. */ integrate int -leput(sc, boff, m) - struct le_softc *sc; +am7990_put(sc, boff, m) + struct am7990_softc *sc; int boff; register struct mbuf *m; { @@ -319,8 +376,8 @@ leput(sc, boff, m) * we copy into clusters. */ integrate struct mbuf * -leget(sc, boff, totlen) - struct le_softc *sc; +am7990_get(sc, boff, totlen) + struct am7990_softc *sc; int boff, totlen; { register struct mbuf *m; @@ -367,8 +424,8 @@ leget(sc, boff, totlen) * Pass a packet to the higher levels. */ integrate void -leread(sc, boff, len) - register struct le_softc *sc; +am7990_read(sc, boff, len) + register struct am7990_softc *sc; int boff, len; { struct mbuf *m; @@ -385,7 +442,7 @@ leread(sc, boff, len) } /* Pull packet off interface. */ - m = leget(sc, boff, len); + m = am7990_get(sc, boff, len); if (m == 0) { ifp->if_ierrors++; return; @@ -441,8 +498,8 @@ leread(sc, boff, len) } integrate void -lerint(sc) - struct le_softc *sc; +am7990_rint(sc) + struct am7990_softc *sc; { register int bix; int rp; @@ -487,9 +544,10 @@ lerint(sc) } else { #ifdef LEDEBUG if (sc->sc_debug) - recv_print(sc, sc->sc_last_rd); + am7990_recv_print(sc, sc->sc_last_rd); #endif - leread(sc, LE_RBUFADDR(sc, bix), (int)rmd.rmd3 - 4); + am7990_read(sc, LE_RBUFADDR(sc, bix), + (int)rmd.rmd3 - 4); } rmd.rmd1_bits = LE_R1_OWN; @@ -515,8 +573,8 @@ lerint(sc) } integrate void -letint(sc) - register struct le_softc *sc; +am7990_tint(sc) + register struct am7990_softc *sc; { register int bix; struct letmd tmd; @@ -546,20 +604,23 @@ letint(sc) if (tmd.tmd1_bits & LE_T1_ERR) { if (tmd.tmd3 & LE_T3_BUFF) - printf("%s: transmit buffer error\n", sc->sc_dev.dv_xname); + printf("%s: transmit buffer error\n", + sc->sc_dev.dv_xname); else if (tmd.tmd3 & LE_T3_UFLO) printf("%s: underflow\n", sc->sc_dev.dv_xname); if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { - lereset(sc); + am7990_reset(sc); return; } if (tmd.tmd3 & LE_T3_LCAR) - printf("%s: lost carrier\n", sc->sc_dev.dv_xname); + printf("%s: lost carrier\n", + sc->sc_dev.dv_xname); if (tmd.tmd3 & LE_T3_LCOL) ifp->if_collisions++; if (tmd.tmd3 & LE_T3_RTRY) { printf("%s: excessive collisions, tdr %d\n", - sc->sc_dev.dv_xname, tmd.tmd3 & LE_T3_TDR_MASK); + sc->sc_dev.dv_xname, + tmd.tmd3 & LE_T3_TDR_MASK); ifp->if_collisions += 16; } ifp->if_oerrors++; @@ -580,7 +641,7 @@ letint(sc) sc->sc_first_td = bix; - lestart(ifp); + am7990_start(ifp); if (sc->sc_no_td == 0) ifp->if_timer = 0; @@ -590,22 +651,22 @@ letint(sc) * Controller interrupt. */ int -leintr(arg) +am7990_intr(arg) register void *arg; { - register struct le_softc *sc = arg; + register struct am7990_softc *sc = arg; register u_int16_t isr; - isr = lerdcsr(sc, LE_CSR0); + isr = (*sc->sc_rdcsr)(sc, LE_CSR0); #ifdef LEDEBUG if (sc->sc_debug) - printf("%s: leintr entering with isr=%04x\n", + printf("%s: am7990_intr entering with isr=%04x\n", sc->sc_dev.dv_xname, isr); #endif if ((isr & LE_C0_INTR) == 0) return (0); - lewrcsr(sc, LE_CSR0, + (*sc->sc_wrcsr)(sc, LE_CSR0, isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR | LE_C0_RINT | LE_C0_TINT | LE_C0_IDON)); if (isr & LE_C0_ERR) { @@ -629,7 +690,7 @@ leintr(arg) } if (isr & LE_C0_MERR) { printf("%s: memory error\n", sc->sc_dev.dv_xname); - lereset(sc); + am7990_reset(sc); return (1); } } @@ -637,26 +698,38 @@ leintr(arg) if ((isr & LE_C0_RXON) == 0) { printf("%s: receiver disabled\n", sc->sc_dev.dv_xname); ifp->if_ierrors++; - lereset(sc); + am7990_reset(sc); return (1); } if ((isr & LE_C0_TXON) == 0) { printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname); ifp->if_oerrors++; - lereset(sc); + am7990_reset(sc); return (1); } if (isr & LE_C0_RINT) - lerint(sc); + am7990_rint(sc); if (isr & LE_C0_TINT) - letint(sc); + am7990_tint(sc); return (1); } #undef ifp +void +am7990_watchdog(ifp) + struct ifnet *ifp; +{ + struct am7990_softc *sc = ifp->if_softc; + + log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); + ++ifp->if_oerrors; + + am7990_reset(sc); +} + /* * Setup output on interface. * Get another datagram to send off of the interface queue, and map it to the @@ -664,10 +737,10 @@ leintr(arg) * Called only at splimp or interrupt level. */ void -lestart(ifp) +am7990_start(ifp) register struct ifnet *ifp; { - register struct le_softc *sc = LE_SOFTC(ifp->if_unit); + register struct am7990_softc *sc = ifp->if_softc; register int bix; register struct mbuf *m; struct letmd tmd; @@ -705,7 +778,7 @@ lestart(ifp) /* * Copy the mbuf chain into the transmit buffer. */ - len = leput(sc, LE_TBUFADDR(sc, bix), m); + len = am7990_put(sc, LE_TBUFADDR(sc, bix), m); #ifdef LEDEBUG if (len > ETHERMTU + sizeof(struct ether_header)) @@ -725,10 +798,10 @@ lestart(ifp) #ifdef LEDEBUG if (sc->sc_debug) - xmit_print(sc, sc->sc_last_td); + am7990_xmit_print(sc, sc->sc_last_td); #endif - lewrcsr(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); if (++bix == sc->sc_ntbuf) bix = 0; @@ -747,12 +820,12 @@ lestart(ifp) * Process an ioctl request. */ int -leioctl(ifp, cmd, data) +am7990_ioctl(ifp, cmd, data) register struct ifnet *ifp; u_long cmd; caddr_t data; { - struct le_softc *sc = LE_SOFTC(ifp->if_unit); + register struct am7990_softc *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; int s, error = 0; @@ -772,12 +845,12 @@ leioctl(ifp, cmd, data) switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: - leinit(sc); + am7990_init(sc); arp_ifinit(&sc->sc_arpcom, ifa); break; #endif default: - leinit(sc); + am7990_init(sc); break; } break; @@ -789,7 +862,7 @@ leioctl(ifp, cmd, data) * If interface is marked down and it is running, then * stop it. */ - lestop(sc); + am7990_stop(sc); ifp->if_flags &= ~IFF_RUNNING; } else if ((ifp->if_flags & IFF_UP) != 0 && (ifp->if_flags & IFF_RUNNING) == 0) { @@ -797,14 +870,14 @@ leioctl(ifp, cmd, data) * If interface is marked up and it is stopped, then * start it. */ - leinit(sc); + am7990_init(sc); } else { /* * Reset the interface to pick up changes in any other * flags that affect hardware registers. */ - /*lestop(sc);*/ - leinit(sc); + /*am7990_stop(sc);*/ + am7990_init(sc); } #ifdef LEDEBUG if (ifp->if_flags & IFF_DEBUG) @@ -825,7 +898,7 @@ leioctl(ifp, cmd, data) * Multicast list has changed; set the hardware filter * accordingly. */ - lereset(sc); + am7990_reset(sc); error = 0; } break; @@ -839,10 +912,18 @@ leioctl(ifp, cmd, data) return (error); } +hide void +am7990_shutdown(arg) + void *arg; +{ + + am7990_stop((struct am7990_softc *)arg); +} + #ifdef LEDEBUG void -recv_print(sc, no) - struct le_softc *sc; +am7990_recv_print(sc, no) + struct am7990_softc *sc; int no; { struct lermd rmd; @@ -853,7 +934,8 @@ recv_print(sc, no) len = rmd.rmd3; printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no, len); - printf("%s: status %04x\n", sc->sc_dev.dv_xname, lerdcsr(sc, LE_CSR0)); + printf("%s: status %04x\n", sc->sc_dev.dv_xname, + (*sc->sc_rdcsr)(sc, LE_CSR0)); printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", sc->sc_dev.dv_xname, rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3); @@ -867,8 +949,8 @@ recv_print(sc, no) } void -xmit_print(sc, no) - struct le_softc *sc; +am7990_xmit_print(sc, no) + struct am7990_softc *sc; int no; { struct letmd tmd; @@ -879,7 +961,8 @@ xmit_print(sc, no) len = -tmd.tmd2; printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no, len); - printf("%s: status %04x\n", sc->sc_dev.dv_xname, lerdcsr(sc, LE_CSR0)); + printf("%s: status %04x\n", sc->sc_dev.dv_xname, + (*sc->sc_rdcsr)(sc, LE_CSR0)); printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", sc->sc_dev.dv_xname, tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3); @@ -897,7 +980,7 @@ xmit_print(sc, no) * Set up the logical address filter. */ void -lesetladrf(ac, af) +am7990_setladrf(ac, af) struct arpcom *ac; u_int16_t *af; { @@ -974,7 +1057,6 @@ allmulti: * (3) gap16 (16 bytes of data followed by 16 bytes of padding). */ -#ifdef LE_NEED_BUF_CONTIG /* * contig: contiguous data with no padding. * @@ -983,7 +1065,7 @@ allmulti: void am7990_copytobuf_contig(sc, from, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *from; int boff, len; { @@ -997,7 +1079,7 @@ am7990_copytobuf_contig(sc, from, boff, len) void am7990_copyfrombuf_contig(sc, to, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *to; int boff, len; { @@ -1011,7 +1093,7 @@ am7990_copyfrombuf_contig(sc, to, boff, len) void am7990_zerobuf_contig(sc, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; int boff, len; { volatile caddr_t buf = sc->sc_mem; @@ -1021,9 +1103,13 @@ am7990_zerobuf_contig(sc, boff, len) */ bzero(buf + boff, len); } -#endif /* LE_NEED_BUF_CONTIG */ -#ifdef LE_NEED_BUF_GAP2 +#if 0 +/* + * Examples only; duplicate these and tweak (if necessary) in + * machine-specific front-ends. + */ + /* * gap2: two bytes of data followed by two bytes of pad. * @@ -1033,7 +1119,7 @@ am7990_zerobuf_contig(sc, boff, len) void am7990_copytobuf_gap2(sc, fromv, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *fromv; int boff; register int len; @@ -1062,7 +1148,7 @@ am7990_copytobuf_gap2(sc, fromv, boff, len) void am7990_copyfrombuf_gap2(sc, tov, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *tov; int boff, len; { @@ -1092,7 +1178,7 @@ am7990_copyfrombuf_gap2(sc, tov, boff, len) void am7990_zerobuf_gap2(sc, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; int boff, len; { volatile caddr_t buf = sc->sc_mem; @@ -1111,9 +1197,7 @@ am7990_zerobuf_gap2(sc, boff, len) len -= 2; } } -#endif /* LE_NEED_BUF_GAP2 */ -#ifdef LE_NEED_BUF_GAP16 /* * gap16: 16 bytes of data followed by 16 bytes of pad. * @@ -1122,7 +1206,7 @@ am7990_zerobuf_gap2(sc, boff, len) void am7990_copytobuf_gap16(sc, fromv, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *fromv; int boff; register int len; @@ -1147,7 +1231,7 @@ am7990_copytobuf_gap16(sc, fromv, boff, len) void am7990_copyfrombuf_gap16(sc, tov, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; void *tov; int boff, len; { @@ -1171,7 +1255,7 @@ am7990_copyfrombuf_gap16(sc, tov, boff, len) void am7990_zerobuf_gap16(sc, boff, len) - struct le_softc *sc; + struct am7990_softc *sc; int boff, len; { volatile caddr_t buf = sc->sc_mem; @@ -1189,4 +1273,4 @@ am7990_zerobuf_gap16(sc, boff, len) xfer = min(len, 16); } } -#endif /* LE_NEED_BUF_GAP16 */ +#endif /* Example only */ diff --git a/sys/dev/ic/am7990var.h b/sys/dev/ic/am7990var.h index 337bc871fb5..1aa1afd7442 100644 --- a/sys/dev/ic/am7990var.h +++ b/sys/dev/ic/am7990var.h @@ -1,5 +1,5 @@ -/* $OpenBSD: am7990var.h,v 1.4 1996/05/02 13:51:46 deraadt Exp $ */ -/* $NetBSD: am7990var.h,v 1.6 1996/04/22 02:40:49 christos Exp $ */ +/* $OpenBSD: am7990var.h,v 1.5 1996/05/10 12:41:11 deraadt Exp $ */ +/* $NetBSD: am7990var.h,v 1.7 1996/05/07 01:38:37 thorpej Exp $ */ /* * Copyright (c) 1995 Charles M. Hannum. All rights reserved. @@ -32,30 +32,97 @@ #ifdef DDB #define integrate +#define hide #else #define integrate static __inline +#define hide static #endif -void leconfig __P((struct le_softc *)); -void leinit __P((struct le_softc *)); -int leioctl __P((struct ifnet *, u_long, caddr_t)); -void lememinit __P((struct le_softc *)); -void lereset __P((struct le_softc *)); -void lesetladrf __P((struct arpcom *, u_int16_t *)); -void lestart __P((struct ifnet *)); -void lestop __P((struct le_softc *)); -void lewatchdog __P((int)); +/* + * Ethernet software status per device. + * + * Each interface is referenced by a network interface structure, + * arpcom.ac_if, which the routing code uses to locate the interface. + * This structure contains the output queue for the interface, its address, ... + * + * NOTE: this structure MUST be the first element in machine-dependent + * le_softc structures! This is designed SPECIFICALLY to make it possible + * to simply cast a "void *" to "struct le_softc *" or to + * "struct am7990_softc *". Among other things, this saves a lot of hair + * in the interrupt handlers. + */ +struct am7990_softc { + struct device sc_dev; /* base device glue */ + struct arpcom sc_arpcom; /* Ethernet common part */ + + /* + * Memory functions: + * + * copy to/from descriptor + * copy to/from buffer + * zero bytes in buffer + */ + void (*sc_copytodesc) + __P((struct am7990_softc *, void *, int, int)); + void (*sc_copyfromdesc) + __P((struct am7990_softc *, void *, int, int)); + void (*sc_copytobuf) + __P((struct am7990_softc *, void *, int, int)); + void (*sc_copyfrombuf) + __P((struct am7990_softc *, void *, int, int)); + void (*sc_zerobuf) + __P((struct am7990_softc *, int, int)); + + /* + * Machine-dependent functions: + * + * read/write CSR + * hardware init hook - may be NULL + */ + u_int16_t (*sc_rdcsr) + __P((struct am7990_softc *, u_int16_t)); + void (*sc_wrcsr) + __P((struct am7990_softc *, u_int16_t, u_int16_t)); + void (*sc_hwinit) __P((struct am7990_softc *)); + + void *sc_sh; /* shutdownhook cookie */ + + u_int16_t sc_conf3; /* CSR3 value */ -integrate void lehwinit __P((struct le_softc *)); -integrate u_int16_t lerdcsr __P((struct le_softc *, u_int16_t)); -integrate void lewrcsr __P((struct le_softc *, u_int16_t, u_int16_t)); + void *sc_mem; /* base address of RAM -- CPU's view */ + u_long sc_addr; /* base address of RAM -- LANCE's view */ -integrate void lerint __P((struct le_softc *)); -integrate void letint __P((struct le_softc *)); + u_long sc_memsize; /* size of RAM */ -integrate int leput __P((struct le_softc *, int, struct mbuf *)); -integrate struct mbuf *leget __P((struct le_softc *, int, int)); -integrate void leread __P((struct le_softc *, int, int)); + int sc_nrbuf; /* number of receive buffers */ + int sc_ntbuf; /* number of transmit buffers */ + int sc_last_rd; + int sc_first_td, sc_last_td, sc_no_td; + + int sc_initaddr; + int sc_rmdaddr; + int sc_tmdaddr; + int sc_rbufaddr; + int sc_tbufaddr; + +#ifdef LEDEBUG + int sc_debug; +#endif +}; + +/* Export this to machine-dependent drivers. */ +extern struct cfdriver le_cd; + +void am7990_config __P((struct am7990_softc *)); +void am7990_init __P((struct am7990_softc *)); +int am7990_ioctl __P((struct ifnet *, u_long, caddr_t)); +void am7990_meminit __P((struct am7990_softc *)); +void am7990_reset __P((struct am7990_softc *)); +void am7990_setladrf __P((struct arpcom *, u_int16_t *)); +void am7990_start __P((struct ifnet *)); +void am7990_stop __P((struct am7990_softc *)); +void am7990_watchdog __P((struct ifnet *)); +int am7990_intr __P((void *)); /* * The following functions are only useful on certain cpu/bus @@ -63,18 +130,16 @@ integrate void leread __P((struct le_softc *, int, int)); * maximum efficiency, but machine-independent versions are provided * for drivers that have not yet been optimized. */ -#ifdef LE_NEED_BUF_CONTIG -void am7990_copytobuf_contig __P((struct le_softc *, void *, int, int)); -void am7990_copyfrombuf_contig __P((struct le_softc *, void *, int, int)); -void am7990_zerobuf_contig __P((struct le_softc *, int, int)); -#endif /* LE_NEED_BUF_CONTIG */ -#ifdef LE_NEED_BUF_GAP2 -void am7990_copytobuf_gap2 __P((struct le_softc *, void *, int, int)); -void am7990_copyfrombuf_gap2 __P((struct le_softc *, void *, int, int)); -void am7990_zerobuf_gap2 __P((struct le_softc *, int, int)); -#endif /* LE_NEED_BUF_GAP2 */ -#ifdef LE_NEED_BUF_GAP16 -void am7990_copytobuf_gap16 __P((struct le_softc *, void *, int, int)); -void am7990_copyfrombuf_gap16 __P((struct le_softc *, void *, int, int)); -void am7990_zerobuf_gap16 __P((struct le_softc *, int, int)); -#endif /* LE_NEED_BUF_GAP16 */ +void am7990_copytobuf_contig __P((struct am7990_softc *, void *, int, int)); +void am7990_copyfrombuf_contig __P((struct am7990_softc *, void *, int, int)); +void am7990_zerobuf_contig __P((struct am7990_softc *, int, int)); + +#if 0 /* Example only - see am7990.c */ +void am7990_copytobuf_gap2 __P((struct am7990_softc *, void *, int, int)); +void am7990_copyfrombuf_gap2 __P((struct am7990_softc *, void *, int, int)); +void am7990_zerobuf_gap2 __P((struct am7990_softc *, int, int)); + +void am7990_copytobuf_gap16 __P((struct am7990_softc *, void *, int, int)); +void am7990_copyfrombuf_gap16 __P((struct am7990_softc *, void *, int, int)); +void am7990_zerobuf_gap16 __P((struct am7990_softc *, int, int)); +#endif /* Example only */ diff --git a/sys/dev/ic/elink3.c b/sys/dev/ic/elink3.c index fa99384c50a..8eeba382af5 100644 --- a/sys/dev/ic/elink3.c +++ b/sys/dev/ic/elink3.c @@ -1,4 +1,4 @@ -/* $NetBSD: elink3.c,v 1.4 1996/05/03 19:08:47 christos Exp $ */ +/* $NetBSD: elink3.c,v 1.5 1996/05/07 01:43:13 thorpej Exp $ */ /* * Copyright (c) 1994 Herb Peyerl @@ -80,7 +80,7 @@ static int epstatus __P((struct ep_softc *)); void epinit __P((struct ep_softc *)); int epioctl __P((struct ifnet *, u_long, caddr_t)); void epstart __P((struct ifnet *)); -void epwatchdog __P((int)); +void epwatchdog __P((struct ifnet *)); void epreset __P((struct ep_softc *)); void epread __P((struct ep_softc *)); struct mbuf *epget __P((struct ep_softc *, int)); @@ -96,12 +96,11 @@ epconfig(sc, conn) struct ep_softc *sc; u_int conn; { + struct ifnet *ifp = &sc->sc_arpcom.ac_if; bus_chipset_tag_t bc = sc->sc_bc; bus_io_handle_t ioh = sc->sc_ioh; u_short i; - struct ifnet *ifp = &sc->sc_arpcom.ac_if; - sc->ep_connectors = 0; if (conn & IS_AUI) { printf("aui"); @@ -139,8 +138,8 @@ epconfig(sc, conn) printf(" address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); - ifp->if_unit = sc->sc_dev.dv_unit; - ifp->if_name = ep_cd.cd_name; + bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); + ifp->if_softc = sc; ifp->if_start = epstart; ifp->if_ioctl = epioctl; ifp->if_watchdog = epwatchdog; @@ -294,7 +293,7 @@ void epstart(ifp) struct ifnet *ifp; { - register struct ep_softc *sc = ep_cd.cd_devs[ifp->if_unit]; + register struct ep_softc *sc = ifp->if_softc; bus_chipset_tag_t bc = sc->sc_bc; bus_io_handle_t ioh = sc->sc_ioh; struct mbuf *m, *m0; @@ -798,7 +797,7 @@ epioctl(ifp, cmd, data) u_long cmd; caddr_t data; { - struct ep_softc *sc = ep_cd.cd_devs[ifp->if_unit]; + struct ep_softc *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; int s, error = 0; @@ -893,10 +892,10 @@ epreset(sc) } void -epwatchdog(unit) - int unit; +epwatchdog(ifp) + struct ifnet *ifp; { - struct ep_softc *sc = ep_cd.cd_devs[unit]; + struct ep_softc *sc = ifp->if_softc; log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); ++sc->sc_arpcom.ac_if.if_oerrors; diff --git a/sys/dev/ic/i82595reg.h b/sys/dev/ic/i82595reg.h new file mode 100644 index 00000000000..9d6a9812f46 --- /dev/null +++ b/sys/dev/ic/i82595reg.h @@ -0,0 +1,219 @@ +/* $NetBSD: i82595reg.h,v 1.1 1996/05/06 21:36:51 is Exp $ */ + +/* + * Copyright (c) 1996, Ignatios Souvatzis. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Ignatios Souvatzis + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Intel 82595 Ethernet chip register, bit, and structure definitions. + * + * Written by is with reference to Intel's i82595FX data sheet, with some + * clarification coming from looking at the Clarkson Packet Driver code for this + * chip written by Russ Nelson and others; + * + * and + * + * configuration EEPROM layout. Written with reference to Intels + * public "LAN595 Hardware and Software Specifications" document. + */ + +/* registers */ + +/* bank0 */ + +#define COMMAND_REG 0 /* available in any bank */ + +#define MC_SETUP_CMD 0x03 +#define XMT_CMD 0x04 +#define TDR_CMD 0x05 +#define DUMP_CMD 0x06 +#define DIAG_CMD 0x07 +#define RCV_ENABLE_CMD 0x08 +#define RCV_DISABLE_CMD 0x0a +#define RCV_STOP_CMD 0x0b +#define RESET_CMD 0x0e +#define TRISTATE_CMD 0x16 +#define NO_TRISTATE_CMD 0x17 +#define POWER_DOWN_CMD 0x18 +#define SLEEP_MODE_CMD 0x19 +#define NEGOTIATE_CMD 0x1a +#define RESUME_XMT_CMD 0x1c +#define SEL_RESET_CMD 0x1e +#define BANK_SEL(n) (n<<6) /* 0, 1, 2 */ + +#define STATUS_REG 1 + +#define RX_STP_INT 0x01 +#define RX_INT 0x02 +#define TX_INT 0x04 +#define EXEC_INT 0x08 +#define EXEC_STATUS 0x30 + +#define ID_REG 2 + +#define ID_REG_MASK 0x2c +#define ID_REG_SIG 0x24 +#define R_ROBIN_BITS 0xc0 +#define R_ROBIN_SHIFT 6 +#define AUTO_ENABLE 0x10 + +#define INT_MASK_REG 3 + +#define RX_STOP_BIT 0x01 +#define RX_BIT 0x02 +#define TX_BIT 0x04 +#define EXEC_BIT 0x08 +#define ALL_INTS 0x0f + +#define RCV_START_LOW 4 +#define RCV_START_HIGH 5 + +#define RCV_STOP_LOW 6 +#define RCV_STOP_HIGH 7 + +#define XMT_ADDR_REG 0x0a +#define HOST_ADDR_REG 0x0c +#define MEM_PORT_REG 0x0e + +/* -------------------- bank1 -------------------- */ + +#define REG1 1 + +#define WORD_WIDTH 0x02 +#define INT_ENABLE 0x80 + +#define INT_NO_REG 2 + +#define RCV_LOWER_LIMIT_REG 8 +#define RCV_UPPER_LIMIT_REG 9 + +#define XMT_LOWER_LIMIT_REG 10 +#define XMT_UPPER_LIMIT_REG 11 + +/* bank2 */ + +/* reg1, apparently */ + +#define XMT_CHAIN_INT 0x20 /* interupt at end of xmt chain */ +#define XMT_CHAIN_ERRSTOP 0x40 /* int at end of chain even if err */ +#define RCV_DISCARD_BAD 0x80 /* Throw bad frames away and continue */ + +#define RECV_MODES_REG 2 + +#define PROMISC_MODE 0x01 +#define NO_RX_CRC 0x04 +#define NO_ADD_INS 0x10 +#define MULTI_IA 0x20 + +#define MATCH_ID (NO_ADD_INS | NO_RX_CRC | 0x02) +#define MATCH_ALL (NO_ADD_INS | NO_RX_CRC | 0x01) +#define MATCH_BRDCST (NO_ADD_INS | NO_RX_CRC) + +#define MEDIA_SELECT 3 + +#define TPE_BIT 0x04 +#define BNC_BIT 0x20 +#define TEST_MODE_MASK 0x3f + +#define I_ADD(n) (n+4) /* 0..5 -> 4..9 */ + +#define EEPROM_REG 10 + +#define EEDO 8 +#define EEDI 4 +#define EECS 2 +#define EESK 1 + +/* + * EEPROM layout. Written with reference to Intels public "LAN595 Hardware and + * Software Specifications" document. + */ + +#define EEPPW0 0 +#define EEPP_BusWidth 0x0004 +#define EEPP_FlashAdrs 0x0038 +#define EEPP_FLASHTRANSFORM {-1, -1, 0xC8000, 0xCC000, 0xD0000, \ + 0xD4000, 0xD8000, 0xDC000} +#define EEPP_AutoIO 0x0040 +#define EEPP_IOMapping 0xfc00 + +#define EEPPW1 1 +#define EEPP_Int 0x0007 +#define EEPP_INTMAP {3, 5, 9, 10, 11, -1, -1, -1} +#define EEPP_RINTMAP {0xff, 0xff, 0x02, 0x00, 0xff, 0x01, 0xff, \ + 0xff, 0xff, 0x02, 0x03, 0x04 } + +#define EEPP_LinkInteg 0x0008 +#define EEPP_PolarCorr 0x0010 +#define EEPP_AuiTpe 0x0020 +#define EEPP_Jabber 0x0040 +#define EEPP_AutoPort 0x0080 +#define EEPP_SmOut 0x0100 +#define EEPP_BootFls 0x0200 +#define EEPP_DramSize 0x1000 +#define EEPP_AltReady 0x2000 + +#define EEPPEther2 2 +#define EEPPEther1 3 +#define EEPPEther0 4 + +#define EEPPEther2a 0x3c +#define EEPPEther1a 0x3d +#define EEPPEther0a 0x3e + +#define EEPPW5 5 +#define EEPP_BncTpe 0x0001 +#define EEPP_RomSlct 0x0006 /* none, NetWare, NDIS, rsrvd. */ +#define EEPP_NumConn 0x0008 /* 0=2, 1=3 */ + +#define EEPW6 6 +#define EEPP_BoardRev 0x00FF + +#define EEPP_LENGTH 0x40 +#define EEPP_CHKSUM 0xBABA /* Intel claim 0x0, but this seems to be wrong */ + +#define I595_XMT_HDRLEN 8 + +#define CMD_MASK 0x001f +#define TX_DONE 0x0080 +#define CHAIN 0x8000 + +#define XMT_STATUS 0x02 +#define XMT_CHAIN 0x04 +#define XMT_COUNT 0x06 + +#define I595_RCV_HDRLEN 8 + +#define RCV_DONE 0x0008 +#define RX_OK 0x2000 +#define RX_ERR 0x0d81 + + diff --git a/sys/dev/ic/pdq_ifsubr.c b/sys/dev/ic/pdq_ifsubr.c index 13fe3f58900..4526538ab41 100644 --- a/sys/dev/ic/pdq_ifsubr.c +++ b/sys/dev/ic/pdq_ifsubr.c @@ -1,5 +1,5 @@ -/* $OpenBSD: pdq_ifsubr.c,v 1.1 1996/04/18 23:47:23 niklas Exp $ */ -/* $NetBSD: pdq_ifsubr.c,v 1.2 1996/03/11 21:41:32 thorpej Exp $ */ +/* $OpenBSD: pdq_ifsubr.c,v 1.2 1996/05/10 12:41:12 deraadt Exp $ */ +/* $NetBSD: pdq_ifsubr.c,v 1.3 1996/05/07 01:43:15 thorpej Exp $ */ /*- * Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com) @@ -407,8 +407,8 @@ pdq_ifioctl( void pdq_ifattach( pdq_softc_t *sc, - ifnet_ret_t (*ifinit)(int unit), - ifnet_ret_t (*ifwatchdog)(int unit)) + pdq_ifinit_t ifinit, + pdq_ifwatchdog_t ifwatchdog) { struct ifnet *ifp = &sc->sc_if; diff --git a/sys/dev/ic/pdqvar.h b/sys/dev/ic/pdqvar.h index d4ebce5e453..3b40d483578 100644 --- a/sys/dev/ic/pdqvar.h +++ b/sys/dev/ic/pdqvar.h @@ -1,5 +1,5 @@ -/* $OpenBSD: pdqvar.h,v 1.2 1996/04/18 23:47:25 niklas Exp $ */ -/* $NetBSD: pdqvar.h,v 1.4 1996/03/11 21:41:35 thorpej Exp $ */ +/* $OpenBSD: pdqvar.h,v 1.3 1996/05/10 12:41:13 deraadt Exp $ */ +/* $NetBSD: pdqvar.h,v 1.5 1996/05/07 01:43:17 thorpej Exp $ */ /*- * Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com) @@ -142,13 +142,21 @@ typedef struct { #define sc_if sc_ac.ac_if #define sc_bpf sc_if.if_bpf +#if defined(__NetBSD__) +typedef ifnet_ret_t (*pdq_ifwatchdog_t)(struct ifnet *ifp); +typedef ifnet_ret_t (*pdq_ifinit_t)(struct ifnet *ifp); +#else +typedef ifnet_ret_t (*pdq_ifwatchdog_t)(int unit); +typedef ifnet_ret_t (*pdq_ifinit_t)(int unit); +#endif + extern void pdq_ifreset(pdq_softc_t *sc); extern void pdq_ifinit(pdq_softc_t *sc); extern void pdq_ifwatchdog(pdq_softc_t *sc); extern ifnet_ret_t pdq_ifstart(struct ifnet *ifp); extern int pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data); -extern void pdq_ifattach(pdq_softc_t *sc, ifnet_ret_t (*ifinit)(int unit), - ifnet_ret_t (*ifwatchdog)(int unit)); +extern void pdq_ifattach(pdq_softc_t *sc, pdq_ifinit_t ifinit, + pdq_ifwatchdog_t ifwatchdog); #endif /* PDQ_HWSUPPORT */ #elif defined(DLPI_PDQ) #include diff --git a/sys/dev/ic/smc90cx6.c b/sys/dev/ic/smc90cx6.c index afa12df2b80..7b45e10a9d4 100644 --- a/sys/dev/ic/smc90cx6.c +++ b/sys/dev/ic/smc90cx6.c @@ -1,4 +1,4 @@ -/* $NetBSD: smc90cx6.c,v 1.16 1996/03/20 13:28:50 is Exp $ */ +/* $NetBSD: smc90cx6.c,v 1.17 1996/05/07 01:43:18 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Ignatios Souvatzis @@ -183,7 +183,7 @@ void bah_stop __P((struct bah_softc *)); void bah_start __P((struct ifnet *)); int bahintr __P((struct bah_softc *sc)); int bah_ioctl __P((struct ifnet *, unsigned long, caddr_t)); -void bah_watchdog __P((int)); +void bah_watchdog __P((struct ifnet *)); void movepout __P((u_char *from, u_char __volatile *to, int len)); void movepin __P((u_char __volatile *from, u_char *to, int len)); void bah_srint __P((void *vsc, void *dummy)); @@ -272,8 +272,8 @@ bah_zbus_attach(parent, self, aux) */ bah_stop(sc); - ifp->if_unit = sc->sc_dev.dv_unit; - ifp->if_name = bah_cd.cd_name; + bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); + ifp->if_softc = sc; ifp->if_output = arc_output; ifp->if_start = bah_start; ifp->if_ioctl = bah_ioctl; @@ -360,8 +360,8 @@ bah_reset(sc) linkaddress = sc->sc_base->dipswitches; #if defined(BAH_DEBUG) && (BAH_DEBUG > 2) - printf("bah%ld: reset: card reset, link addr = 0x%02x (%ld)\n", - ifp->if_unit, linkaddress, linkaddress); + printf("%s: reset: card reset, link addr = 0x%02x (%ld)\n", + sc->sc_dev.dv_xname, linkaddress, linkaddress); #endif sc->sc_arccom.ac_anaddr = linkaddress; @@ -540,7 +540,7 @@ bah_start(ifp) u_long copystart, lencopy, perbyte; #endif - sc = bah_cd.cd_devs[ifp->if_unit]; + sc = ifp->if_softc; #if defined(BAH_DEBUG) && (BAH_DEBUG > 3) printf("%s: start(0x%x)\n", sc->sc_dev.dv_xname, ifp); @@ -1150,7 +1150,7 @@ bah_ioctl(ifp, command, data) int s, error; error = 0; - sc = bah_cd.cd_devs[ifp->if_unit]; + sc = ifp->if_softc; ifa = (struct ifaddr *)data; s = splnet(); @@ -1217,14 +1217,10 @@ bah_ioctl(ifp, command, data) */ void -bah_watchdog(unit) -int unit; -{ - struct bah_softc *sc; +bah_watchdog(ifp) struct ifnet *ifp; - - sc = bah_cd.cd_devs[unit]; - ifp = &(sc->sc_arccom.ac_if); +{ + struct bah_softc *sc = ifp->if_softc; sc->sc_base->command = ARC_TXDIS; return; -- cgit v1.2.3