Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Oct 2023 15:35:08 GMT
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 29776aa436cf - main - dwc: Move interrupt related code to core and dma file
Message-ID:  <202310051535.395FZ8SI012783@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=29776aa436cf248950bcf755c6a53ec0590d89bf

commit 29776aa436cf248950bcf755c6a53ec0590d89bf
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2023-10-03 16:04:03 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2023-10-05 15:34:40 +0000

    dwc: Move interrupt related code to core and dma file
    
    No functional changes intended.
---
 sys/dev/dwc/dwc1000_core.c | 19 +++++++++++++++++++
 sys/dev/dwc/dwc1000_core.h |  2 ++
 sys/dev/dwc/dwc1000_dma.c  | 35 +++++++++++++++++++++++++++++++++++
 sys/dev/dwc/dwc1000_dma.h  |  1 +
 sys/dev/dwc/if_dwc.c       | 38 +++++++++-----------------------------
 5 files changed, 66 insertions(+), 29 deletions(-)

diff --git a/sys/dev/dwc/dwc1000_core.c b/sys/dev/dwc/dwc1000_core.c
index c93019a49f3e..6cf836f87be2 100644
--- a/sys/dev/dwc/dwc1000_core.c
+++ b/sys/dev/dwc/dwc1000_core.c
@@ -419,3 +419,22 @@ dwc1000_harvest_stats(struct dwc_softc *sc)
 
 	dwc1000_clear_stats(sc);
 }
+
+void
+dwc1000_intr(struct dwc_softc *sc)
+{
+	uint32_t reg;
+
+	DWC_ASSERT_LOCKED(sc);
+
+	reg = READ4(sc, INTERRUPT_STATUS);
+	if (reg)
+		READ4(sc, SGMII_RGMII_SMII_CTRL_STATUS);
+}
+
+void
+dwc1000_intr_disable(struct dwc_softc *sc)
+{
+
+	WRITE4(sc, INTERRUPT_ENABLE, 0);
+}
diff --git a/sys/dev/dwc/dwc1000_core.h b/sys/dev/dwc/dwc1000_core.h
index 2069215bfffe..cb7d1f3946e9 100644
--- a/sys/dev/dwc/dwc1000_core.h
+++ b/sys/dev/dwc/dwc1000_core.h
@@ -39,5 +39,7 @@ void dwc1000_enable_csum_offload(struct dwc_softc *sc);
 void dwc1000_setup_rxfilter(struct dwc_softc *sc);
 void dwc1000_get_hwaddr(struct dwc_softc *sc, uint8_t *hwaddr);
 void dwc1000_harvest_stats(struct dwc_softc *sc);
+void dwc1000_intr(struct dwc_softc *softc);
+void dwc1000_intr_disable(struct dwc_softc *sc);
 
 #endif	/* __DWC1000_CORE_H__ */
diff --git a/sys/dev/dwc/dwc1000_dma.c b/sys/dev/dwc/dwc1000_dma.c
index ad8bdbcfc883..3d95c9d8e764 100644
--- a/sys/dev/dwc/dwc1000_dma.c
+++ b/sys/dev/dwc/dwc1000_dma.c
@@ -810,3 +810,38 @@ dma1000_free(struct dwc_softc *sc)
 	if (sc->txdesc_tag != NULL)
 		bus_dma_tag_destroy(sc->txdesc_tag);
 }
+
+/*
+ * Interrupt function
+ */
+
+int
+dma1000_intr(struct dwc_softc *sc)
+{
+	uint32_t reg;
+	int rv;
+
+	DWC_ASSERT_LOCKED(sc);
+
+	rv = 0;
+	reg = READ4(sc, DMA_STATUS);
+	if (reg & DMA_STATUS_NIS) {
+		if (reg & DMA_STATUS_RI)
+			dma1000_rxfinish_locked(sc);
+
+		if (reg & DMA_STATUS_TI) {
+			dma1000_txfinish_locked(sc);
+			dma1000_txstart(sc);
+		}
+	}
+
+	if (reg & DMA_STATUS_AIS) {
+		if (reg & DMA_STATUS_FBI) {
+			/* Fatal bus error */
+			rv = EIO;
+		}
+	}
+
+	WRITE4(sc, DMA_STATUS, reg & DMA_STATUS_INTR_MASK);
+	return (rv);
+}
diff --git a/sys/dev/dwc/dwc1000_dma.h b/sys/dev/dwc/dwc1000_dma.h
index b4af29076625..96a98c2d6d51 100644
--- a/sys/dev/dwc/dwc1000_dma.h
+++ b/sys/dev/dwc/dwc1000_dma.h
@@ -50,5 +50,6 @@ int dma1000_setup_txbuf(struct dwc_softc *sc, int idx, struct mbuf **mp);
 void dma1000_txfinish_locked(struct dwc_softc *sc);
 void dma1000_rxfinish_locked(struct dwc_softc *sc);
 void dma1000_txstart(struct dwc_softc *sc);
+int dma1000_intr(struct dwc_softc *sc);
 
 #endif	/* __DWC1000_DMA_H__ */
diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c
index 107158cebf02..896e2f2205a0 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -300,38 +300,18 @@ static void
 dwc_intr(void *arg)
 {
 	struct dwc_softc *sc;
-	uint32_t reg;
+	int rv;
 
 	sc = arg;
-
 	DWC_LOCK(sc);
-
-	reg = READ4(sc, INTERRUPT_STATUS);
-	if (reg)
-		READ4(sc, SGMII_RGMII_SMII_CTRL_STATUS);
-
-	reg = READ4(sc, DMA_STATUS);
-	if (reg & DMA_STATUS_NIS) {
-		if (reg & DMA_STATUS_RI)
-			dma1000_rxfinish_locked(sc);
-
-		if (reg & DMA_STATUS_TI) {
-			dma1000_txfinish_locked(sc);
-			dwc_txstart_locked(sc);
-		}
-	}
-
-	if (reg & DMA_STATUS_AIS) {
-		if (reg & DMA_STATUS_FBI) {
-			/* Fatal bus error */
-			device_printf(sc->dev,
-			    "Ethernet DMA error, restarting controller.\n");
-			dwc_stop_locked(sc);
-			dwc_init_locked(sc);
-		}
+	dwc1000_intr(sc);
+	rv = dma1000_intr(sc);
+	if (rv == EIO) {
+		device_printf(sc->dev,
+		  "Ethernet DMA error, restarting controller.\n");
+		dwc_stop_locked(sc);
+		dwc_init_locked(sc);
 	}
-
-	WRITE4(sc, DMA_STATUS, reg & DMA_STATUS_INTR_MASK);
 	DWC_UNLOCK(sc);
 }
 
@@ -706,7 +686,7 @@ dwc_detach(device_t dev)
 	 * Disable and tear down interrupts before anything else, so we don't
 	 * race with the handler.
 	 */
-	WRITE4(sc, INTERRUPT_ENABLE, 0);
+	dwc1000_intr_disable(sc);
 	if (sc->intr_cookie != NULL) {
 		bus_teardown_intr(dev, sc->res[1], sc->intr_cookie);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202310051535.395FZ8SI012783>