Skip to content

Commit 445eb64

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: ethernet: mtk_eth_soc: add basic support for MT7988 SoC
Introduce support for ethernet chip available in MT7988 SoC to mtk_eth_soc driver. As a first step support only the first GMAC which is hard-wired to the internal DSA switch having 4 built-in gigabit Ethernet PHYs. Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org> Link: https://lore.kernel.org/r/25c8377095b95d186872eeda7aa055da83e8f0ca.1690246605.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c75e416 commit 445eb64

File tree

3 files changed

+273
-28
lines changed

3 files changed

+273
-28
lines changed

drivers/net/ethernet/mediatek/mtk_eth_path.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const char *mtk_eth_path_name(u64 path)
4343
static int set_mux_gdm1_to_gmac1_esw(struct mtk_eth *eth, u64 path)
4444
{
4545
bool updated = true;
46-
u32 val, mask, set;
46+
u32 mask, set, reg;
4747

4848
switch (path) {
4949
case MTK_ETH_PATH_GMAC1_SGMII:
@@ -59,11 +59,13 @@ static int set_mux_gdm1_to_gmac1_esw(struct mtk_eth *eth, u64 path)
5959
break;
6060
}
6161

62-
if (updated) {
63-
val = mtk_r32(eth, MTK_MAC_MISC);
64-
val = (val & mask) | set;
65-
mtk_w32(eth, val, MTK_MAC_MISC);
66-
}
62+
if (mtk_is_netsys_v3_or_greater(eth))
63+
reg = MTK_MAC_MISC_V3;
64+
else
65+
reg = MTK_MAC_MISC;
66+
67+
if (updated)
68+
mtk_m32(eth, mask, set, reg);
6769

6870
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
6971
mtk_eth_path_name(path), __func__, updated);

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 180 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,54 @@ static const struct mtk_reg_map mt7986_reg_map = {
152152
.pse_oq_sta = 0x01a0,
153153
};
154154

155+
static const struct mtk_reg_map mt7988_reg_map = {
156+
.tx_irq_mask = 0x461c,
157+
.tx_irq_status = 0x4618,
158+
.pdma = {
159+
.rx_ptr = 0x6900,
160+
.rx_cnt_cfg = 0x6904,
161+
.pcrx_ptr = 0x6908,
162+
.glo_cfg = 0x6a04,
163+
.rst_idx = 0x6a08,
164+
.delay_irq = 0x6a0c,
165+
.irq_status = 0x6a20,
166+
.irq_mask = 0x6a28,
167+
.adma_rx_dbg0 = 0x6a38,
168+
.int_grp = 0x6a50,
169+
},
170+
.qdma = {
171+
.qtx_cfg = 0x4400,
172+
.qtx_sch = 0x4404,
173+
.rx_ptr = 0x4500,
174+
.rx_cnt_cfg = 0x4504,
175+
.qcrx_ptr = 0x4508,
176+
.glo_cfg = 0x4604,
177+
.rst_idx = 0x4608,
178+
.delay_irq = 0x460c,
179+
.fc_th = 0x4610,
180+
.int_grp = 0x4620,
181+
.hred = 0x4644,
182+
.ctx_ptr = 0x4700,
183+
.dtx_ptr = 0x4704,
184+
.crx_ptr = 0x4710,
185+
.drx_ptr = 0x4714,
186+
.fq_head = 0x4720,
187+
.fq_tail = 0x4724,
188+
.fq_count = 0x4728,
189+
.fq_blen = 0x472c,
190+
.tx_sch_rate = 0x4798,
191+
},
192+
.gdm1_cnt = 0x1c00,
193+
.gdma_to_ppe = 0x3333,
194+
.ppe_base = 0x2000,
195+
.wdma_base = {
196+
[0] = 0x4800,
197+
[1] = 0x4c00,
198+
},
199+
.pse_iq_sta = 0x0180,
200+
.pse_oq_sta = 0x01a0,
201+
};
202+
155203
/* strings used by ethtool */
156204
static const struct mtk_ethtool_stats {
157205
char str[ETH_GSTRING_LEN];
@@ -179,10 +227,54 @@ static const struct mtk_ethtool_stats {
179227
};
180228

181229
static const char * const mtk_clks_source_name[] = {
182-
"ethif", "sgmiitop", "esw", "gp0", "gp1", "gp2", "fe", "trgpll",
183-
"sgmii_tx250m", "sgmii_rx250m", "sgmii_cdr_ref", "sgmii_cdr_fb",
184-
"sgmii2_tx250m", "sgmii2_rx250m", "sgmii2_cdr_ref", "sgmii2_cdr_fb",
185-
"sgmii_ck", "eth2pll", "wocpu0", "wocpu1", "netsys0", "netsys1"
230+
"ethif",
231+
"sgmiitop",
232+
"esw",
233+
"gp0",
234+
"gp1",
235+
"gp2",
236+
"gp3",
237+
"xgp1",
238+
"xgp2",
239+
"xgp3",
240+
"crypto",
241+
"fe",
242+
"trgpll",
243+
"sgmii_tx250m",
244+
"sgmii_rx250m",
245+
"sgmii_cdr_ref",
246+
"sgmii_cdr_fb",
247+
"sgmii2_tx250m",
248+
"sgmii2_rx250m",
249+
"sgmii2_cdr_ref",
250+
"sgmii2_cdr_fb",
251+
"sgmii_ck",
252+
"eth2pll",
253+
"wocpu0",
254+
"wocpu1",
255+
"netsys0",
256+
"netsys1",
257+
"ethwarp_wocpu2",
258+
"ethwarp_wocpu1",
259+
"ethwarp_wocpu0",
260+
"top_usxgmii0_sel",
261+
"top_usxgmii1_sel",
262+
"top_sgm0_sel",
263+
"top_sgm1_sel",
264+
"top_xfi_phy0_xtal_sel",
265+
"top_xfi_phy1_xtal_sel",
266+
"top_eth_gmii_sel",
267+
"top_eth_refck_50m_sel",
268+
"top_eth_sys_200m_sel",
269+
"top_eth_sys_sel",
270+
"top_eth_xgmii_sel",
271+
"top_eth_mii_sel",
272+
"top_netsys_sel",
273+
"top_netsys_500m_sel",
274+
"top_netsys_pao_2x_sel",
275+
"top_netsys_sync_250m_sel",
276+
"top_netsys_ppefb_250m_sel",
277+
"top_netsys_warp_sel",
186278
};
187279

188280
void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg)
@@ -195,7 +287,7 @@ u32 mtk_r32(struct mtk_eth *eth, unsigned reg)
195287
return __raw_readl(eth->base + reg);
196288
}
197289

