git: afa0f66e81cc - main - dwc: Move the txstart dma part to dwc1000_dma

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 05 Oct 2023 15:35:04 UTC
The branch main has been updated by manu:

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

commit afa0f66e81ccd6a946133bb9aceaf1fe59370431
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2023-09-28 20:34:47 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2023-10-05 15:34:39 +0000

    dwc: Move the txstart dma part to dwc1000_dma
    
    This is dma related to move it to the dma file.
    
    No functional changes intended.
---
 sys/dev/dwc/dwc1000_dma.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/dwc/dwc1000_dma.h |  8 +-------
 sys/dev/dwc/if_dwc.c      | 36 +----------------------------------
 3 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/sys/dev/dwc/dwc1000_dma.c b/sys/dev/dwc/dwc1000_dma.c
index a04f65de8501..505e3fcaebef 100644
--- a/sys/dev/dwc/dwc1000_dma.c
+++ b/sys/dev/dwc/dwc1000_dma.c
@@ -60,6 +60,15 @@
 #include <dev/dwc/dwc1000_reg.h>
 #include <dev/dwc/dwc1000_dma.h>
 
+#define	WATCHDOG_TIMEOUT_SECS	5
+
+static inline uint32_t
+next_txidx(struct dwc_softc *sc, uint32_t curidx)
+{
+
+	return ((curidx + 1) % TX_DESC_COUNT);
+}
+
 static inline uint32_t
 next_rxidx(struct dwc_softc *sc, uint32_t curidx)
 {
@@ -372,6 +381,45 @@ dma1000_txfinish_locked(struct dwc_softc *sc)
 	}
 }
 
+void
+dma1000_txstart(struct dwc_softc *sc)
+{
+	int enqueued;
+	struct mbuf *m;
+
+	enqueued = 0;
+
+	for (;;) {
+		if (sc->tx_desccount > (TX_DESC_COUNT - TX_MAP_MAX_SEGS  + 1)) {
+			if_setdrvflagbits(sc->ifp, IFF_DRV_OACTIVE, 0);
+			break;
+		}
+
+		if (sc->tx_mapcount == (TX_MAP_COUNT - 1)) {
+			if_setdrvflagbits(sc->ifp, IFF_DRV_OACTIVE, 0);
+			break;
+		}
+
+		m = if_dequeue(sc->ifp);
+		if (m == NULL)
+			break;
+		if (dma1000_setup_txbuf(sc, sc->tx_map_head, &m) != 0) {
+			if_sendq_prepend(sc->ifp, m);
+			if_setdrvflagbits(sc->ifp, IFF_DRV_OACTIVE, 0);
+			break;
+		}
+		bpf_mtap_if(sc->ifp, m);
+		sc->tx_map_head = next_txidx(sc, sc->tx_map_head);
+		sc->tx_mapcount++;
+		++enqueued;
+	}
+
+	if (enqueued != 0) {
+		WRITE4(sc, TRANSMIT_POLL_DEMAND, 0x1);
+		sc->tx_watchdog_count = WATCHDOG_TIMEOUT_SECS;
+	}
+}
+
 void
 dma1000_rxfinish_locked(struct dwc_softc *sc)
 {
diff --git a/sys/dev/dwc/dwc1000_dma.h b/sys/dev/dwc/dwc1000_dma.h
index 613faeee91ff..97cebd07f215 100644
--- a/sys/dev/dwc/dwc1000_dma.h
+++ b/sys/dev/dwc/dwc1000_dma.h
@@ -149,12 +149,6 @@ void dma1000_stop(struct dwc_softc *sc);
 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);
-
-static inline uint32_t
-next_txidx(struct dwc_softc *sc, uint32_t curidx)
-{
-
-	return ((curidx + 1) % TX_DESC_COUNT);
-}
+void dma1000_txstart(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 29f78dd94a9a..107158cebf02 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -79,7 +79,6 @@
 #include "miibus_if.h"
 
 #define	MAC_RESET_TIMEOUT	100
-#define	WATCHDOG_TIMEOUT_SECS	5
 
 static struct resource_spec dwc_spec[] = {
 	{ SYS_RES_MEMORY,	0,	RF_ACTIVE },
@@ -139,8 +138,6 @@ static void
 dwc_txstart_locked(struct dwc_softc *sc)
 {
 	if_t ifp;
-	struct mbuf *m;
-	int enqueued;
 
 	DWC_ASSERT_LOCKED(sc);
 
@@ -152,38 +149,7 @@ dwc_txstart_locked(struct dwc_softc *sc)
 	if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
 	    IFF_DRV_RUNNING)
 		return;
-
-	enqueued = 0;
-
-	for (;;) {
-		if (sc->tx_desccount > (TX_DESC_COUNT - TX_MAP_MAX_SEGS  + 1)) {
-			if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
-			break;
-		}
-
-		if (sc->tx_mapcount == (TX_MAP_COUNT - 1)) {
-			if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
-			break;
-		}
-
-		m = if_dequeue(ifp);
-		if (m == NULL)
-			break;
-		if (dma1000_setup_txbuf(sc, sc->tx_map_head, &m) != 0) {
-			if_sendq_prepend(ifp, m);
-			if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
-			break;
-		}
-		bpf_mtap_if(ifp, m);
-		sc->tx_map_head = next_txidx(sc, sc->tx_map_head);
-		sc->tx_mapcount++;
-		++enqueued;
-	}
-
-	if (enqueued != 0) {
-		WRITE4(sc, TRANSMIT_POLL_DEMAND, 0x1);
-		sc->tx_watchdog_count = WATCHDOG_TIMEOUT_SECS;
-	}
+	dma1000_txstart(sc);
 }
 
 static void