Commit 5c05c1db authored by Russell King's avatar Russell King Committed by David S. Miller

net: phylink, dsa: eliminate phylink_fixed_state_cb()

Move the callback into the phylink_config structure, rather than
providing a callback to set this up.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Tested-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6861d6d9
...@@ -480,8 +480,8 @@ static void phylink_get_fixed_state(struct phylink *pl, ...@@ -480,8 +480,8 @@ static void phylink_get_fixed_state(struct phylink *pl,
struct phylink_link_state *state) struct phylink_link_state *state)
{ {
*state = pl->link_config; *state = pl->link_config;
if (pl->get_fixed_state) if (pl->config->get_fixed_state)
pl->get_fixed_state(pl->netdev, state); pl->config->get_fixed_state(pl->config, state);
else if (pl->link_gpio) else if (pl->link_gpio)
state->link = !!gpiod_get_value_cansleep(pl->link_gpio); state->link = !!gpiod_get_value_cansleep(pl->link_gpio);
...@@ -1044,32 +1044,6 @@ void phylink_disconnect_phy(struct phylink *pl) ...@@ -1044,32 +1044,6 @@ void phylink_disconnect_phy(struct phylink *pl)
} }
EXPORT_SYMBOL_GPL(phylink_disconnect_phy); EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
/**
* phylink_fixed_state_cb() - allow setting a fixed link callback
* @pl: a pointer to a &struct phylink returned from phylink_create()
* @cb: callback to execute to determine the fixed link state.
*
* The MAC driver should call this driver when the state of its link
* can be determined through e.g: an out of band MMIO register.
*/
int phylink_fixed_state_cb(struct phylink *pl,
void (*cb)(struct net_device *dev,
struct phylink_link_state *state))
{
/* It does not make sense to let the link be overriden unless we use
* MLO_AN_FIXED
*/
if (pl->cfg_link_an_mode != MLO_AN_FIXED)
return -EINVAL;
mutex_lock(&pl->state_mutex);
pl->get_fixed_state = cb;
mutex_unlock(&pl->state_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(phylink_fixed_state_cb);
/** /**
* phylink_mac_change() - notify phylink of a change in MAC state * phylink_mac_change() - notify phylink of a change in MAC state
* @pl: a pointer to a &struct phylink returned from phylink_create() * @pl: a pointer to a &struct phylink returned from phylink_create()
...@@ -1106,6 +1080,8 @@ static irqreturn_t phylink_link_handler(int irq, void *data) ...@@ -1106,6 +1080,8 @@ static irqreturn_t phylink_link_handler(int irq, void *data)
*/ */
void phylink_start(struct phylink *pl) void phylink_start(struct phylink *pl)
{ {
bool poll = false;
ASSERT_RTNL(); ASSERT_RTNL();
phylink_info(pl, "configuring for %s/%s link mode\n", phylink_info(pl, "configuring for %s/%s link mode\n",
...@@ -1142,10 +1118,18 @@ void phylink_start(struct phylink *pl) ...@@ -1142,10 +1118,18 @@ void phylink_start(struct phylink *pl)
irq = 0; irq = 0;
} }
if (irq <= 0) if (irq <= 0)
mod_timer(&pl->link_poll, jiffies + HZ); poll = true;
}
switch (pl->cfg_link_an_mode) {
case MLO_AN_FIXED:
poll |= pl->config->poll_fixed_state;
break;
case MLO_AN_INBAND:
poll |= pl->config->pcs_poll;
break;
} }
if ((pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state) || if (poll)
pl->config->pcs_poll)
mod_timer(&pl->link_poll, jiffies + HZ); mod_timer(&pl->link_poll, jiffies + HZ);
if (pl->phydev) if (pl->phydev)
phy_start(pl->phydev); phy_start(pl->phydev);
......
...@@ -67,6 +67,9 @@ struct phylink_config { ...@@ -67,6 +67,9 @@ struct phylink_config {
struct device *dev; struct device *dev;
enum phylink_op_type type; enum phylink_op_type type;
bool pcs_poll; bool pcs_poll;
bool poll_fixed_state;
void (*get_fixed_state)(struct phylink_config *config,
struct phylink_link_state *state);
}; };
/** /**
...@@ -366,9 +369,6 @@ void phylink_destroy(struct phylink *); ...@@ -366,9 +369,6 @@ void phylink_destroy(struct phylink *);
int phylink_connect_phy(struct phylink *, struct phy_device *); int phylink_connect_phy(struct phylink *, struct phy_device *);
int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
void phylink_disconnect_phy(struct phylink *); void phylink_disconnect_phy(struct phylink *);
int phylink_fixed_state_cb(struct phylink *,
void (*cb)(struct net_device *dev,
struct phylink_link_state *));
void phylink_mac_change(struct phylink *, bool up); void phylink_mac_change(struct phylink *, bool up);
......
...@@ -1590,10 +1590,10 @@ void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up) ...@@ -1590,10 +1590,10 @@ void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
} }
EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change); EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
static void dsa_slave_phylink_fixed_state(struct net_device *dev, static void dsa_slave_phylink_fixed_state(struct phylink_config *config,
struct phylink_link_state *state) struct phylink_link_state *state)
{ {
struct dsa_port *dp = dsa_slave_to_port(dev); struct dsa_port *dp = container_of(config, struct dsa_port, pl_config);
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
/* No need to check that this operation is valid, the callback would /* No need to check that this operation is valid, the callback would
...@@ -1633,6 +1633,15 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -1633,6 +1633,15 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
dp->pl_config.dev = &slave_dev->dev; dp->pl_config.dev = &slave_dev->dev;
dp->pl_config.type = PHYLINK_NETDEV; dp->pl_config.type = PHYLINK_NETDEV;
/* The get_fixed_state callback takes precedence over polling the
* link GPIO in PHYLINK (see phylink_get_fixed_state). Only set
* this if the switch provides such a callback.
*/
if (ds->ops->phylink_fixed_state) {
dp->pl_config.get_fixed_state = dsa_slave_phylink_fixed_state;
dp->pl_config.poll_fixed_state = true;
}
dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode, dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode,
&dsa_port_phylink_mac_ops); &dsa_port_phylink_mac_ops);
if (IS_ERR(dp->pl)) { if (IS_ERR(dp->pl)) {
...@@ -1641,13 +1650,6 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -1641,13 +1650,6 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
return PTR_ERR(dp->pl); return PTR_ERR(dp->pl);
} }
/* Register only if the switch provides such a callback, since this
* callback takes precedence over polling the link GPIO in PHYLINK
* (see phylink_get_fixed_state).
*/
if (ds->ops->phylink_fixed_state)
phylink_fixed_state_cb(dp->pl, dsa_slave_phylink_fixed_state);
if (ds->ops->get_phy_flags) if (ds->ops->get_phy_flags)
phy_flags = ds->ops->get_phy_flags(ds, dp->index); phy_flags = ds->ops->get_phy_flags(ds, dp->index);
......
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