Commit eb067347 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by David S. Miller

net: ethernet: mtk_eth_soc: add txd_size to mtk_soc_data

In order to remove mtk_tx_dma size dependency, introduce txd_size in
mtk_soc_data data structure. Rely on txd_size in mtk_init_fq_dma() and
mtk_dma_free() routines.
This is a preliminary patch to add mt7986 ethernet support.
Tested-by: default avatarSam Shih <sam.shih@mediatek.com>
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 731f3fd6
...@@ -808,20 +808,20 @@ static inline bool mtk_rx_get_desc(struct mtk_rx_dma *rxd, ...@@ -808,20 +808,20 @@ static inline bool mtk_rx_get_desc(struct mtk_rx_dma *rxd,
/* the qdma core needs scratch memory to be setup */ /* the qdma core needs scratch memory to be setup */
static int mtk_init_fq_dma(struct mtk_eth *eth) static int mtk_init_fq_dma(struct mtk_eth *eth)
{ {
const struct mtk_soc_data *soc = eth->soc;
dma_addr_t phy_ring_tail; dma_addr_t phy_ring_tail;
int cnt = MTK_DMA_SIZE; int cnt = MTK_DMA_SIZE;
dma_addr_t dma_addr; dma_addr_t dma_addr;
int i; int i;
eth->scratch_ring = dma_alloc_coherent(eth->dma_dev, eth->scratch_ring = dma_alloc_coherent(eth->dma_dev,
cnt * sizeof(struct mtk_tx_dma), cnt * soc->txrx.txd_size,
&eth->phy_scratch_ring, &eth->phy_scratch_ring,
GFP_KERNEL); GFP_KERNEL);
if (unlikely(!eth->scratch_ring)) if (unlikely(!eth->scratch_ring))
return -ENOMEM; return -ENOMEM;
eth->scratch_head = kcalloc(cnt, MTK_QDMA_PAGE_SIZE, eth->scratch_head = kcalloc(cnt, MTK_QDMA_PAGE_SIZE, GFP_KERNEL);
GFP_KERNEL);
if (unlikely(!eth->scratch_head)) if (unlikely(!eth->scratch_head))
return -ENOMEM; return -ENOMEM;
...@@ -831,16 +831,19 @@ static int mtk_init_fq_dma(struct mtk_eth *eth) ...@@ -831,16 +831,19 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr))) if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
return -ENOMEM; return -ENOMEM;
phy_ring_tail = eth->phy_scratch_ring + phy_ring_tail = eth->phy_scratch_ring + soc->txrx.txd_size * (cnt - 1);
(sizeof(struct mtk_tx_dma) * (cnt - 1));
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
eth->scratch_ring[i].txd1 = struct mtk_tx_dma *txd;
(dma_addr + (i * MTK_QDMA_PAGE_SIZE));
txd = (void *)eth->scratch_ring + i * soc->txrx.txd_size;
txd->txd1 = dma_addr + i * MTK_QDMA_PAGE_SIZE;
if (i < cnt - 1) if (i < cnt - 1)
eth->scratch_ring[i].txd2 = (eth->phy_scratch_ring + txd->txd2 = eth->phy_scratch_ring +
((i + 1) * sizeof(struct mtk_tx_dma))); (i + 1) * soc->txrx.txd_size;
eth->scratch_ring[i].txd3 = TX_DMA_SDL(MTK_QDMA_PAGE_SIZE);
txd->txd3 = TX_DMA_PLEN0(MTK_QDMA_PAGE_SIZE);
txd->txd4 = 0;
} }
mtk_w32(eth, eth->phy_scratch_ring, MTK_QDMA_FQ_HEAD); mtk_w32(eth, eth->phy_scratch_ring, MTK_QDMA_FQ_HEAD);
...@@ -2131,6 +2134,7 @@ static int mtk_dma_init(struct mtk_eth *eth) ...@@ -2131,6 +2134,7 @@ static int mtk_dma_init(struct mtk_eth *eth)
static void mtk_dma_free(struct mtk_eth *eth) static void mtk_dma_free(struct mtk_eth *eth)
{ {
const struct mtk_soc_data *soc = eth->soc;
int i; int i;
for (i = 0; i < MTK_MAC_COUNT; i++) for (i = 0; i < MTK_MAC_COUNT; i++)
...@@ -2138,9 +2142,8 @@ static void mtk_dma_free(struct mtk_eth *eth) ...@@ -2138,9 +2142,8 @@ static void mtk_dma_free(struct mtk_eth *eth)
netdev_reset_queue(eth->netdev[i]); netdev_reset_queue(eth->netdev[i]);
if (eth->scratch_ring) { if (eth->scratch_ring) {
dma_free_coherent(eth->dma_dev, dma_free_coherent(eth->dma_dev,
MTK_DMA_SIZE * sizeof(struct mtk_tx_dma), MTK_DMA_SIZE * soc->txrx.txd_size,
eth->scratch_ring, eth->scratch_ring, eth->phy_scratch_ring);
eth->phy_scratch_ring);
eth->scratch_ring = NULL; eth->scratch_ring = NULL;
eth->phy_scratch_ring = 0; eth->phy_scratch_ring = 0;
} }
...@@ -3373,6 +3376,9 @@ static const struct mtk_soc_data mt2701_data = { ...@@ -3373,6 +3376,9 @@ static const struct mtk_soc_data mt2701_data = {
.hw_features = MTK_HW_FEATURES, .hw_features = MTK_HW_FEATURES,
.required_clks = MT7623_CLKS_BITMAP, .required_clks = MT7623_CLKS_BITMAP,
.required_pctl = true, .required_pctl = true,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
static const struct mtk_soc_data mt7621_data = { static const struct mtk_soc_data mt7621_data = {
...@@ -3381,6 +3387,9 @@ static const struct mtk_soc_data mt7621_data = { ...@@ -3381,6 +3387,9 @@ static const struct mtk_soc_data mt7621_data = {
.required_clks = MT7621_CLKS_BITMAP, .required_clks = MT7621_CLKS_BITMAP,
.required_pctl = false, .required_pctl = false,
.offload_version = 2, .offload_version = 2,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
static const struct mtk_soc_data mt7622_data = { static const struct mtk_soc_data mt7622_data = {
...@@ -3390,6 +3399,9 @@ static const struct mtk_soc_data mt7622_data = { ...@@ -3390,6 +3399,9 @@ static const struct mtk_soc_data mt7622_data = {
.required_clks = MT7622_CLKS_BITMAP, .required_clks = MT7622_CLKS_BITMAP,
.required_pctl = false, .required_pctl = false,
.offload_version = 2, .offload_version = 2,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
static const struct mtk_soc_data mt7623_data = { static const struct mtk_soc_data mt7623_data = {
...@@ -3398,6 +3410,9 @@ static const struct mtk_soc_data mt7623_data = { ...@@ -3398,6 +3410,9 @@ static const struct mtk_soc_data mt7623_data = {
.required_clks = MT7623_CLKS_BITMAP, .required_clks = MT7623_CLKS_BITMAP,
.required_pctl = true, .required_pctl = true,
.offload_version = 2, .offload_version = 2,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
static const struct mtk_soc_data mt7629_data = { static const struct mtk_soc_data mt7629_data = {
...@@ -3406,6 +3421,9 @@ static const struct mtk_soc_data mt7629_data = { ...@@ -3406,6 +3421,9 @@ static const struct mtk_soc_data mt7629_data = {
.hw_features = MTK_HW_FEATURES, .hw_features = MTK_HW_FEATURES,
.required_clks = MT7629_CLKS_BITMAP, .required_clks = MT7629_CLKS_BITMAP,
.required_pctl = false, .required_pctl = false,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
static const struct mtk_soc_data rt5350_data = { static const struct mtk_soc_data rt5350_data = {
...@@ -3413,6 +3431,9 @@ static const struct mtk_soc_data rt5350_data = { ...@@ -3413,6 +3431,9 @@ static const struct mtk_soc_data rt5350_data = {
.hw_features = MTK_HW_FEATURES_MT7628, .hw_features = MTK_HW_FEATURES_MT7628,
.required_clks = MT7628_CLKS_BITMAP, .required_clks = MT7628_CLKS_BITMAP,
.required_pctl = false, .required_pctl = false,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
},
}; };
const struct of_device_id of_mtk_match[] = { const struct of_device_id of_mtk_match[] = {
......
...@@ -867,6 +867,7 @@ struct mtk_tx_dma_desc_info { ...@@ -867,6 +867,7 @@ struct mtk_tx_dma_desc_info {
* the target SoC * the target SoC
* @required_pctl A bool value to show whether the SoC requires * @required_pctl A bool value to show whether the SoC requires
* the extra setup for those pins used by GMAC. * the extra setup for those pins used by GMAC.
* @txd_size Tx DMA descriptor size.
*/ */
struct mtk_soc_data { struct mtk_soc_data {
u32 ana_rgc3; u32 ana_rgc3;
...@@ -875,6 +876,9 @@ struct mtk_soc_data { ...@@ -875,6 +876,9 @@ struct mtk_soc_data {
bool required_pctl; bool required_pctl;
u8 offload_version; u8 offload_version;
netdev_features_t hw_features; netdev_features_t hw_features;
struct {
u32 txd_size;
} txrx;
}; };
/* currently no SoC has more than 2 macs */ /* currently no SoC has more than 2 macs */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment