Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/imx Modified enet_attach_common().



details:   https://anonhg.NetBSD.org/src/rev/13447203170a
branches:  trunk
changeset: 457842:13447203170a
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Tue Jul 23 06:36:36 2019 +0000

description:
Modified enet_attach_common().

diffstat:

 sys/arch/arm/imx/if_enet.c      |  59 +++----------------------------
 sys/arch/arm/imx/if_enet_imx6.c |  41 +++++++++++++++++----
 sys/arch/arm/imx/if_enet_imx7.c |  75 +++++++++++++++++++++++++++++++---------
 sys/arch/arm/imx/if_enetvar.h   |   8 ++--
 4 files changed, 100 insertions(+), 83 deletions(-)

diffs (truncated from 334 to 300 lines):

diff -r 4b77d0963b10 -r 13447203170a sys/arch/arm/imx/if_enet.c
--- a/sys/arch/arm/imx/if_enet.c        Tue Jul 23 06:35:40 2019 +0000
+++ b/sys/arch/arm/imx/if_enet.c        Tue Jul 23 06:36:36 2019 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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_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 @@
 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_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 @@
 
        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 @@
        splx(s);
 }
 
-static int
+int
 enet_intr(void *arg)
 {
        struct enet_softc *sc;
diff -r 4b77d0963b10 -r 13447203170a sys/arch/arm/imx/if_enet_imx6.c
--- a/sys/arch/arm/imx/if_enet_imx6.c   Tue Jul 23 06:35:40 2019 +0000
+++ b/sys/arch/arm/imx/if_enet_imx6.c   Tue Jul 23 06:36:36 2019 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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 @@
 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 @@
 
        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
diff -r 4b77d0963b10 -r 13447203170a sys/arch/arm/imx/if_enet_imx7.c
--- a/sys/arch/arm/imx/if_enet_imx7.c   Tue Jul 23 06:35:40 2019 +0000
+++ b/sys/arch/arm/imx/if_enet_imx7.c   Tue Jul 23 06:36:36 2019 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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 @@
 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 @@
        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;
        }
 
-       enet_attach_common(self, aa->aa_iot, aa->aa_dmat, aa->aa_addr,
-           aa->aa_size, aa->aa_irq);
+       /* 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;
+       }
+
+       if (enet_attach_common(self) != 0)
+               goto failure;
+
+       return;
+
+failure:
+       bus_space_unmap(sc->sc_iot, sc->sc_ioh, aa->aa_size);



Home | Main Index | Thread Index | Old Index