Skip to content

Commit

Permalink
net: ethernet: mtk_eth_soc: rely on txd_size in mtk_tx_alloc/mtk_tx_c…
Browse files Browse the repository at this point in the history
…lean

This is a preliminary patch to add mt7986 ethernet support.

Tested-by: Sam Shih <sam.shih@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Lorenzo Bianconi authored and David S. Miller committed May 22, 2022
1 parent eb06734 commit 0e05744
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions drivers/net/ethernet/mediatek/mtk_eth_soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,10 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)

static int mtk_tx_alloc(struct mtk_eth *eth)
{
const struct mtk_soc_data *soc = eth->soc;
struct mtk_tx_ring *ring = &eth->tx_ring;
int i, sz = sizeof(*ring->dma);
int i, sz = soc->txrx.txd_size;
struct mtk_tx_dma *txd;

ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
GFP_KERNEL);
Expand All @@ -1609,8 +1611,10 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
int next = (i + 1) % MTK_DMA_SIZE;
u32 next_ptr = ring->phys + next * sz;

ring->dma[i].txd2 = next_ptr;
ring->dma[i].txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
txd = (void *)ring->dma + i * sz;
txd->txd2 = next_ptr;
txd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
txd->txd4 = 0;
}

/* On MT7688 (PDMA only) this driver uses the ring->dma structs
Expand All @@ -1632,7 +1636,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
ring->dma_size = MTK_DMA_SIZE;
atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
ring->next_free = &ring->dma[0];
ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
ring->last_free = (void *)txd;
ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
ring->thresh = MAX_SKB_FRAGS;

Expand Down Expand Up @@ -1665,6 +1669,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)

static void mtk_tx_clean(struct mtk_eth *eth)
{
const struct mtk_soc_data *soc = eth->soc;
struct mtk_tx_ring *ring = &eth->tx_ring;
int i;

Expand All @@ -1677,17 +1682,15 @@ static void mtk_tx_clean(struct mtk_eth *eth)

if (ring->dma) {
dma_free_coherent(eth->dma_dev,
MTK_DMA_SIZE * sizeof(*ring->dma),
ring->dma,
ring->phys);
MTK_DMA_SIZE * soc->txrx.txd_size,
ring->dma, ring->phys);
ring->dma = NULL;
}

if (ring->dma_pdma) {
dma_free_coherent(eth->dma_dev,
MTK_DMA_SIZE * sizeof(*ring->dma_pdma),
ring->dma_pdma,
ring->phys_pdma);
MTK_DMA_SIZE * soc->txrx.txd_size,
ring->dma_pdma, ring->phys_pdma);
ring->dma_pdma = NULL;
}
}
Expand Down

0 comments on commit 0e05744

Please sign in to comment.