1 From f8c221dc7383a50defcc5b96595e092159dbe928 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Sat, 9 Nov 2019 15:02:59 +0200
4 Subject: [PATCH] net: mscc: ocelot: refactor adjust_link into a
5 netdev-independent function
7 This will be called from the Felix DSA frontend, which will work in
8 PHYLIB compatibility mode initially.
10 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
13 drivers/net/ethernet/mscc/ocelot.c | 27 +++++++++++++++++----------
14 1 file changed, 17 insertions(+), 10 deletions(-)
16 --- a/drivers/net/ethernet/mscc/ocelot.c
17 +++ b/drivers/net/ethernet/mscc/ocelot.c
18 @@ -410,15 +410,13 @@ static u16 ocelot_wm_enc(u16 value)
22 -static void ocelot_port_adjust_link(struct net_device *dev)
23 +static void ocelot_adjust_link(struct ocelot *ocelot, int port,
24 + struct phy_device *phydev)
26 - struct ocelot_port_private *priv = netdev_priv(dev);
27 - struct ocelot_port *ocelot_port = &priv->port;
28 - struct ocelot *ocelot = ocelot_port->ocelot;
29 + struct ocelot_port *ocelot_port = ocelot->ports[port];
30 int speed, atop_wm, mode = 0;
31 - u8 port = priv->chip_port;
33 - switch (dev->phydev->speed) {
34 + switch (phydev->speed) {
36 speed = OCELOT_SPEED_10;
38 @@ -434,14 +432,14 @@ static void ocelot_port_adjust_link(stru
39 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
42 - netdev_err(dev, "Unsupported PHY speed: %d\n",
43 - dev->phydev->speed);
44 + dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n",
45 + port, phydev->speed);
49 - phy_print_status(dev->phydev);
50 + phy_print_status(phydev);
52 - if (!dev->phydev->link)
56 /* Only full duplex supported for now */
57 @@ -536,6 +534,15 @@ static void ocelot_port_adjust_link(stru
58 ocelot_write(ocelot, ocelot_wm_enc(atop_wm), SYS_ATOP_TOT_CFG);
61 +static void ocelot_port_adjust_link(struct net_device *dev)
63 + struct ocelot_port_private *priv = netdev_priv(dev);
64 + struct ocelot *ocelot = priv->port.ocelot;
65 + int port = priv->chip_port;
67 + ocelot_adjust_link(ocelot, port, dev->phydev);
70 static void ocelot_port_enable(struct ocelot *ocelot, int port,
71 struct phy_device *phy)