kernel: mtk_eth_soc: release MAC_MCR_FORCE_LINK only when MAC is up
[openwrt/staging/nbd.git] / target / linux / generic / pending-6.1 / 737-net-ethernet-mtk_eth_soc-add-paths-and-SerDes-modes-.patch
index afe561ab31f5cf6c082557154b21c6555e283563..2b379c915867d99e999bc636d770c397d419efb0 100644 (file)
@@ -1,4 +1,4 @@
-From 91bda2f441f9e37273922028ffc48ce8e91bf5bd Mon Sep 17 00:00:00 2001
+From d5e337e7aecc2e1cc9e96768062610adb95f8f72 Mon Sep 17 00:00:00 2001
 From: Daniel Golle <daniel@makrotopia.org>
 Date: Tue, 12 Dec 2023 03:51:14 +0000
 Subject: [PATCH] net: ethernet: mtk_eth_soc: add paths and SerDes modes for
@@ -19,9 +19,9 @@ modes.
 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
 ---
  drivers/net/ethernet/mediatek/mtk_eth_path.c | 122 +++++++-
- drivers/net/ethernet/mediatek/mtk_eth_soc.c  | 291 +++++++++++++++++--
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c  | 292 +++++++++++++++++--
  drivers/net/ethernet/mediatek/mtk_eth_soc.h  | 107 ++++++-
- 3 files changed, 469 insertions(+), 51 deletions(-)
+ 3 files changed, 470 insertions(+), 51 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_path.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_path.c
@@ -390,24 +390,25 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        /* Enable SGMII */
        if (interface == PHY_INTERFACE_MODE_SGMII ||
            phy_interface_mode_is_8023z(interface))
-@@ -677,10 +762,13 @@ static void mtk_mac_link_down(struct phy
+@@ -676,10 +761,14 @@ static void mtk_mac_link_down(struct phy
  {
        struct mtk_mac *mac = container_of(config, struct mtk_mac,
                                           phylink_config);
 -      u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  
--      mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN);
+-      mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK);
 -      mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
 +      if (!mtk_interface_mode_is_xgmii(interface)) {
-+              mtk_m32(mac->hw, MAC_MCR_TX_EN | MAC_MCR_RX_EN, 0, MTK_MAC_MCR(mac->id));
-+              mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0, MTK_XGMAC_STS(mac->id));
-+      } else if (mac->id != MTK_GMAC1_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));
 +      }
  }
  
  static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx,
-@@ -752,13 +840,11 @@ static void mtk_set_queue_speed(struct m
+@@ -751,13 +840,11 @@ static void mtk_set_queue_speed(struct m
        mtk_w32(eth, val, soc->reg_map->qdma.qtx_sch + ofs);
  }
  
@@ -425,7 +426,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        u32 mcr;
  
        mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
-@@ -792,9 +878,63 @@ static void mtk_mac_link_up(struct phyli
+@@ -791,9 +878,63 @@ static void mtk_mac_link_up(struct phyli
        mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
  }
  
@@ -470,7 +471,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
 +      struct mtk_mac *mac = container_of(config, struct mtk_mac,
 +                                         phylink_config);
 +
-+      if (mtk_interface_mode_is_xgmii(interface))
++      if (mtk_is_netsys_v3_or_greater(mac->hw) && mtk_interface_mode_is_xgmii(interface))
 +              mtk_xgdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
 +                                   tx_pause, rx_pause);
 +      else
@@ -489,7 +490,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        .mac_finish = mtk_mac_finish,
        .mac_link_down = mtk_mac_link_down,
        .mac_link_up = mtk_mac_link_up,
-@@ -3373,6 +3513,9 @@ static int mtk_open(struct net_device *d
+@@ -3372,6 +3513,9 @@ static int mtk_open(struct net_device *d
        struct mtk_eth *eth = mac->hw;
        int i, err;
  
@@ -499,7 +500,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
        if (err) {
                netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
-@@ -3501,6 +3644,9 @@ static int mtk_stop(struct net_device *d
+@@ -3500,6 +3644,9 @@ static int mtk_stop(struct net_device *d
        for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
                mtk_ppe_stop(eth->ppe[i]);
  
@@ -509,7 +510,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        return 0;
  }
  
-@@ -4498,6 +4644,7 @@ static const struct net_device_ops mtk_n
+@@ -4497,6 +4644,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);
@@ -517,7 +518,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        phy_interface_t phy_mode;
        struct phylink *phylink;
        struct mtk_mac *mac;
-@@ -4533,16 +4680,41 @@ static int mtk_add_mac(struct mtk_eth *e
+@@ -4532,16 +4680,41 @@ static int mtk_add_mac(struct mtk_eth *e
        mac->id = id;
        mac->hw = eth;
        mac->of_node = np;
@@ -567,7 +568,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        }
  
        memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
-@@ -4616,8 +4788,21 @@ static int mtk_add_mac(struct mtk_eth *e
+@@ -4615,8 +4788,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);
@@ -589,7 +590,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        phylink = phylink_create(&mac->phylink_config,
                                 of_fwnode_handle(mac->of_node),
                                 phy_mode, &mtk_phylink_ops);
-@@ -4662,6 +4847,26 @@ free_netdev:
+@@ -4661,6 +4847,26 @@ free_netdev:
        return err;
  }
  
@@ -616,7 +617,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
  {
        struct net_device *dev, *tmp;
-@@ -4805,7 +5010,8 @@ static int mtk_probe(struct platform_dev
+@@ -4804,7 +5010,8 @@ static int mtk_probe(struct platform_dev
                        regmap_write(cci, 0, 3);
        }
  
@@ -626,7 +627,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
                err = mtk_sgmii_init(eth);
  
                if (err)
-@@ -4916,6 +5122,24 @@ static int mtk_probe(struct platform_dev
+@@ -4915,6 +5122,24 @@ static int mtk_probe(struct platform_dev
                }
        }
  
@@ -651,7 +652,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
        if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
                err = devm_request_irq(eth->dev, eth->irq[0],
                                       mtk_handle_irq, 0,
-@@ -5018,6 +5242,11 @@ static int mtk_remove(struct platform_de
+@@ -5017,6 +5242,11 @@ static int mtk_remove(struct platform_de
                mtk_stop(eth->netdev[i]);
                mac = netdev_priv(eth->netdev[i]);
                phylink_disconnect_phy(mac->phylink);