diff options
author | brooks <brooks@FreeBSD.org> | 2005-06-10 16:49:24 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2005-06-10 16:49:24 +0000 |
commit | 567ba9b00a248431e7c1147c4e079fd7a11b9ecf (patch) | |
tree | f65b6d7834b40dfcd48534829a0a1e9529ab87ee /sys/dev/ie | |
parent | 3eaa67c3ad947d85be5350e0e184cd6ee5b93a52 (diff) | |
download | FreeBSD-src-567ba9b00a248431e7c1147c4e079fd7a11b9ecf.zip FreeBSD-src-567ba9b00a248431e7c1147c4e079fd7a11b9ecf.tar.gz |
Stop embedding struct ifnet at the top of driver softcs. Instead the
struct ifnet or the layer 2 common structure it was embedded in have
been replaced with a struct ifnet pointer to be filled by a call to the
new function, if_alloc(). The layer 2 common structure is also allocated
via if_alloc() based on the interface type. It is hung off the new
struct ifnet member, if_l2com.
This change removes the size of these structures from the kernel ABI and
will allow us to better manage them as interfaces come and go.
Other changes of note:
- Struct arpcom is no longer referenced in normal interface code.
Instead the Ethernet address is accessed via the IFP2ENADDR() macro.
To enforce this ac_enaddr has been renamed to _ac_enaddr.
- The second argument to ether_ifattach is now always the mac address
from driver private storage rather than sometimes being ac_enaddr.
Reviewed by: sobomax, sam
Diffstat (limited to 'sys/dev/ie')
-rw-r--r-- | sys/dev/ie/if_ie.c | 79 | ||||
-rw-r--r-- | sys/dev/ie/if_ie_isa.c | 16 | ||||
-rw-r--r-- | sys/dev/ie/if_ievar.h | 3 |
3 files changed, 53 insertions, 45 deletions
diff --git a/sys/dev/ie/if_ie.c b/sys/dev/ie/if_ie.c index 71845e9..febdc69 100644 --- a/sys/dev/ie/if_ie.c +++ b/sys/dev/ie/if_ie.c @@ -266,7 +266,11 @@ ie_attach(device_t dev) int factor; sc = device_get_softc(dev); - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(sc->dev, "can not if_alloc()\n"); + return (ENOSPC); + } sc->dev = dev; sc->unit = device_get_unit(dev); @@ -290,8 +294,10 @@ ie_attach(device_t dev) sc->rframes = (volatile struct ie_recv_frame_desc **) malloc(allocsize, M_DEVBUF, M_NOWAIT); - if (sc->rframes == NULL) + if (sc->rframes == NULL) { + if_free(ifp); return (ENXIO); + } sc->rbuffs = (volatile struct ie_recv_buf_desc **)&sc->rframes[sc->nframes]; sc->cbuffs = (volatile u_char **)&sc->rbuffs[sc->nrxbufs]; @@ -319,7 +325,7 @@ ie_attach(device_t dev) EVENTHANDLER_REGISTER(shutdown_post_sync, ee16_shutdown, sc, SHUTDOWN_PRI_DEFAULT); - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->enaddr); return (0); } @@ -417,9 +423,9 @@ ierint(struct ie_softc *sc) status = sc->rframes[i]->ie_fd_status; if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) { - sc->arpcom.ac_if.if_ipackets++; + sc->ifp->if_ipackets++; if (!--timesthru) { - sc->arpcom.ac_if.if_ierrors += + sc->ifp->if_ierrors += sc->scb->ie_err_crc + sc->scb->ie_err_align + sc->scb->ie_err_resource + @@ -459,32 +465,32 @@ ietint(struct ie_softc *sc) int status; int i; - sc->arpcom.ac_if.if_timer = 0; - sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; + sc->ifp->if_timer = 0; + sc->ifp->if_flags &= ~IFF_OACTIVE; for (i = 0; i < sc->xmit_count; i++) { status = sc->xmit_cmds[i]->ie_xmit_status; if (status & IE_XS_LATECOLL) { printf("ie%d: late collision\n", sc->unit); - sc->arpcom.ac_if.if_collisions++; - sc->arpcom.ac_if.if_oerrors++; + sc->ifp->if_collisions++; + sc->ifp->if_oerrors++; } else if (status & IE_XS_NOCARRIER) { printf("ie%d: no carrier\n", sc->unit); - sc->arpcom.ac_if.if_oerrors++; + sc->ifp->if_oerrors++; } else if (status & IE_XS_LOSTCTS) { printf("ie%d: lost CTS\n", sc->unit); - sc->arpcom.ac_if.if_oerrors++; + sc->ifp->if_oerrors++; } else if (status & IE_XS_UNDERRUN) { printf("ie%d: DMA underrun\n", sc->unit); - sc->arpcom.ac_if.if_oerrors++; + sc->ifp->if_oerrors++; } else if (status & IE_XS_EXCMAX) { printf("ie%d: too many collisions\n", sc->unit); - sc->arpcom.ac_if.if_collisions += 16; - sc->arpcom.ac_if.if_oerrors++; + sc->ifp->if_collisions += 16; + sc->ifp->if_oerrors++; } else { - sc->arpcom.ac_if.if_opackets++; - sc->arpcom.ac_if.if_collisions += status & IE_XS_MAXCOLL; + sc->ifp->if_opackets++; + sc->ifp->if_collisions += status & IE_XS_MAXCOLL; } } sc->xmit_count = 0; @@ -501,7 +507,7 @@ ietint(struct ie_softc *sc) /* Wish I knew why this seems to be necessary... */ sc->xmit_cmds[0]->ie_xmit_status |= IE_STAT_COMPL; - iestart(&sc->arpcom.ac_if); + iestart(sc->ifp); return (0); /* shouldn't be necessary */ } @@ -529,7 +535,7 @@ iernr(struct ie_softc *sc) #endif ie_ack(sc, IE_ST_WHENCE); - sc->arpcom.ac_if.if_ierrors++; + sc->ifp->if_ierrors++; return (0); } @@ -593,7 +599,7 @@ check_eh(struct ie_softc *sc, struct ether_header *eh) return (1); /* Always accept packets directed at us */ - if (ether_equal(eh->ether_dhost, sc->arpcom.ac_enaddr)) + if (ether_equal(eh->ether_dhost, IFP2ENADDR(sc->ifp))) return (1); /* Must have IFF_ALLMULTI but not IFF_PROMISC set. The chip is @@ -678,7 +684,7 @@ ieget(struct ie_softc *sc, struct mbuf **mp) */ if (!check_eh(sc, &eh)) { ie_drop_packet_buffer(sc); - sc->arpcom.ac_if.if_ierrors--; /* just this case, it's not an + sc->ifp->if_ierrors--; /* just this case, it's not an * error */ return (-1); @@ -692,7 +698,7 @@ ieget(struct ie_softc *sc, struct mbuf **mp) } *mp = m; - m->m_pkthdr.rcvif = &sc->arpcom.ac_if; + m->m_pkthdr.rcvif = sc->ifp; m->m_len = MHLEN; resid = m->m_pkthdr.len = totlen; top = 0; @@ -827,7 +833,7 @@ nextbuf: static void ie_readframe(struct ie_softc *sc, int num/* frame number to read */) { - struct ifnet *ifp = &sc->arpcom.ac_if; + struct ifnet *ifp = sc->ifp; struct ie_recv_frame_desc rfd; struct mbuf *m = 0; #ifdef DEBUG @@ -849,7 +855,7 @@ ie_readframe(struct ie_softc *sc, int num/* frame number to read */) if (rfd.ie_fd_status & IE_FD_OK) { if (ieget(sc, &m)) { - sc->arpcom.ac_if.if_ierrors++; /* this counts as an + sc->ifp->if_ierrors++; /* this counts as an * error */ return; } @@ -927,7 +933,7 @@ iestart(struct ifnet *ifp) return; do { - IF_DEQUEUE(&sc->arpcom.ac_if.if_snd, m); + IF_DEQUEUE(&sc->ifp->if_snd, m); if (!m) break; @@ -947,7 +953,7 @@ iestart(struct ifnet *ifp) * See if bpf is listening on this interface, let it see the * packet before we commit it to the wire. */ - BPF_TAP(&sc->arpcom.ac_if, + BPF_TAP(sc->ifp, (void *)sc->xmit_cbuffs[sc->xmit_count], len); sc->xmit_buffs[sc->xmit_count]->ie_xmit_flags = @@ -1231,8 +1237,8 @@ iereset(struct ie_softc *sc) int s = splimp(); printf("ie%d: reset\n", sc->unit); - sc->arpcom.ac_if.if_flags &= ~IFF_UP; - ieioctl(&sc->arpcom.ac_if, SIOCSIFFLAGS, 0); + sc->ifp->if_flags &= ~IFF_UP; + ieioctl(sc->ifp, SIOCSIFFLAGS, 0); /* * Stop i82586 dead in its tracks. @@ -1248,8 +1254,8 @@ iereset(struct ie_softc *sc) panic("ie disappeared!"); #endif - sc->arpcom.ac_if.if_flags |= IFF_UP; - ieioctl(&sc->arpcom.ac_if, SIOCSIFFLAGS, 0); + sc->ifp->if_flags |= IFF_UP; + ieioctl(sc->ifp, SIOCSIFFLAGS, 0); splx(s); return; @@ -1524,7 +1530,7 @@ ieinit(xsc) cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; - bcopy((volatile char *)sc->arpcom.ac_enaddr, + bcopy((volatile char *)IFP2ENADDR(sc->ifp), (volatile char *)&cmd->ie_address, sizeof cmd->ie_address); scb->ie_command_list = MK_16(MEM(sc), cmd); if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) @@ -1595,9 +1601,9 @@ ieinit(xsc) ee16_interrupt_enable(sc); ee16_chan_attn(sc); } - sc->arpcom.ac_if.if_flags |= IFF_RUNNING; /* tell higher levels + sc->ifp->if_flags |= IFF_RUNNING; /* tell higher levels * we're here */ - sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; + sc->ifp->if_flags &= ~IFF_OACTIVE; start_receiver(sc); @@ -1670,14 +1676,14 @@ ie_mc_reset(struct ie_softc *sc) * Step through the list of addresses. */ sc->mcast_count = 0; - TAILQ_FOREACH(ifma, &sc->arpcom.ac_if.if_multiaddrs, ifma_link) { + TAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) { if (ifma->ifma_addr->sa_family != AF_LINK) continue; /* XXX - this is broken... */ if (sc->mcast_count >= MAXMCAST) { - sc->arpcom.ac_if.if_flags |= IFF_ALLMULTI; - ieioctl(&sc->arpcom.ac_if, SIOCSIFFLAGS, (void *) 0); + sc->ifp->if_flags |= IFF_ALLMULTI; + ieioctl(sc->ifp, SIOCSIFFLAGS, (void *) 0); goto setflag; } bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr), @@ -1780,7 +1786,7 @@ ie_detach (device_t dev) struct ifnet * ifp; sc = device_get_softc(dev); - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; if (sc->hard_type == IE_EE16) ee16_shutdown(sc, 0); @@ -1788,6 +1794,7 @@ ie_detach (device_t dev) ie_stop(sc); ifp->if_flags &= ~IFF_RUNNING; ether_ifdetach(ifp); + if_free(ifp); ie_release_resources(dev); return (0); diff --git a/sys/dev/ie/if_ie_isa.c b/sys/dev/ie/if_ie_isa.c index 53ed256..564176f 100644 --- a/sys/dev/ie/if_ie_isa.c +++ b/sys/dev/ie/if_ie_isa.c @@ -259,7 +259,7 @@ ie_isa_3C507_attach (device_t dev) goto bad; } - sl_read_ether(sc, sc->arpcom.ac_enaddr); + sl_read_ether(sc, sc->enaddr); /* Clear the interrupt latch just in case. */ outb(PORT(sc) + IE507_ICTRL, 1); @@ -526,14 +526,14 @@ ie_isa_ee16_attach (device_t dev) * the softc for use by the 586 setup code. */ eaddrtemp = ie_ee16_hw_read_eeprom(PORT(sc), IEE16_EEPROM_ENET_HIGH); - sc->arpcom.ac_enaddr[1] = eaddrtemp & 0xFF; - sc->arpcom.ac_enaddr[0] = eaddrtemp >> 8; + sc->enaddr[1] = eaddrtemp & 0xFF; + sc->enaddr[0] = eaddrtemp >> 8; eaddrtemp = ie_ee16_hw_read_eeprom(PORT(sc), IEE16_EEPROM_ENET_MID); - sc->arpcom.ac_enaddr[3] = eaddrtemp & 0xFF; - sc->arpcom.ac_enaddr[2] = eaddrtemp >> 8; + sc->enaddr[3] = eaddrtemp & 0xFF; + sc->enaddr[2] = eaddrtemp >> 8; eaddrtemp = ie_ee16_hw_read_eeprom(PORT(sc), IEE16_EEPROM_ENET_LOW); - sc->arpcom.ac_enaddr[5] = eaddrtemp & 0xFF; - sc->arpcom.ac_enaddr[4] = eaddrtemp >> 8; + sc->enaddr[5] = eaddrtemp & 0xFF; + sc->enaddr[4] = eaddrtemp >> 8; /* disable the board interrupts */ outb(PORT(sc) + IEE16_IRQ, sc->irq_encoded); @@ -757,7 +757,7 @@ ie_isa_sl_attach (device_t dev) case IE_STARLAN10: case IE_SLFIBER: case IE_NI5210: - sl_read_ether(sc, sc->arpcom.ac_enaddr); + sl_read_ether(sc, sc->enaddr); break; default: if (bootverbose) diff --git a/sys/dev/ie/if_ievar.h b/sys/dev/ie/if_ievar.h index a57b2d0..2d3851f 100644 --- a/sys/dev/ie/if_ievar.h +++ b/sys/dev/ie/if_ievar.h @@ -17,12 +17,13 @@ enum ie_hardware { * Ethernet status, per interface. */ struct ie_softc { - struct arpcom arpcom; + struct ifnet *ifp; void (*ie_reset_586) (struct ie_softc *); void (*ie_chan_attn) (struct ie_softc *); enum ie_hardware hard_type; int hard_vers; int unit; + u_char enaddr[6]; device_t dev; |