if (interface == PHY_INTERFACE_MODE_SGMII ||
phy_interface_mode_is_8023z(interface)) {
sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
-@@ -543,21 +584,13 @@ static struct phylink_pcs *mtk_mac_selec
- }
+@@ -559,6 +600,9 @@ static int mtk_mac_prepare(struct phylin
+ MTK_XGMAC_FORCE_MODE(mac->id), MTK_XGMAC_STS(mac->id));
+ }
- static int mtk_mac_prepare(struct phylink_config *config, unsigned int mode,
-- phy_interface_t iface)
-+ phy_interface_t interface)
- {
- struct mtk_mac *mac = container_of(config, struct mtk_mac,
- phylink_config);
-- struct mtk_eth *eth = mac->hw;
-
-- if (mtk_interface_mode_is_xgmii(eth, iface) &&
-- mac->id != MTK_GMAC1_ID) {
-- mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE,
-- XMAC_MCR_TRX_DISABLE, MTK_XMAC_MCR(mac->id));
--
-- mtk_m32(mac->hw, MTK_XGMAC_FORCE_MODE(mac->id) |
-- MTK_XGMAC_FORCE_LINK(mac->id),
-- MTK_XGMAC_FORCE_MODE(mac->id), MTK_XGMAC_STS(mac->id));
-- }
-+ if (mac->pextp && mac->interface != interface)
++ if (mac->pextp && mac->interface != iface)
+ phy_reset(mac->pextp);
-
++
return 0;
}
-@@ -602,6 +635,15 @@ static void mtk_mac_config(struct phylin
+
+@@ -602,6 +646,15 @@ static void mtk_mac_config(struct phylin
goto init_err;
}
break;
case PHY_INTERFACE_MODE_INTERNAL:
if (mac->id == MTK_GMAC2_ID &&
MTK_HAS_CAPS(eth->soc->caps, MTK_2P5GPHY)) {
-@@ -655,8 +697,6 @@ static void mtk_mac_config(struct phylin
+@@ -655,8 +708,6 @@ static void mtk_mac_config(struct phylin
val &= ~SYSCFG0_GE_MODE(SYSCFG0_GE_MASK, mac->id);
val |= SYSCFG0_GE_MODE(ge_mode, mac->id);
regmap_write(eth->ethsys, ETHSYS_SYSCFG0, val);
}
/* SGMII */
-@@ -673,21 +713,40 @@ static void mtk_mac_config(struct phylin
+@@ -673,21 +724,40 @@ static void mtk_mac_config(struct phylin
/* Save the syscfg0 value for mac_finish */
mac->syscfg0 = val;
+ if (mtk_interface_mode_is_xgmii(eth, state->interface)) {
+ mtk_w32(mac->hw, MTK_GDMA_XGDM_SEL, MTK_GDMA_EG_CTRL(mac->id));
+ mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
-
-- if (mac->id == MTK_GMAC1_ID)
-- mtk_setup_bridge_switch(eth);
++
+ if (mac->id == MTK_GMAC1_ID)
+ mtk_setup_bridge_switch(eth);
+ } else {
+ mtk_w32(eth, 0, MTK_GDMA_EG_CTRL(mac->id));
-+
+
+- if (mac->id == MTK_GMAC1_ID)
+- mtk_setup_bridge_switch(eth);
+ /* FIXME: In current hardware design, we have to reset FE
+ * when swtiching XGDM to GDM. Therefore, here trigger an SER
+ * to let GDM go back to the initial state.
return;
err_phy:
-@@ -708,6 +767,10 @@ static int mtk_mac_finish(struct phylink
+@@ -708,6 +778,10 @@ static int mtk_mac_finish(struct phylink
struct mtk_eth *eth = mac->hw;
u32 mcr_cur, mcr_new;
/* Enable SGMII */
if (interface == PHY_INTERFACE_MODE_SGMII ||
phy_interface_mode_is_8023z(interface))
-@@ -734,16 +797,11 @@ static void mtk_mac_link_down(struct phy
- phylink_config);
-
- if (!mtk_interface_mode_is_xgmii(mac->hw, interface)) {
-- /* GMAC modes */
-- mtk_m32(mac->hw,
-- MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK, 0,
-- MTK_MAC_MCR(mac->id));
-- } else if (mac->id != MTK_GMAC1_ID) {
-- /* XGMAC except for built-in switch */
-- mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, XMAC_MCR_TRX_DISABLE,
-- MTK_XMAC_MCR(mac->id));
-- mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0,
-- MTK_XGMAC_STS(mac->id));
-+ mtk_m32(mac->hw, MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK, 0, MTK_MAC_MCR(mac->id));
-+ if (mtk_is_netsys_v3_or_greater(mac->hw))
-+ mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0, MTK_XGMAC_STS(mac->id));
-+ } else if (mtk_is_netsys_v3_or_greater(mac->hw) && mac->id != MTK_GMAC1_ID) {
-+ mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, XMAC_MCR_TRX_DISABLE, MTK_XMAC_MCR(mac->id));
- }
- }
-
-@@ -858,10 +916,9 @@ static void mtk_gdm_mac_link_up(struct m
- static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
- struct phy_device *phy,
- unsigned int mode, phy_interface_t interface,
-- int speed, int duplex, bool tx_pause,
-- bool rx_pause)
-+ int speed, int duplex, bool tx_pause, bool rx_pause)
+@@ -861,7 +935,7 @@ static void mtk_xgdm_mac_link_up(struct
+ int speed, int duplex, bool tx_pause,
+ bool rx_pause)
{
- u32 mcr;
+ u32 mcr, force_link = 0;
if (mac->id == MTK_GMAC1_ID)
return;
-@@ -869,15 +926,15 @@ static void mtk_xgdm_mac_link_up(struct
- /* Eliminate the interference(before link-up) caused by PHY noise */
- mtk_m32(mac->hw, XMAC_LOGIC_RST, 0, MTK_XMAC_LOGIC_RST(mac->id));
- mdelay(20);
-- mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR,
-- MTK_XMAC_CNT_CTRL(mac->id));
-+ mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR, MTK_XMAC_CNT_CTRL(mac->id));
+@@ -872,8 +946,10 @@ static void mtk_xgdm_mac_link_up(struct
+ mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR,
+ MTK_XMAC_CNT_CTRL(mac->id));
- mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id),
- MTK_XGMAC_FORCE_LINK(mac->id), MTK_XGMAC_STS(mac->id));
+ mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), force_link, MTK_XGMAC_STS(mac->id));
mcr = mtk_r32(mac->hw, MTK_XMAC_MCR(mac->id));
-- mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC |
-- XMAC_MCR_TRX_DISABLE);
-+ mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC | XMAC_MCR_TRX_DISABLE);
- /* Configure pause modes -
- * phylink will avoid these for half duplex
- */
-@@ -903,8 +960,13 @@ static void mtk_mac_link_up(struct phyli
+ mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC |
+@@ -903,6 +979,10 @@ static void mtk_mac_link_up(struct phyli
else
mtk_gdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
tx_pause, rx_pause);
+ phy_set_mode_ext(mac->pextp, PHY_MODE_ETHERNET, interface);
}
-+
static void mtk_mac_disable_tx_lpi(struct phylink_config *config)
- {
- struct mtk_mac *mac = container_of(config, struct mtk_mac,
-@@ -3765,6 +3827,9 @@ static int mtk_open(struct net_device *d
+@@ -3765,6 +3845,9 @@ static int mtk_open(struct net_device *d
ppe_num = eth->soc->ppe_num;
err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
if (err) {
netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
-@@ -3912,6 +3977,9 @@ static int mtk_stop(struct net_device *d
+@@ -3912,6 +3995,9 @@ static int mtk_stop(struct net_device *d
for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
mtk_ppe_stop(eth->ppe[i]);
return 0;
}
-@@ -4968,6 +5036,7 @@ static const struct net_device_ops mtk_n
+@@ -4968,6 +5054,7 @@ static const struct net_device_ops mtk_n
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const __be32 *_id = of_get_property(np, "reg", NULL);
phy_interface_t phy_mode;
struct phylink *phylink;
struct mtk_mac *mac;
-@@ -5004,16 +5073,44 @@ static int mtk_add_mac(struct mtk_eth *e
+@@ -5004,16 +5091,44 @@ static int mtk_add_mac(struct mtk_eth *e
mac->id = id;
mac->hw = eth;
mac->of_node = np;
}
memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
-@@ -5099,8 +5196,21 @@ static int mtk_add_mac(struct mtk_eth *e
+@@ -5099,8 +5214,21 @@ static int mtk_add_mac(struct mtk_eth *e
phy_interface_zero(mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
mac->phylink_config.supported_interfaces);
phylink = phylink_create(&mac->phylink_config,
of_fwnode_handle(mac->of_node),
phy_mode, &mtk_phylink_ops);
-@@ -5156,6 +5266,26 @@ free_netdev:
+@@ -5156,6 +5284,26 @@ free_netdev:
return err;
}
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
{
struct net_device *dev, *tmp;
-@@ -5309,7 +5439,8 @@ static int mtk_probe(struct platform_dev
+@@ -5309,7 +5457,8 @@ static int mtk_probe(struct platform_dev
regmap_write(cci, 0, 3);
}
err = mtk_sgmii_init(eth);
if (err)
-@@ -5418,6 +5549,24 @@ static int mtk_probe(struct platform_dev
+@@ -5418,6 +5567,24 @@ static int mtk_probe(struct platform_dev
}
}
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
err = devm_request_irq(eth->dev, eth->irq[MTK_FE_IRQ_SHARED],
mtk_handle_irq, 0,
-@@ -5528,6 +5677,11 @@ static void mtk_remove(struct platform_d
+@@ -5528,6 +5695,11 @@ static void mtk_remove(struct platform_d
mtk_stop(eth->netdev[i]);
mac = netdev_priv(eth->netdev[i]);
phylink_disconnect_phy(mac->phylink);
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -5715,7 +5715,7 @@ static const struct mtk_soc_data mt2701_
+@@ -5733,7 +5733,7 @@ static const struct mtk_soc_data mt2701_
DESC_SIZE(struct mtk_rx_dma),
.irq_done_mask = MTK_RX_DONE_INT,
.dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
-@@ -5743,7 +5743,7 @@ static const struct mtk_soc_data mt7621_
+@@ -5761,7 +5761,7 @@ static const struct mtk_soc_data mt7621_
DESC_SIZE(struct mtk_rx_dma),
.irq_done_mask = MTK_RX_DONE_INT,
.dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
-@@ -5773,7 +5773,7 @@ static const struct mtk_soc_data mt7622_
+@@ -5791,7 +5791,7 @@ static const struct mtk_soc_data mt7622_
DESC_SIZE(struct mtk_rx_dma),
.irq_done_mask = MTK_RX_DONE_INT,
.dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
-@@ -5802,7 +5802,7 @@ static const struct mtk_soc_data mt7623_
+@@ -5820,7 +5820,7 @@ static const struct mtk_soc_data mt7623_
DESC_SIZE(struct mtk_rx_dma),
.irq_done_mask = MTK_RX_DONE_INT,
.dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
-@@ -5828,7 +5828,7 @@ static const struct mtk_soc_data mt7629_
+@@ -5846,7 +5846,7 @@ static const struct mtk_soc_data mt7629_
DESC_SIZE(struct mtk_rx_dma),
.irq_done_mask = MTK_RX_DONE_INT,
.dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
-@@ -5860,7 +5860,7 @@ static const struct mtk_soc_data mt7981_
+@@ -5878,7 +5878,7 @@ static const struct mtk_soc_data mt7981_
.dma_l4_valid = RX_DMA_L4_VALID_V2,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
};
-@@ -5890,7 +5890,7 @@ static const struct mtk_soc_data mt7986_
+@@ -5908,7 +5908,7 @@ static const struct mtk_soc_data mt7986_
.dma_l4_valid = RX_DMA_L4_VALID_V2,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
};
-@@ -5943,7 +5943,7 @@ static const struct mtk_soc_data rt5350_
+@@ -5961,7 +5961,7 @@ static const struct mtk_soc_data rt5350_
.dma_l4_valid = RX_DMA_L4_VALID_PDMA,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,