[rtems-libbsd commit] if_dwc: Simplify tx desc setup

Sebastian Huber sebh at rtems.org
Tue Jan 10 10:06:12 UTC 2017


Module:    rtems-libbsd
Branch:    master
Commit:    d9ff8281d707326749e010766f9a32267a395bef
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=d9ff8281d707326749e010766f9a32267a395bef

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar 30 11:51:36 2015 +0200

if_dwc: Simplify tx desc setup

---

 freebsd/sys/dev/dwc/if_dwc.c | 45 ++++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/freebsd/sys/dev/dwc/if_dwc.c b/freebsd/sys/dev/dwc/if_dwc.c
index ae0ae87..f7e9775 100644
--- a/freebsd/sys/dev/dwc/if_dwc.c
+++ b/freebsd/sys/dev/dwc/if_dwc.c
@@ -177,40 +177,28 @@ dwc_setup_txdesc(struct dwc_softc *sc, int idx, bus_addr_t paddr,
     uint32_t len)
 {
 	uint32_t flags;
-	uint32_t nidx;
-
-	nidx = next_txidx(sc, idx);
 
-	/* Addr/len 0 means we're clearing the descriptor after xmit done. */
-	if (paddr == 0 || len == 0) {
-		flags = 0;
-		--sc->txcount;
-	} else {
-		if (sc->mactype == DWC_GMAC_ALT_DESC)
-			flags = DDESC_CNTL_TXCHAIN | DDESC_CNTL_TXFIRST
-			    | DDESC_CNTL_TXLAST | DDESC_CNTL_TXINT;
-		else
-			flags = DDESC_TDES0_TXCHAIN | DDESC_TDES0_TXFIRST
-			    | DDESC_TDES0_TXLAST | DDESC_TDES0_TXINT;
-		++sc->txcount;
-	}
+	++sc->txcount;
 
 	sc->txdesc_ring[idx].addr = (uint32_t)(paddr);
 	if (sc->mactype == DWC_GMAC_ALT_DESC) {
+		flags = DDESC_CNTL_TXCHAIN | DDESC_CNTL_TXFIRST
+		    | DDESC_CNTL_TXLAST | DDESC_CNTL_TXINT;
 		sc->txdesc_ring[idx].tdes0 = 0;
 		sc->txdesc_ring[idx].tdes1 = flags | len;
 	} else {
+		flags = DDESC_TDES0_TXCHAIN | DDESC_TDES0_TXFIRST
+		    | DDESC_TDES0_TXLAST | DDESC_TDES0_TXINT;
 		sc->txdesc_ring[idx].tdes0 = flags;
 		sc->txdesc_ring[idx].tdes1 = len;
 	}
+	wmb();
 
-	if (paddr && len) {
-		wmb();
-		sc->txdesc_ring[idx].tdes0 |= DDESC_TDES0_OWN;
-		wmb();
-	}
+	sc->txdesc_ring[idx].tdes0 = DDESC_TDES0_TXCHAIN | DDESC_TDES0_TXFIRST
+	    | DDESC_TDES0_TXLAST | DDESC_TDES0_TXINT | DDESC_TDES0_OWN;
+	wmb();
 
-	return (nidx);
+	return (next_txidx(sc, idx));
 }
 
 static int
@@ -728,7 +716,7 @@ dwc_txfinish_locked(struct dwc_softc *sc)
 		bus_dmamap_unload(sc->txbuf_tag, bmap->map);
 		m_freem(bmap->mbuf);
 		bmap->mbuf = NULL;
-		dwc_setup_txdesc(sc, sc->tx_idx_tail, 0, 0);
+		--sc->txcount;
 		sc->tx_idx_tail = next_txidx(sc, sc->tx_idx_tail);
 	}
 
@@ -880,6 +868,14 @@ setup_dma(struct dwc_softc *sc)
 	}
 
 	for (idx = 0; idx < TX_DESC_COUNT; idx++) {
+		sc->txdesc_ring[idx].addr = 0;
+		if (sc->mactype == DWC_GMAC_ALT_DESC) {
+			sc->txdesc_ring[idx].tdes0 = 0;
+			sc->txdesc_ring[idx].tdes1 = DDESC_CNTL_TXCHAIN;
+		} else {
+			sc->txdesc_ring[idx].tdes0 = DDESC_TDES0_TXCHAIN;
+			sc->txdesc_ring[idx].tdes1 = 0;
+		}
 		nidx = next_txidx(sc, idx);
 		sc->txdesc_ring[idx].addr_next = sc->txdesc_ring_paddr +
 		    (nidx * sizeof(struct dwc_hwdesc));
@@ -910,7 +906,6 @@ setup_dma(struct dwc_softc *sc)
 			    "could not create TX buffer DMA map.\n");
 			goto out;
 		}
-		dwc_setup_txdesc(sc, idx, 0, 0);
 	}
 
 	/*
@@ -1147,7 +1142,7 @@ dwc_attach(device_t dev)
 	sc = device_get_softc(dev);
 	sc->dev = dev;
 	sc->rx_idx = 0;
-	sc->txcount = TX_DESC_COUNT;
+	sc->txcount = 0;
 	sc->mii_clk = IF_DWC_MII_CLK(dev);
 	sc->mactype = IF_DWC_MAC_TYPE(dev);
 



More information about the vc mailing list