Skip to content

Commit 23c167a

Browse files
committed
Merge branch 'net-ethernet-mtk_eth_soc-improve-support-for-mt7988'
Daniel Golle says: ==================== net: ethernet: mtk_eth_soc: improve support for MT7988 This series fixes and completes commit 445eb64 ("net: ethernet: mtk_eth_soc: add basic support for MT7988 SoC") and also adds support for using the in-SoC SRAM to previous MT7986 and MT7981 SoCs. ==================== Link: https://lore.kernel.org/r/cover.1692721443.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents e83fabb + 2d75891 commit 23c167a

File tree

2 files changed

+196
-50
lines changed

2 files changed

+196
-50
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 153 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,10 +1135,13 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
11351135
dma_addr_t dma_addr;
11361136
int i;
11371137

1138-
eth->scratch_ring = dma_alloc_coherent(eth->dma_dev,
1139-
cnt * soc->txrx.txd_size,
1140-
&eth->phy_scratch_ring,
1141-
GFP_KERNEL);
1138+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SRAM))
1139+
eth->scratch_ring = eth->sram_base;
1140+
else
1141+
eth->scratch_ring = dma_alloc_coherent(eth->dma_dev,
1142+
cnt * soc->txrx.txd_size,
1143+
&eth->phy_scratch_ring,
1144+
GFP_KERNEL);
11421145
if (unlikely(!eth->scratch_ring))
11431146
return -ENOMEM;
11441147

@@ -1325,6 +1328,10 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,
13251328
data = TX_DMA_PLEN0(info->size);
13261329
if (info->last)
13271330
data |= TX_DMA_LS0;
1331+
1332+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
1333+
data |= TX_DMA_PREP_ADDR64(info->addr);
1334+
13281335
WRITE_ONCE(desc->txd3, data);
13291336

13301337
/* set forward port */
@@ -1994,6 +2001,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
19942001
bool xdp_flush = false;
19952002
int idx;
19962003
struct sk_buff *skb;
2004+
u64 addr64 = 0;
19972005
u8 *data, *new_data;
19982006
struct mtk_rx_dma_v2 *rxd, trxd;
19992007
int done = 0, bytes = 0;
@@ -2109,7 +2117,10 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
21092117
goto release_desc;
21102118
}
21112119

2112-
dma_unmap_single(eth->dma_dev, trxd.rxd1,
2120+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
2121+
addr64 = RX_DMA_GET_ADDR64(trxd.rxd2);
2122+
2123+
dma_unmap_single(eth->dma_dev, ((u64)trxd.rxd1 | addr64),
21132124
ring->buf_size, DMA_FROM_DEVICE);
21142125

21152126
skb = build_skb(data, ring->frag_size);
@@ -2175,6 +2186,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
21752186
else
21762187
rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
21772188

2189+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
2190+
rxd->rxd2 |= RX_DMA_PREP_ADDR64(dma_addr);
2191+
21782192
ring->calc_idx = idx;
21792193
done++;
21802194
}
@@ -2446,8 +2460,14 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
24462460
if (!ring->buf)
24472461
goto no_tx_mem;
24482462

2449-
ring->dma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
2450-
&ring->phys, GFP_KERNEL);
2463+
if (MTK_HAS_CAPS(soc->caps, MTK_SRAM)) {
2464+
ring->dma = eth->sram_base + ring_size * sz;
2465+
ring->phys = eth->phy_scratch_ring + ring_size * (dma_addr_t)sz;
2466+
} else {
2467+
ring->dma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
2468+
&ring->phys, GFP_KERNEL);
2469+
}
2470+
24512471
if (!ring->dma)
24522472
goto no_tx_mem;
24532473

