static int phylink_mii_read(struct phylink *pl, unsigned int phy_id, unsigned int reg) { struct phylink_link_state state; int val = 0xffff; switch (pl->link_an_mode) { case MLO_AN_FIXED: if (phy_id == 0) { phylink_get_fixed_state(pl, &state); val = phylink_mii_emul_read(pl->netdev, reg, &state, true); } break; case MLO_AN_PHY: return -EOPNOTSUPP; case MLO_AN_SGMII: /* No phy, fall through to 8023z method */ case MLO_AN_8023Z: if (phy_id == 0) { val = phylink_get_mac_state(pl, &state); if (val < 0) return val; val = phylink_mii_emul_read(pl->netdev, reg, &state, true); } break; } return val & 0xffff; }
int phylink_ethtool_ksettings_get(struct phylink *pl, struct ethtool_link_ksettings *kset) { struct phylink_link_state link_state; WARN_ON(!lockdep_rtnl_is_held()); if (pl->phydev) { phy_ethtool_ksettings_get(pl->phydev, kset); } else { kset->base.port = pl->link_port; } linkmode_copy(kset->link_modes.supported, pl->supported); switch (pl->link_an_mode) { case MLO_AN_FIXED: /* We are using fixed settings. Report these as the * current link settings - and note that these also * represent the supported speeds/duplex/pause modes. */ phylink_get_fixed_state(pl, &link_state); phylink_get_ksettings(&link_state, kset); break; case MLO_AN_SGMII: /* If there is a phy attached, then use the reported * settings from the phy with no modification. */ if (pl->phydev) break; case MLO_AN_8023Z: phylink_get_mac_state(pl, &link_state); /* The MAC is reporting the link results from its own PCS * layer via in-band status. Report these as the current * link settings. */ phylink_get_ksettings(&link_state, kset); break; } return 0; }
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; mutex_lock(&pl->state_mutex); if (pl->phylink_disable_state) { pl->mac_link_dropped = false; link_state.link = false; } else if (pl->mac_link_dropped) { link_state.link = false; } else { switch (pl->link_an_mode) { case MLO_AN_PHY: link_state = pl->phy_state; phylink_resolve_flow(pl, &link_state); phylink_mac_config(pl, &link_state); break; case MLO_AN_FIXED: phylink_get_fixed_state(pl, &link_state); phylink_mac_config(pl, &link_state); break; case MLO_AN_SGMII: phylink_get_mac_state(pl, &link_state); if (pl->phydev) { bool changed = false; link_state.link = link_state.link && pl->phy_state.link; if (pl->phy_state.interface != link_state.interface) { link_state.interface = pl->phy_state.interface; changed = true; } /* Propagate the flow control from the PHY * to the MAC. Also propagate the interface * if changed. */ if (pl->phy_state.link || changed) { link_state.pause |= pl->phy_state.pause; phylink_resolve_flow(pl, &link_state); phylink_mac_config(pl, &link_state); } } break; case MLO_AN_8023Z: phylink_get_mac_state(pl, &link_state); break; } } if (link_state.link != netif_carrier_ok(ndev)) { if (!link_state.link) { netif_carrier_off(ndev); pl->ops->mac_link_down(ndev, pl->link_an_mode); netdev_info(ndev, "Link is Down\n"); } else { pl->ops->mac_link_up(ndev, pl->link_an_mode, pl->phydev); netif_carrier_on(ndev); netdev_info(ndev, "Link is Up - %s/%s - flow control %s\n", phy_speed_to_str(link_state.speed), phy_duplex_to_str(link_state.duplex), phylink_pause_to_str(link_state.pause)); } } if (!link_state.link && pl->mac_link_dropped) { pl->mac_link_dropped = false; queue_work(system_power_efficient_wq, &pl->resolve); } mutex_unlock(&pl->state_mutex); }
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; mutex_lock(&pl->state_mutex); if (pl->phylink_disable_state) { pl->mac_link_dropped = false; link_state.link = false; } else if (pl->mac_link_dropped) { link_state.link = false; } else { switch (pl->link_an_mode) { case MLO_AN_PHY: link_state = pl->phy_state; phylink_resolve_flow(pl, &link_state); phylink_mac_config_up(pl, &link_state); break; case MLO_AN_FIXED: phylink_get_fixed_state(pl, &link_state); phylink_mac_config_up(pl, &link_state); break; case MLO_AN_INBAND: phylink_get_mac_state(pl, &link_state); /* If we have a phy, the "up" state is the union of * both the PHY and the MAC */ if (pl->phydev) link_state.link &= pl->phy_state.link; /* Only update if the PHY link is up */ if (pl->phydev && pl->phy_state.link) { link_state.interface = pl->phy_state.interface; /* If we have a PHY, we need to update with * the pause mode bits. */ link_state.pause |= pl->phy_state.pause; phylink_resolve_flow(pl, &link_state); phylink_mac_config(pl, &link_state); } break; } } if (link_state.link != netif_carrier_ok(ndev)) { if (!link_state.link) { netif_carrier_off(ndev); pl->ops->mac_link_down(ndev, pl->link_an_mode, pl->phy_state.interface); netdev_info(ndev, "Link is Down\n"); } else { pl->ops->mac_link_up(ndev, pl->link_an_mode, pl->phy_state.interface, pl->phydev); netif_carrier_on(ndev); netdev_info(ndev, "Link is Up - %s/%s - flow control %s\n", phy_speed_to_str(link_state.speed), phy_duplex_to_str(link_state.duplex), phylink_pause_to_str(link_state.pause)); } } if (!link_state.link && pl->mac_link_dropped) { pl->mac_link_dropped = false; queue_work(system_power_efficient_wq, &pl->resolve); } mutex_unlock(&pl->state_mutex); }