if_dwc: Simplify tx desc setup

This commit is contained in:
Sebastian Huber
2015-03-30 11:51:36 +02:00
parent 941021287a
commit d9ff8281d7

View File

@@ -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->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;
}
if (paddr && len) {
wmb();
sc->txdesc_ring[idx].tdes0 |= DDESC_TDES0_OWN;
wmb();
}
return (nidx);
sc->txdesc_ring[idx].tdes0 = DDESC_TDES0_TXCHAIN | DDESC_TDES0_TXFIRST
| DDESC_TDES0_TXLAST | DDESC_TDES0_TXINT | DDESC_TDES0_OWN;
wmb();
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);