@@ -2546,8 +2566,7 @@ static void mtk_tx_clean(struct mtk_eth *eth)
25462566
kfree(ring->buf);
25472567
ring->buf = NULL;
25482568
}
2549-
2550-
if (ring->dma) {
2569+
if (!MTK_HAS_CAPS(soc->caps, MTK_SRAM) && ring->dma) {
25512570
dma_free_coherent(eth->dma_dev,
25522571
ring->dma_size * soc->txrx.txd_size,
25532572
ring->dma, ring->phys);
@@ -2566,9 +2585,14 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
25662585
{
25672586
const struct mtk_reg_map *reg_map = eth->soc->reg_map;
25682587
struct mtk_rx_ring *ring;
2569-
int rx_data_len, rx_dma_size;
2588+
int rx_data_len, rx_dma_size, tx_ring_size;
25702589
int i;
25712590

2591+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
2592+
tx_ring_size = MTK_QDMA_RING_SIZE;
2593+
else
2594+
tx_ring_size = MTK_DMA_SIZE;
2595+
25722596
if (rx_flag == MTK_RX_FLAGS_QDMA) {
25732597
if (ring_no)
25742598
return -EINVAL;
@@ -2603,9 +2627,20 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
26032627
ring->page_pool = pp;
26042628
}
26052629

2606-
ring->dma = dma_alloc_coherent(eth->dma_dev,
2607-
rx_dma_size * eth->soc->txrx.rxd_size,
2608-
&ring->phys, GFP_KERNEL);
2630+
if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SRAM) ||
2631+
rx_flag != MTK_RX_FLAGS_NORMAL) {
2632+
ring->dma = dma_alloc_coherent(eth->dma_dev,
2633+
rx_dma_size * eth->soc->txrx.rxd_size,
2634+
&ring->phys, GFP_KERNEL);
2635+
} else {
2636+
struct mtk_tx_ring *tx_ring = &eth->tx_ring;
2637+
2638+
ring->dma = tx_ring->dma + tx_ring_size *
2639+
eth->soc->txrx.txd_size * (ring_no + 1);
2640+
ring->phys = tx_ring->phys + tx_ring_size *
2641+
eth->soc->txrx.txd_size * (ring_no + 1);
2642+
}
2643+
26092644
if (!ring->dma)
26102645
return -ENOMEM;
26112646

@@ -2646,6 +2681,9 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
26462681
else
26472682
rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
26482683

2684+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
2685+
rxd->rxd2 |= RX_DMA_PREP_ADDR64(dma_addr);
2686+
26492687
rxd->rxd3 = 0;
26502688
rxd->rxd4 = 0;
26512689
if (mtk_is_netsys_v2_or_greater(eth)) {
@@ -2690,8 +2728,9 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
26902728
return 0;
26912729
}
26922730

2693-
static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring)
2731+
static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring, bool in_sram)
26942732
{
2733+
u64 addr64 = 0;
26952734
int i;
26962735

26972736
if (ring->data && ring->dma) {
@@ -2705,15 +2744,18 @@ static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring)
27052744
if (!rxd->rxd1)
27062745
continue;
27072746

2708-
dma_unmap_single(eth->dma_dev, rxd->rxd1,
2747+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
2748+
addr64 = RX_DMA_GET_ADDR64(rxd->rxd2);
2749+
2750+
dma_unmap_single(eth->dma_dev, ((u64)rxd->rxd1 | addr64),
27092751
ring->buf_size, DMA_FROM_DEVICE);
27102752
mtk_rx_put_buff(ring, ring->data[i], false);
27112753
}
27122754
kfree(ring->data);
27132755
ring->data = NULL;
27142756
}
27152757

