Commit 5b52e57c authored by David S. Miller's avatar David S. Miller

Merge branch 'net-dsa-use-generic-slave-phydev'

Vivien Didelot says:

====================
net: dsa: use generic slave phydev

DSA currently stores a phy_device pointer in each slave private
structure. This requires to implement our own ethtool ksettings
accessors and such.

This patchset removes the private phy_device in favor of the one
provided in the net_device structure, and thus allows us to use the
generic phy_ethtool_* functions.
====================
Tested-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f6fc5b49 69b2c162
......@@ -79,7 +79,6 @@ struct dsa_slave_priv {
* The phylib phy_device pointer for the PHY connected
* to this port.
*/
struct phy_device *phy;
phy_interface_t phy_interface;
int old_link;
int old_pause;
......
......@@ -96,12 +96,12 @@ static int dsa_slave_open(struct net_device *dev)
goto clear_allmulti;
}
err = dsa_port_enable(dp, p->phy);
err = dsa_port_enable(dp, dev->phydev);
if (err)
goto clear_promisc;
if (p->phy)
phy_start(p->phy);
if (dev->phydev)
phy_start(dev->phydev);
return 0;
......@@ -124,10 +124,10 @@ static int dsa_slave_close(struct net_device *dev)
struct net_device *master = dsa_master_netdev(p);
struct dsa_port *dp = p->dp;
if (p->phy)
phy_stop(p->phy);
if (dev->phydev)
phy_stop(dev->phydev);
dsa_port_disable(dp, p->phy);
dsa_port_disable(dp, dev->phydev);
dev_mc_unsync(master, dev);
dev_uc_unsync(master, dev);
......@@ -264,12 +264,10 @@ dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct dsa_slave_priv *p = netdev_priv(dev);
if (p->phy != NULL)
return phy_mii_ioctl(p->phy, ifr, cmd);
if (!dev->phydev)
return -ENODEV;
return -EOPNOTSUPP;
return phy_mii_ioctl(dev->phydev, ifr, cmd);
}
static int dsa_slave_port_attr_set(struct net_device *dev,
......@@ -422,31 +420,6 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
}
/* ethtool operations *******************************************************/
static int
dsa_slave_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
struct dsa_slave_priv *p = netdev_priv(dev);
if (!p->phy)
return -EOPNOTSUPP;
phy_ethtool_ksettings_get(p->phy, cmd);
return 0;
}
static int
dsa_slave_set_link_ksettings(struct net_device *dev,
const struct ethtool_link_ksettings *cmd)
{
struct dsa_slave_priv *p = netdev_priv(dev);
if (p->phy != NULL)
return phy_ethtool_ksettings_set(p->phy, cmd);
return -EOPNOTSUPP;
}
static void dsa_slave_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *drvinfo)
......@@ -477,26 +450,14 @@ dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
ds->ops->get_regs(ds, p->dp->index, regs, _p);
}
static int dsa_slave_nway_reset(struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
if (p->phy != NULL)
return genphy_restart_aneg(p->phy);
return -EOPNOTSUPP;
}
static u32 dsa_slave_get_link(struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
if (!dev->phydev)
return -ENODEV;
if (p->phy != NULL) {
genphy_update_link(p->phy);
return p->phy->link;
}
genphy_update_link(dev->phydev);
return -EOPNOTSUPP;
return dev->phydev->link;
}
static int dsa_slave_get_eeprom_len(struct net_device *dev)
......@@ -631,7 +592,7 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
int ret;
/* Port's PHY and MAC both need to be EEE capable */
if (!p->phy)
if (!dev->phydev)
return -ENODEV;
if (!ds->ops->set_mac_eee)
......@@ -642,12 +603,12 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
return ret;
if (e->eee_enabled) {
ret = phy_init_eee(p->phy, 0);
ret = phy_init_eee(dev->phydev, 0);
if (ret)
return ret;
}
return phy_ethtool_set_eee(p->phy, e);
return phy_ethtool_set_eee(dev->phydev, e);
}
static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
......@@ -657,7 +618,7 @@ static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
int ret;
/* Port's PHY and MAC both need to be EEE capable */
if (!p->phy)
if (!dev->phydev)
return -ENODEV;
if (!ds->ops->get_mac_eee)
......@@ -667,7 +628,7 @@ static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
if (ret)
return ret;
return phy_ethtool_get_eee(p->phy, e);
return phy_ethtool_get_eee(dev->phydev, e);
}
#ifdef CONFIG_NET_POLL_CONTROLLER
......@@ -919,7 +880,7 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
.get_drvinfo = dsa_slave_get_drvinfo,
.get_regs_len = dsa_slave_get_regs_len,
.get_regs = dsa_slave_get_regs,
.nway_reset = dsa_slave_nway_reset,
.nway_reset = phy_ethtool_nway_reset,
.get_link = dsa_slave_get_link,
.get_eeprom_len = dsa_slave_get_eeprom_len,
.get_eeprom = dsa_slave_get_eeprom,
......@@ -931,8 +892,8 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
.get_wol = dsa_slave_get_wol,
.set_eee = dsa_slave_set_eee,
.get_eee = dsa_slave_get_eee,
.get_link_ksettings = dsa_slave_get_link_ksettings,
.set_link_ksettings = dsa_slave_set_link_ksettings,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
.get_rxnfc = dsa_slave_get_rxnfc,
.set_rxnfc = dsa_slave_set_rxnfc,
};
......@@ -976,26 +937,26 @@ static void dsa_slave_adjust_link(struct net_device *dev)
struct dsa_switch *ds = p->dp->ds;
unsigned int status_changed = 0;
if (p->old_link != p->phy->link) {
if (p->old_link != dev->phydev->link) {
status_changed = 1;
p->old_link = p->phy->link;
p->old_link = dev->phydev->link;
}
if (p->old_duplex != p->phy->duplex) {
if (p->old_duplex != dev->phydev->duplex) {
status_changed = 1;
p->old_duplex = p->phy->duplex;
p->old_duplex = dev->phydev->duplex;
}
if (p->old_pause != p->phy->pause) {
if (p->old_pause != dev->phydev->pause) {
status_changed = 1;
p->old_pause = p->phy->pause;
p->old_pause = dev->phydev->pause;
}
if (ds->ops->adjust_link && status_changed)
ds->ops->adjust_link(ds, p->dp->index, p->phy);
ds->ops->adjust_link(ds, p->dp->index, dev->phydev);
if (status_changed)
phy_print_status(p->phy);
phy_print_status(dev->phydev);
}
static int dsa_slave_fixed_link_update(struct net_device *dev,
......@@ -1020,17 +981,18 @@ static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
struct dsa_slave_priv *p = netdev_priv(slave_dev);
struct dsa_switch *ds = p->dp->ds;
p->phy = mdiobus_get_phy(ds->slave_mii_bus, addr);
if (!p->phy) {
slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr);
if (!slave_dev->phydev) {
netdev_err(slave_dev, "no phy at %d\n", addr);
return -ENODEV;
}
/* Use already configured phy mode */
if (p->phy_interface == PHY_INTERFACE_MODE_NA)
p->phy_interface = p->phy->interface;
return phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
p->phy_interface);
p->phy_interface = slave_dev->phydev->interface;
return phy_connect_direct(slave_dev, slave_dev->phydev,
dsa_slave_adjust_link, p->phy_interface);
}
static int dsa_slave_phy_setup(struct net_device *slave_dev)
......@@ -1082,22 +1044,23 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
return ret;
}
} else {
p->phy = of_phy_connect(slave_dev, phy_dn,
dsa_slave_adjust_link,
phy_flags,
p->phy_interface);
slave_dev->phydev = of_phy_connect(slave_dev, phy_dn,
dsa_slave_adjust_link,
phy_flags,
p->phy_interface);
}
of_node_put(phy_dn);
}
if (p->phy && phy_is_fixed)
fixed_phy_set_link_update(p->phy, dsa_slave_fixed_link_update);
if (slave_dev->phydev && phy_is_fixed)
fixed_phy_set_link_update(slave_dev->phydev,
dsa_slave_fixed_link_update);
/* We could not connect to a designated PHY, so use the switch internal
* MDIO bus instead
*/
if (!p->phy) {
if (!slave_dev->phydev) {
ret = dsa_slave_phy_connect(slave_dev, p->dp->index);
if (ret) {
netdev_err(slave_dev, "failed to connect to port %d: %d\n",
......@@ -1108,7 +1071,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
}
}
phy_attached_info(p->phy);
phy_attached_info(slave_dev->phydev);
return 0;
}
......@@ -1128,12 +1091,12 @@ int dsa_slave_suspend(struct net_device *slave_dev)
netif_device_detach(slave_dev);
if (p->phy) {
phy_stop(p->phy);
if (slave_dev->phydev) {
phy_stop(slave_dev->phydev);
p->old_pause = -1;
p->old_link = -1;
p->old_duplex = -1;
phy_suspend(p->phy);
phy_suspend(slave_dev->phydev);
}
return 0;
......@@ -1141,13 +1104,11 @@ int dsa_slave_suspend(struct net_device *slave_dev)
int dsa_slave_resume(struct net_device *slave_dev)
{
struct dsa_slave_priv *p = netdev_priv(slave_dev);
netif_device_attach(slave_dev);
if (p->phy) {
phy_resume(p->phy);
phy_start(p->phy);
if (slave_dev->phydev) {
phy_resume(slave_dev->phydev);
phy_start(slave_dev->phydev);
}
return 0;
......@@ -1240,8 +1201,8 @@ void dsa_slave_destroy(struct net_device *slave_dev)
port_dn = p->dp->dn;
netif_carrier_off(slave_dev);
if (p->phy) {
phy_disconnect(p->phy);
if (slave_dev->phydev) {
phy_disconnect(slave_dev->phydev);
if (of_phy_is_fixed_link(port_dn))
of_phy_deregister_fixed_link(port_dn);
......
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