198-
static u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned reg)
290+
u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned int reg)
199291
{
200292
u32 val;
201293

@@ -400,6 +492,19 @@ static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth,
400492
dev_err(eth->dev, "Missing PLL configuration, ethernet may not work\n");
401493
}
402494

495+
static void mtk_setup_bridge_switch(struct mtk_eth *eth)
496+
{
497+
/* Force Port1 XGMAC Link Up */
498+
mtk_m32(eth, 0, MTK_XGMAC_FORCE_LINK(MTK_GMAC1_ID),
499+
MTK_XGMAC_STS(MTK_GMAC1_ID));
500+
501+
/* Adjust GSW bridge IPG to 11 */
502+
mtk_m32(eth, GSWTX_IPG_MASK | GSWRX_IPG_MASK,
503+
(GSW_IPG_11 << GSWTX_IPG_SHIFT) |
504+
(GSW_IPG_11 << GSWRX_IPG_SHIFT),
505+
MTK_GSW_CFG);
506+
}
507+
403508
static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config,
404509
phy_interface_t interface)
405510
{
@@ -459,6 +564,8 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
459564
goto init_err;
460565
}
461566
break;
567+
case PHY_INTERFACE_MODE_INTERNAL:
568+
break;
462569
default:
463570
goto err_phy;
464571
}
@@ -528,6 +635,15 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
528635
return;
529636
}
530637

638+
/* Setup gmac */
639+
if (mtk_is_netsys_v3_or_greater(eth) &&
640+
mac->interface == PHY_INTERFACE_MODE_INTERNAL) {
641+
mtk_w32(mac->hw, MTK_GDMA_XGDM_SEL, MTK_GDMA_EG_CTRL(mac->id));
642+
mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
643+
644+
mtk_setup_bridge_switch(eth);
645+
}
646+
531647
return;
532648

533649
err_phy:
@@ -740,11 +856,15 @@ static int mtk_mdio_init(struct mtk_eth *eth)
740856
}
741857
divider = min_t(unsigned int, DIV_ROUND_UP(MDC_MAX_FREQ, max_clk), 63);
742858

859+
/* Configure MDC Turbo Mode */
860+
if (mtk_is_netsys_v3_or_greater(eth))
861+
mtk_m32(eth, 0, MISC_MDC_TURBO, MTK_MAC_MISC_V3);
862+
743863
/* Configure MDC Divider */
744-
val = mtk_r32(eth, MTK_PPSC);
745-
val &= ~PPSC_MDC_CFG;
746-
val |= FIELD_PREP(PPSC_MDC_CFG, divider) | PPSC_MDC_TURBO;
747-
mtk_w32(eth, val, MTK_PPSC);
864+
val = FIELD_PREP(PPSC_MDC_CFG, divider);
865+
if (!mtk_is_netsys_v3_or_greater(eth))
866+
val |= PPSC_MDC_TURBO;
867+
mtk_m32(eth, PPSC_MDC_CFG, val, MTK_PPSC);
748868

749869
dev_dbg(eth->dev, "MDC is running on %d Hz\n", MDC_MAX_FREQ / divider);
750870

@@ -1205,10 +1325,19 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,
12051325
data |= TX_DMA_LS0;
12061326
WRITE_ONCE(desc->txd3, data);
12071327

