1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Fri, 20 May 2022 20:11:28 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: add txd_size to mtk_soc_data
5 In order to remove mtk_tx_dma size dependency, introduce txd_size in
6 mtk_soc_data data structure. Rely on txd_size in mtk_init_fq_dma() and
7 mtk_dma_free() routines.
8 This is a preliminary patch to add mt7986 ethernet support.
10 Tested-by: Sam Shih <sam.shih@mediatek.com>
11 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
15 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
16 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 @@ -837,20 +837,20 @@ static void *mtk_max_lro_buf_alloc(gfp_t
18 /* the qdma core needs scratch memory to be setup */
19 static int mtk_init_fq_dma(struct mtk_eth *eth)
21 + const struct mtk_soc_data *soc = eth->soc;
22 dma_addr_t phy_ring_tail;
23 int cnt = MTK_DMA_SIZE;
27 eth->scratch_ring = dma_alloc_coherent(eth->dma_dev,
28 - cnt * sizeof(struct mtk_tx_dma),
29 + cnt * soc->txrx.txd_size,
30 ð->phy_scratch_ring,
32 if (unlikely(!eth->scratch_ring))
35 - eth->scratch_head = kcalloc(cnt, MTK_QDMA_PAGE_SIZE,
37 + eth->scratch_head = kcalloc(cnt, MTK_QDMA_PAGE_SIZE, GFP_KERNEL);
38 if (unlikely(!eth->scratch_head))
41 @@ -860,16 +860,19 @@ static int mtk_init_fq_dma(struct mtk_et
42 if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
45 - phy_ring_tail = eth->phy_scratch_ring +
46 - (sizeof(struct mtk_tx_dma) * (cnt - 1));
47 + phy_ring_tail = eth->phy_scratch_ring + soc->txrx.txd_size * (cnt - 1);
49 for (i = 0; i < cnt; i++) {
50 - eth->scratch_ring[i].txd1 =
51 - (dma_addr + (i * MTK_QDMA_PAGE_SIZE));
52 + struct mtk_tx_dma *txd;
54 + txd = (void *)eth->scratch_ring + i * soc->txrx.txd_size;
55 + txd->txd1 = dma_addr + i * MTK_QDMA_PAGE_SIZE;
57 - eth->scratch_ring[i].txd2 = (eth->phy_scratch_ring +
58 - ((i + 1) * sizeof(struct mtk_tx_dma)));
59 - eth->scratch_ring[i].txd3 = TX_DMA_SDL(MTK_QDMA_PAGE_SIZE);
60 + txd->txd2 = eth->phy_scratch_ring +
61 + (i + 1) * soc->txrx.txd_size;
63 + txd->txd3 = TX_DMA_PLEN0(MTK_QDMA_PAGE_SIZE);
67 mtk_w32(eth, eth->phy_scratch_ring, MTK_QDMA_FQ_HEAD);
68 @@ -2169,6 +2172,7 @@ static int mtk_dma_init(struct mtk_eth *
70 static void mtk_dma_free(struct mtk_eth *eth)
72 + const struct mtk_soc_data *soc = eth->soc;
75 for (i = 0; i < MTK_MAC_COUNT; i++)
76 @@ -2176,9 +2180,8 @@ static void mtk_dma_free(struct mtk_eth
77 netdev_reset_queue(eth->netdev[i]);
78 if (eth->scratch_ring) {
79 dma_free_coherent(eth->dma_dev,
80 - MTK_DMA_SIZE * sizeof(struct mtk_tx_dma),
82 - eth->phy_scratch_ring);
83 + MTK_DMA_SIZE * soc->txrx.txd_size,
84 + eth->scratch_ring, eth->phy_scratch_ring);
85 eth->scratch_ring = NULL;
86 eth->phy_scratch_ring = 0;
88 @@ -3390,6 +3393,9 @@ static const struct mtk_soc_data mt2701_
89 .hw_features = MTK_HW_FEATURES,
90 .required_clks = MT7623_CLKS_BITMAP,
91 .required_pctl = true,
93 + .txd_size = sizeof(struct mtk_tx_dma),
97 static const struct mtk_soc_data mt7621_data = {
98 @@ -3398,6 +3404,9 @@ static const struct mtk_soc_data mt7621_
99 .required_clks = MT7621_CLKS_BITMAP,
100 .required_pctl = false,
101 .offload_version = 2,
103 + .txd_size = sizeof(struct mtk_tx_dma),
107 static const struct mtk_soc_data mt7622_data = {
108 @@ -3407,6 +3416,9 @@ static const struct mtk_soc_data mt7622_
109 .required_clks = MT7622_CLKS_BITMAP,
110 .required_pctl = false,
111 .offload_version = 2,
113 + .txd_size = sizeof(struct mtk_tx_dma),
117 static const struct mtk_soc_data mt7623_data = {
118 @@ -3415,6 +3427,9 @@ static const struct mtk_soc_data mt7623_
119 .required_clks = MT7623_CLKS_BITMAP,
120 .required_pctl = true,
121 .offload_version = 2,
123 + .txd_size = sizeof(struct mtk_tx_dma),
127 static const struct mtk_soc_data mt7629_data = {
128 @@ -3423,6 +3438,9 @@ static const struct mtk_soc_data mt7629_
129 .hw_features = MTK_HW_FEATURES,
130 .required_clks = MT7629_CLKS_BITMAP,
131 .required_pctl = false,
133 + .txd_size = sizeof(struct mtk_tx_dma),
137 static const struct mtk_soc_data rt5350_data = {
138 @@ -3430,6 +3448,9 @@ static const struct mtk_soc_data rt5350_
139 .hw_features = MTK_HW_FEATURES_MT7628,
140 .required_clks = MT7628_CLKS_BITMAP,
141 .required_pctl = false,
143 + .txd_size = sizeof(struct mtk_tx_dma),
147 const struct of_device_id of_mtk_match[] = {
148 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
149 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
150 @@ -863,6 +863,7 @@ struct mtk_tx_dma_desc_info {
152 * @required_pctl A bool value to show whether the SoC requires
153 * the extra setup for those pins used by GMAC.
154 + * @txd_size Tx DMA descriptor size.
156 struct mtk_soc_data {
158 @@ -871,6 +872,9 @@ struct mtk_soc_data {
161 netdev_features_t hw_features;
167 /* currently no SoC has more than 2 macs */