Commit 43de6195 authored by Ioana Ciornei's avatar Ioana Ciornei Committed by David S. Miller

net: phylink: Add PHYLINK_DEV operation type

In the PHYLINK_DEV operation type, the PHYLINK infrastructure can work
without an attached net_device. For printing usecases, instead, a struct
device * should be passed to PHYLINK using the phylink_config structure.

Also, netif_carrier_* calls ar guarded by the presence of a valid
net_device. When using the PHYLINK_DEV operation type, we cannot check
link status using the netif_carrier_ok() API so instead, keep an
internal state of the MAC and call mac_link_{down,up} only when the link
changed.
Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 44cc27e4
......@@ -42,6 +42,8 @@ struct phylink {
struct net_device *netdev;
const struct phylink_mac_ops *ops;
struct phylink_config *config;
struct device *dev;
unsigned int old_link_state:1;
unsigned long phylink_disable_state; /* bitmask of disables */
struct phy_device *phydev;
......@@ -404,6 +406,7 @@ static void phylink_mac_link_up(struct phylink *pl,
pl->phy_state.interface,
pl->phydev);
if (ndev)
netif_carrier_on(ndev);
netdev_info(ndev,
......@@ -417,6 +420,7 @@ static void phylink_mac_link_down(struct phylink *pl)
{
struct net_device *ndev = pl->netdev;
if (ndev)
netif_carrier_off(ndev);
pl->ops->mac_link_down(pl->config, pl->link_an_mode,
pl->phy_state.interface);
......@@ -428,6 +432,7 @@ static void phylink_resolve(struct work_struct *w)
struct phylink *pl = container_of(w, struct phylink, resolve);
struct phylink_link_state link_state;
struct net_device *ndev = pl->netdev;
int link_changed;
mutex_lock(&pl->state_mutex);
if (pl->phylink_disable_state) {
......@@ -470,7 +475,13 @@ static void phylink_resolve(struct work_struct *w)
}
}
if (link_state.link != netif_carrier_ok(ndev)) {
if (pl->netdev)
link_changed = (link_state.link != netif_carrier_ok(ndev));
else
link_changed = (link_state.link != pl->old_link_state);
if (link_changed) {
pl->old_link_state = link_state.link;
if (!link_state.link)
phylink_mac_link_down(pl);
else
......@@ -571,6 +582,8 @@ struct phylink *phylink_create(struct phylink_config *config,
pl->config = config;
if (config->type == PHYLINK_NETDEV) {
pl->netdev = to_net_dev(config->dev);
} else if (config->type == PHYLINK_DEV) {
pl->dev = config->dev;
} else {
kfree(pl);
return ERR_PTR(-EINVAL);
......@@ -910,6 +923,7 @@ void phylink_start(struct phylink *pl)
phy_modes(pl->link_config.interface));
/* Always set the carrier off */
if (pl->netdev)
netif_carrier_off(pl->netdev);
/* Apply the link configuration to the MAC when starting. This allows
......@@ -1255,6 +1269,7 @@ int phylink_ethtool_set_pauseparam(struct phylink *pl,
switch (pl->link_an_mode) {
case MLO_AN_PHY:
/* Silently mark the carrier down, and then trigger a resolve */
if (pl->netdev)
netif_carrier_off(pl->netdev);
phylink_run_resolve(pl);
break;
......
......@@ -56,6 +56,7 @@ struct phylink_link_state {
enum phylink_op_type {
PHYLINK_NETDEV = 0,
PHYLINK_DEV,
};
/**
......
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