git: fd23372bd562 - stable/12 - if_dwc: Add dwc_stop_dma and use it in dwc_stop_locked

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Thu, 11 Aug 2022 14:53:14 UTC
The branch stable/12 has been updated by mhorne:

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

commit fd23372bd562f381682658c02d5b3952162e29c8
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2020-11-20 11:29:00 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-08-11 14:52:02 +0000

    if_dwc: Add dwc_stop_dma and use it in dwc_stop_locked
    
    No functional changes intended
    
    (cherry picked from commit afd0c3c26801cd038203da1df61be9728e3369a4)
---
 sys/dev/dwc/if_dwc.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c
index aa8fbc9a12b3..d4bc4caffa32 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -214,6 +214,7 @@ static void dwc_setup_rxfilter(struct dwc_softc *sc);
 static void dwc_setup_core(struct dwc_softc *sc);
 static void dwc_enable_mac(struct dwc_softc *sc, bool enable);
 static void dwc_init_dma(struct dwc_softc *sc);
+static void dwc_stop_dma(struct dwc_softc *sc);
 
 static inline uint32_t
 next_rxidx(struct dwc_softc *sc, uint32_t curidx)
@@ -359,7 +360,6 @@ static void
 dwc_stop_locked(struct dwc_softc *sc)
 {
 	struct ifnet *ifp;
-	uint32_t reg;
 
 	DWC_ASSERT_LOCKED(sc);
 
@@ -370,22 +370,8 @@ dwc_stop_locked(struct dwc_softc *sc)
 
 	callout_stop(&sc->dwc_callout);
 
-	/* Stop DMA TX */
-	reg = READ4(sc, OPERATION_MODE);
-	reg &= ~(MODE_ST);
-	WRITE4(sc, OPERATION_MODE, reg);
-
-	/* Flush TX */
-	reg = READ4(sc, OPERATION_MODE);
-	reg |= (MODE_FTF);
-	WRITE4(sc, OPERATION_MODE, reg);
-
+	dwc_stop_dma(sc);
 	dwc_enable_mac(sc, false);
-
-	/* Stop DMA RX */
-	reg = READ4(sc, OPERATION_MODE);
-	reg &= ~(MODE_SR);
-	WRITE4(sc, OPERATION_MODE, reg);
 }
 
 static void dwc_clear_stats(struct dwc_softc *sc)
@@ -819,6 +805,29 @@ dwc_init_dma(struct dwc_softc *sc)
 	WRITE4(sc, OPERATION_MODE, reg);
 }
 
+static void
+dwc_stop_dma(struct dwc_softc *sc)
+{
+	uint32_t reg;
+
+	DWC_ASSERT_LOCKED(sc);
+
+	/* Stop DMA TX */
+	reg = READ4(sc, OPERATION_MODE);
+	reg &= ~(MODE_ST);
+	WRITE4(sc, OPERATION_MODE, reg);
+
+	/* Flush TX */
+	reg = READ4(sc, OPERATION_MODE);
+	reg |= (MODE_FTF);
+	WRITE4(sc, OPERATION_MODE, reg);
+
+	/* Stop DMA RX */
+	reg = READ4(sc, OPERATION_MODE);
+	reg &= ~(MODE_SR);
+	WRITE4(sc, OPERATION_MODE, reg);
+}
+
 static int
 dwc_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 {