Module Name: src Committed By: hkenken Date: Tue Jul 23 06:36:36 UTC 2019
Modified Files: src/sys/arch/arm/imx: if_enet.c if_enet_imx6.c if_enet_imx7.c if_enetvar.h Log Message: Modified enet_attach_common(). To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/arch/arm/imx/if_enet.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/imx/if_enet_imx6.c cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/imx/if_enet_imx7.c cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/imx/if_enetvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/imx/if_enet.c diff -u src/sys/arch/arm/imx/if_enet.c:1.23 src/sys/arch/arm/imx/if_enet.c:1.24 --- src/sys/arch/arm/imx/if_enet.c:1.23 Tue May 28 07:41:46 2019 +++ src/sys/arch/arm/imx/if_enet.c Tue Jul 23 06:36:36 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_enet.c,v 1.23 2019/05/28 07:41:46 msaitoh Exp $ */ +/* $NetBSD: if_enet.c,v 1.24 2019/07/23 06:36:36 hkenken Exp $ */ /* * Copyright (c) 2014 Ryo Shimizu <r...@nerv.org> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.23 2019/05/28 07:41:46 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.24 2019/07/23 06:36:36 hkenken Exp $"); #include "vlan.h" @@ -132,7 +132,6 @@ static void enet_attach_evcnt(struct ene static void enet_update_evcnt(struct enet_softc *); #endif -static int enet_intr(void *); static void enet_tick(void *); static int enet_tx_intr(void *); static int enet_rx_intr(void *); @@ -170,30 +169,16 @@ static int enet_alloc_dma(struct enet_so CFATTACH_DECL_NEW(enet, sizeof(struct enet_softc), enet_match, enet_attach, NULL, NULL); -void -enet_attach_common(device_t self, bus_space_tag_t iot, - bus_dma_tag_t dmat, bus_addr_t addr, bus_size_t size, int irq) +int +enet_attach_common(device_t self) { struct enet_softc *sc = device_private(self); struct ifnet *ifp; struct mii_data * const mii = &sc->sc_mii; - sc->sc_dev = self; - sc->sc_iot = iot; - sc->sc_addr = addr; - sc->sc_dmat = dmat; - - aprint_naive("\n"); - aprint_normal(": Gigabit Ethernet Controller\n"); - if (bus_space_map(sc->sc_iot, sc->sc_addr, size, 0, - &sc->sc_ioh)) { - aprint_error_dev(self, "cannot map registers\n"); - return; - } - /* allocate dma buffer */ if (enet_alloc_ring(sc)) - return; + return -1; #define IS_ENADDR_ZERO(enaddr) \ ((enaddr[0] | enaddr[1] | enaddr[2] | \ @@ -225,32 +210,6 @@ enet_attach_common(device_t self, bus_sp enet_init_regs(sc, 1); - /* setup interrupt handlers */ - if ((sc->sc_ih = intr_establish(irq, IPL_NET, - IST_LEVEL, enet_intr, sc)) == NULL) { - aprint_error_dev(self, "unable to establish interrupt\n"); - goto failure; - } - - if (sc->sc_imxtype == 7) { - /* i.MX7 use 3 interrupts */ - if ((sc->sc_ih2 = intr_establish(irq + 1, IPL_NET, - IST_LEVEL, enet_intr, sc)) == NULL) { - aprint_error_dev(self, - "unable to establish 2nd interrupt\n"); - intr_disestablish(sc->sc_ih); - goto failure; - } - if ((sc->sc_ih3 = intr_establish(irq + 2, IPL_NET, - IST_LEVEL, enet_intr, sc)) == NULL) { - aprint_error_dev(self, - "unable to establish 3rd interrupt\n"); - intr_disestablish(sc->sc_ih2); - intr_disestablish(sc->sc_ih); - goto failure; - } - } - /* callout will be scheduled from enet_init() */ callout_init(&sc->sc_tick_ch, 0); callout_setfunc(&sc->sc_tick_ch, enet_tick, sc); @@ -312,11 +271,7 @@ enet_attach_common(device_t self, bus_sp sc->sc_stopping = false; - return; - - failure: - bus_space_unmap(sc->sc_iot, sc->sc_ioh, size); - return; + return 0; } #ifdef ENET_EVENT_COUNTER @@ -446,7 +401,7 @@ enet_tick(void *arg) splx(s); } -static int +int enet_intr(void *arg) { struct enet_softc *sc; Index: src/sys/arch/arm/imx/if_enet_imx6.c diff -u src/sys/arch/arm/imx/if_enet_imx6.c:1.4 src/sys/arch/arm/imx/if_enet_imx6.c:1.5 --- src/sys/arch/arm/imx/if_enet_imx6.c:1.4 Thu Jun 20 08:16:19 2019 +++ src/sys/arch/arm/imx/if_enet_imx6.c Tue Jul 23 06:36:36 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_enet_imx6.c,v 1.4 2019/06/20 08:16:19 hkenken Exp $ */ +/* $NetBSD: if_enet_imx6.c,v 1.5 2019/07/23 06:36:36 hkenken Exp $ */ /* * Copyright (c) 2014 Ryo Shimizu <r...@nerv.org> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_enet_imx6.c,v 1.4 2019/06/20 08:16:19 hkenken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_enet_imx6.c,v 1.5 2019/07/23 06:36:36 hkenken Exp $"); #include "locators.h" #include "imxccm.h" @@ -71,18 +71,19 @@ enet_match(device_t parent __unused, str void enet_attach(device_t parent, device_t self, void *aux) { - struct enet_softc *sc; - struct axi_attach_args *aa; + struct enet_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; #if NIMXOCOTP > 0 uint32_t eaddr; #endif - aa = aux; - sc = device_private(self); - if (aa->aa_size == AXICF_SIZE_DEFAULT) aa->aa_size = AIPS_ENET_SIZE; + sc->sc_dev = self; + sc->sc_iot = aa->aa_iot; + sc->sc_dmat = aa->aa_dmat; + sc->sc_imxtype = 6; /* i.MX6 */ if (IMX6_CHIPID_MAJOR(imx6_chip_id()) == CHIPID_MAJOR_IMX6UL) sc->sc_rgmii = 0; @@ -144,8 +145,30 @@ enet_attach(device_t parent, device_t se sc->sc_pllclock = clk_get_rate(sc->sc_clk_enet_ref); - enet_attach_common(self, aa->aa_iot, aa->aa_dmat, aa->aa_addr, - aa->aa_size, aa->aa_irq); + if (bus_space_map(sc->sc_iot, aa->aa_addr, aa->aa_size, 0, + &sc->sc_ioh)) { + aprint_error_dev(self, "cannot map registers\n"); + return; + } + + aprint_naive("\n"); + aprint_normal(": Gigabit Ethernet Controller\n"); + + /* setup interrupt handlers */ + if ((sc->sc_ih = intr_establish(aa->aa_irq, IPL_NET, + IST_LEVEL, enet_intr, sc)) == NULL) { + aprint_error_dev(self, "unable to establish interrupt\n"); + goto failure; + } + + if (enet_attach_common(self) != 0) + goto failure; + + return; + +failure: + bus_space_unmap(sc->sc_iot, sc->sc_ioh, aa->aa_size); + return; } static int Index: src/sys/arch/arm/imx/if_enet_imx7.c diff -u src/sys/arch/arm/imx/if_enet_imx7.c:1.2 src/sys/arch/arm/imx/if_enet_imx7.c:1.3 --- src/sys/arch/arm/imx/if_enet_imx7.c:1.2 Fri Jun 9 18:14:59 2017 +++ src/sys/arch/arm/imx/if_enet_imx7.c Tue Jul 23 06:36:36 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_enet_imx7.c,v 1.2 2017/06/09 18:14:59 ryo Exp $ */ +/* $NetBSD: if_enet_imx7.c,v 1.3 2019/07/23 06:36:36 hkenken Exp $ */ /* * Copyright (c) 2014 Ryo Shimizu <r...@nerv.org> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_enet_imx7.c,v 1.2 2017/06/09 18:14:59 ryo Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_enet_imx7.c,v 1.3 2019/07/23 06:36:36 hkenken Exp $"); #include "locators.h" #include "imxccm.h" @@ -69,18 +69,30 @@ enet_match(device_t parent __unused, str void enet_attach(device_t parent, device_t self, void *aux) { - struct enet_softc *sc; - struct axi_attach_args *aa; - - aa = aux; - sc = device_private(self); + struct enet_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; if (aa->aa_size == AXICF_SIZE_DEFAULT) aa->aa_size = AIPS_ENET_SIZE; + sc->sc_dev = self; + sc->sc_iot = aa->aa_iot; + sc->sc_dmat = aa->aa_dmat; + sc->sc_imxtype = 7; /* i.MX7 */ sc->sc_rgmii = 1; + switch (aa->aa_addr) { + case (IMX7_AIPS_BASE + AIPS3_ENET1_BASE): + sc->sc_unit = 0; + get_mac_from_ocotp(sc, self, "enet1-ocotp-mac"); + break; + case (IMX7_AIPS_BASE + AIPS3_ENET2_BASE): + sc->sc_unit = 1; + get_mac_from_ocotp(sc, self, "enet2-ocotp-mac"); + break; + } + #if NIMXCCM > 0 /* PLL power up */ if (imx7_pll_power(CCM_ANALOG_PLL_ENET, 1) != 0) { @@ -93,20 +105,47 @@ enet_attach(device_t parent, device_t se sc->sc_pllclock = 1000000000; #endif - switch (aa->aa_addr) { - case (IMX7_AIPS_BASE + AIPS3_ENET1_BASE): - sc->sc_unit = 0; - get_mac_from_ocotp(sc, self, "enet1-ocotp-mac"); - break; + if (bus_space_map(sc->sc_iot, aa->aa_addr, aa->aa_size, 0, + &sc->sc_ioh)) { + aprint_error_dev(self, "cannot map registers\n"); + return; + } - case (IMX7_AIPS_BASE + AIPS3_ENET2_BASE): - sc->sc_unit = 1; - get_mac_from_ocotp(sc, self, "enet2-ocotp-mac"); - break; + aprint_naive("\n"); + aprint_normal(": Gigabit Ethernet Controller\n"); + + /* setup interrupt handlers */ + if ((sc->sc_ih = intr_establish(aa->aa_irq, IPL_NET, + IST_LEVEL, enet_intr, sc)) == NULL) { + aprint_error_dev(self, "unable to establish interrupt\n"); + goto failure; + } + + /* i.MX7 use 3 interrupts */ + if ((sc->sc_ih2 = intr_establish(aa->aa_irq + 1, IPL_NET, + IST_LEVEL, enet_intr, sc)) == NULL) { + aprint_error_dev(self, + "unable to establish 2nd interrupt\n"); + intr_disestablish(sc->sc_ih); + goto failure; + } + if ((sc->sc_ih3 = intr_establish(aa->aa_irq + 2, IPL_NET, + IST_LEVEL, enet_intr, sc)) == NULL) { + aprint_error_dev(self, + "unable to establish 3rd interrupt\n"); + intr_disestablish(sc->sc_ih2); + intr_disestablish(sc->sc_ih); + goto failure; } - enet_attach_common(self, aa->aa_iot, aa->aa_dmat, aa->aa_addr, - aa->aa_size, aa->aa_irq); + if (enet_attach_common(self) != 0) + goto failure; + + return; + +failure: + bus_space_unmap(sc->sc_iot, sc->sc_ioh, aa->aa_size); + return; } static void Index: src/sys/arch/arm/imx/if_enetvar.h diff -u src/sys/arch/arm/imx/if_enetvar.h:1.3 src/sys/arch/arm/imx/if_enetvar.h:1.4 --- src/sys/arch/arm/imx/if_enetvar.h:1.3 Thu Jun 20 08:16:19 2019 +++ src/sys/arch/arm/imx/if_enetvar.h Tue Jul 23 06:36:36 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_enetvar.h,v 1.3 2019/06/20 08:16:19 hkenken Exp $ */ +/* $NetBSD: if_enetvar.h,v 1.4 2019/07/23 06:36:36 hkenken Exp $ */ /* * Copyright (c) 2014 Ryo Shimizu <r...@nerv.org> @@ -51,7 +51,6 @@ struct enet_rxsoft { struct enet_softc { device_t sc_dev; - bus_addr_t sc_addr; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; bus_dma_tag_t sc_dmat; @@ -131,9 +130,10 @@ struct enet_softc { #endif /* ENET_EVENT_COUNTER */ }; -void enet_attach_common(device_t, bus_space_tag_t, bus_dma_tag_t, - bus_addr_t, bus_size_t, int); +int enet_attach_common(device_t); int enet_match(device_t, cfdata_t, void *); void enet_attach(device_t, device_t, void *); +int enet_intr(void *); + #endif /* _ARM_IMX_IF_ENETVAR_H_ */