1208-
if (mac->id == MTK_GMAC3_ID)
1209-
data = PSE_GDM3_PORT;
1210-
else
1211-
data = (mac->id + 1) << TX_DMA_FPORT_SHIFT_V2; /* forward port */
1328+
/* set forward port */
1329+
switch (mac->id) {
1330+
case MTK_GMAC1_ID:
1331+
data = PSE_GDM1_PORT << TX_DMA_FPORT_SHIFT_V2;
1332+
break;
1333+
case MTK_GMAC2_ID:
1334+
data = PSE_GDM2_PORT << TX_DMA_FPORT_SHIFT_V2;
1335+
break;
1336+
case MTK_GMAC3_ID:
1337+
data = PSE_GDM3_PORT << TX_DMA_FPORT_SHIFT_V2;
1338+
break;
1339+
}
1340+
12121341
data |= TX_DMA_SWC_V2 | QID_BITS_V2(info->qid);
12131342
WRITE_ONCE(desc->txd4, data);
12141343

@@ -4387,6 +4516,17 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
43874516
mac->phylink_config.supported_interfaces);
43884517
}
43894518

4519+
if (mtk_is_netsys_v3_or_greater(mac->hw) &&
4520+
MTK_HAS_CAPS(mac->hw->soc->caps, MTK_ESW_BIT) &&
4521+
id == MTK_GMAC1_ID) {
4522+
mac->phylink_config.mac_capabilities = MAC_ASYM_PAUSE |
4523+
MAC_SYM_PAUSE |
4524+
MAC_10000FD;
4525+
phy_interface_zero(mac->phylink_config.supported_interfaces);
4526+
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
4527+
mac->phylink_config.supported_interfaces);
4528+
}
4529+
43904530
phylink = phylink_create(&mac->phylink_config,
43914531
of_fwnode_handle(mac->of_node),
43924532
phy_mode, &mtk_phylink_ops);
@@ -4913,6 +5053,24 @@ static const struct mtk_soc_data mt7986_data = {
49135053
},
49145054
};
49155055

5056+
static const struct mtk_soc_data mt7988_data = {
5057+
.reg_map = &mt7988_reg_map,
5058+
.ana_rgc3 = 0x128,
5059+
.caps = MT7988_CAPS,
5060+
.hw_features = MTK_HW_FEATURES,
5061+
.required_clks = MT7988_CLKS_BITMAP,
5062+
.required_pctl = false,
5063+
.version = 3,
5064+
.txrx = {
5065+
.txd_size = sizeof(struct mtk_tx_dma_v2),
5066+
.rxd_size = sizeof(struct mtk_rx_dma_v2),
5067+
.rx_irq_done_mask = MTK_RX_DONE_INT_V2,
5068+
.rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
5069+
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
5070+
.dma_len_offset = 8,
5071+
},
5072+
};
5073+
49165074
static const struct mtk_soc_data rt5350_data = {
49175075
.reg_map = &mt7628_reg_map,
49185076
.caps = MT7628_CAPS,
@@ -4931,14 +5089,15 @@ static const struct mtk_soc_data rt5350_data = {
49315089
};
49325090

49335091
const struct of_device_id of_mtk_match[] = {
4934-
{ .compatible = "mediatek,mt2701-eth", .data = &mt2701_data},
4935-
{ .compatible = "mediatek,mt7621-eth", .data = &mt7621_data},
4936-
{ .compatible = "mediatek,mt7622-eth", .data = &mt7622_data},
4937-
{ .compatible = "mediatek,mt7623-eth", .data = &mt7623_data},
4938-
{ .compatible = "mediatek,mt7629-eth", .data = &mt7629_data},
4939-
{ .compatible = "mediatek,mt7981-eth", .data = &mt7981_data},
4940-
{ .compatible = "mediatek,mt7986-eth", .data = &mt7986_data},
4941-
{ .compatible = "ralink,rt5350-eth", .data = &rt5350_data},
5092+
{ .compatible = "mediatek,mt2701-eth", .data = &mt2701_data },
5093+
{ .compatible = "mediatek,mt7621-eth", .data = &mt7621_data },
5094+
{ .compatible = "mediatek,mt7622-eth", .data = &mt7622_data },
5095+
{ .compatible = "mediatek,mt7623-eth", .data = &mt7623_data },
5096+
{ .compatible = "mediatek,mt7629-eth", .data = &mt7629_data },
5097+
{ .compatible = "mediatek,mt7981-eth", .data = &mt7981_data },
5098+
{ .compatible = "mediatek,mt7986-eth", .data = &mt7986_data },
5099+
{ .compatible = "mediatek,mt7988-eth", .data = &mt7988_data },
5100+
{ .compatible = "ralink,rt5350-eth", .data = &rt5350_data },
49425101
{},
49435102
};
49445103
MODULE_DEVICE_TABLE(of, of_mtk_match);

0 commit comments

Comments
 (0)