Commit c16a5033 authored by Yoshihiro Shimoda's avatar Yoshihiro Shimoda Committed by David S. Miller

net: renesas: rswitch: Convert to phy_device

Intended to set phy_device->host_interfaces by phylink in the future.
But there is difficult to implement phylink properly, especially
supporting the in-band mode on this driver because extra initialization
is needed after linked the ethernet PHY up. So, convert to phy_device
from phylink.
Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b46f1e57
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include <linux/phylink.h>
#include <linux/phy/phy.h> #include <linux/phy/phy.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
...@@ -1139,61 +1138,78 @@ static void rswitch_mii_unregister(struct rswitch_device *rdev) ...@@ -1139,61 +1138,78 @@ static void rswitch_mii_unregister(struct rswitch_device *rdev)
} }
} }
static void rswitch_mac_config(struct phylink_config *config, static void rswitch_adjust_link(struct net_device *ndev)
unsigned int mode,
const struct phylink_link_state *state)
{ {
} struct rswitch_device *rdev = netdev_priv(ndev);
struct phy_device *phydev = ndev->phydev;
static void rswitch_mac_link_down(struct phylink_config *config, /* Current hardware has a restriction not to change speed at runtime */
unsigned int mode, if (phydev->link != rdev->etha->link) {
phy_interface_t interface) phy_print_status(phydev);
{ rdev->etha->link = phydev->link;
}
} }
static void rswitch_mac_link_up(struct phylink_config *config, static void rswitch_phy_remove_link_mode(struct rswitch_device *rdev,
struct phy_device *phydev, unsigned int mode, struct phy_device *phydev)
phy_interface_t interface, int speed,
int duplex, bool tx_pause, bool rx_pause)
{ {
/* Current hardware cannot change speed at runtime */ /* Current hardware has a restriction not to change speed at runtime */
} switch (rdev->etha->speed) {
case SPEED_2500:
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_100baseT_Full_BIT);
break;
case SPEED_1000:
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_2500baseX_Full_BIT);
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_100baseT_Full_BIT);
break;
case SPEED_100:
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_2500baseX_Full_BIT);
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
break;
default:
break;
}
static const struct phylink_mac_ops rswitch_phylink_ops = { phy_set_max_speed(phydev, rdev->etha->speed);
.mac_config = rswitch_mac_config, }
.mac_link_down = rswitch_mac_link_down,
.mac_link_up = rswitch_mac_link_up,
};
static int rswitch_phylink_init(struct rswitch_device *rdev) static int rswitch_phy_device_init(struct rswitch_device *rdev)
{ {
struct phylink *phylink; struct phy_device *phydev;
struct device_node *phy;
if (!rdev->np_port) if (!rdev->np_port)
return -ENODEV; return -ENODEV;
rdev->phylink_config.dev = &rdev->ndev->dev; phy = of_parse_phandle(rdev->np_port, "phy-handle", 0);
rdev->phylink_config.type = PHYLINK_NETDEV; if (!phy)
__set_bit(PHY_INTERFACE_MODE_SGMII, rdev->phylink_config.supported_interfaces); return -ENODEV;
__set_bit(PHY_INTERFACE_MODE_USXGMII, rdev->phylink_config.supported_interfaces);
rdev->phylink_config.mac_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD; phydev = of_phy_connect(rdev->ndev, phy, rswitch_adjust_link, 0,
rdev->etha->phy_interface);
of_node_put(phy);
if (!phydev)
return -ENOENT;
phylink = phylink_create(&rdev->phylink_config, &rdev->np_port->fwnode, phy_set_max_speed(phydev, SPEED_2500);
rdev->etha->phy_interface, &rswitch_phylink_ops); phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
if (IS_ERR(phylink)) phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Full_BIT);
return PTR_ERR(phylink); phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
rswitch_phy_remove_link_mode(rdev, phydev);
rdev->phylink = phylink; phy_attached_info(phydev);
return phylink_of_phy_connect(rdev->phylink, rdev->np_port, rdev->etha->phy_interface); return 0;
} }
static void rswitch_phylink_deinit(struct rswitch_device *rdev) static void rswitch_phy_device_deinit(struct rswitch_device *rdev)
{ {
rtnl_lock(); if (rdev->ndev->phydev) {
phylink_disconnect_phy(rdev->phylink); phy_disconnect(rdev->ndev->phydev);
rtnl_unlock(); rdev->ndev->phydev = NULL;
phylink_destroy(rdev->phylink); }
} }
static int rswitch_serdes_set_params(struct rswitch_device *rdev) static int rswitch_serdes_set_params(struct rswitch_device *rdev)
...@@ -1223,9 +1239,9 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev) ...@@ -1223,9 +1239,9 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev)
if (err < 0) if (err < 0)
return err; return err;
err = rswitch_phylink_init(rdev); err = rswitch_phy_device_init(rdev);
if (err < 0) if (err < 0)
goto err_phylink_init; goto err_phy_device_init;
rdev->serdes = devm_of_phy_get(&rdev->priv->pdev->dev, rdev->np_port, NULL); rdev->serdes = devm_of_phy_get(&rdev->priv->pdev->dev, rdev->np_port, NULL);
if (IS_ERR(rdev->serdes)) { if (IS_ERR(rdev->serdes)) {
...@@ -1241,9 +1257,9 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev) ...@@ -1241,9 +1257,9 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev)
err_serdes_set_params: err_serdes_set_params:
err_serdes_phy_get: err_serdes_phy_get:
rswitch_phylink_deinit(rdev); rswitch_phy_device_deinit(rdev);
err_phylink_init: err_phy_device_init:
rswitch_mii_unregister(rdev); rswitch_mii_unregister(rdev);
return err; return err;
...@@ -1251,7 +1267,7 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev) ...@@ -1251,7 +1267,7 @@ static int rswitch_ether_port_init_one(struct rswitch_device *rdev)
static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev) static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev)
{ {
rswitch_phylink_deinit(rdev); rswitch_phy_device_deinit(rdev);
rswitch_mii_unregister(rdev); rswitch_mii_unregister(rdev);
} }
...@@ -1299,7 +1315,7 @@ static int rswitch_open(struct net_device *ndev) ...@@ -1299,7 +1315,7 @@ static int rswitch_open(struct net_device *ndev)
{ {
struct rswitch_device *rdev = netdev_priv(ndev); struct rswitch_device *rdev = netdev_priv(ndev);
phylink_start(rdev->phylink); phy_start(ndev->phydev);
napi_enable(&rdev->napi); napi_enable(&rdev->napi);
netif_start_queue(ndev); netif_start_queue(ndev);
...@@ -1319,7 +1335,7 @@ static int rswitch_stop(struct net_device *ndev) ...@@ -1319,7 +1335,7 @@ static int rswitch_stop(struct net_device *ndev)
rswitch_enadis_data_irq(rdev->priv, rdev->tx_queue->index, false); rswitch_enadis_data_irq(rdev->priv, rdev->tx_queue->index, false);
rswitch_enadis_data_irq(rdev->priv, rdev->rx_queue->index, false); rswitch_enadis_data_irq(rdev->priv, rdev->rx_queue->index, false);
phylink_stop(rdev->phylink); phy_stop(ndev->phydev);
napi_disable(&rdev->napi); napi_disable(&rdev->napi);
return 0; return 0;
...@@ -1447,8 +1463,6 @@ static int rswitch_hwstamp_set(struct net_device *ndev, struct ifreq *req) ...@@ -1447,8 +1463,6 @@ static int rswitch_hwstamp_set(struct net_device *ndev, struct ifreq *req)
static int rswitch_eth_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) static int rswitch_eth_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
{ {
struct rswitch_device *rdev = netdev_priv(ndev);
if (!netif_running(ndev)) if (!netif_running(ndev))
return -EINVAL; return -EINVAL;
...@@ -1458,7 +1472,7 @@ static int rswitch_eth_ioctl(struct net_device *ndev, struct ifreq *req, int cmd ...@@ -1458,7 +1472,7 @@ static int rswitch_eth_ioctl(struct net_device *ndev, struct ifreq *req, int cmd
case SIOCSHWTSTAMP: case SIOCSHWTSTAMP:
return rswitch_hwstamp_set(ndev, req); return rswitch_hwstamp_set(ndev, req);
default: default:
return phylink_mii_ioctl(rdev->phylink, req, cmd); return phy_mii_ioctl(ndev->phydev, req, cmd);
} }
} }
......
...@@ -943,8 +943,6 @@ struct rswitch_device { ...@@ -943,8 +943,6 @@ struct rswitch_device {
struct rswitch_private *priv; struct rswitch_private *priv;
struct net_device *ndev; struct net_device *ndev;
struct napi_struct napi; struct napi_struct napi;
struct phylink *phylink;
struct phylink_config phylink_config;
void __iomem *addr; void __iomem *addr;
struct rswitch_gwca_queue *tx_queue; struct rswitch_gwca_queue *tx_queue;
struct rswitch_gwca_queue *rx_queue; struct rswitch_gwca_queue *rx_queue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment