diff --git a/sys/dev/le/am7990.c b/sys/dev/le/am7990.c index 66dce0e6ac1d..b3d81cf01420 100644 --- a/sys/dev/le/am7990.c +++ b/sys/dev/le/am7990.c @@ -1,621 +1,621 @@ /* $NetBSD: am7990.c,v 1.68 2005/12/11 12:21:25 christos Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-3-Clause * * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace * Simulation Facility, NASA Ames Research Center. * * 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. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS * 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. */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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. Neither the name of the University nor the names of its contributors * may 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 REGENTS OR CONTRIBUTORS 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. * * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void am7990_meminit(struct lance_softc *); static void am7990_rint(struct lance_softc *); static void am7990_tint(struct lance_softc *); static void am7990_start_locked(struct lance_softc *sc); #ifdef LEDEBUG static void am7990_recv_print(struct lance_softc *, int); static void am7990_xmit_print(struct lance_softc *, int); #endif int am7990_config(struct am7990_softc *sc, const char* name, int unit) { int error, mem; sc->lsc.sc_meminit = am7990_meminit; sc->lsc.sc_start_locked = am7990_start_locked; error = lance_config(&sc->lsc, name, unit); if (error != 0) return (error); mem = 0; sc->lsc.sc_initaddr = mem; mem += sizeof(struct leinit); sc->lsc.sc_rmdaddr = mem; mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; sc->lsc.sc_tmdaddr = mem; mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; sc->lsc.sc_rbufaddr = mem; mem += LEBLEN * sc->lsc.sc_nrbuf; sc->lsc.sc_tbufaddr = mem; mem += LEBLEN * sc->lsc.sc_ntbuf; if (mem > sc->lsc.sc_memsize) panic("%s: memsize", __func__); lance_attach(&sc->lsc); return (0); } void am7990_detach(struct am7990_softc *sc) { lance_detach(&sc->lsc); } /* * Set up the initialization block and the descriptor rings. */ static void am7990_meminit(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct leinit init; struct lermd rmd; struct letmd tmd; u_long a; int bix; LE_LOCK_ASSERT(sc, MA_OWNED); - if (ifp->if_flags & IFF_PROMISC) + if (if_getflags(ifp) & IFF_PROMISC) init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; else init.init_mode = LE_MODE_NORMAL; init.init_padr[0] = (sc->sc_enaddr[1] << 8) | sc->sc_enaddr[0]; init.init_padr[1] = (sc->sc_enaddr[3] << 8) | sc->sc_enaddr[2]; init.init_padr[2] = (sc->sc_enaddr[5] << 8) | sc->sc_enaddr[4]; lance_setladrf(sc, init.init_ladrf); sc->sc_last_rd = 0; sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; a = sc->sc_addr + LE_RMDADDR(sc, 0); init.init_rdra = a; init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13); a = sc->sc_addr + LE_TMDADDR(sc, 0); init.init_tdra = a; init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13); (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); /* * Set up receive ring descriptors. */ for (bix = 0; bix < sc->sc_nrbuf; bix++) { a = sc->sc_addr + LE_RBUFADDR(sc, bix); rmd.rmd0 = a; rmd.rmd1_hadr = a >> 16; rmd.rmd1_bits = LE_R1_OWN; rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), sizeof(rmd)); } /* * Set up transmit ring descriptors. */ for (bix = 0; bix < sc->sc_ntbuf; bix++) { a = sc->sc_addr + LE_TBUFADDR(sc, bix); tmd.tmd0 = a; tmd.tmd1_hadr = a >> 16; tmd.tmd1_bits = 0; tmd.tmd2 = LE_XMD2_ONES; tmd.tmd3 = 0; (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), sizeof(tmd)); } } static void am7990_rint(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct mbuf *m; struct lermd rmd; int bix, rp; #if defined(LANCE_REVC_BUG) struct ether_header *eh; /* Make sure this is short-aligned, for ether_cmp(). */ static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 }; #endif bix = sc->sc_last_rd; /* Process all buffers with valid data. */ for (;;) { rp = LE_RMDADDR(sc, bix); (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); if (rmd.rmd1_bits & LE_R1_OWN) break; m = NULL; if ((rmd.rmd1_bits & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)) { if (rmd.rmd1_bits & LE_R1_ERR) { #ifdef LEDEBUG if (rmd.rmd1_bits & LE_R1_ENP) { if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) { if (rmd.rmd1_bits & LE_R1_FRAM) if_printf(ifp, "framing error\n"); if (rmd.rmd1_bits & LE_R1_CRC) if_printf(ifp, "crc mismatch\n"); } } else if (rmd.rmd1_bits & LE_R1_OFLO) if_printf(ifp, "overflow\n"); #endif if (rmd.rmd1_bits & LE_R1_BUFF) if_printf(ifp, "receive buffer error\n"); } else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)) if_printf(ifp, "dropping chained buffer\n"); } else { #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) am7990_recv_print(sc, bix); #endif /* Pull the packet off the interface. */ m = lance_get(sc, LE_RBUFADDR(sc, bix), (int)rmd.rmd3 - ETHER_CRC_LEN); } rmd.rmd1_bits = LE_R1_OWN; rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); if (++bix == sc->sc_nrbuf) bix = 0; if (m != NULL) { if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); #ifdef LANCE_REVC_BUG /* * The old LANCE (Rev. C) chips have a bug which * causes garbage to be inserted in front of the * received packet. The workaround is to ignore * packets with an invalid destination address * (garbage will usually not match). * Of course, this precludes multicast support... */ eh = mtod(m, struct ether_header *); if (ether_cmp(eh->ether_dhost, sc->sc_enaddr) && ether_cmp(eh->ether_dhost, bcast_enaddr)) { m_freem(m); continue; } #endif /* Pass the packet up. */ LE_UNLOCK(sc); - (*ifp->if_input)(ifp, m); + if_input(ifp, m); LE_LOCK(sc); } else if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); } sc->sc_last_rd = bix; } static void am7990_tint(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct letmd tmd; int bix; bix = sc->sc_first_td; for (;;) { if (sc->sc_no_td <= 0) break; (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), sizeof(tmd)); #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "trans tmd: " "ladr %04x, hadr %02x, flags %02x, " "bcnt %04x, mcnt %04x\n", tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3); #endif if (tmd.tmd1_bits & LE_T1_OWN) break; - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); if (tmd.tmd1_bits & LE_T1_ERR) { if (tmd.tmd3 & LE_T3_BUFF) if_printf(ifp, "transmit buffer error\n"); else if (tmd.tmd3 & LE_T3_UFLO) if_printf(ifp, "underflow\n"); if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { lance_init_locked(sc); return; } if (tmd.tmd3 & LE_T3_LCAR) { if (sc->sc_flags & LE_CARRIER) if_link_state_change(ifp, LINK_STATE_DOWN); sc->sc_flags &= ~LE_CARRIER; if (sc->sc_nocarrier) (*sc->sc_nocarrier)(sc); else if_printf(ifp, "lost carrier\n"); } if (tmd.tmd3 & LE_T3_LCOL) if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); if (tmd.tmd3 & LE_T3_RTRY) { #ifdef LEDEBUG if_printf(ifp, "excessive collisions, tdr %d\n", tmd.tmd3 & LE_T3_TDR_MASK); #endif if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 16); } if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } else { if (tmd.tmd1_bits & LE_T1_ONE) if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); else if (tmd.tmd1_bits & LE_T1_MORE) /* Real number is unknown. */ if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 2); if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); } if (++bix == sc->sc_ntbuf) bix = 0; --sc->sc_no_td; } sc->sc_first_td = bix; sc->sc_wdog_timer = sc->sc_no_td > 0 ? 5 : 0; } /* * Controller interrupt */ void am7990_intr(void *arg) { struct lance_softc *sc = arg; - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; uint16_t isr; LE_LOCK(sc); if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } isr = (*sc->sc_rdcsr)(sc, LE_CSR0); #if defined(LEDEBUG) && LEDEBUG > 1 if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); #endif if ((isr & LE_C0_INTR) == 0) { LE_UNLOCK(sc); return; } /* * Clear interrupt source flags and turn off interrupts. If we * don't clear these flags before processing their sources we * could completely miss some interrupt events as the NIC can * change these flags while we're in this handler. We toggle * the interrupt enable bit in order to keep receiving them * (some chips work without this, some don't). */ (*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD | LE_C0_STOP | LE_C0_STRT | LE_C0_INIT)); if (isr & LE_C0_ERR) { if (isr & LE_C0_BABL) { #ifdef LEDEBUG if_printf(ifp, "babble\n"); #endif if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } #if 0 if (isr & LE_C0_CERR) { if_printf(ifp, "collision error\n"); if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); } #endif if (isr & LE_C0_MISS) { #ifdef LEDEBUG if_printf(ifp, "missed packet\n"); #endif if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); } if (isr & LE_C0_MERR) { if_printf(ifp, "memory error\n"); lance_init_locked(sc); LE_UNLOCK(sc); return; } } if ((isr & LE_C0_RXON) == 0) { if_printf(ifp, "receiver disabled\n"); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } if ((isr & LE_C0_TXON) == 0) { if_printf(ifp, "transmitter disabled\n"); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } /* * Pretend we have carrier; if we don't this will be cleared shortly. */ if (!(sc->sc_flags & LE_CARRIER)) if_link_state_change(ifp, LINK_STATE_UP); sc->sc_flags |= LE_CARRIER; if (isr & LE_C0_RINT) am7990_rint(sc); if (isr & LE_C0_TINT) am7990_tint(sc); /* Enable interrupts again. */ (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); - if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + if (!if_sendq_empty(ifp)) am7990_start_locked(sc); LE_UNLOCK(sc); } /* * Set up output on interface. * Get another datagram to send off of the interface queue, and map it to the * interface before starting the output. */ static void am7990_start_locked(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct letmd tmd; struct mbuf *m; int bix, enq, len, rp; LE_LOCK_ASSERT(sc, MA_OWNED); - if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) return; bix = sc->sc_last_td; enq = 0; for (; sc->sc_no_td < sc->sc_ntbuf && - !IFQ_DRV_IS_EMPTY(&ifp->if_snd);) { + !if_sendq_empty(ifp);) { rp = LE_TMDADDR(sc, bix); (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); if (tmd.tmd1_bits & LE_T1_OWN) { - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); if_printf(ifp, "missing buffer, no_td = %d, last_td = %d\n", sc->sc_no_td, sc->sc_last_td); } - IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + m = if_dequeue(ifp); if (m == NULL) break; /* * If BPF is listening on this interface, let it see the packet * before we commit it to the wire. */ BPF_MTAP(ifp, m); /* * Copy the mbuf chain into the transmit buffer. */ len = lance_put(sc, LE_TBUFADDR(sc, bix), m); #ifdef LEDEBUG if (len > ETHERMTU + ETHER_HDR_LEN) if_printf(ifp, "packet length %d\n", len); #endif /* * Init transmit registers, and set transmit start flag. */ tmd.tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP; tmd.tmd2 = -len | LE_XMD2_ONES; tmd.tmd3 = 0; (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) am7990_xmit_print(sc, bix); #endif (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); enq++; if (++bix == sc->sc_ntbuf) bix = 0; if (++sc->sc_no_td == sc->sc_ntbuf) { - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); break; } } sc->sc_last_td = bix; if (enq > 0) sc->sc_wdog_timer = 5; } #ifdef LEDEBUG static void am7990_recv_print(struct lance_softc *sc, int no) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct ether_header eh; struct lermd rmd; uint16_t len; (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); len = rmd.rmd3; if_printf(ifp, "receive buffer %d, len = %d\n", no, len); if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); if_printf(ifp, "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3); if (len - ETHER_CRC_LEN >= sizeof(eh)) { (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), ntohs(eh.ether_type)); } } static void am7990_xmit_print(struct lance_softc *sc, int no) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct ether_header eh; struct letmd tmd; uint16_t len; (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); len = -tmd.tmd2; if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); if_printf(ifp, "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3); if (len >= sizeof(eh)) { (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), ntohs(eh.ether_type)); } } #endif /* LEDEBUG */ diff --git a/sys/dev/le/am79900.c b/sys/dev/le/am79900.c index 316e12388ffd..a3b7a8245d05 100644 --- a/sys/dev/le/am79900.c +++ b/sys/dev/le/am79900.c @@ -1,658 +1,658 @@ /* $NetBSD: am79900.c,v 1.17 2005/12/24 20:27:29 perry Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-3-Clause * * Copyright (c) 1997 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe. * * 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. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS * 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. */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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. Neither the name of the University nor the names of its contributors * may 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 REGENTS OR CONTRIBUTORS 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. * * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */ /*- * Copyright (c) 1998 * Matthias Drochner. All rights reserved. * Copyright (c) 1995 Charles M. Hannum. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may 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 REGENTS OR CONTRIBUTORS 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. * * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void am79900_meminit(struct lance_softc *); static void am79900_rint(struct lance_softc *); static void am79900_tint(struct lance_softc *); static void am79900_start_locked(struct lance_softc *sc); #ifdef LEDEBUG static void am79900_recv_print(struct lance_softc *, int); static void am79900_xmit_print(struct lance_softc *, int); #endif int am79900_config(struct am79900_softc *sc, const char* name, int unit) { int error, mem; sc->lsc.sc_meminit = am79900_meminit; sc->lsc.sc_start_locked = am79900_start_locked; error = lance_config(&sc->lsc, name, unit); if (error != 0) return (error); mem = 0; sc->lsc.sc_initaddr = mem; mem += sizeof(struct leinit); sc->lsc.sc_rmdaddr = mem; mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; sc->lsc.sc_tmdaddr = mem; mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; sc->lsc.sc_rbufaddr = mem; mem += LEBLEN * sc->lsc.sc_nrbuf; sc->lsc.sc_tbufaddr = mem; mem += LEBLEN * sc->lsc.sc_ntbuf; if (mem > sc->lsc.sc_memsize) panic("%s: memsize", __func__); lance_attach(&sc->lsc); return (0); } void am79900_detach(struct am79900_softc *sc) { lance_detach(&sc->lsc); } /* * Set up the initialization block and the descriptor rings. */ static void am79900_meminit(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct leinit init; struct lermd rmd; struct letmd tmd; u_long a; int bix; LE_LOCK_ASSERT(sc, MA_OWNED); - if (ifp->if_flags & IFF_PROMISC) + if (if_getflags(ifp) & IFF_PROMISC) init.init_mode = LE_HTOLE32(LE_MODE_NORMAL | LE_MODE_PROM); else init.init_mode = LE_HTOLE32(LE_MODE_NORMAL); init.init_mode |= LE_HTOLE32(((ffs(sc->sc_ntbuf) - 1) << 28) | ((ffs(sc->sc_nrbuf) - 1) << 20)); init.init_padr[0] = LE_HTOLE32(sc->sc_enaddr[0] | (sc->sc_enaddr[1] << 8) | (sc->sc_enaddr[2] << 16) | (sc->sc_enaddr[3] << 24)); init.init_padr[1] = LE_HTOLE32(sc->sc_enaddr[4] | (sc->sc_enaddr[5] << 8)); lance_setladrf(sc, init.init_ladrf); sc->sc_last_rd = 0; sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; a = sc->sc_addr + LE_RMDADDR(sc, 0); init.init_rdra = LE_HTOLE32(a); a = sc->sc_addr + LE_TMDADDR(sc, 0); init.init_tdra = LE_HTOLE32(a); (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); /* * Set up receive ring descriptors. */ for (bix = 0; bix < sc->sc_nrbuf; bix++) { a = sc->sc_addr + LE_RBUFADDR(sc, bix); rmd.rmd0 = LE_HTOLE32(a); rmd.rmd1 = LE_HTOLE32(LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff)); rmd.rmd2 = 0; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), sizeof(rmd)); } /* * Set up transmit ring descriptors. */ for (bix = 0; bix < sc->sc_ntbuf; bix++) { a = sc->sc_addr + LE_TBUFADDR(sc, bix); tmd.tmd0 = LE_HTOLE32(a); tmd.tmd1 = LE_HTOLE32(LE_T1_ONES); tmd.tmd2 = 0; tmd.tmd3 = 0; (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), sizeof(tmd)); } } static inline void am79900_rint(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct mbuf *m; struct lermd rmd; uint32_t rmd1; int bix, rp; #if defined(__i386__) struct ether_header *eh; #endif bix = sc->sc_last_rd; /* Process all buffers with valid data. */ for (;;) { rp = LE_RMDADDR(sc, bix); (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); rmd1 = LE_LE32TOH(rmd.rmd1); if (rmd1 & LE_R1_OWN) break; m = NULL; if ((rmd1 & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)){ if (rmd1 & LE_R1_ERR) { #ifdef LEDEBUG if (rmd1 & LE_R1_ENP) { if ((rmd1 & LE_R1_OFLO) == 0) { if (rmd1 & LE_R1_FRAM) if_printf(ifp, "framing error\n"); if (rmd1 & LE_R1_CRC) if_printf(ifp, "crc mismatch\n"); } } else if (rmd1 & LE_R1_OFLO) if_printf(ifp, "overflow\n"); #endif if (rmd1 & LE_R1_BUFF) if_printf(ifp, "receive buffer error\n"); } else if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)) if_printf(ifp, "dropping chained buffer\n"); } else { #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) am79900_recv_print(sc, bix); #endif /* Pull the packet off the interface. */ m = lance_get(sc, LE_RBUFADDR(sc, bix), (LE_LE32TOH(rmd.rmd2) & 0xfff) - ETHER_CRC_LEN); } rmd.rmd1 = LE_HTOLE32(LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff)); rmd.rmd2 = 0; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); if (++bix == sc->sc_nrbuf) bix = 0; if (m != NULL) { if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); #if defined(__i386__) /* * The VMware LANCE does not present IFF_SIMPLEX * behavior on multicast packets. Thus drop the * packet if it is from ourselves. */ eh = mtod(m, struct ether_header *); if (!ether_cmp(eh->ether_shost, sc->sc_enaddr)) { m_freem(m); continue; } #endif /* Pass the packet up. */ LE_UNLOCK(sc); - (*ifp->if_input)(ifp, m); + if_input(ifp, m); LE_LOCK(sc); } else if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); } sc->sc_last_rd = bix; } static inline void am79900_tint(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct letmd tmd; uint32_t tmd1, tmd2; int bix; bix = sc->sc_first_td; for (;;) { if (sc->sc_no_td <= 0) break; (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), sizeof(tmd)); tmd1 = LE_LE32TOH(tmd.tmd1); #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "trans tmd: " "adr %08x, flags/blen %08x\n", LE_LE32TOH(tmd.tmd0), tmd1); #endif if (tmd1 & LE_T1_OWN) break; - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); if (tmd1 & LE_T1_ERR) { tmd2 = LE_LE32TOH(tmd.tmd2); if (tmd2 & LE_T2_BUFF) if_printf(ifp, "transmit buffer error\n"); else if (tmd2 & LE_T2_UFLO) if_printf(ifp, "underflow\n"); if (tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { lance_init_locked(sc); return; } if (tmd2 & LE_T2_LCAR) { if (sc->sc_flags & LE_CARRIER) if_link_state_change(ifp, LINK_STATE_DOWN); sc->sc_flags &= ~LE_CARRIER; if (sc->sc_nocarrier) (*sc->sc_nocarrier)(sc); else if_printf(ifp, "lost carrier\n"); } if (tmd2 & LE_T2_LCOL) if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); if (tmd2 & LE_T2_RTRY) { #ifdef LEDEBUG if_printf(ifp, "excessive collisions\n"); #endif if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 16); } if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } else { if (tmd1 & LE_T1_ONE) if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); else if (tmd1 & LE_T1_MORE) /* Real number is unknown. */ if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 2); if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); } if (++bix == sc->sc_ntbuf) bix = 0; --sc->sc_no_td; } sc->sc_first_td = bix; sc->sc_wdog_timer = sc->sc_no_td > 0 ? 5 : 0; } /* * Controller interrupt */ void am79900_intr(void *arg) { struct lance_softc *sc = arg; - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; uint16_t isr; LE_LOCK(sc); if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } isr = (*sc->sc_rdcsr)(sc, LE_CSR0); #if defined(LEDEBUG) && LEDEBUG > 1 if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); #endif if ((isr & LE_C0_INTR) == 0) { LE_UNLOCK(sc); return; } /* * Clear interrupt source flags and turn off interrupts. If we * don't clear these flags before processing their sources we * could completely miss some interrupt events as the NIC can * change these flags while we're in this handler. We toggle * the interrupt enable bit in order to keep receiving them * (some chips work without this, some don't). */ (*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD | LE_C0_STOP | LE_C0_STRT | LE_C0_INIT)); if (isr & LE_C0_ERR) { if (isr & LE_C0_BABL) { #ifdef LEDEBUG if_printf(ifp, "babble\n"); #endif if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } #if 0 if (isr & LE_C0_CERR) { if_printf(ifp, "collision error\n"); if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); } #endif if (isr & LE_C0_MISS) { #ifdef LEDEBUG if_printf(ifp, "missed packet\n"); #endif if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); } if (isr & LE_C0_MERR) { if_printf(ifp, "memory error\n"); lance_init_locked(sc); LE_UNLOCK(sc); return; } } if ((isr & LE_C0_RXON) == 0) { if_printf(ifp, "receiver disabled\n"); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } if ((isr & LE_C0_TXON) == 0) { if_printf(ifp, "transmitter disabled\n"); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); lance_init_locked(sc); LE_UNLOCK(sc); return; } /* * Pretend we have carrier; if we don't this will be cleared shortly. */ if (!(sc->sc_flags & LE_CARRIER)) if_link_state_change(ifp, LINK_STATE_UP); sc->sc_flags |= LE_CARRIER; if (isr & LE_C0_RINT) am79900_rint(sc); if (isr & LE_C0_TINT) am79900_tint(sc); /* Enable interrupts again. */ (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); - if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + if (!if_sendq_empty(ifp)) am79900_start_locked(sc); LE_UNLOCK(sc); } /* * Set up output on interface. * Get another datagram to send off of the interface queue, and map it to the * interface before starting the output. */ static void am79900_start_locked(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct letmd tmd; struct mbuf *m; int bix, enq, len, rp; LE_LOCK_ASSERT(sc, MA_OWNED); - if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) return; bix = sc->sc_last_td; enq = 0; for (; sc->sc_no_td < sc->sc_ntbuf && - !IFQ_DRV_IS_EMPTY(&ifp->if_snd);) { + !if_sendq_empty(ifp);) { rp = LE_TMDADDR(sc, bix); (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); if (LE_LE32TOH(tmd.tmd1) & LE_T1_OWN) { - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); if_printf(ifp, "missing buffer, no_td = %d, last_td = %d\n", sc->sc_no_td, sc->sc_last_td); } - IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + m = if_dequeue(ifp); if (m == NULL) break; /* * If BPF is listening on this interface, let it see the packet * before we commit it to the wire. */ BPF_MTAP(ifp, m); /* * Copy the mbuf chain into the transmit buffer. */ len = lance_put(sc, LE_TBUFADDR(sc, bix), m); #ifdef LEDEBUG if (len > ETHERMTU + ETHER_HDR_LEN) if_printf(ifp, "packet length %d\n", len); #endif /* * Init transmit registers, and set transmit start flag. */ tmd.tmd1 = LE_HTOLE32(LE_T1_OWN | LE_T1_STP | LE_T1_ENP | LE_T1_ONES | (-len & 0xfff)); tmd.tmd2 = 0; tmd.tmd3 = 0; (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); #ifdef LEDEBUG if (sc->sc_flags & LE_DEBUG) am79900_xmit_print(sc, bix); #endif (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); enq++; if (++bix == sc->sc_ntbuf) bix = 0; if (++sc->sc_no_td == sc->sc_ntbuf) { - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); break; } } sc->sc_last_td = bix; if (enq > 0) sc->sc_wdog_timer = 5; } #ifdef LEDEBUG static void am79900_recv_print(struct lance_softc *sc, int no) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct ether_header eh; struct lermd rmd; uint16_t len; (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); len = LE_LE32TOH(rmd.rmd2) & 0xfff; if_printf(ifp, "receive buffer %d, len = %d\n", no, len); if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); if_printf(ifp, "adr %08x, flags/blen %08x\n", LE_LE32TOH(rmd.rmd0), LE_LE32TOH(rmd.rmd1)); if (len - ETHER_CRC_LEN >= sizeof(eh)) { (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), ntohs(eh.ether_type)); } } static void am79900_xmit_print(struct lance_softc *sc, int no) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct ether_header eh; struct letmd tmd; uint16_t len; (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); len = -(LE_LE32TOH(tmd.tmd1) & 0xfff); if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); if_printf(ifp, "adr %08x, flags/blen %08x\n", LE_LE32TOH(tmd.tmd0), LE_LE32TOH(tmd.tmd1)); if (len >= sizeof(eh)) { (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), ntohs(eh.ether_type)); } } #endif /* LEDEBUG */ diff --git a/sys/dev/le/lance.c b/sys/dev/le/lance.c index 65504bd8142a..050fcfe36184 100644 --- a/sys/dev/le/lance.c +++ b/sys/dev/le/lance.c @@ -1,823 +1,822 @@ /* $NetBSD: lance.c,v 1.34 2005/12/24 20:27:30 perry Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace * Simulation Facility, NASA Ames Research Center. * * 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. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS * 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. */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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. Neither the name of the University nor the names of its contributors * may 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 REGENTS OR CONTRIBUTORS 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. * * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -static void lance_start(struct ifnet *); +static void lance_start(if_t); static void lance_stop(struct lance_softc *); static void lance_init(void *); static void lance_watchdog(void *s); -static int lance_mediachange(struct ifnet *); -static void lance_mediastatus(struct ifnet *, struct ifmediareq *); -static int lance_ioctl(struct ifnet *, u_long, caddr_t); +static int lance_mediachange(if_t); +static void lance_mediastatus(if_t, struct ifmediareq *); +static int lance_ioctl(if_t, u_long, caddr_t); int lance_config(struct lance_softc *sc, const char* name, int unit) { - struct ifnet *ifp; + if_t ifp; int i, nbuf; if (LE_LOCK_INITIALIZED(sc) == 0) return (ENXIO); ifp = sc->sc_ifp = if_alloc(IFT_ETHER); if (ifp == NULL) return (ENOSPC); callout_init_mtx(&sc->sc_wdog_ch, &sc->sc_mtx, 0); /* Initialize ifnet structure. */ - ifp->if_softc = sc; + if_setsoftc(ifp, sc); if_initname(ifp, name, unit); - ifp->if_start = lance_start; - ifp->if_ioctl = lance_ioctl; - ifp->if_init = lance_init; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + if_setstartfn(ifp, lance_start); + if_setioctlfn(ifp, lance_ioctl); + if_setinitfn(ifp, lance_init); + if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); #ifdef LANCE_REVC_BUG - ifp->if_flags &= ~IFF_MULTICAST; + if_setflagsbit(ifp, 0, IFF_MULTICAST); #endif - ifp->if_baudrate = IF_Mbps(10); - IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); - ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; - IFQ_SET_READY(&ifp->if_snd); + if_setbaudrate(ifp, IF_Mbps(10)); + if_setsendqlen(ifp, ifqmaxlen); + if_setsendqready(ifp); /* Initialize ifmedia structures. */ ifmedia_init(&sc->sc_media, 0, lance_mediachange, lance_mediastatus); if (sc->sc_supmedia != NULL) { for (i = 0; i < sc->sc_nsupmedia; i++) ifmedia_add(&sc->sc_media, sc->sc_supmedia[i], 0, NULL); ifmedia_set(&sc->sc_media, sc->sc_defaultmedia); } else { ifmedia_add(&sc->sc_media, IFM_MAKEWORD(IFM_ETHER, IFM_MANUAL, 0, 0), 0, NULL); ifmedia_set(&sc->sc_media, IFM_MAKEWORD(IFM_ETHER, IFM_MANUAL, 0, 0)); } switch (sc->sc_memsize) { case 8192: sc->sc_nrbuf = 4; sc->sc_ntbuf = 1; break; case 16384: sc->sc_nrbuf = 8; sc->sc_ntbuf = 2; break; case 32768: sc->sc_nrbuf = 16; sc->sc_ntbuf = 4; break; case 65536: sc->sc_nrbuf = 32; sc->sc_ntbuf = 8; break; case 131072: sc->sc_nrbuf = 64; sc->sc_ntbuf = 16; break; case 262144: sc->sc_nrbuf = 128; sc->sc_ntbuf = 32; break; default: /* weird memory size; cope with it */ nbuf = sc->sc_memsize / LEBLEN; sc->sc_ntbuf = nbuf / 5; sc->sc_nrbuf = nbuf - sc->sc_ntbuf; } if_printf(ifp, "%d receive buffers, %d transmit buffers\n", sc->sc_nrbuf, sc->sc_ntbuf); /* Make sure the chip is stopped. */ LE_LOCK(sc); lance_stop(sc); LE_UNLOCK(sc); return (0); } void lance_attach(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; /* Attach the interface. */ ether_ifattach(ifp, sc->sc_enaddr); /* Claim 802.1q capability. */ - ifp->if_hdrlen = sizeof(struct ether_vlan_header); - ifp->if_capabilities |= IFCAP_VLAN_MTU; - ifp->if_capenable |= IFCAP_VLAN_MTU; + if_setifheaderlen(ifp, sizeof(struct ether_vlan_header)); + if_setcapabilitiesbit(ifp, IFCAP_VLAN_MTU, 0); + if_setcapenablebit(ifp, IFCAP_VLAN_MTU, 0); } void lance_detach(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; LE_LOCK(sc); lance_stop(sc); LE_UNLOCK(sc); callout_drain(&sc->sc_wdog_ch); ether_ifdetach(ifp); if_free(ifp); } void lance_suspend(struct lance_softc *sc) { LE_LOCK(sc); lance_stop(sc); LE_UNLOCK(sc); } void lance_resume(struct lance_softc *sc) { LE_LOCK(sc); - if (sc->sc_ifp->if_flags & IFF_UP) + if (if_getflags(sc->sc_ifp) & IFF_UP) lance_init_locked(sc); LE_UNLOCK(sc); } static void -lance_start(struct ifnet *ifp) +lance_start(if_t ifp) { - struct lance_softc *sc = ifp->if_softc; + struct lance_softc *sc = if_getsoftc(ifp); LE_LOCK(sc); (*sc->sc_start_locked)(sc); LE_UNLOCK(sc); } static void lance_stop(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; LE_LOCK_ASSERT(sc, MA_OWNED); /* * Mark the interface down and cancel the watchdog timer. */ - ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + if_setdrvflagbits(ifp, 0, (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)); callout_stop(&sc->sc_wdog_ch); sc->sc_wdog_timer = 0; (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); } static void lance_init(void *xsc) { struct lance_softc *sc = (struct lance_softc *)xsc; LE_LOCK(sc); lance_init_locked(sc); LE_UNLOCK(sc); } /* * Initialization of interface; set up initialization block * and transmit/receive descriptor rings. */ void lance_init_locked(struct lance_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; u_long a; int timo; LE_LOCK_ASSERT(sc, MA_OWNED); (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); DELAY(100); /* Newer LANCE chips have a reset register. */ if (sc->sc_hwreset) (*sc->sc_hwreset)(sc); /* Set the correct byte swapping mode, etc. */ (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3); /* Set the current media. This may require the chip to be stopped. */ if (sc->sc_mediachange) (void)(*sc->sc_mediachange)(sc); /* * Update our private copy of the Ethernet address. * We NEED the copy so we can ensure its alignment! */ - memcpy(sc->sc_enaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN); + memcpy(sc->sc_enaddr, if_getlladdr(ifp), ETHER_ADDR_LEN); /* Set up LANCE init block. */ (*sc->sc_meminit)(sc); /* Give LANCE the physical address of its init block. */ a = sc->sc_addr + LE_INITADDR(sc); (*sc->sc_wrcsr)(sc, LE_CSR1, a & 0xffff); (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16); /* Try to initialize the LANCE. */ DELAY(100); (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT); /* Wait for initialization to finish. */ for (timo = 100000; timo; timo--) if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) break; if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) { /* Start the LANCE. */ (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT); - ifp->if_drv_flags |= IFF_DRV_RUNNING; - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); + if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); sc->sc_wdog_timer = 0; callout_reset(&sc->sc_wdog_ch, hz, lance_watchdog, sc); (*sc->sc_start_locked)(sc); } else if_printf(ifp, "controller failed to initialize\n"); if (sc->sc_hwinit) (*sc->sc_hwinit)(sc); } /* * Routine to copy from mbuf chain to transmit buffer in * network buffer memory. */ int lance_put(struct lance_softc *sc, int boff, struct mbuf *m) { struct mbuf *n; int len, tlen = 0; LE_LOCK_ASSERT(sc, MA_OWNED); for (; m; m = n) { len = m->m_len; if (len == 0) { n = m_free(m); m = NULL; continue; } (*sc->sc_copytobuf)(sc, mtod(m, caddr_t), boff, len); boff += len; tlen += len; n = m_free(m); m = NULL; } if (tlen < LEMINSIZE) { (*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen); tlen = LEMINSIZE; } return (tlen); } /* * Pull data off an interface. * Len is length of data, with local net header stripped. * We copy the data into mbufs. When full cluster sized units are present * we copy into clusters. */ struct mbuf * lance_get(struct lance_softc *sc, int boff, int totlen) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct mbuf *m, *m0, *newm; caddr_t newdata; int len; if (totlen <= ETHER_HDR_LEN || totlen > LEBLEN - ETHER_CRC_LEN) { #ifdef LEDEBUG if_printf(ifp, "invalid packet size %d; dropping\n", totlen); #endif return (NULL); } MGETHDR(m0, M_NOWAIT, MT_DATA); if (m0 == NULL) return (NULL); m0->m_pkthdr.rcvif = ifp; m0->m_pkthdr.len = totlen; len = MHLEN; m = m0; while (totlen > 0) { if (totlen >= MINCLSIZE) { if (!(MCLGET(m, M_NOWAIT))) goto bad; len = MCLBYTES; } if (m == m0) { newdata = (caddr_t) ALIGN(m->m_data + ETHER_HDR_LEN) - ETHER_HDR_LEN; len -= newdata - m->m_data; m->m_data = newdata; } m->m_len = len = min(totlen, len); (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len); boff += len; totlen -= len; if (totlen > 0) { MGET(newm, M_NOWAIT, MT_DATA); if (newm == NULL) goto bad; len = MLEN; m = m->m_next = newm; } } return (m0); bad: m_freem(m0); return (NULL); } static void lance_watchdog(void *xsc) { struct lance_softc *sc = (struct lance_softc *)xsc; - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; LE_LOCK_ASSERT(sc, MA_OWNED); if (sc->sc_wdog_timer == 0 || --sc->sc_wdog_timer != 0) { callout_reset(&sc->sc_wdog_ch, hz, lance_watchdog, sc); return; } if_printf(ifp, "device timeout\n"); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); lance_init_locked(sc); } static int -lance_mediachange(struct ifnet *ifp) +lance_mediachange(if_t ifp) { - struct lance_softc *sc = ifp->if_softc; + struct lance_softc *sc = if_getsoftc(ifp); if (sc->sc_mediachange) { /* * For setting the port in LE_CSR15 the PCnet chips must * be powered down or stopped and unlike documented may * not take effect without an initialization. So don't * invoke (*sc_mediachange) directly here but go through * lance_init_locked(). */ LE_LOCK(sc); lance_stop(sc); lance_init_locked(sc); - if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + if (!if_sendq_empty(ifp)) (*sc->sc_start_locked)(sc); LE_UNLOCK(sc); } return (0); } static void -lance_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) +lance_mediastatus(if_t ifp, struct ifmediareq *ifmr) { - struct lance_softc *sc = ifp->if_softc; + struct lance_softc *sc = if_getsoftc(ifp); LE_LOCK(sc); - if (!(ifp->if_flags & IFF_UP)) { + if (!(if_getflags(ifp) & IFF_UP)) { LE_UNLOCK(sc); return; } ifmr->ifm_status = IFM_AVALID; if (sc->sc_flags & LE_CARRIER) ifmr->ifm_status |= IFM_ACTIVE; if (sc->sc_mediastatus) (*sc->sc_mediastatus)(sc, ifmr); LE_UNLOCK(sc); } /* * Process an ioctl request. */ static int -lance_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +lance_ioctl(if_t ifp, u_long cmd, caddr_t data) { - struct lance_softc *sc = ifp->if_softc; + struct lance_softc *sc = if_getsoftc(ifp); struct ifreq *ifr = (struct ifreq *)data; int error = 0; switch (cmd) { case SIOCSIFFLAGS: LE_LOCK(sc); - if (ifp->if_flags & IFF_PROMISC) { + if (if_getflags(ifp) & IFF_PROMISC) { if (!(sc->sc_flags & LE_PROMISC)) { sc->sc_flags |= LE_PROMISC; lance_init_locked(sc); } } else if (sc->sc_flags & LE_PROMISC) { sc->sc_flags &= ~LE_PROMISC; lance_init_locked(sc); } - if ((ifp->if_flags & IFF_ALLMULTI) && + if ((if_getflags(ifp) & IFF_ALLMULTI) && !(sc->sc_flags & LE_ALLMULTI)) { sc->sc_flags |= LE_ALLMULTI; lance_init_locked(sc); - } else if (!(ifp->if_flags & IFF_ALLMULTI) && + } else if (!(if_getflags(ifp) & IFF_ALLMULTI) && (sc->sc_flags & LE_ALLMULTI)) { sc->sc_flags &= ~LE_ALLMULTI; lance_init_locked(sc); } - if (!(ifp->if_flags & IFF_UP) && - ifp->if_drv_flags & IFF_DRV_RUNNING) { + if (!(if_getflags(ifp) & IFF_UP) && + if_getdrvflags(ifp) & IFF_DRV_RUNNING) { /* * If interface is marked down and it is running, then * stop it. */ lance_stop(sc); - } else if (ifp->if_flags & IFF_UP && - !(ifp->if_drv_flags & IFF_DRV_RUNNING)) { + } else if (if_getflags(ifp) & IFF_UP && + !(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { /* * If interface is marked up and it is stopped, then * start it. */ lance_init_locked(sc); } #ifdef LEDEBUG - if (ifp->if_flags & IFF_DEBUG) + if (if_getflags(ifp) & IFF_DEBUG) sc->sc_flags |= LE_DEBUG; else sc->sc_flags &= ~LE_DEBUG; #endif LE_UNLOCK(sc); break; case SIOCADDMULTI: case SIOCDELMULTI: /* * Multicast list has changed; set the hardware filter * accordingly. */ LE_LOCK(sc); - if (ifp->if_drv_flags & IFF_DRV_RUNNING) + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) lance_init_locked(sc); LE_UNLOCK(sc); break; case SIOCGIFMEDIA: case SIOCSIFMEDIA: error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd); break; default: error = ether_ioctl(ifp, cmd, data); break; } return (error); } struct lance_hash_maddr_ctx { struct lance_softc *sc; uint16_t *af; }; static u_int lance_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) { struct lance_hash_maddr_ctx *ctx = arg; struct lance_softc *sc = ctx->sc; uint32_t crc; crc = ether_crc32_le(LLADDR(sdl), ETHER_ADDR_LEN); /* Just want the 6 most significant bits. */ crc >>= 26; /* Set the corresponding bit in the filter. */ ctx->af[crc >> 4] |= LE_HTOLE16(1 << (crc & 0xf)); return (1); } /* * Set up the logical address filter. */ void lance_setladrf(struct lance_softc *sc, uint16_t *af) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct lance_hash_maddr_ctx ctx = { sc, af }; /* * Set up multicast address filter by passing all multicast addresses * through a crc generator, and then using the high order 6 bits as an * index into the 64 bit logical address filter. The high order bit * selects the word, while the rest of the bits select the bit within * the word. */ - if (ifp->if_flags & IFF_PROMISC || sc->sc_flags & LE_ALLMULTI) { + if (if_getflags(ifp) & IFF_PROMISC || sc->sc_flags & LE_ALLMULTI) { af[0] = af[1] = af[2] = af[3] = 0xffff; return; } af[0] = af[1] = af[2] = af[3] = 0x0000; if_foreach_llmaddr(ifp, lance_hash_maddr, &ctx); } /* * Routines for accessing the transmit and receive buffers. * The various CPU and adapter configurations supported by this * driver require three different access methods for buffers * and descriptors: * (1) contig (contiguous data; no padding), * (2) gap2 (two bytes of data followed by two bytes of padding), * (3) gap16 (16 bytes of data followed by 16 bytes of padding). */ /* * contig: contiguous data with no padding. * * Buffers may have any alignment. */ void lance_copytobuf_contig(struct lance_softc *sc, void *from, int boff, int len) { volatile caddr_t buf = sc->sc_mem; /* * Just call memcpy() to do the work. */ memcpy(buf + boff, from, len); } void lance_copyfrombuf_contig(struct lance_softc *sc, void *to, int boff, int len) { volatile caddr_t buf = sc->sc_mem; /* * Just call memcpy() to do the work. */ memcpy(to, buf + boff, len); } void lance_zerobuf_contig(struct lance_softc *sc, int boff, int len) { volatile caddr_t buf = sc->sc_mem; /* * Just let memset() do the work */ memset(buf + boff, 0, len); } #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. * * Buffers must be 4-byte aligned. The code doesn't worry about * doing an extra byte. */ static void lance_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t from = fromv; volatile uint16_t *bptr; if (boff & 0x1) { /* Handle unaligned first byte. */ bptr = ((volatile uint16_t *)buf) + (boff - 1); *bptr = (*from++ << 8) | (*bptr & 0xff); bptr += 2; len--; } else bptr = ((volatile uint16_t *)buf) + boff; while (len > 1) { *bptr = (from[1] << 8) | (from[0] & 0xff); bptr += 2; from += 2; len -= 2; } if (len == 1) *bptr = (uint16_t)*from; } static void lance_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t to = tov; volatile uint16_t *bptr; uint16_t tmp; if (boff & 0x1) { /* Handle unaligned first byte. */ bptr = ((volatile uint16_t *)buf) + (boff - 1); *to++ = (*bptr >> 8) & 0xff; bptr += 2; len--; } else bptr = ((volatile uint16_t *)buf) + boff; while (len > 1) { tmp = *bptr; *to++ = tmp & 0xff; *to++ = (tmp >> 8) & 0xff; bptr += 2; len -= 2; } if (len == 1) *to = *bptr & 0xff; } static void lance_zerobuf_gap2(struct lance_softc *sc, int boff, int len) { volatile caddr_t buf = sc->sc_mem; volatile uint16_t *bptr; if ((unsigned)boff & 0x1) { bptr = ((volatile uint16_t *)buf) + (boff - 1); *bptr &= 0xff; bptr += 2; len--; } else bptr = ((volatile uint16_t *)buf) + boff; while (len > 0) { *bptr = 0; bptr += 2; len -= 2; } } /* * gap16: 16 bytes of data followed by 16 bytes of pad. * * Buffers must be 32-byte aligned. */ static void lance_copytobuf_gap16(struct lance_softc *sc, void *fromv, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t bptr, from = fromv; int xfer; bptr = buf + ((boff << 1) & ~0x1f); boff &= 0xf; xfer = min(len, 16 - boff); while (len > 0) { memcpy(bptr + boff, from, xfer); from += xfer; bptr += 32; boff = 0; len -= xfer; xfer = min(len, 16); } } static void lance_copyfrombuf_gap16(struct lance_softc *sc, void *tov, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t bptr, to = tov; int xfer; bptr = buf + ((boff << 1) & ~0x1f); boff &= 0xf; xfer = min(len, 16 - boff); while (len > 0) { memcpy(to, bptr + boff, xfer); to += xfer; bptr += 32; boff = 0; len -= xfer; xfer = min(len, 16); } } static void lance_zerobuf_gap16(struct lance_softc *sc, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t bptr; int xfer; bptr = buf + ((boff << 1) & ~0x1f); boff &= 0xf; xfer = min(len, 16 - boff); while (len > 0) { memset(bptr + boff, 0, xfer); bptr += 32; boff = 0; len -= xfer; xfer = min(len, 16); } } #endif /* Example only */ diff --git a/sys/dev/le/lancevar.h b/sys/dev/le/lancevar.h index 092f78668e0a..87b5f3c748f9 100644 --- a/sys/dev/le/lancevar.h +++ b/sys/dev/le/lancevar.h @@ -1,209 +1,209 @@ /* $NetBSD: lancevar.h,v 1.10 2005/12/11 12:21:27 christos Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace * Simulation Facility, NASA Ames Research Center. * * 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. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS * 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. */ /* $FreeBSD$ */ #ifndef _DEV_LE_LANCEVAR_H_ #define _DEV_LE_LANCEVAR_H_ struct lance_softc { - struct ifnet *sc_ifp; + if_t sc_ifp; struct ifmedia sc_media; struct mtx sc_mtx; struct callout sc_wdog_ch; int sc_wdog_timer; /* * Memory functions: * * copy to/from descriptor * copy to/from buffer * zero bytes in buffer */ void (*sc_copytodesc)(struct lance_softc *, void *, int, int); void (*sc_copyfromdesc)(struct lance_softc *, void *, int, int); void (*sc_copytobuf)(struct lance_softc *, void *, int, int); void (*sc_copyfrombuf)(struct lance_softc *, void *, int, int); void (*sc_zerobuf)(struct lance_softc *, int, int); /* * Machine-dependent functions: * * read/write CSR * hardware reset hook - may be NULL * hardware init hook - may be NULL * no carrier hook - may be NULL * media change hook - may be NULL */ uint16_t (*sc_rdcsr)(struct lance_softc *, uint16_t); void (*sc_wrcsr)(struct lance_softc *, uint16_t, uint16_t); void (*sc_hwreset)(struct lance_softc *); void (*sc_hwinit)(struct lance_softc *); int (*sc_hwintr)(struct lance_softc *); void (*sc_nocarrier)(struct lance_softc *); int (*sc_mediachange)(struct lance_softc *); void (*sc_mediastatus)(struct lance_softc *, struct ifmediareq *); /* * Media-supported by this interface. If this is NULL, * the only supported media is assumed to be "manual". */ const int *sc_supmedia; int sc_nsupmedia; int sc_defaultmedia; uint16_t sc_conf3; /* CSR3 value */ void *sc_mem; /* base address of RAM - CPU's view */ bus_addr_t sc_addr; /* base address of RAM - LANCE's view */ bus_size_t sc_memsize; /* size of RAM */ int sc_nrbuf; /* number of receive buffers */ int sc_ntbuf; /* number of transmit buffers */ int sc_last_rd; int sc_first_td; int sc_last_td; int sc_no_td; int sc_initaddr; int sc_rmdaddr; int sc_tmdaddr; int sc_rbufaddr; int sc_tbufaddr; uint8_t sc_enaddr[ETHER_ADDR_LEN]; void (*sc_meminit)(struct lance_softc *); void (*sc_start_locked)(struct lance_softc *); int sc_flags; #define LE_ALLMULTI (1 << 0) #define LE_BSWAP (1 << 1) #define LE_CARRIER (1 << 2) #define LE_DEBUG (1 << 3) #define LE_PROMISC (1 << 4) }; #define LE_LOCK_INIT(_sc, _name) \ mtx_init(&(_sc)->sc_mtx, _name, MTX_NETWORK_LOCK, MTX_DEF) #define LE_LOCK_INITIALIZED(_sc) mtx_initialized(&(_sc)->sc_mtx) #define LE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define LE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) #define LE_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what)) #define LE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx) /* * Unfortunately, manual byte swapping is only necessary for the PCnet-PCI * variants but not for the original LANCE or ILACC so we cannot do this * with #ifdefs resolved at compile time. */ #define LE_HTOLE16(v) (((sc)->sc_flags & LE_BSWAP) ? htole16(v) : (v)) #define LE_HTOLE32(v) (((sc)->sc_flags & LE_BSWAP) ? htole32(v) : (v)) #define LE_LE16TOH(v) (((sc)->sc_flags & LE_BSWAP) ? le16toh(v) : (v)) #define LE_LE32TOH(v) (((sc)->sc_flags & LE_BSWAP) ? le32toh(v) : (v)) int lance_config(struct lance_softc *, const char*, int); void lance_attach(struct lance_softc *); void lance_detach(struct lance_softc *); void lance_suspend(struct lance_softc *); void lance_resume(struct lance_softc *); void lance_init_locked(struct lance_softc *); int lance_put(struct lance_softc *, int, struct mbuf *); struct mbuf *lance_get(struct lance_softc *, int, int); void lance_setladrf(struct lance_softc *, u_int16_t *); /* * The following functions are only useful on certain CPU/bus * combinations. They should be written in assembly language for * maximum efficiency, but machine-independent versions are provided * for drivers that have not yet been optimized. */ void lance_copytobuf_contig(struct lance_softc *, void *, int, int); void lance_copyfrombuf_contig(struct lance_softc *, void *, int, int); void lance_zerobuf_contig(struct lance_softc *, int, int); #if 0 /* Example only - see lance.c */ void lance_copytobuf_gap2(struct lance_softc *, void *, int, int); void lance_copyfrombuf_gap2(struct lance_softc *, void *, int, int); void lance_zerobuf_gap2(struct lance_softc *, int, int); void lance_copytobuf_gap16(struct lance_softc *, void *, int, int); void lance_copyfrombuf_gap16(struct lance_softc *, void *, int, int); void lance_zerobuf_gap16(struct lance_softc *, int, int); #endif /* Example only */ /* * Compare two Ether/802 addresses for equality, inlined and * unrolled for speed. Use this like memcmp(). * * XXX: Add for stuff like this? * XXX: or maybe add it to libkern.h instead? * * "I'd love to have an inline assembler version of this." * XXX: Who wanted that? mycroft? I wrote one, but this * version in C is as good as hand-coded assembly. -gwr * * Please do NOT tweak this without looking at the actual * assembly code generated before and after your tweaks! */ static inline uint16_t ether_cmp(void *one, void *two) { uint16_t *a = (u_short *)one; uint16_t *b = (u_short *)two; uint16_t diff; #ifdef m68k /* * The post-increment-pointer form produces the best * machine code for m68k. This was carefully tuned * so it compiles to just 8 short (2-byte) op-codes! */ diff = *a++ - *b++; diff |= *a++ - *b++; diff |= *a++ - *b++; #else /* * Most modern CPUs do better with a single expression. * Note that short-cut evaluation is NOT helpful here, * because it just makes the code longer, not faster! */ diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]); #endif return (diff); } #endif /* _DEV_LE_LANCEVAR_H_ */