Autoconfiguration cleanup for eca(4):

- Use device_t and cfdata_t.
- Split device_t out of eca_softc.
- Use aprint_*() rather than printf().
- Use device_xname().
This commit is contained in:
bjh21 2009-01-19 23:43:14 +00:00
parent 804a5a414b
commit 0d3e94c475
2 changed files with 27 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_eca.c,v 1.10 2009/01/07 20:56:40 bjh21 Exp $ */
/* $NetBSD: if_eca.c,v 1.11 2009/01/19 23:43:14 bjh21 Exp $ */
/*-
* Copyright (c) 2001 Ben Harris
@ -29,7 +29,7 @@
#include <sys/param.h>
__KERNEL_RCSID(0, "$NetBSD: if_eca.c,v 1.10 2009/01/07 20:56:40 bjh21 Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_eca.c,v 1.11 2009/01/19 23:43:14 bjh21 Exp $");
#include <sys/device.h>
#include <sys/malloc.h>
@ -51,8 +51,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_eca.c,v 1.10 2009/01/07 20:56:40 bjh21 Exp $");
#include <dev/ic/mc6854reg.h>
#include <arch/acorn26/ioc/if_ecavar.h>
static int eca_match(struct device *, struct cfdata *, void *);
static void eca_attach(struct device *, struct device *, void *);
static int eca_match(device_t, cfdata_t, void *);
static void eca_attach(device_t, device_t, void *);
static int eca_init(struct ifnet *);
static void eca_stop(struct ifnet *ifp, int disable);
@ -73,11 +73,11 @@ static void eca_gotframe(void *);
struct eca_softc *eca_fiqowner;
CFATTACH_DECL(eca, sizeof(struct eca_softc),
CFATTACH_DECL_NEW(eca, sizeof(struct eca_softc),
eca_match, eca_attach, NULL, NULL);
static int
eca_match(struct device *parent, struct cfdata *cf, void *aux)
eca_match(device_t parent, cfdata_t cf, void *aux)
{
struct ioc_attach_args *ioc = aux;
@ -90,20 +90,21 @@ eca_match(struct device *parent, struct cfdata *cf, void *aux)
}
static void
eca_attach(struct device *parent, struct device *self, void *aux)
eca_attach(device_t parent, device_t self, void *aux)
{
struct eca_softc *sc = (void *)self;
struct eca_softc *sc = device_private(self);
struct ioc_attach_args *ioc = aux;
struct ifnet *ifp = &sc->sc_ec.ec_if;
u_int8_t myaddr[ECO_ADDR_LEN];
sc->sc_dev = self;
sc->sc_iot = ioc->ioc_sync_t;
sc->sc_ioh = ioc->ioc_sync_h;
myaddr[0] = cmos_read(0x40);
myaddr[1] = 0;
printf(": station %s", eco_sprintf(myaddr));
aprint_normal(": station %s", eco_sprintf(myaddr));
/* It's traditional to print the clock state at boot. */
if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, MC6854_SR2) &
MC6854_SR2_NDCD))
@ -111,7 +112,7 @@ eca_attach(struct device *parent, struct device *self, void *aux)
/* Initialise ifnet structure. */
strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
strcpy(ifp->if_xname, device_xname(sc->sc_dev));
ifp->if_softc = sc;
ifp->if_init = eca_init;
ifp->if_stop = eca_stop;
@ -123,8 +124,8 @@ eca_attach(struct device *parent, struct device *self, void *aux)
sc->sc_rx_soft = softint_establish(IPL_SOFTNET, eca_gotframe, sc);
sc->sc_tx_soft = softint_establish(IPL_SOFTNET, eca_txdone, sc);
if (sc->sc_rx_soft == NULL || sc->sc_tx_soft == NULL) {
printf("\n%s: failed to establish software interrupt\n",
sc->sc_dev.dv_xname);
aprint_error_dev(sc->sc_dev,
"failed to establish software interrupt\n");
return;
}
@ -136,7 +137,7 @@ eca_attach(struct device *parent, struct device *self, void *aux)
sc->sc_fiqhandler.fh_flags = 0;
sc->sc_fiqhandler.fh_regs = &sc->sc_fiqstate.efs_rx_fiqregs;
printf("\n");
aprint_normal("\n");
}
static int
@ -265,16 +266,17 @@ eca_tx_downgrade(void)
} else {
sr1 = bus_space_read_1(iot, ioh, MC6854_SR1);
if (sr1 & MC6854_SR1_TXU)
log(LOG_ERR, "%s: Tx underrun\n", sc->sc_dev.dv_xname);
log(LOG_ERR, "%s: Tx underrun\n",
device_xname(sc->sc_dev));
else if (sr1 & MC6854_SR1_NCTS)
log(LOG_WARNING, "%s: collision\n",
sc->sc_dev.dv_xname);
device_xname(sc->sc_dev));
else {
log(LOG_ERR, "%s: incomplete transmission\n",
sc->sc_dev.dv_xname);
device_xname(sc->sc_dev));
snprintb(buf, 128, MC6854_SR1_BITS, sr1);
log(LOG_ERR, "%s: SR1 = %s\n",
sc->sc_dev.dv_xname, buf);
device_xname(sc->sc_dev), buf);
}
bus_space_write_1(iot, ioh, MC6854_CR2,
sc->sc_cr2 | MC6854_CR2_CLR_TX_ST);
@ -492,7 +494,7 @@ eca_gotframe(void *arg)
fiq_getregs(&fr);
mtail = sc->sc_fiqstate.efs_rx_curmbuf;
log(LOG_ERR, "%s: Rx overrun (state = %d, len = %ld)\n",
sc->sc_dev.dv_xname, sc->sc_ec.ec_state,
device_xname(sc->sc_dev), sc->sc_ec.ec_state,
(char *)(fr.fr_r9) - mtod(mtail, char *));
ifp->if_ierrors++;
@ -501,19 +503,20 @@ eca_gotframe(void *arg)
bus_space_write_1(iot, ioh, MC6854_CR1,
sc->sc_cr1 | MC6854_CR1_DISCONTINUE);
} else if (sr2 & MC6854_SR2_RXABT) {
log(LOG_NOTICE, "%s: Rx abort\n", sc->sc_dev.dv_xname);
log(LOG_NOTICE, "%s: Rx abort\n", device_xname(sc->sc_dev));
ifp->if_ierrors++;
} else if (sr2 & MC6854_SR2_ERR) {
log(LOG_NOTICE, "%s: CRC error\n", sc->sc_dev.dv_xname);
log(LOG_NOTICE, "%s: CRC error\n", device_xname(sc->sc_dev));
ifp->if_ierrors++;
}
if (__predict_false(sr2 & MC6854_SR2_NDCD)) {
log(LOG_ERR, "%s: No clock\n", sc->sc_dev.dv_xname);
log(LOG_ERR, "%s: No clock\n", device_xname(sc->sc_dev));
ifp->if_ierrors++;
}
if (sc->sc_fiqstate.efs_rx_curmbuf == NULL) {
log(LOG_NOTICE, "%s: Oversized frame\n", sc->sc_dev.dv_xname);
log(LOG_NOTICE, "%s: Oversized frame\n",
device_xname(sc->sc_dev));
ifp->if_ierrors++;
/* Discard the rest of the frame. */
if (!sc->sc_transmitting)

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ecavar.h,v 1.1 2002/03/24 15:47:16 bjh21 Exp $ */
/* $NetBSD: if_ecavar.h,v 1.2 2009/01/19 23:43:14 bjh21 Exp $ */
/*-
* Copyright (c) 2001 Ben Harris
@ -52,7 +52,7 @@ struct eca_fiqstate {
};
struct eca_softc {
struct device sc_dev;
device_t sc_dev;
struct ecocom sc_ec;
u_int8_t sc_cr1;
u_int8_t sc_cr2;