summaryrefslogtreecommitdiffstats
path: root/sys/dev/en
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2005-06-10 16:49:24 +0000
committerbrooks <brooks@FreeBSD.org>2005-06-10 16:49:24 +0000
commit567ba9b00a248431e7c1147c4e079fd7a11b9ecf (patch)
treef65b6d7834b40dfcd48534829a0a1e9529ab87ee /sys/dev/en
parent3eaa67c3ad947d85be5350e0e184cd6ee5b93a52 (diff)
downloadFreeBSD-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/en')
-rw-r--r--sys/dev/en/if_en_pci.c34
-rw-r--r--sys/dev/en/midway.c103
-rw-r--r--sys/dev/en/midwayvar.h3
3 files changed, 73 insertions, 67 deletions
diff --git a/sys/dev/en/if_en_pci.c b/sys/dev/en/if_en_pci.c
index 8409352..c167e2a 100644
--- a/sys/dev/en/if_en_pci.c
+++ b/sys/dev/en/if_en_pci.c
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <net/if_atm.h>
#include <net/if_media.h>
+#include <net/if_types.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -149,7 +150,7 @@ adp_busreset(void *v)
dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
if ((dummy & (ADP_PCIREG_SWAP_WORD | ADP_PCIREG_SWAP_DMA)) !=
ADP_PCIREG_SWAP_DMA)
- if_printf(&sc->ifatm.ifnet, "adp_busreset: Adaptec ATM did "
+ if_printf(sc->ifp, "adp_busreset: Adaptec ATM did "
"NOT reset!\n");
}
@@ -197,8 +198,11 @@ en_pci_attach(device_t dev)
sc = device_get_softc(dev);
scp = (struct en_pci_softc *)sc;
+ sc->ifp = if_alloc(IFT_ATM);
+ if (sc->ifp == NULL)
+ return (ENOSPC);
- if_initname(&(sc->ifatm.ifnet), device_get_name(dev),
+ if_initname(sc->ifp, device_get_name(dev),
device_get_unit(dev));
/*
@@ -273,7 +277,8 @@ en_pci_attach(device_t dev)
en_intr, sc, &scp->ih);
if (error) {
en_reset(sc);
- atm_ifdetach(&sc->ifatm.ifnet);
+ atm_ifdetach(sc->ifp);
+ if_free(sc->ifp);
device_printf(dev, "could not setup irq\n");
bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
@@ -299,16 +304,17 @@ en_pci_detach(device_t dev)
/*
* Stop DMA and drop transmit queue.
*/
- if ((sc->ifatm.ifnet.if_flags & IFF_RUNNING)) {
- if_printf(&sc->ifatm.ifnet, "still running\n");
- sc->ifatm.ifnet.if_flags &= ~IFF_RUNNING;
+ if ((sc->ifp->if_flags & IFF_RUNNING)) {
+ if_printf(sc->ifp, "still running\n");
+ sc->ifp->if_flags &= ~IFF_RUNNING;
}
/*
* Close down routes etc.
*/
en_reset(sc);
- atm_ifdetach(&sc->ifatm.ifnet);
+ atm_ifdetach(sc->ifp);
+ if_free(sc->ifp);
/*
* Deallocate resources.
@@ -347,8 +353,8 @@ adp_get_macaddr(struct en_pci_softc *scp)
struct en_softc * sc = (struct en_softc *)scp;
int lcv;
- for (lcv = 0; lcv < sizeof(sc->ifatm.mib.esi); lcv++)
- sc->ifatm.mib.esi[lcv] = bus_space_read_1(sc->en_memt,
+ for (lcv = 0; lcv < sizeof(IFP2IFATM(sc->ifp)->mib.esi); lcv++)
+ IFP2IFATM(sc->ifp)->mib.esi[lcv] = bus_space_read_1(sc->en_memt,
sc->en_base, MID_ADPMACOFF + lcv);
}
@@ -447,13 +453,13 @@ eni_get_macaddr(device_t dev, struct en_pci_softc *scp)
data = EN_PROM_MAGIC | EN_PROM_DATA | EN_PROM_CLK;
pci_write_config(dev, EN_TONGA, data, 4);
- for (i = 0; i < sizeof(sc->ifatm.mib.esi); i ++)
- sc->ifatm.mib.esi[i] = eni_get_byte(dev, &data, i + EN_ESI);
+ for (i = 0; i < sizeof(IFP2IFATM(sc->ifp)->mib.esi); i ++)
+ IFP2IFATM(sc->ifp)->mib.esi[i] = eni_get_byte(dev, &data, i + EN_ESI);
- sc->ifatm.mib.serial = 0;
+ IFP2IFATM(sc->ifp)->mib.serial = 0;
for (i = 0; i < 4; i++) {
- sc->ifatm.mib.serial <<= 8;
- sc->ifatm.mib.serial |= eni_get_byte(dev, &data, i + EN_SERIAL);
+ IFP2IFATM(sc->ifp)->mib.serial <<= 8;
+ IFP2IFATM(sc->ifp)->mib.serial |= eni_get_byte(dev, &data, i + EN_SERIAL);
}
/* stop operation */
data &= ~EN_PROM_DATA;
diff --git a/sys/dev/en/midway.c b/sys/dev/en/midway.c
index 265b60e..165655e 100644
--- a/sys/dev/en/midway.c
+++ b/sys/dev/en/midway.c
@@ -90,7 +90,7 @@ __FBSDID("$FreeBSD$");
*/
#define DBG(SC, FL, PRINT) do { \
if ((SC)->debug & DBG_##FL) { \
- if_printf(&(SC)->ifatm.ifnet, "%s: "#FL": ", __func__); \
+ if_printf((SC)->ifp, "%s: "#FL": ", __func__); \
printf PRINT; \
printf("\n"); \
} \
@@ -395,7 +395,7 @@ en_dump_packet(struct en_softc *sc, struct mbuf *m)
int len;
u_char *ptr;
- if_printf(&sc->ifatm.ifnet, "packet len=%d", plen);
+ if_printf(sc->ifp, "packet len=%d", plen);
while (m != NULL) {
totlen += m->m_len;
ptr = mtod(m, u_char *);
@@ -445,7 +445,7 @@ en_map_ctor(void *mem, int size, void *arg, int flags)
err = bus_dmamap_create(sc->txtag, 0, &map->map);
if (err != 0) {
- if_printf(&sc->ifatm.ifnet, "cannot create DMA map %d\n", err);
+ if_printf(sc->ifp, "cannot create DMA map %d\n", err);
return (err);
}
map->flags = ENMAP_ALLOC;
@@ -754,7 +754,7 @@ en_txdma(struct en_softc *sc, struct en_txslot *slot)
lastm->m_next = NULL;
if (error != 0) {
- if_printf(&sc->ifatm.ifnet, "loading TX map failed %d\n",
+ if_printf(sc->ifp, "loading TX map failed %d\n",
error);
goto dequeue_drop;
}
@@ -770,13 +770,13 @@ en_txdma(struct en_softc *sc, struct en_txslot *slot)
}
EN_COUNT(sc->stats.launch);
- sc->ifatm.ifnet.if_opackets++;
+ sc->ifp->if_opackets++;
sc->vccs[tx.vci]->opackets++;
sc->vccs[tx.vci]->obytes += tx.datalen;
#ifdef ENABLE_BPF
- if (sc->ifatm.ifnet.if_bpf != NULL) {
+ if (sc->ifp->if_bpf != NULL) {
/*
* adjust the top of the mbuf to skip the TBD if present
* before passing the packet to bpf.
@@ -794,7 +794,7 @@ en_txdma(struct en_softc *sc, struct en_txslot *slot)
tx.m->m_pkthdr.len = tx.datalen;
}
- BPF_MTAP(&sc->ifatm.ifnet, tx.m);
+ BPF_MTAP(sc->ifp, tx.m);
}
#endif
@@ -1314,12 +1314,12 @@ en_close_vcc(struct en_softc *sc, struct atmio_closevcc *cl)
goto done;
vc->vflags |= VCC_CLOSE_RX;
- while ((sc->ifatm.ifnet.if_flags & IFF_RUNNING) &&
+ while ((sc->ifp->if_flags & IFF_RUNNING) &&
(vc->vflags & VCC_DRAIN))
cv_wait(&sc->cv_close, &sc->en_mtx);
en_close_finish(sc, vc);
- if (!(sc->ifatm.ifnet.if_flags & IFF_RUNNING)) {
+ if (!(sc->ifp->if_flags & IFF_RUNNING)) {
error = EIO;
goto done;
}
@@ -1349,8 +1349,8 @@ en_reset_ul(struct en_softc *sc)
struct en_rxslot *rx;
int lcv;
- if_printf(&sc->ifatm.ifnet, "reset\n");
- sc->ifatm.ifnet.if_flags &= ~IFF_RUNNING;
+ if_printf(sc->ifp, "reset\n");
+ sc->ifp->if_flags &= ~IFF_RUNNING;
if (sc->en_busreset)
sc->en_busreset(sc);
@@ -1439,14 +1439,14 @@ en_init(struct en_softc *sc)
int vc, slot;
uint32_t loc;
- if ((sc->ifatm.ifnet.if_flags & IFF_UP) == 0) {
+ if ((sc->ifp->if_flags & IFF_UP) == 0) {
DBG(sc, INIT, ("going down"));
en_reset(sc); /* to be safe */
return;
}
DBG(sc, INIT, ("going up"));
- sc->ifatm.ifnet.if_flags |= IFF_RUNNING; /* enable */
+ sc->ifp->if_flags |= IFF_RUNNING; /* enable */
if (sc->en_busreset)
sc->en_busreset(sc);
@@ -1820,7 +1820,7 @@ en_rx_drain(struct en_softc *sc, u_int drq)
if (EN_DQ_LEN(drq) != 0) {
_IF_DEQUEUE(&slot->indma, m);
KASSERT(m != NULL, ("drqsync: %s: lost mbuf in slot %zu!",
- sc->ifatm.ifnet.if_xname, slot - sc->rxslot));
+ sc->ifp->if_xname, slot - sc->rxslot));
uma_zfree(sc->map_zone, (struct en_map *)m->m_pkthdr.rcvif);
}
if ((vc = slot->vcc) == NULL) {
@@ -1856,8 +1856,8 @@ en_rx_drain(struct en_softc *sc, u_int drq)
"hand %p", slot - sc->rxslot, vc->vcc.vci, m,
EN_DQ_LEN(drq), vc->rxhand));
- m->m_pkthdr.rcvif = &sc->ifatm.ifnet;
- sc->ifatm.ifnet.if_ipackets++;
+ m->m_pkthdr.rcvif = sc->ifp;
+ sc->ifp->if_ipackets++;
vc->ipackets++;
vc->ibytes += m->m_pkthdr.len;
@@ -1867,9 +1867,9 @@ en_rx_drain(struct en_softc *sc, u_int drq)
en_dump_packet(sc, m);
#endif
#ifdef ENABLE_BPF
- BPF_MTAP(&sc->ifatm.ifnet, m);
+ BPF_MTAP(sc->ifp, m);
#endif
- atm_input(&sc->ifatm.ifnet, &ah, m, vc->rxhand);
+ atm_input(sc->ifp, &ah, m, vc->rxhand);
}
}
@@ -2250,16 +2250,16 @@ en_service(struct en_softc *sc)
if (MID_RBD_CNT(rbd) * MID_ATMDATASZ <
MID_PDU_LEN(pdu)) {
- if_printf(&sc->ifatm.ifnet, "invalid AAL5 length\n");
+ if_printf(sc->ifp, "invalid AAL5 length\n");
rx.post_skip = MID_RBD_CNT(rbd) * MID_ATMDATASZ;
mlen = 0;
- sc->ifatm.ifnet.if_ierrors++;
+ sc->ifp->if_ierrors++;
} else if (rbd & MID_RBD_CRCERR) {
- if_printf(&sc->ifatm.ifnet, "CRC error\n");
+ if_printf(sc->ifp, "CRC error\n");
rx.post_skip = MID_RBD_CNT(rbd) * MID_ATMDATASZ;
mlen = 0;
- sc->ifatm.ifnet.if_ierrors++;
+ sc->ifp->if_ierrors++;
} else {
mlen = MID_PDU_LEN(pdu);
@@ -2334,7 +2334,7 @@ en_service(struct en_softc *sc)
en_rxdma_load, &rx, BUS_DMA_NOWAIT);
if (error != 0) {
- if_printf(&sc->ifatm.ifnet, "loading RX map failed "
+ if_printf(sc->ifp, "loading RX map failed "
"%d\n", error);
uma_zfree(sc->map_zone, map);
m_freem(m);
@@ -2430,11 +2430,11 @@ en_intr(void *arg)
* unexpected errors that need a reset
*/
if ((reg & (MID_INT_IDENT | MID_INT_LERR | MID_INT_DMA_ERR)) != 0) {
- if_printf(&sc->ifatm.ifnet, "unexpected interrupt=0x%b, "
+ if_printf(sc->ifp, "unexpected interrupt=0x%b, "
"resetting\n", reg, MID_INTBITS);
#ifdef EN_DEBUG
kdb_enter("en: unexpected error");
- sc->ifatm.ifnet.if_flags &= ~IFF_RUNNING; /* FREEZE! */
+ sc->ifp->if_flags &= ~IFF_RUNNING; /* FREEZE! */
#else
en_reset_ul(sc);
en_init(sc);
@@ -2493,7 +2493,7 @@ en_intr(void *arg)
static int
en_utopia_readregs(struct ifatm *ifatm, u_int reg, uint8_t *val, u_int *n)
{
- struct en_softc *sc = ifatm->ifnet.if_softc;
+ struct en_softc *sc = ifatm->ifp->if_softc;
u_int i;
EN_CHECKLOCK(sc);
@@ -2514,7 +2514,7 @@ en_utopia_readregs(struct ifatm *ifatm, u_int reg, uint8_t *val, u_int *n)
static int
en_utopia_writereg(struct ifatm *ifatm, u_int reg, u_int mask, u_int val)
{
- struct en_softc *sc = ifatm->ifnet.if_softc;
+ struct en_softc *sc = ifatm->ifp->if_softc;
uint32_t regval;
EN_CHECKLOCK(sc);
@@ -2797,13 +2797,14 @@ en_dmaprobe(struct en_softc *sc)
int
en_attach(struct en_softc *sc)
{
- struct ifnet *ifp = &sc->ifatm.ifnet;
+ struct ifnet *ifp = sc->ifp;
int sz;
uint32_t reg, lcv, check, ptr, sav, midvloc;
#ifdef EN_DEBUG
sc->debug = EN_DEBUG;
#endif
+
/*
* Probe card to determine memory size.
*
@@ -2852,7 +2853,7 @@ en_attach(struct en_softc *sc)
reg = en_read(sc, MID_RESID);
- if_printf(&sc->ifatm.ifnet, "ATM midway v%d, board IDs %d.%d, %s%s%s, "
+ if_printf(sc->ifp, "ATM midway v%d, board IDs %d.%d, %s%s%s, "
"%ldKB on-board RAM\n", MID_VER(reg), MID_MID(reg), MID_DID(reg),
(MID_IS_SABRE(reg)) ? "sabre controller, " : "",
(MID_IS_SUNI(reg)) ? "SUNI" : "Utopia",
@@ -2862,31 +2863,31 @@ en_attach(struct en_softc *sc)
/*
* fill in common ATM interface stuff
*/
- sc->ifatm.mib.hw_version = (MID_VER(reg) << 16) |
+ IFP2IFATM(sc->ifp)->mib.hw_version = (MID_VER(reg) << 16) |
(MID_MID(reg) << 8) | MID_DID(reg);
if (MID_DID(reg) & 0x4)
- sc->ifatm.mib.media = IFM_ATM_UTP_155;
+ IFP2IFATM(sc->ifp)->mib.media = IFM_ATM_UTP_155;
else
- sc->ifatm.mib.media = IFM_ATM_MM_155;
+ IFP2IFATM(sc->ifp)->mib.media = IFM_ATM_MM_155;
- sc->ifatm.mib.pcr = ATM_RATE_155M;
- sc->ifatm.mib.vpi_bits = 0;
- sc->ifatm.mib.vci_bits = MID_VCI_BITS;
- sc->ifatm.mib.max_vccs = MID_N_VC;
- sc->ifatm.mib.max_vpcs = 0;
+ IFP2IFATM(sc->ifp)->mib.pcr = ATM_RATE_155M;
+ IFP2IFATM(sc->ifp)->mib.vpi_bits = 0;
+ IFP2IFATM(sc->ifp)->mib.vci_bits = MID_VCI_BITS;
+ IFP2IFATM(sc->ifp)->mib.max_vccs = MID_N_VC;
+ IFP2IFATM(sc->ifp)->mib.max_vpcs = 0;
if (sc->is_adaptec) {
- sc->ifatm.mib.device = ATM_DEVICE_ADP155P;
+ IFP2IFATM(sc->ifp)->mib.device = ATM_DEVICE_ADP155P;
if (sc->bestburstlen == 64 && sc->alburst == 0)
- if_printf(&sc->ifatm.ifnet,
+ if_printf(sc->ifp,
"passed 64 byte DMA test\n");
else
- if_printf(&sc->ifatm.ifnet, "FAILED DMA TEST: "
+ if_printf(sc->ifp, "FAILED DMA TEST: "
"burst=%d, alburst=%d\n", sc->bestburstlen,
sc->alburst);
} else {
- sc->ifatm.mib.device = ATM_DEVICE_ENI155P;
- if_printf(&sc->ifatm.ifnet, "maximum DMA burst length = %d "
+ IFP2IFATM(sc->ifp)->mib.device = ATM_DEVICE_ENI155P;
+ if_printf(sc->ifp, "maximum DMA burst length = %d "
"bytes%s\n", sc->bestburstlen, sc->alburst ?
sc->noalbursts ? " (no large bursts)" : " (must align)" :
"");
@@ -2895,7 +2896,7 @@ en_attach(struct en_softc *sc)
/*
* link into network subsystem and prepare card
*/
- sc->ifatm.ifnet.if_softc = sc;
+ sc->ifp->if_softc = sc;
ifp->if_flags = IFF_SIMPLEX;
ifp->if_ioctl = en_ioctl;
ifp->if_start = en_start;
@@ -2925,8 +2926,8 @@ en_attach(struct en_softc *sc)
goto fail;
#endif
- sc->ifatm.phy = &sc->utopia;
- utopia_attach(&sc->utopia, &sc->ifatm, &sc->media, &sc->en_mtx,
+ IFP2IFATM(sc->ifp)->phy = &sc->utopia;
+ utopia_attach(&sc->utopia, IFP2IFATM(sc->ifp), &sc->media, &sc->en_mtx,
&sc->sysctl_ctx, SYSCTL_CHILDREN(sc->sysctl_tree),
&en_utopia_methods);
utopia_init_media(&sc->utopia);
@@ -2960,7 +2961,7 @@ en_attach(struct en_softc *sc)
ptr = roundup(ptr, EN_TXSZ * 1024); /* align */
sz = sz - (ptr - sav);
if (EN_TXSZ*1024 * EN_NTX > sz) {
- if_printf(&sc->ifatm.ifnet, "EN_NTX/EN_TXSZ too big\n");
+ if_printf(sc->ifp, "EN_NTX/EN_TXSZ too big\n");
goto fail;
}
for (lcv = 0 ;lcv < EN_NTX ;lcv++) {
@@ -2979,7 +2980,7 @@ en_attach(struct en_softc *sc)
sz = sz - (ptr - sav);
sc->en_nrx = sz / (EN_RXSZ * 1024);
if (sc->en_nrx <= 0) {
- if_printf(&sc->ifatm.ifnet, "EN_NTX/EN_TXSZ/EN_RXSZ too big\n");
+ if_printf(sc->ifp, "EN_NTX/EN_TXSZ/EN_RXSZ too big\n");
goto fail;
}
@@ -3010,10 +3011,10 @@ en_attach(struct en_softc *sc)
sc->rxslot[lcv].mode));
}
- if_printf(&sc->ifatm.ifnet, "%d %dKB receive buffers, %d %dKB transmit "
+ if_printf(sc->ifp, "%d %dKB receive buffers, %d %dKB transmit "
"buffers\n", sc->en_nrx, EN_RXSZ, EN_NTX, EN_TXSZ);
- if_printf(&sc->ifatm.ifnet, "end station identifier (mac address) "
- "%6D\n", sc->ifatm.mib.esi, ":");
+ if_printf(sc->ifp, "end station identifier (mac address) "
+ "%6D\n", IFP2IFATM(sc->ifp)->mib.esi, ":");
/*
* Start SUNI stuff. This will call our readregs/writeregs
@@ -3302,7 +3303,7 @@ en_dump(int unit, int level)
if (unit != -1 && unit != lcv)
continue;
- if_printf(&sc->ifatm.ifnet, "dumping device at level 0x%b\n",
+ if_printf(sc->ifp, "dumping device at level 0x%b\n",
level, END_BITS);
if (sc->dtq_us == 0) {
diff --git a/sys/dev/en/midwayvar.h b/sys/dev/en/midwayvar.h
index 27e047d..8c2a8c5 100644
--- a/sys/dev/en/midwayvar.h
+++ b/sys/dev/en/midwayvar.h
@@ -153,8 +153,7 @@ struct en_vcc {
* softc
*/
struct en_softc {
- /* bsd glue */
- struct ifatm ifatm; /* ATM network ifnet handle */
+ struct ifnet *ifp;
device_t dev;
/* bus glue */
OpenPOWER on IntegriCloud