2716-
if (ring->dma) {
2758+
if (!in_sram && ring->dma) {
27172759
dma_free_coherent(eth->dma_dev,
27182760
ring->dma_size * eth->soc->txrx.rxd_size,
27192761
ring->dma, ring->phys);
@@ -3073,21 +3115,21 @@ static void mtk_dma_free(struct mtk_eth *eth)
30733115
for (i = 0; i < MTK_MAX_DEVS; i++)
30743116
if (eth->netdev[i])
30753117
netdev_reset_queue(eth->netdev[i]);
3076-
if (eth->scratch_ring) {
3118+
if (!MTK_HAS_CAPS(soc->caps, MTK_SRAM) && eth->scratch_ring) {
30773119
dma_free_coherent(eth->dma_dev,
30783120
MTK_QDMA_RING_SIZE * soc->txrx.txd_size,
30793121
eth->scratch_ring, eth->phy_scratch_ring);
30803122
eth->scratch_ring = NULL;
30813123
eth->phy_scratch_ring = 0;
30823124
}
30833125
mtk_tx_clean(eth);
3084-
mtk_rx_clean(eth, &eth->rx_ring[0]);
3085-
mtk_rx_clean(eth, &eth->rx_ring_qdma);
3126+
mtk_rx_clean(eth, &eth->rx_ring[0], MTK_HAS_CAPS(soc->caps, MTK_SRAM));
3127+
mtk_rx_clean(eth, &eth->rx_ring_qdma, false);
30863128

30873129
if (eth->hwlro) {
30883130
mtk_hwlro_rx_uninit(eth);
30893131
for (i = 1; i < MTK_MAX_RX_RING_NUM; i++)
3090-
mtk_rx_clean(eth, &eth->rx_ring[i]);
3132+
mtk_rx_clean(eth, &eth->rx_ring[i], false);
30913133
}
30923134

30933135
kfree(eth->scratch_head);
@@ -3613,19 +3655,34 @@ static void mtk_hw_reset(struct mtk_eth *eth)
36133655
{
36143656
u32 val;
36153657

3616-
if (mtk_is_netsys_v2_or_greater(eth)) {
3658+
if (mtk_is_netsys_v2_or_greater(eth))
36173659
regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0);
3660+
3661+
if (mtk_is_netsys_v3_or_greater(eth)) {
3662+
val = RSTCTRL_PPE0_V3;
3663+
3664+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3665+
val |= RSTCTRL_PPE1_V3;
3666+
3667+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
3668+
val |= RSTCTRL_PPE2;
3669+
3670+
val |= RSTCTRL_WDMA0 | RSTCTRL_WDMA1 | RSTCTRL_WDMA2;
3671+
} else if (mtk_is_netsys_v2_or_greater(eth)) {
36183672
val = RSTCTRL_PPE0_V2;
3673+
3674+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3675+
val |= RSTCTRL_PPE1;
36193676
} else {
36203677
val = RSTCTRL_PPE0;
36213678
}
36223679

3623-
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3624-
val |= RSTCTRL_PPE1;
3625-
36263680
ethsys_reset(eth, RSTCTRL_ETH | RSTCTRL_FE | val);
36273681

3628-
if (mtk_is_netsys_v2_or_greater(eth))
3682+
if (mtk_is_netsys_v3_or_greater(eth))
3683+
regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN,
3684+
0x6f8ff);
3685+
else if (mtk_is_netsys_v2_or_greater(eth))
36293686
regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN,
36303687
0x3ffffff);
36313688
}
@@ -3651,13 +3708,21 @@ static void mtk_hw_warm_reset(struct mtk_eth *eth)
36513708
return;
36523709
}
36533710

3654-
if (mtk_is_netsys_v2_or_greater(eth))
3711+
if (mtk_is_netsys_v3_or_greater(eth)) {
3712+
rst_mask = RSTCTRL_ETH | RSTCTRL_PPE0_V3;
3713+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3714+
rst_mask |= RSTCTRL_PPE1_V3;
3715+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
3716+
rst_mask |= RSTCTRL_PPE2;
3717+
3718+
rst_mask |= RSTCTRL_WDMA0 | RSTCTRL_WDMA1 | RSTCTRL_WDMA2;
3719+
} else if (mtk_is_netsys_v2_or_greater(eth)) {
36553720
rst_mask = RSTCTRL_ETH | RSTCTRL_PPE0_V2;
3656-
else
3721+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3722+
rst_mask |= RSTCTRL_PPE1;
3723+
} else {
36573724
rst_mask = RSTCTRL_ETH | RSTCTRL_PPE0;
3658-
3659-
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
3660-
rst_mask |= RSTCTRL_PPE1;
3725+
}
36613726

36623727
regmap_update_bits(eth->ethsys, ETHSYS_RSTCTRL, rst_mask, rst_mask);
36633728

@@ -4009,11 +4074,17 @@ static void mtk_prepare_for_reset(struct mtk_eth *eth)
40094074
u32 val;
40104075
int i;
40114076

4012-
/* disabe FE P3 and P4 */
4013-
val = mtk_r32(eth, MTK_FE_GLO_CFG) | MTK_FE_LINK_DOWN_P3;
4014-
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
4015-
val |= MTK_FE_LINK_DOWN_P4;
4016-
mtk_w32(eth, val, MTK_FE_GLO_CFG);
4077+
/* set FE PPE ports link down */
4078+
for (i = MTK_GMAC1_ID;
4079+
i <= (mtk_is_netsys_v3_or_greater(eth) ? MTK_GMAC3_ID : MTK_GMAC2_ID);
4080+
i += 2) {
4081+
val = mtk_r32(eth, MTK_FE_GLO_CFG(i)) | MTK_FE_LINK_DOWN_P(PSE_PPE0_PORT);
4082+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
4083+
val |= MTK_FE_LINK_DOWN_P(PSE_PPE1_PORT);
4084+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
4085+
val |= MTK_FE_LINK_DOWN_P(PSE_PPE2_PORT);
4086+
mtk_w32(eth, val, MTK_FE_GLO_CFG(i));
4087+
}
40174088

