Module Name: src Committed By: tsutsui Date: Sun May 17 00:40:44 UTC 2009
Modified Files: src/sys/dev/ic: hme.c hmevar.h src/sys/dev/pci: if_hme_pci.c src/sys/dev/sbus: if_hme_sbus.c Log Message: Split device_t/softc. Tested PCI HME on i386. Sbus HME is compile test only. To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 src/sys/dev/ic/hme.c cvs rdiff -u -r1.18 -r1.19 src/sys/dev/ic/hmevar.h cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/if_hme_pci.c cvs rdiff -u -r1.29 -r1.30 src/sys/dev/sbus/if_hme_sbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/hme.c diff -u src/sys/dev/ic/hme.c:1.78 src/sys/dev/ic/hme.c:1.79 --- src/sys/dev/ic/hme.c:1.78 Tue May 12 14:25:17 2009 +++ src/sys/dev/ic/hme.c Sun May 17 00:40:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hme.c,v 1.78 2009/05/12 14:25:17 cegger Exp $ */ +/* $NetBSD: hme.c,v 1.79 2009/05/17 00:40:43 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.78 2009/05/12 14:25:17 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.79 2009/05/17 00:40:43 tsutsui Exp $"); /* #define HMEDEBUG */ @@ -196,7 +196,7 @@ if ((error = bus_dmamem_alloc(dmatag, size, 2048, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) { - aprint_error_dev(&sc->sc_dev, "DMA buffer alloc error %d\n", + aprint_error_dev(sc->sc_dev, "DMA buffer alloc error %d\n", error); return; } @@ -205,7 +205,7 @@ if ((error = bus_dmamem_map(dmatag, &seg, rseg, size, &sc->sc_rb.rb_membase, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) { - aprint_error_dev(&sc->sc_dev, "DMA buffer map error %d\n", + aprint_error_dev(sc->sc_dev, "DMA buffer map error %d\n", error); bus_dmamap_unload(dmatag, sc->sc_dmamap); bus_dmamem_free(dmatag, &seg, rseg); @@ -214,7 +214,7 @@ if ((error = bus_dmamap_create(dmatag, size, 1, size, 0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) { - aprint_error_dev(&sc->sc_dev, "DMA map create error %d\n", + aprint_error_dev(sc->sc_dev, "DMA map create error %d\n", error); return; } @@ -223,18 +223,18 @@ if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap, sc->sc_rb.rb_membase, size, NULL, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) { - aprint_error_dev(&sc->sc_dev, "DMA buffer map load error %d\n", + aprint_error_dev(sc->sc_dev, "DMA buffer map load error %d\n", error); bus_dmamem_free(dmatag, &seg, rseg); return; } sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr; - printf("%s: Ethernet address %s\n", device_xname(&sc->sc_dev), + aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n", ether_sprintf(sc->sc_enaddr)); /* Initialize ifnet structure. */ - strlcpy(ifp->if_xname, device_xname(&sc->sc_dev), IFNAMSIZ); + strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); ifp->if_softc = sc; ifp->if_start = hme_start; ifp->if_ioctl = hme_ioctl; @@ -263,9 +263,9 @@ * the RJ45 (internal) PHY first, so that the MII PHY is always * instance 1. */ - mii_attach(&sc->sc_dev, mii, 0xffffffff, + mii_attach(sc->sc_dev, mii, 0xffffffff, HME_PHYAD_INTERNAL, MII_OFFSET_ANY, MIIF_FORCEANEG); - mii_attach(&sc->sc_dev, mii, 0xffffffff, + mii_attach(sc->sc_dev, mii, 0xffffffff, HME_PHYAD_EXTERNAL, MII_OFFSET_ANY, MIIF_FORCEANEG); child = LIST_FIRST(&mii->mii_phys); @@ -288,7 +288,8 @@ * connector. */ if (child->mii_phy > 1 || child->mii_inst > 1) { - aprint_error_dev(&sc->sc_dev, "cannot accommodate MII device %s" + aprint_error_dev(sc->sc_dev, + "cannot accommodate MII device %s" " at phy %d, instance %d\n", device_xname(child->mii_dev), child->mii_phy, child->mii_inst); @@ -323,7 +324,7 @@ panic("hme_config: can't establish shutdownhook"); #if NRND > 0 - rnd_attach_source(&sc->rnd_source, device_xname(&sc->sc_dev), + rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev), RND_TYPE_NET, 0); #endif @@ -379,7 +380,7 @@ DELAY(20); } - printf("%s: hme_stop: reset failed\n", device_xname(&sc->sc_dev)); + printf("%s: hme_stop: reset failed\n", device_xname(sc->sc_dev)); } void @@ -862,7 +863,7 @@ ETHERMTU + sizeof(struct ether_header))) { #ifdef HMEDEBUG printf("%s: invalid packet size %d; dropping\n", - device_xname(&sc->sc_dev), len); + device_xname(sc->sc_dev), len); #endif ifp->if_ierrors++; return; @@ -893,7 +894,7 @@ void hme_start(struct ifnet *ifp) { - struct hme_softc *sc = (struct hme_softc *)ifp->if_softc; + struct hme_softc *sc = ifp->if_softc; void *txd = sc->sc_rb.rb_txd; struct mbuf *m; unsigned int txflags; @@ -1064,7 +1065,7 @@ if (flags & HME_XD_OFL) { printf("%s: buffer overflow, ri=%d; flags=0x%x\n", - device_xname(&sc->sc_dev), ri, flags); + device_xname(sc->sc_dev), ri, flags); } else hme_read(sc, ri, flags); @@ -1107,7 +1108,7 @@ st = bus_space_read_4(t, mif, HME_MIFI_STAT); sm = bus_space_read_4(t, mif, HME_MIFI_SM); printf("%s: XXXlink status changed: cfg=%x, stat %x, sm %x\n", - device_xname(&sc->sc_dev), cf, st, sm); + device_xname(sc->sc_dev), cf, st, sm); return (1); } @@ -1126,7 +1127,7 @@ hme_reset(sc); snprintb(bits, sizeof(bits), HME_SEB_STAT_BITS, status); - printf("%s: status=%s\n", device_xname(&sc->sc_dev), bits); + printf("%s: status=%s\n", device_xname(sc->sc_dev), bits); return (1); } @@ -1134,7 +1135,7 @@ int hme_intr(void *v) { - struct hme_softc *sc = (struct hme_softc *)v; + struct hme_softc *sc = v; bus_space_tag_t t = sc->sc_bustag; bus_space_handle_t seb = sc->sc_seb; uint32_t status; @@ -1164,7 +1165,7 @@ { struct hme_softc *sc = ifp->if_softc; - log(LOG_ERR, "%s: device timeout\n", device_xname(&sc->sc_dev)); + log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev)); ++ifp->if_oerrors; hme_reset(sc); @@ -1209,7 +1210,7 @@ static int hme_mii_readreg(device_t self, int phy, int reg) { - struct hme_softc *sc = (void *)self; + struct hme_softc *sc = device_private(self); bus_space_tag_t t = sc->sc_bustag; bus_space_handle_t mif = sc->sc_mif; bus_space_handle_t mac = sc->sc_mac; @@ -1267,7 +1268,7 @@ } v = 0; - printf("%s: mii_read timeout\n", device_xname(&sc->sc_dev)); + printf("%s: mii_read timeout\n", device_xname(sc->sc_dev)); out: /* Restore MIFI_CFG register */ @@ -1280,7 +1281,7 @@ static void hme_mii_writereg(device_t self, int phy, int reg, int val) { - struct hme_softc *sc = (void *)self; + struct hme_softc *sc = device_private(self); bus_space_tag_t t = sc->sc_bustag; bus_space_handle_t mif = sc->sc_mif; bus_space_handle_t mac = sc->sc_mac; @@ -1336,7 +1337,7 @@ goto out; } - printf("%s: mii_write timeout\n", device_xname(&sc->sc_dev)); + printf("%s: mii_write timeout\n", device_xname(sc->sc_dev)); out: /* Restore MIFI_CFG register */ bus_space_write_4(t, mif, HME_MIFI_CFG, mifi_cfg); @@ -1347,7 +1348,7 @@ static void hme_mii_statchg(device_t dev) { - struct hme_softc *sc = (void *)dev; + struct hme_softc *sc = device_private(dev); bus_space_tag_t t = sc->sc_bustag; bus_space_handle_t mac = sc->sc_mac; uint32_t v; @@ -1520,8 +1521,10 @@ void hme_shutdown(void *arg) { + struct hme_softc *sc; - hme_stop((struct hme_softc *)arg, false); + sc = arg; + hme_stop(sc, false); } /* Index: src/sys/dev/ic/hmevar.h diff -u src/sys/dev/ic/hmevar.h:1.18 src/sys/dev/ic/hmevar.h:1.19 --- src/sys/dev/ic/hmevar.h:1.18 Thu Apr 16 14:08:18 2009 +++ src/sys/dev/ic/hmevar.h Sun May 17 00:40:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hmevar.h,v 1.18 2009/04/16 14:08:18 tsutsui Exp $ */ +/* $NetBSD: hmevar.h,v 1.19 2009/05/17 00:40:43 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ }; struct hme_softc { - struct device sc_dev; /* boilerplate device view */ + device_t sc_dev; /* boilerplate device view */ struct ethercom sc_ethercom; /* Ethernet common part */ struct mii_data sc_mii; /* MII media control */ struct callout sc_tick_ch; /* tick callout */ Index: src/sys/dev/pci/if_hme_pci.c diff -u src/sys/dev/pci/if_hme_pci.c:1.28 src/sys/dev/pci/if_hme_pci.c:1.29 --- src/sys/dev/pci/if_hme_pci.c:1.28 Tue May 12 08:23:00 2009 +++ src/sys/dev/pci/if_hme_pci.c Sun May 17 00:40:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: if_hme_pci.c,v 1.28 2009/05/12 08:23:00 cegger Exp $ */ +/* $NetBSD: if_hme_pci.c,v 1.29 2009/05/17 00:40:43 tsutsui Exp $ */ /* * Copyright (c) 2000 Matthew R. Green @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_hme_pci.c,v 1.28 2009/05/12 08:23:00 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_hme_pci.c,v 1.29 2009/05/17 00:40:43 tsutsui Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -77,7 +77,7 @@ int hmematch_pci(device_t, cfdata_t, void *); void hmeattach_pci(device_t, device_t, void *); -CFATTACH_DECL(hme_pci, sizeof(struct hme_pci_softc), +CFATTACH_DECL_NEW(hme_pci, sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci, NULL, NULL); int @@ -152,7 +152,9 @@ #define PROMDATA_DATA2 0x0a #endif /* HME_USE_LOCAL_MAC_ADDRESS */ - printf(": Sun Happy Meal Ethernet, rev. %d\n", + sc->sc_dev = self; + + aprint_normal(": Sun Happy Meal Ethernet, rev. %d\n", PCI_REVISION(pa->pa_class)); /* @@ -192,30 +194,29 @@ #define PCI_HME_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0, - &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0) - { - aprint_error_dev(&sc->sc_dev, "unable to map device registers\n"); + &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0) { + aprint_error_dev(self, "unable to map device registers\n"); return; } sc->sc_seb = hsc->hsc_memh; if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x2000, 0x1000, &sc->sc_etx)) { - aprint_error_dev(&sc->sc_dev, "unable to subregion ETX registers\n"); + aprint_error_dev(self, "unable to subregion ETX registers\n"); return; } if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x4000, 0x1000, &sc->sc_erx)) { - aprint_error_dev(&sc->sc_dev, "unable to subregion ERX registers\n"); + aprint_error_dev(self, "unable to subregion ERX registers\n"); return; } if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x6000, 0x1000, &sc->sc_mac)) { - aprint_error_dev(&sc->sc_dev, "unable to subregion MAC registers\n"); + aprint_error_dev(self, "unable to subregion MAC registers\n"); return; } if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x7000, 0x1000, &sc->sc_mif)) { - aprint_error_dev(&sc->sc_dev, "unable to subregion MIF registers\n"); + aprint_error_dev(self, "unable to subregion MIF registers\n"); return; } @@ -297,26 +298,26 @@ #ifdef __sparc__ prom_getether(PCITAG_NODE(pa->pa_tag), sc->sc_enaddr); #else - printf("%s: no Ethernet address found\n", device_xname(&sc->sc_dev)); + printf("%s: no Ethernet address found\n", device_xname(self)); #endif /* * Map and establish our interrupt. */ if (pci_intr_map(pa, &ih) != 0) { - aprint_error_dev(&sc->sc_dev, "unable to map interrupt\n"); + aprint_error_dev(self, "unable to map interrupt\n"); return; } intrstr = pci_intr_string(pa->pa_pc, ih); hsc->hsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, hme_intr, sc); if (hsc->hsc_ih == NULL) { - aprint_error_dev(&sc->sc_dev, "unable to establish interrupt"); + aprint_error_dev(self, "unable to establish interrupt"); if (intrstr != NULL) - printf(" at %s", intrstr); - printf("\n"); + aprint_error(" at %s", intrstr); + aprint_error("\n"); return; } - printf("%s: interrupting at %s\n", device_xname(&sc->sc_dev), intrstr); + aprint_normal_dev(self, "interrupting at %s\n", intrstr); sc->sc_burst = 16; /* XXX */ Index: src/sys/dev/sbus/if_hme_sbus.c diff -u src/sys/dev/sbus/if_hme_sbus.c:1.29 src/sys/dev/sbus/if_hme_sbus.c:1.30 --- src/sys/dev/sbus/if_hme_sbus.c:1.29 Sun May 17 00:28:35 2009 +++ src/sys/dev/sbus/if_hme_sbus.c Sun May 17 00:40:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: if_hme_sbus.c,v 1.29 2009/05/17 00:28:35 tsutsui Exp $ */ +/* $NetBSD: if_hme_sbus.c,v 1.30 2009/05/17 00:40:44 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.29 2009/05/17 00:28:35 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.30 2009/05/17 00:40:44 tsutsui Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -66,7 +66,7 @@ int hmematch_sbus(device_t, cfdata_t, void *); void hmeattach_sbus(device_t, device_t, void *); -CFATTACH_DECL(hme_sbus, sizeof(struct hmesbus_softc), +CFATTACH_DECL_NEW(hme_sbus, sizeof(struct hmesbus_softc), hmematch_sbus, hmeattach_sbus, NULL, NULL); int @@ -83,25 +83,26 @@ hmeattach_sbus(device_t parent, device_t self, void *aux) { struct sbus_attach_args *sa = aux; - struct hmesbus_softc *hsc = (void *)self; + struct hmesbus_softc *hsc = device_private(self); struct hme_softc *sc = &hsc->hsc_hme; struct sbus_softc *sbsc = device_private(parent); struct sbusdev *sd = &hsc->hsc_sbus; u_int32_t burst, sbusburst; int node; + sc->sc_dev = self; node = sa->sa_node; /* Pass on the bus tags */ sc->sc_bustag = sa->sa_bustag; sc->sc_dmatag = sa->sa_dmatag; - printf(": Sun Happy Meal Ethernet (%s)\n", + aprint_normal(": Sun Happy Meal Ethernet (%s)\n", sa->sa_name); if (sa->sa_nreg < 5) { - printf("%s: only %d register sets\n", - device_xname(self), sa->sa_nreg); + aprint_error_dev(self, "only %d register sets\n", + sa->sa_nreg); return; }