From a2592955809f1fca98f297d12dc50eeec479354c Mon Sep 17 00:00:00 2001 From: jsg Date: Sun, 26 Jun 2016 09:06:35 +0000 Subject: [PATCH] Dynamically attach cpsw(4) with the FDT. --- share/man/man4/man4.armv7/cpsw.4 | 6 +-- sys/arch/armv7/conf/GENERIC | 4 +- sys/arch/armv7/conf/RAMDISK | 4 +- sys/arch/armv7/omap/files.omap | 4 +- sys/arch/armv7/omap/if_cpsw.c | 65 +++++++++++++++++++++++--------- sys/arch/armv7/omap/omap.c | 3 +- 6 files changed, 58 insertions(+), 28 deletions(-) diff --git a/share/man/man4/man4.armv7/cpsw.4 b/share/man/man4/man4.armv7/cpsw.4 index 8512a42f01b..00d6b7f0fe1 100644 --- a/share/man/man4/man4.armv7/cpsw.4 +++ b/share/man/man4/man4.armv7/cpsw.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cpsw.4,v 1.2 2014/04/08 01:18:19 brad Exp $ +.\" $OpenBSD: cpsw.4,v 1.3 2016/06/26 09:06:35 jsg Exp $ .\" Copyright (c) 2013 Brandon Mercer .\" .\" Permission to use, copy, modify, and distribute this software for any @@ -13,14 +13,14 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 8 2014 $ +.Dd $Mdocdate: June 26 2016 $ .Dt CPSW 4 armv7 .Os .Sh NAME .Nm cpsw .Nd Texas Instruments CPSW Ethernet device .Sh SYNOPSIS -.Cd "cpsw* at omap?" +.Cd "cpsw* at fdt?" .Sh DESCRIPTION The .Nm diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC index cb1e5b7c091..70b02284b00 100644 --- a/sys/arch/armv7/conf/GENERIC +++ b/sys/arch/armv7/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.25 2016/06/26 07:25:05 jsg Exp $ +# $OpenBSD: GENERIC,v 1.26 2016/06/26 09:06:35 jsg Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -72,7 +72,7 @@ iic* at tiiic? gptimer* at omap? # general purpose timers dmtimer* at omap? # am335x dual mode timers omusbtll* at omap? -cpsw* at omap? +cpsw* at fdt? com* at fdt? # onboard uarts ommmc* at fdt? # SD/MMC card controller sdmmc* at ommmc? # SD/MMC bus diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK index b272214fdf5..5bcdf34aa0e 100644 --- a/sys/arch/armv7/conf/RAMDISK +++ b/sys/arch/armv7/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.22 2016/06/26 07:25:05 jsg Exp $ +# $OpenBSD: RAMDISK,v 1.23 2016/06/26 09:06:35 jsg Exp $ machine armv7 arm @@ -71,7 +71,7 @@ iic* at tiiic? gptimer* at omap? # general purpose timers dmtimer* at omap? # am335x dual mode timers omusbtll* at omap? -cpsw* at omap? +cpsw* at fdt? com* at fdt? # onboard uarts ommmc* at fdt? # SD/MMC card controller sdmmc* at ommmc? # SD/MMC bus diff --git a/sys/arch/armv7/omap/files.omap b/sys/arch/armv7/omap/files.omap index 9a2c4640099..9567097aff2 100644 --- a/sys/arch/armv7/omap/files.omap +++ b/sys/arch/armv7/omap/files.omap @@ -1,4 +1,4 @@ -# $OpenBSD: files.omap,v 1.12 2016/06/26 07:25:05 jsg Exp $ +# $OpenBSD: files.omap,v 1.13 2016/06/26 09:06:35 jsg Exp $ define omap {} device omap: omap @@ -14,7 +14,7 @@ attach ommmc at fdt file arch/armv7/omap/ommmc.c ommmc device cpsw: ether, ifnet, mii, ifmedia -attach cpsw at omap +attach cpsw at fdt file arch/armv7/omap/if_cpsw.c cpsw device prcm diff --git a/sys/arch/armv7/omap/if_cpsw.c b/sys/arch/armv7/omap/if_cpsw.c index ad47506f092..fd5c575af9e 100644 --- a/sys/arch/armv7/omap/if_cpsw.c +++ b/sys/arch/armv7/omap/if_cpsw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cpsw.c,v 1.34 2016/04/13 11:33:59 mpi Exp $ */ +/* $OpenBSD: if_cpsw.c,v 1.35 2016/06/26 09:06:35 jsg Exp $ */ /* $NetBSD: if_cpsw.c,v 1.3 2013/04/17 14:36:34 bouyer Exp $ */ /* @@ -67,6 +67,7 @@ #include #include +#include #include #include @@ -85,6 +86,8 @@ #include #include +#include + #define CPSW_TXFRAGS 16 #define OMAP2SCM_MAC_ID0_LO 0x630 @@ -153,6 +156,7 @@ struct cpsw_softc { #define DEVNAME(_sc) ((_sc)->sc_dev.dv_xname) +int cpsw_match(struct device *, void *, void *); void cpsw_attach(struct device *, struct device *, void *); void cpsw_start(struct ifnet *); @@ -180,7 +184,7 @@ void cpsw_get_mac_addr(struct cpsw_softc *); struct cfattach cpsw_ca = { sizeof(struct cpsw_softc), - NULL, + cpsw_match, cpsw_attach }; @@ -326,41 +330,68 @@ cpsw_mdio_init(struct cpsw_softc *sc) sc->sc_active_port); } +int +cpsw_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "ti,cpsw"); +} + void cpsw_attach(struct device *parent, struct device *self, void *aux) { struct cpsw_softc *sc = (struct cpsw_softc *)self; - struct armv7_attach_args *aa = aux; + struct fdt_attach_args *faa = aux; struct arpcom * const ac = &sc->sc_ac; struct ifnet * const ifp = &ac->ac_if; u_int32_t idver; int error; u_int i; + uint32_t intr[4]; + uint32_t memsize; + + if (faa->fa_nreg < 2 || (faa->fa_nintr != 4 && faa->fa_nintr != 12)) + return; + + for (i = 0; i < 4; i++) { + if (faa->fa_nintr == 4) + intr[i] = faa->fa_intr[i]; + else + intr[i] = faa->fa_intr[(3 * i) + 1]; + } + + /* + * fa_reg[1] is size of CPSW_SS and CPSW_PORT + * fa_reg[3] is size of CPSW_WR + * we map a size that is a superset of both + */ + memsize = 0x4000; timeout_set(&sc->sc_tick, cpsw_tick, sc); cpsw_get_mac_addr(sc); - sc->sc_rxthih = arm_intr_establish(aa->aa_dev->irq[0] + - CPSW_INTROFF_RXTH, IPL_NET, cpsw_rxthintr, sc, DEVNAME(sc)); - sc->sc_rxih = arm_intr_establish(aa->aa_dev->irq[0] + - CPSW_INTROFF_RX, IPL_NET, cpsw_rxintr, sc, DEVNAME(sc)); - sc->sc_txih = arm_intr_establish(aa->aa_dev->irq[0] + - CPSW_INTROFF_TX, IPL_NET, cpsw_txintr, sc, DEVNAME(sc)); - sc->sc_miscih = arm_intr_establish(aa->aa_dev->irq[0] + - CPSW_INTROFF_MISC, IPL_NET, cpsw_miscintr, sc, DEVNAME(sc)); + sc->sc_rxthih = arm_intr_establish(intr[0], IPL_NET, cpsw_rxthintr, sc, + DEVNAME(sc)); + sc->sc_rxih = arm_intr_establish(intr[1], IPL_NET, cpsw_rxintr, sc, + DEVNAME(sc)); + sc->sc_txih = arm_intr_establish(intr[2], IPL_NET, cpsw_txintr, sc, + DEVNAME(sc)); + sc->sc_miscih = arm_intr_establish(intr[3], IPL_NET, cpsw_miscintr, sc, + DEVNAME(sc)); - sc->sc_bst = aa->aa_iot; - sc->sc_bdt = aa->aa_dmat; + sc->sc_bst = faa->fa_iot; + sc->sc_bdt = faa->fa_dmat; - error = bus_space_map(sc->sc_bst, aa->aa_dev->mem[0].addr, - aa->aa_dev->mem[0].size, 0, &sc->sc_bsh); + error = bus_space_map(sc->sc_bst, faa->fa_reg[0], + memsize, 0, &sc->sc_bsh); if (error) { printf("can't map registers: %d\n", error); return; } - sc->sc_txdescs_pa = aa->aa_dev->mem[0].addr + + sc->sc_txdescs_pa = faa->fa_reg[0] + CPSW_CPPI_RAM_TXDESCS_BASE; error = bus_space_subregion(sc->sc_bst, sc->sc_bsh, CPSW_CPPI_RAM_TXDESCS_BASE, CPSW_CPPI_RAM_TXDESCS_SIZE, @@ -370,7 +401,7 @@ cpsw_attach(struct device *parent, struct device *self, void *aux) return; } - sc->sc_rxdescs_pa = aa->aa_dev->mem[0].addr + + sc->sc_rxdescs_pa = faa->fa_reg[0] + CPSW_CPPI_RAM_RXDESCS_BASE; error = bus_space_subregion(sc->sc_bst, sc->sc_bsh, CPSW_CPPI_RAM_RXDESCS_BASE, CPSW_CPPI_RAM_RXDESCS_SIZE, diff --git a/sys/arch/armv7/omap/omap.c b/sys/arch/armv7/omap/omap.c index a9ab55a7903..ad93d0bf0d0 100644 --- a/sys/arch/armv7/omap/omap.c +++ b/sys/arch/armv7/omap/omap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: omap.c,v 1.14 2016/06/26 07:25:05 jsg Exp $ */ +/* $OpenBSD: omap.c,v 1.15 2016/06/26 09:06:35 jsg Exp $ */ /* * Copyright (c) 2005,2008 Dale Rahn * @@ -61,7 +61,6 @@ struct board_dev beaglebone_devs[] = { { "omgpio", 1 }, { "omgpio", 2 }, { "omgpio", 3 }, - { "cpsw", 0 }, { NULL, 0 } }; -- 2.20.1