summaryrefslogtreecommitdiffstats
path: root/sys/dev/tx
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/tx
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/tx')
-rw-r--r--sys/dev/tx/if_tx.c61
-rw-r--r--sys/dev/tx/if_txvar.h5
2 files changed, 36 insertions, 30 deletions
diff --git a/sys/dev/tx/if_tx.c b/sys/dev/tx/if_tx.c
index 18fe63f..f059887 100644
--- a/sys/dev/tx/if_tx.c
+++ b/sys/dev/tx/if_tx.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
+#include <net/if_types.h>
#include <net/bpf.h>
@@ -224,6 +225,7 @@ epic_attach(dev)
epic_softc_t *sc;
int unit, error;
int i, s, rid, tmp;
+ u_char eaddr[6];
s = splimp();
@@ -235,7 +237,12 @@ epic_attach(dev)
sc->dev = dev;
/* Fill ifnet structure. */
- ifp = &sc->sc_if;
+ ifp = sc->ifp = if_alloc(IFT_ETHER);
+ if (ifp == NULL) {
+ device_printf(dev, "can not if_alloc()\n");
+ error = ENOSPC;
+ goto fail;
+ }
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST|IFF_NEEDSGIANT;
@@ -361,7 +368,7 @@ epic_attach(dev)
/* Read MAC address from EEPROM. */
for (i = 0; i < ETHER_ADDR_LEN / sizeof(u_int16_t); i++)
- ((u_int16_t *)sc->sc_macaddr)[i] = epic_read_eeprom(sc,i);
+ ((u_int16_t *)eaddr)[i] = epic_read_eeprom(sc,i);
/* Set Non-Volatile Control Register from EEPROM. */
CSR_WRITE_4(sc, NVCTL, epic_read_eeprom(sc, EEPROM_NVCTL) & 0x1F);
@@ -423,7 +430,7 @@ epic_attach(dev)
}
/* Attach to OS's managers. */
- ether_ifattach(ifp, sc->sc_macaddr);
+ ether_ifattach(ifp, eaddr);
splx(s);
return (0);
@@ -440,6 +447,8 @@ static void
epic_release(epic_softc_t *sc)
{
+ if (sc->ifp != NULL)
+ if_free(sc->ifp);
if (sc->irq)
bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq);
if (sc->res)
@@ -484,7 +493,7 @@ epic_detach(dev)
s = splimp();
sc = device_get_softc(dev);
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->ifp;
ether_ifdetach(ifp);
@@ -720,7 +729,7 @@ static void
epic_rx_done(sc)
epic_softc_t *sc;
{
- struct ifnet *ifp = &sc->sc_if;
+ struct ifnet *ifp = sc->ifp;
u_int16_t len;
struct epic_rx_buffer *buf;
struct epic_rx_desc *desc;
@@ -831,10 +840,10 @@ epic_tx_done(sc)
/* Check for errors and collisions. */
if (status & 0x0001)
- sc->sc_if.if_opackets++;
+ sc->ifp->if_opackets++;
else
- sc->sc_if.if_oerrors++;
- sc->sc_if.if_collisions += (status >> 8) & 0x1F;
+ sc->ifp->if_oerrors++;
+ sc->ifp->if_collisions += (status >> 8) & 0x1F;
#ifdef EPIC_DIAG
if ((status & 0x1001) == 0x1001)
device_printf(sc->dev,
@@ -843,7 +852,7 @@ epic_tx_done(sc)
}
if (sc->pending_txs < TX_RING_SIZE)
- sc->sc_if.if_flags &= ~IFF_OACTIVE;
+ sc->ifp->if_flags &= ~IFF_OACTIVE;
bus_dmamap_sync(sc->ttag, sc->tmap,
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
}
@@ -874,14 +883,14 @@ epic_intr(arg)
#endif
if ((CSR_READ_4(sc, COMMAND) & COMMAND_RXQUEUED) == 0)
CSR_WRITE_4(sc, COMMAND, COMMAND_RXQUEUED);
- sc->sc_if.if_ierrors++;
+ sc->ifp->if_ierrors++;
}
}
if (status & (INTSTAT_TXC|INTSTAT_TCC|INTSTAT_TQE)) {
epic_tx_done(sc);
- if (sc->sc_if.if_snd.ifq_head != NULL)
- epic_ifstart(&sc->sc_if);
+ if (sc->ifp->if_snd.ifq_head != NULL)
+ epic_ifstart(sc->ifp);
}
/* Check for rare errors */
@@ -904,19 +913,19 @@ epic_intr(arg)
#ifdef EPIC_DIAG
device_printf(sc->dev, "CRC/Alignment error\n");
#endif
- sc->sc_if.if_ierrors++;
+ sc->ifp->if_ierrors++;
}
if (status & INTSTAT_TXU) {
epic_tx_underrun(sc);
- sc->sc_if.if_oerrors++;
+ sc->ifp->if_oerrors++;
}
}
}
/* If no packets are pending, then no timeouts. */
if (sc->pending_txs == 0)
- sc->sc_if.if_timer = 0;
+ sc->ifp->if_timer = 0;
}
/*
@@ -1205,9 +1214,9 @@ epic_miibus_statchg(dev)
/* Update baudrate. */
if (IFM_SUBTYPE(media) == IFM_100_TX ||
IFM_SUBTYPE(media) == IFM_100_FX)
- sc->sc_if.if_baudrate = 100000000;
+ sc->ifp->if_baudrate = 100000000;
else
- sc->sc_if.if_baudrate = 10000000;
+ sc->ifp->if_baudrate = 10000000;
epic_stop_activity(sc);
epic_set_tx_mode(sc);
@@ -1252,7 +1261,7 @@ epic_init(xsc)
void *xsc;
{
epic_softc_t *sc = xsc;
- struct ifnet *ifp = &sc->sc_if;
+ struct ifnet *ifp = sc->ifp;
int s, i;
s = splimp();
@@ -1285,9 +1294,9 @@ epic_init(xsc)
CSR_WRITE_4(sc, PTCDAR, sc->tx_addr);
/* Put node address to EPIC. */
- CSR_WRITE_4(sc, LAN0, ((u_int16_t *)sc->sc_macaddr)[0]);
- CSR_WRITE_4(sc, LAN1, ((u_int16_t *)sc->sc_macaddr)[1]);
- CSR_WRITE_4(sc, LAN2, ((u_int16_t *)sc->sc_macaddr)[2]);
+ CSR_WRITE_4(sc, LAN0, ((u_int16_t *)IFP2ENADDR(sc->ifp))[0]);
+ CSR_WRITE_4(sc, LAN1, ((u_int16_t *)IFP2ENADDR(sc->ifp))[1]);
+ CSR_WRITE_4(sc, LAN2, ((u_int16_t *)IFP2ENADDR(sc->ifp))[2]);
/* Set tx mode, includeing transmit threshold. */
epic_set_tx_mode(sc);
@@ -1343,7 +1352,7 @@ epic_set_rx_mode(sc)
u_int32_t flags;
u_int32_t rxcon;
- flags = sc->sc_if.if_flags;
+ flags = sc->ifp->if_flags;
rxcon = RXCON_DEFAULT;
#ifdef EPIC_EARLY_RX
@@ -1386,7 +1395,7 @@ epic_set_mc_table(sc)
u_int16_t filter[4];
u_int8_t h;
- ifp = &sc->sc_if;
+ ifp = sc->ifp;
if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) {
CSR_WRITE_4(sc, MC0, 0xFFFF);
CSR_WRITE_4(sc, MC1, 0xFFFF);
@@ -1508,7 +1517,7 @@ epic_queue_last_packet(sc)
/* Prepare mbuf. */
m0->m_len = min(MHLEN, ETHER_MIN_LEN - ETHER_CRC_LEN);
m0->m_pkthdr.len = m0->m_len;
- m0->m_pkthdr.rcvif = &sc->sc_if;
+ m0->m_pkthdr.rcvif = sc->ifp;
bzero(mtod(m0, caddr_t), m0->m_len);
/* Fill fragments list. */
@@ -1560,7 +1569,7 @@ epic_stop(sc)
s = splimp();
- sc->sc_if.if_timer = 0;
+ sc->ifp->if_timer = 0;
untimeout((timeout_t *)epic_stats_update, sc, sc->stat_ch);
@@ -1579,7 +1588,7 @@ epic_stop(sc)
CSR_WRITE_4(sc, GENCTL, GENCTL_POWER_DOWN);
/* Mark as stoped */
- sc->sc_if.if_flags &= ~IFF_RUNNING;
+ sc->ifp->if_flags &= ~IFF_RUNNING;
splx(s);
}
diff --git a/sys/dev/tx/if_txvar.h b/sys/dev/tx/if_txvar.h
index 1277244..a1322c9 100644
--- a/sys/dev/tx/if_txvar.h
+++ b/sys/dev/tx/if_txvar.h
@@ -70,7 +70,7 @@ struct epic_tx_buffer {
/* Driver status structure */
typedef struct {
- struct arpcom arpcom;
+ struct ifnet *ifp;
struct resource *res;
struct resource *irq;
@@ -124,9 +124,6 @@ struct epic_type {
char *name;
};
-#define sc_if arpcom.ac_if
-#define sc_macaddr arpcom.ac_enaddr
-
#define CSR_WRITE_4(sc, reg, val) \
bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
#define CSR_WRITE_2(sc, reg, val) \
OpenPOWER on IntegriCloud