257cfdec4ae3b81964cd57dfd36dfed0a559d841
[oweals/openwrt.git] / target / linux / mvebu / patches-4.19 / 535-net-marvell-neta-add-comphy-support.patch
1 From a10c1c8191e04c21769656c2ca8e1c69a6218954 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 7 Feb 2019 16:19:26 +0000
4 Subject: [PATCH] net: marvell: neta: add comphy support
5
6 Add support for the common phy binding, so that we can reconfigure the
7 comphy according to the desired ethernet speed.  This will allow us to
8 support 1000base-X and 2500base-X SFPs dynamically on SolidRun Clearfog.
9
10 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13  drivers/net/ethernet/marvell/mvneta.c | 45 +++++++++++++++++++++++++++++++----
14  1 file changed, 41 insertions(+), 4 deletions(-)
15
16 --- a/drivers/net/ethernet/marvell/mvneta.c
17 +++ b/drivers/net/ethernet/marvell/mvneta.c
18 @@ -27,6 +27,7 @@
19  #include <linux/of_irq.h>
20  #include <linux/of_mdio.h>
21  #include <linux/of_net.h>
22 +#include <linux/phy/phy.h>
23  #include <linux/phy.h>
24  #include <linux/phylink.h>
25  #include <linux/platform_device.h>
26 @@ -436,6 +437,7 @@ struct mvneta_port {
27         struct device_node *dn;
28         unsigned int tx_csum_limit;
29         struct phylink *phylink;
30 +       struct phy *comphy;
31  
32         struct mvneta_bm *bm_priv;
33         struct mvneta_bm_pool *pool_long;
34 @@ -3153,6 +3155,8 @@ static void mvneta_start_dev(struct mvne
35  {
36         int cpu;
37  
38 +       WARN_ON(phy_power_on(pp->comphy));
39 +
40         mvneta_max_rx_size_set(pp, pp->pkt_size);
41         mvneta_txq_max_tx_size_set(pp, pp->pkt_size);
42  
43 @@ -3215,6 +3219,8 @@ static void mvneta_stop_dev(struct mvnet
44  
45         mvneta_tx_reset(pp);
46         mvneta_rx_reset(pp);
47 +
48 +       WARN_ON(phy_power_off(pp->comphy));
49  }
50  
51  static void mvneta_percpu_enable(void *arg)
52 @@ -3340,6 +3346,7 @@ static int mvneta_set_mac_addr(struct ne
53  static void mvneta_validate(struct net_device *ndev, unsigned long *supported,
54                             struct phylink_link_state *state)
55  {
56 +       struct mvneta_port *pp = netdev_priv(ndev);
57         __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
58  
59         /* We only support QSGMII, SGMII, 802.3z and RGMII modes */
60 @@ -3360,8 +3367,13 @@ static void mvneta_validate(struct net_d
61         phylink_set(mask, Pause);
62  
63         /* Half-duplex at speeds higher than 100Mbit is unsupported */
64 -       phylink_set(mask, 1000baseT_Full);
65 -       phylink_set(mask, 1000baseX_Full);
66 +       if (pp->comphy || state->interface != PHY_INTERFACE_MODE_2500BASEX) {
67 +               phylink_set(mask, 1000baseT_Full);
68 +               phylink_set(mask, 1000baseX_Full);
69 +       }
70 +       if (pp->comphy || state->interface == PHY_INTERFACE_MODE_2500BASEX) {
71 +               phylink_set(mask, 2500baseX_Full);
72 +       }
73  
74         if (!phy_interface_mode_is_8023z(state->interface)) {
75                 /* 10M and 100M are only supported in non-802.3z mode */
76 @@ -3375,6 +3387,11 @@ static void mvneta_validate(struct net_d
77                    __ETHTOOL_LINK_MODE_MASK_NBITS);
78         bitmap_and(state->advertising, state->advertising, mask,
79                    __ETHTOOL_LINK_MODE_MASK_NBITS);
80 +
81 +       /* We can only operate at 2500BaseX or 1000BaseX.  If requested
82 +        * to advertise both, only report advertising at 2500BaseX.
83 +        */
84 +       phylink_helper_basex_speed(state);
85  }
86  
87  static int mvneta_mac_link_state(struct net_device *ndev,
88 @@ -3386,7 +3403,9 @@ static int mvneta_mac_link_state(struct
89         gmac_stat = mvreg_read(pp, MVNETA_GMAC_STATUS);
90  
91         if (gmac_stat & MVNETA_GMAC_SPEED_1000)
92 -               state->speed = SPEED_1000;
93 +               state->speed =
94 +                       state->interface == PHY_INTERFACE_MODE_2500BASEX ?
95 +                       SPEED_2500 : SPEED_1000;
96         else if (gmac_stat & MVNETA_GMAC_SPEED_100)
97                 state->speed = SPEED_100;
98         else
99 @@ -3501,12 +3520,20 @@ static void mvneta_mac_config(struct net
100                             MVNETA_GMAC_FORCE_LINK_DOWN);
101         }
102  
103 +
104         /* When at 2.5G, the link partner can send frames with shortened
105          * preambles.
106          */
107         if (state->speed == SPEED_2500)
108                 new_ctrl4 |= MVNETA_GMAC4_SHORT_PREAMBLE_ENABLE;
109  
110 +       if (pp->comphy &&
111 +           (state->interface == PHY_INTERFACE_MODE_SGMII ||
112 +            state->interface == PHY_INTERFACE_MODE_1000BASEX ||
113 +            state->interface == PHY_INTERFACE_MODE_2500BASEX))
114 +               WARN_ON(phy_set_mode_ext(pp->comphy, PHY_MODE_ETHERNET,
115 +                                        state->interface));
116 +
117         if (new_ctrl0 != gmac_ctrl0)
118                 mvreg_write(pp, MVNETA_GMAC_CTRL_0, new_ctrl0);
119         if (new_ctrl2 != gmac_ctrl2)
120 @@ -4419,7 +4446,7 @@ static int mvneta_port_power_up(struct m
121         if (phy_mode == PHY_INTERFACE_MODE_QSGMII)
122                 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_QSGMII_SERDES_PROTO);
123         else if (phy_mode == PHY_INTERFACE_MODE_SGMII ||
124 -                phy_mode == PHY_INTERFACE_MODE_1000BASEX)
125 +                phy_interface_mode_is_8023z(phy_mode))
126                 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
127         else if (!phy_interface_mode_is_rgmii(phy_mode))
128                 return -EINVAL;
129 @@ -4436,6 +4463,7 @@ static int mvneta_probe(struct platform_
130         struct mvneta_port *pp;
131         struct net_device *dev;
132         struct phylink *phylink;
133 +       struct phy *comphy;
134         const char *dt_mac_addr;
135         char hw_mac_addr[ETH_ALEN];
136         const char *mac_from;
137 @@ -4461,6 +4489,14 @@ static int mvneta_probe(struct platform_
138                 goto err_free_irq;
139         }
140  
141 +       comphy = devm_of_phy_get(&pdev->dev, dn, NULL);
142 +       if (comphy == ERR_PTR(-EPROBE_DEFER)) {
143 +               err = -EPROBE_DEFER;
144 +               goto err_free_irq;
145 +       } else if (IS_ERR(comphy)) {
146 +               comphy = NULL;
147 +       }
148 +
149         phylink = phylink_create(dev, pdev->dev.fwnode, phy_mode,
150                                  &mvneta_phylink_ops);
151         if (IS_ERR(phylink)) {
152 @@ -4477,6 +4513,7 @@ static int mvneta_probe(struct platform_
153         pp = netdev_priv(dev);
154         spin_lock_init(&pp->lock);
155         pp->phylink = phylink;
156 +       pp->comphy = comphy;
157         pp->phy_interface = phy_mode;
158         pp->dn = dn;
159