40184089
/* adjust PPE configurations to prepare for reset */
40194090
for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
@@ -4074,11 +4145,18 @@ static void mtk_pending_work(struct work_struct *work)
40744145
}
40754146
}
40764147

4077-
/* enabe FE P3 and P4 */
4078-
val = mtk_r32(eth, MTK_FE_GLO_CFG) & ~MTK_FE_LINK_DOWN_P3;
4079-
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
4080-
val &= ~MTK_FE_LINK_DOWN_P4;
4081-
mtk_w32(eth, val, MTK_FE_GLO_CFG);
4148+
/* set FE PPE ports link up */
4149+
for (i = MTK_GMAC1_ID;
4150+
i <= (mtk_is_netsys_v3_or_greater(eth) ? MTK_GMAC3_ID : MTK_GMAC2_ID);
4151+
i += 2) {
4152+
val = mtk_r32(eth, MTK_FE_GLO_CFG(i)) & ~MTK_FE_LINK_DOWN_P(PSE_PPE0_PORT);
4153+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
4154+
val &= ~MTK_FE_LINK_DOWN_P(PSE_PPE1_PORT);
4155+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
4156+
val &= ~MTK_FE_LINK_DOWN_P(PSE_PPE2_PORT);
4157+
4158+
mtk_w32(eth, val, MTK_FE_GLO_CFG(i));
4159+
}
40824160

40834161
clear_bit(MTK_RESETTING, &eth->state);
40844162

@@ -4640,7 +4718,7 @@ static int mtk_sgmii_init(struct mtk_eth *eth)
46404718

46414719
static int mtk_probe(struct platform_device *pdev)
46424720
{
4643-
struct resource *res = NULL;
4721+
struct resource *res = NULL, *res_sram;
46444722
struct device_node *mac_np;
46454723
struct mtk_eth *eth;
46464724
int err, i;
@@ -4660,6 +4738,28 @@ static int mtk_probe(struct platform_device *pdev)
46604738
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
46614739
eth->ip_align = NET_IP_ALIGN;
46624740

4741+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SRAM)) {
4742+
/* SRAM is actual memory and supports transparent access just like DRAM.
4743+
* Hence we don't require __iomem being set and don't need to use accessor
4744+
* functions to read from or write to SRAM.
4745+
*/
4746+
if (mtk_is_netsys_v3_or_greater(eth)) {
4747+
eth->sram_base = (void __force *)devm_platform_ioremap_resource(pdev, 1);
4748+
if (IS_ERR(eth->sram_base))
4749+
return PTR_ERR(eth->sram_base);
4750+
} else {
4751+
eth->sram_base = (void __force *)eth->base + MTK_ETH_SRAM_OFFSET;
4752+
}
4753+
}
4754+
4755+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA)) {
4756+
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(36));
4757+
if (err) {
4758+
dev_err(&pdev->dev, "Wrong DMA config\n");
4759+
return -EINVAL;
4760+
}
4761+
}
4762+
46634763
spin_lock_init(&eth->page_lock);
46644764
spin_lock_init(&eth->tx_irq_lock);
46654765
spin_lock_init(&eth->rx_irq_lock);
@@ -4723,6 +4823,18 @@ static int mtk_probe(struct platform_device *pdev)
47234823
err = -EINVAL;
47244824
goto err_destroy_sgmii;
47254825
}
4826+
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SRAM)) {
4827+
if (mtk_is_netsys_v3_or_greater(eth)) {
4828+
res_sram = platform_get_resource(pdev, IORESOURCE_MEM, 1);
4829+
if (!res_sram) {
4830+
err = -EINVAL;
4831+
goto err_destroy_sgmii;
4832+
}
4833+
eth->phy_scratch_ring = res_sram->start;
4834+
} else {
4835+
eth->phy_scratch_ring = res->start + MTK_ETH_SRAM_OFFSET;
4836+
}
4837+
}
47264838
}
47274839

47284840
if (eth->soc->offload_version) {

0 commit comments

Comments
 (0)