/** * phylink_set_port_modes() - set the port type modes in the ethtool mask * @mask: ethtool link mode mask * * Sets all the port type modes in the ethtool mask. MAC drivers should * use this in their 'validate' callback.
*/ void phylink_set_port_modes(unsignedlong *mask)
{
phylink_set(mask, TP);
phylink_set(mask, AUI);
phylink_set(mask, MII);
phylink_set(mask, FIBRE);
phylink_set(mask, BNC);
phylink_set(mask, Backplane);
}
EXPORT_SYMBOL_GPL(phylink_set_port_modes);
staticconstchar *phylink_pcs_mode_str(unsignedint mode)
{ if (!mode) return"none";
if (mode & PHYLINK_PCS_NEG_OUTBAND) return"outband";
if (mode & PHYLINK_PCS_NEG_INBAND) { if (mode & PHYLINK_PCS_NEG_ENABLED) return"inband,an-enabled"; else return"inband,an-disabled";
}
return"unknown";
}
staticunsignedint phylink_interface_signal_rate(phy_interface_t interface)
{ switch (interface) { case PHY_INTERFACE_MODE_SGMII: case PHY_INTERFACE_MODE_1000BASEX: /* 1.25Mbd */ return 1250; case PHY_INTERFACE_MODE_2500BASEX: /* 3.125Mbd */ return 3125; case PHY_INTERFACE_MODE_5GBASER: /* 5.15625Mbd */ return 5156; case PHY_INTERFACE_MODE_10GBASER: /* 10.3125Mbd */ return 10313; default: return 0;
}
}
/** * phylink_interface_max_speed() - get the maximum speed of a phy interface * @interface: phy interface mode defined by &typedef phy_interface_t * * Determine the maximum speed of a phy interface. This is intended to help * determine the correct speed to pass to the MAC when the phy is performing * rate matching. * * Return: The maximum speed of @interface
*/ staticint phylink_interface_max_speed(phy_interface_t interface)
{ switch (interface) { case PHY_INTERFACE_MODE_100BASEX: case PHY_INTERFACE_MODE_REVRMII: case PHY_INTERFACE_MODE_RMII: case PHY_INTERFACE_MODE_SMII: case PHY_INTERFACE_MODE_REVMII: case PHY_INTERFACE_MODE_MII: case PHY_INTERFACE_MODE_MIILITE: return SPEED_100;
case PHY_INTERFACE_MODE_TBI: case PHY_INTERFACE_MODE_MOCA: case PHY_INTERFACE_MODE_RTBI: case PHY_INTERFACE_MODE_1000BASEX: case PHY_INTERFACE_MODE_1000BASEKX: case PHY_INTERFACE_MODE_TRGMII: case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_PSGMII: case PHY_INTERFACE_MODE_QSGMII: case PHY_INTERFACE_MODE_QUSGMII: case PHY_INTERFACE_MODE_SGMII: case PHY_INTERFACE_MODE_GMII: return SPEED_1000;
case PHY_INTERFACE_MODE_2500BASEX: case PHY_INTERFACE_MODE_10G_QXGMII: return SPEED_2500;
case PHY_INTERFACE_MODE_5GBASER: return SPEED_5000;
case PHY_INTERFACE_MODE_XGMII: case PHY_INTERFACE_MODE_RXAUI: case PHY_INTERFACE_MODE_XAUI: case PHY_INTERFACE_MODE_10GBASER: case PHY_INTERFACE_MODE_10GKR: case PHY_INTERFACE_MODE_USXGMII: return SPEED_10000;
case PHY_INTERFACE_MODE_25GBASER: return SPEED_25000;
case PHY_INTERFACE_MODE_XLGMII: return SPEED_40000;
case PHY_INTERFACE_MODE_50GBASER: case PHY_INTERFACE_MODE_LAUI: return SPEED_50000;
case PHY_INTERFACE_MODE_100GBASEP: return SPEED_100000;
case PHY_INTERFACE_MODE_INTERNAL: case PHY_INTERFACE_MODE_NA: case PHY_INTERFACE_MODE_MAX: /* No idea! Garbage in, unknown out */ return SPEED_UNKNOWN;
}
/* If we get here, someone forgot to add an interface mode above */
WARN_ON_ONCE(1); return SPEED_UNKNOWN;
}
/** * phylink_caps_to_link_caps() - Convert a set of MAC capabilities LINK caps * @caps: A set of MAC capabilities * * Returns: The corresponding set of LINK_CAPA as defined in phy-caps.h
*/ staticunsignedlong phylink_caps_to_link_caps(unsignedlong caps)
{ unsignedlong link_caps = 0; int i;
for (i = 0; i < ARRAY_SIZE(phylink_caps_params); i++) if (caps & phylink_caps_params[i].mask)
link_caps |= phylink_caps_params[i].caps_bit;
return link_caps;
}
staticunsignedlong phylink_link_caps_to_mac_caps(unsignedlong link_caps)
{ unsignedlong caps = 0; int i;
for (i = 0; i < ARRAY_SIZE(phylink_caps_params); i++) if (link_caps & phylink_caps_params[i].caps_bit)
caps |= phylink_caps_params[i].mask;
return caps;
}
/** * phylink_caps_to_linkmodes() - Convert capabilities to ethtool link modes * @linkmodes: ethtool linkmode mask (must be already initialised) * @caps: bitmask of MAC capabilities * * Set all possible pause, speed and duplex linkmodes in @linkmodes that are * supported by the @caps. @linkmodes must have been initialised previously.
*/ staticvoid phylink_caps_to_linkmodes(unsignedlong *linkmodes, unsignedlong caps)
{ unsignedlong link_caps = phylink_caps_to_link_caps(caps);
if (caps & MAC_SYM_PAUSE)
__set_bit(ETHTOOL_LINK_MODE_Pause_BIT, linkmodes);
if (caps & MAC_ASYM_PAUSE)
__set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, linkmodes);
phy_caps_linkmodes(link_caps, linkmodes);
}
/** * phylink_limit_mac_speed - limit the phylink_config to a maximum speed * @config: pointer to a &struct phylink_config * @max_speed: maximum speed * * Mask off MAC capabilities for speeds higher than the @max_speed parameter. * Any further motifications of config.mac_capabilities will override this.
*/ void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed)
{ int i;
for (i = 0; i < ARRAY_SIZE(phylink_caps_params) &&
phylink_caps_params[i].speed > max_speed; i++)
config->mac_capabilities &= ~phylink_caps_params[i].mask;
}
EXPORT_SYMBOL_GPL(phylink_limit_mac_speed);
/** * phylink_cap_from_speed_duplex - Get mac capability from speed/duplex * @speed: the speed to search for * @duplex: the duplex to search for * * Find the mac capability for a given speed and duplex. * * Return: A mask with the mac capability patching @speed and @duplex, or 0 if * there were no matches.
*/ staticunsignedlong phylink_cap_from_speed_duplex(int speed, unsignedint duplex)
{ int i;
for (i = 0; i < ARRAY_SIZE(phylink_caps_params); i++) { if (speed == phylink_caps_params[i].speed &&
duplex == phylink_caps_params[i].duplex) return phylink_caps_params[i].mask;
}
return 0;
}
/** * phylink_get_capabilities() - get capabilities for a given MAC * @interface: phy interface mode defined by &typedef phy_interface_t * @mac_capabilities: bitmask of MAC capabilities * @rate_matching: type of rate matching being performed * * Get the MAC capabilities that are supported by the @interface mode and * @mac_capabilities.
*/ staticunsignedlong phylink_get_capabilities(phy_interface_t interface, unsignedlong mac_capabilities, int rate_matching)
{ unsignedlong link_caps = phy_caps_from_interface(interface); int max_speed = phylink_interface_max_speed(interface); unsignedlong caps = MAC_SYM_PAUSE | MAC_ASYM_PAUSE; unsignedlong matched_caps = 0;
caps |= phylink_link_caps_to_mac_caps(link_caps);
switch (rate_matching) { case RATE_MATCH_OPEN_LOOP: /* TODO */
fallthrough; case RATE_MATCH_NONE:
matched_caps = 0; break; case RATE_MATCH_PAUSE: { /* The MAC must support asymmetric pause towards the local * device for this. We could allow just symmetric pause, but * then we might have to renegotiate if the link partner * doesn't support pause. This is because there's no way to * accept pause frames without transmitting them if we only * support symmetric pause.
*/ if (!(mac_capabilities & MAC_SYM_PAUSE) ||
!(mac_capabilities & MAC_ASYM_PAUSE)) break;
/* We can't adapt if the MAC doesn't support the interface's * max speed at full duplex.
*/ if (mac_capabilities &
phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL))
matched_caps = GENMASK(__fls(caps), __fls(MAC_10HD)); break;
} case RATE_MATCH_CRS: /* The MAC must support half duplex at the interface's max * speed.
*/ if (mac_capabilities &
phylink_cap_from_speed_duplex(max_speed, DUPLEX_HALF)) {
matched_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
matched_caps &= mac_capabilities;
} break;
}
/** * phylink_validate_mask_caps() - Restrict link modes based on caps * @supported: ethtool bitmask for supported link modes. * @state: pointer to a &struct phylink_link_state. * @mac_capabilities: bitmask of MAC capabilities * * Calculate the supported link modes based on @mac_capabilities, and restrict * @supported and @state based on that. Use this function if your capabiliies * aren't constant, such as if they vary depending on the interface.
*/ staticvoid phylink_validate_mask_caps(unsignedlong *supported, struct phylink_link_state *state, unsignedlong mac_capabilities)
{
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; unsignedlong caps;
/* Get the PCS for this interface mode */ if (pl->mac_ops->mac_select_pcs) {
pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); if (IS_ERR(pcs)) return PTR_ERR(pcs);
}
if (pcs) { /* The PCS, if present, must be setup before phylink_create() * has been called. If the ops is not initialised, print an * error and backtrace rather than oopsing the kernel.
*/ if (!pcs->ops) {
phylink_err(pl, "interface %s: uninitialised PCS\n",
phy_modes(state->interface));
dump_stack(); return -EINVAL;
}
/* Ensure that this PCS supports the interface which the MAC * returned it for. It is an error for the MAC to return a PCS * that does not support the interface mode.
*/ if (!phy_interface_empty(pcs->supported_interfaces) &&
!test_bit(state->interface, pcs->supported_interfaces)) {
phylink_err(pl, "MAC returned PCS which does not support %s\n",
phy_modes(state->interface)); return -EINVAL;
}
/* Validate the link parameters with the PCS */ if (pcs->ops->pcs_validate) {
ret = pcs->ops->pcs_validate(pcs, supported, state); if (ret < 0 || phylink_is_empty_linkmode(supported)) return -EINVAL;
/* Ensure the advertising mask is a subset of the * supported mask.
*/
linkmode_and(state->advertising, state->advertising,
supported);
}
}
/* Then validate the link parameters with the MAC */ if (pl->mac_ops->mac_get_caps)
capabilities = pl->mac_ops->mac_get_caps(pl->config,
state->interface); else
capabilities = pl->config->mac_capabilities;
if (fwnode_property_read_bool(fixed_node, "full-duplex"))
pl->link_config.duplex = DUPLEX_FULL;
/* We treat the "pause" and "asym-pause" terminology as * defining the link partner's ability.
*/ if (fwnode_property_read_bool(fixed_node, "pause"))
__set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
pl->link_config.lp_advertising); if (fwnode_property_read_bool(fixed_node, "asym-pause"))
__set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
pl->link_config.lp_advertising);
switch (pl->link_config.interface) { case PHY_INTERFACE_MODE_SGMII: case PHY_INTERFACE_MODE_PSGMII: case PHY_INTERFACE_MODE_QSGMII: case PHY_INTERFACE_MODE_QUSGMII: case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RTBI: case PHY_INTERFACE_MODE_1000BASEX: case PHY_INTERFACE_MODE_2500BASEX: case PHY_INTERFACE_MODE_5GBASER: case PHY_INTERFACE_MODE_25GBASER: case PHY_INTERFACE_MODE_USXGMII: case PHY_INTERFACE_MODE_10G_QXGMII: case PHY_INTERFACE_MODE_10GKR: case PHY_INTERFACE_MODE_10GBASER: case PHY_INTERFACE_MODE_XLGMII: case PHY_INTERFACE_MODE_50GBASER: case PHY_INTERFACE_MODE_LAUI: case PHY_INTERFACE_MODE_100GBASEP:
caps = ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
caps = phylink_get_capabilities(pl->link_config.interface, caps,
RATE_MATCH_NONE);
phylink_caps_to_linkmodes(pl->supported, caps); break;
default:
phylink_err(pl, "incorrect link mode %s for in-band status\n",
phy_modes(pl->link_config.interface)); return -EINVAL;
}
if (phylink_validate(pl, pl->supported, &pl->link_config)) {
phylink_err(pl, "failed to validate link configuration for in-band status\n"); return -EINVAL;
}
}
return 0;
}
staticvoid phylink_apply_manual_flow(struct phylink *pl, struct phylink_link_state *state)
{ /* If autoneg is disabled, pause AN is also disabled */ if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
state->advertising))
state->pause &= ~MLO_PAUSE_AN;
/* Manual configuration of pause modes */ if (!(pl->link_config.pause & MLO_PAUSE_AN))
state->pause = pl->link_config.pause;
}
/* Query inband for a specific interface mode, asking the MAC for the * PCS which will be used to handle the interface mode.
*/ staticunsignedint phylink_inband_caps(struct phylink *pl,
phy_interface_t interface)
{ struct phylink_pcs *pcs;
if (!pl->mac_ops->mac_select_pcs) return 0;
pcs = pl->mac_ops->mac_select_pcs(pl->config, interface); if (!pcs) return 0;
staticenum inband_type phylink_get_inband_type(phy_interface_t interface)
{ switch (interface) { case PHY_INTERFACE_MODE_SGMII: case PHY_INTERFACE_MODE_QSGMII: case PHY_INTERFACE_MODE_QUSGMII: case PHY_INTERFACE_MODE_USXGMII: case PHY_INTERFACE_MODE_10G_QXGMII: /* These protocols are designed for use with a PHY which * communicates its negotiation result back to the MAC via * inband communication. Note: there exist PHYs that run * with SGMII but do not send the inband data.
*/ return INBAND_CISCO_SGMII;
case PHY_INTERFACE_MODE_1000BASEX: case PHY_INTERFACE_MODE_2500BASEX: /* 1000base-X is designed for use media-side for Fibre * connections, and thus the Autoneg bit needs to be * taken into account. We also do this for 2500base-X * as well, but drivers may not support this, so may * need to override this.
*/ return INBAND_BASEX;
default: return INBAND_NONE;
}
}
/** * phylink_pcs_neg_mode() - helper to determine PCS inband mode * @pl: a pointer to a &struct phylink returned from phylink_create() * @pcs: a pointer to &struct phylink_pcs * @interface: interface mode to be used * @advertising: adertisement ethtool link mode mask * * Determines the negotiation mode to be used by the PCS, and returns * one of: * * - %PHYLINK_PCS_NEG_NONE: interface mode does not support inband * - %PHYLINK_PCS_NEG_OUTBAND: an out of band mode (e.g. reading the PHY) * will be used. * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg * disabled * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled * * Note: this is for cases where the PCS itself is involved in negotiation * (e.g. Clause 37, SGMII and similar) not Clause 73.
*/ staticvoid phylink_pcs_neg_mode(struct phylink *pl, struct phylink_pcs *pcs,
phy_interface_t interface, constunsignedlong *advertising)
{ unsignedint pcs_ib_caps = 0; unsignedint phy_ib_caps = 0; unsignedint neg_mode, mode; enum inband_type type;
type = phylink_get_inband_type(interface); if (type == INBAND_NONE) {
pl->pcs_neg_mode = PHYLINK_PCS_NEG_NONE;
pl->act_link_an_mode = pl->req_link_an_mode; return;
}
mode = pl->req_link_an_mode;
pl->phy_ib_mode = 0;
if (pcs)
pcs_ib_caps = phylink_pcs_inband_caps(pcs, interface);
if (pl->phydev)
phy_ib_caps = phy_inband_caps(pl->phydev, interface);
if (pcs_ib_caps && pcs_ib_caps != LINK_INBAND_DISABLE) { /* PCS supports reporting in-band capabilities, and * supports more than disable mode.
*/ if (pcs_ib_caps & LINK_INBAND_DISABLE)
neg_mode = PHYLINK_PCS_NEG_OUTBAND; elseif (pcs_ib_caps & LINK_INBAND_ENABLE)
pcs_ib_only = true;
}
if (phy_ib_caps && phy_ib_caps != LINK_INBAND_DISABLE) { /* PHY supports in-band capabilities, and supports * more than disable mode.
*/ if (phy_ib_caps & LINK_INBAND_DISABLE)
pl->phy_ib_mode = LINK_INBAND_DISABLE; elseif (phy_ib_caps & LINK_INBAND_BYPASS)
pl->phy_ib_mode = LINK_INBAND_BYPASS; elseif (phy_ib_caps & LINK_INBAND_ENABLE)
phy_ib_only = true;
}
/* If either the PCS or PHY requires inband to be enabled, * this is an invalid configuration. Provide a diagnostic * message for this case, but don't try to force the issue.
*/ if (pcs_ib_only || phy_ib_only)
phylink_warn(pl, "firmware wants %s mode, but %s%s%s requires inband\n",
phylink_an_mode_str(mode),
pcs_ib_only ? "PCS" : "",
pcs_ib_only && phy_ib_only ? " and " : "",
phy_ib_only ? "PHY" : "");
neg_mode = PHYLINK_PCS_NEG_OUTBAND;
} elseif (type == INBAND_CISCO_SGMII || pl->phydev) { /* For SGMII modes which are designed to be used with PHYs, or * Base-X with a PHY, we try to use in-band mode where-ever * possible. However, there are some PHYs e.g. BCM84881 which * do not support in-band.
*/ constunsignedint inband_ok = LINK_INBAND_ENABLE |
LINK_INBAND_BYPASS; constunsignedint outband_ok = LINK_INBAND_DISABLE |
LINK_INBAND_BYPASS; /* PCS PHY * D E D E * 0 0 0 0 no information inband enabled * 1 0 0 0 pcs doesn't support outband * 0 1 0 0 pcs required inband enabled * 1 1 0 0 pcs optional inband enabled * 0 0 1 0 phy doesn't support outband * 1 0 1 0 pcs+phy doesn't support outband * 0 1 1 0 pcs required, phy doesn't support, invalid * 1 1 1 0 pcs optional, phy doesn't support, outband * 0 0 0 1 phy required inband enabled * 1 0 0 1 pcs doesn't support, phy required, invalid * 0 1 0 1 pcs+phy required inband enabled * 1 1 0 1 pcs optional, phy required inband enabled * 0 0 1 1 phy optional inband enabled * 1 0 1 1 pcs doesn't support, phy optional, outband * 0 1 1 1 pcs required, phy optional inband enabled * 1 1 1 1 pcs+phy optional inband enabled
*/ if ((!pcs_ib_caps || pcs_ib_caps & inband_ok) &&
(!phy_ib_caps || phy_ib_caps & inband_ok)) { /* In-band supported or unknown at both ends. Enable * in-band mode with or without bypass at the PHY.
*/ if (phy_ib_caps & LINK_INBAND_ENABLE)
pl->phy_ib_mode = LINK_INBAND_ENABLE; elseif (phy_ib_caps & LINK_INBAND_BYPASS)
pl->phy_ib_mode = LINK_INBAND_BYPASS;
neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
} elseif ((!pcs_ib_caps || pcs_ib_caps & outband_ok) &&
(!phy_ib_caps || phy_ib_caps & outband_ok)) { /* Either in-band not supported at at least one end. * In-band bypass at the other end is possible.
*/ if (phy_ib_caps & LINK_INBAND_DISABLE)
pl->phy_ib_mode = LINK_INBAND_DISABLE; elseif (phy_ib_caps & LINK_INBAND_BYPASS)
pl->phy_ib_mode = LINK_INBAND_BYPASS;
neg_mode = PHYLINK_PCS_NEG_OUTBAND; if (pl->phydev)
mode = MLO_AN_PHY;
} else { /* invalid */
phylink_warn(pl, "%s: incompatible in-band capabilities, trying in-band",
phy_modes(interface));
neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
}
} else { /* For Base-X without a PHY */ if (pcs_ib_caps == LINK_INBAND_DISABLE) /* If the PCS doesn't support inband, then inband must * be disabled.
*/
neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED; elseif (pcs_ib_caps == LINK_INBAND_ENABLE) /* If the PCS requires inband, then inband must always * be enabled.
*/
neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED; elseif (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
advertising))
neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED; else
neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
}
if (pl->mac_ops->mac_finish) {
err = pl->mac_ops->mac_finish(pl->config, pl->act_link_an_mode,
state->interface); if (err < 0) {
phylink_err(pl, "mac_finish failed: %pe\n",
ERR_PTR(err));
pl->major_config_failed = true;
}
}
if (pl->phydev && pl->phy_ib_mode) {
err = phy_config_inband(pl->phydev, pl->phy_ib_mode); if (err < 0) {
phylink_err(pl, "phy_config_inband: %pe\n",
ERR_PTR(err));
pl->major_config_failed = true;
}
}
if (pl->sfp_bus) {
rate_kbd = phylink_interface_signal_rate(state->interface); if (rate_kbd)
sfp_upstream_set_signal_rate(pl->sfp_bus, rate_kbd);
}
phylink_pcs_poll_start(pl);
}
/* * Reconfigure for a change of inband advertisement. * If we have a separate PCS, we only need to call its pcs_config() method, * and then restart AN if it indicates something changed. Otherwise, we do * the full MAC reconfiguration.
*/ staticint phylink_change_inband_advert(struct phylink *pl)
{ int ret;
if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) return 0;
/* Modern PCS-based method; update the advert at the PCS, and * restart negotiation if the pcs_config() helper indicates that * the programmed advertisement has changed.
*/
ret = phylink_pcs_config(pl->pcs, pl->pcs_neg_mode, &pl->link_config,
!!(pl->link_config.pause & MLO_PAUSE_AN)); if (ret < 0) return ret;
/* The fixed state is... fixed except for the link state, * which may be determined by a GPIO or a callback.
*/ staticvoid phylink_get_fixed_state(struct phylink *pl, struct phylink_link_state *state)
{
*state = pl->link_config; if (pl->config->get_fixed_state)
pl->config->get_fixed_state(pl->config, state); elseif (pl->link_gpio)
state->link = !!gpiod_get_value_cansleep(pl->link_gpio);
staticvoid phylink_activate_lpi(struct phylink *pl)
{ int err;
if (!test_bit(pl->cur_interface, pl->config->lpi_interfaces)) {
phylink_dbg(pl, "MAC does not support LPI with %s\n",
phy_modes(pl->cur_interface)); return;
}
switch (link_state.rate_matching) { case RATE_MATCH_PAUSE: /* The PHY is doing rate matchion from the media rate (in * the link_state) to the interface speed, and will send * pause frames to the MAC to limit its transmission speed.
*/
speed = phylink_interface_max_speed(link_state.interface);
duplex = DUPLEX_FULL;
rx_pause = true; break;
case RATE_MATCH_CRS: /* The PHY is doing rate matchion from the media rate (in * the link_state) to the interface speed, and will cause * collisions to the MAC to limit its transmission speed.
*/
speed = phylink_interface_max_speed(link_state.interface);
duplex = DUPLEX_HALF; break;
}
if (pl->mac_supports_eee && pl->phy_enable_tx_lpi)
phylink_activate_lpi(pl);
if (ndev)
netif_carrier_on(ndev);
phylink_info(pl, "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));
}
/* The PCS may have a latching link-fail indicator. If the link * was up, bring the link down and re-trigger the resolve. * Otherwise, re-read the PCS state to get the current status * of the link.
*/ if (!link_state.link) { if (cur_link_state)
retrigger = true; else
phylink_mac_pcs_get_state(pl, &link_state);
}
/* If we have a phy, the "up" state is the union of both the * PHY and the MAC
*/ if (phy)
link_state.link &= pl->phy_state.link;
/* Only update if the PHY link is up */ if (phy && pl->phy_state.link) { /* If the interface has changed, force a link down * event if the link isn't already down, and re-resolve.
*/ if (link_state.interface != pl->phy_state.interface) {
retrigger = true;
link_state.link = false;
}
link_state.interface = pl->phy_state.interface;
/* If we are doing rate matching, then the link * speed/duplex comes from the PHY
*/ if (pl->phy_state.rate_matching) {
link_state.rate_matching =
pl->phy_state.rate_matching;
link_state.speed = pl->phy_state.speed;
link_state.duplex = pl->phy_state.duplex;
}
/* If we have a PHY, we need to update with the PHY * flow control bits.
*/
link_state.pause = pl->phy_state.pause;
mac_config = true;
}
}
if (pl->act_link_an_mode != MLO_AN_FIXED)
phylink_apply_manual_flow(pl, &link_state);
if (mac_config) { if (link_state.interface != pl->link_config.interface) { /* The interface has changed, force the link down and * then reconfigure.
*/ if (cur_link_state) {
phylink_link_down(pl);
cur_link_state = false;
}
phylink_major_config(pl, false, &link_state);
pl->link_config.interface = link_state.interface;
}
}
/* If configuration of the interface failed, force the link down * until we get a successful configuration.
*/ if (pl->major_config_failed)
link_state.link = false;
if (link_state.link != cur_link_state) {
pl->old_link_state = link_state.link; if (!link_state.link)
phylink_link_down(pl); else
phylink_link_up(pl, link_state);
} if (!link_state.link && retrigger) {
pl->link_failed = false;
queue_work(system_power_efficient_wq, &pl->resolve);
}
mutex_unlock(&pl->state_mutex); if (phy)
mutex_unlock(&phy->lock);
mutex_unlock(&pl->phydev_mutex);
}
staticvoid phylink_run_resolve(struct phylink *pl)
{ if (!pl->phylink_disable_state)
queue_work(system_power_efficient_wq, &pl->resolve);
}
staticvoid phylink_run_resolve_and_disable(struct phylink *pl, int bit)
{ unsignedlong state = pl->phylink_disable_state;
bus = sfp_bus_find_fwnode(fwnode); if (IS_ERR(bus)) {
phylink_err(pl, "unable to attach SFP bus: %pe\n", bus); return PTR_ERR(bus);
}
pl->sfp_bus = bus;
ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops);
sfp_bus_put(bus);
return ret;
}
/** * phylink_set_fixed_link() - set the fixed link * @pl: a pointer to a &struct phylink returned from phylink_create() * @state: a pointer to a struct phylink_link_state. * * This function is used when the link parameters are known and do not change, * making it suitable for certain types of network connections. * * Returns: zero on success or negative error code.
*/ int phylink_set_fixed_link(struct phylink *pl, conststruct phylink_link_state *state)
{ conststruct link_capabilities *c; unsignedlong *adv;
/** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config * @fwnode: a pointer to a &struct fwnode_handle describing the network * interface * @iface: the desired link mode defined by &typedef phy_interface_t * @mac_ops: a pointer to a &struct phylink_mac_ops for the MAC. * * Create a new phylink instance, and parse the link parameters found in @np. * This will parse in-band modes, fixed-link or SFP configuration. * * Note: the rtnl lock must not be held when calling this function. * * Returns a pointer to a &struct phylink, or an error-pointer value. Users * must use IS_ERR() to check for errors from this function.
*/ struct phylink *phylink_create(struct phylink_config *config, conststruct fwnode_handle *fwnode,
phy_interface_t iface, conststruct phylink_mac_ops *mac_ops)
{ struct phylink *pl; int ret;
/* Validate the supplied configuration */ if (phy_interface_empty(config->supported_interfaces)) {
dev_err(config->dev, "phylink: error: empty supported_interfaces\n"); return ERR_PTR(-EINVAL);
}
pl = kzalloc(sizeof(*pl), GFP_KERNEL); if (!pl) return ERR_PTR(-ENOMEM);
ret = phylink_parse_mode(pl, fwnode); if (ret < 0) {
kfree(pl); return ERR_PTR(ret);
}
if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
ret = phylink_parse_fixedlink(pl, fwnode); if (ret < 0) {
kfree(pl); return ERR_PTR(ret);
}
}
pl->req_link_an_mode = pl->cfg_link_an_mode;
ret = phylink_register_sfp(pl, fwnode); if (ret < 0) {
kfree(pl); return ERR_PTR(ret);
}
return pl;
}
EXPORT_SYMBOL_GPL(phylink_create);
/** * phylink_destroy() - cleanup and destroy the phylink instance * @pl: a pointer to a &struct phylink returned from phylink_create() * * Destroy a phylink instance. Any PHY that has been attached must have been * cleaned up via phylink_disconnect_phy() prior to calling this function. * * Note: the rtnl lock must not be held when calling this function.
*/ void phylink_destroy(struct phylink *pl)
{
sfp_bus_del_upstream(pl->sfp_bus); if (pl->link_gpio)
gpiod_put(pl->link_gpio);
/** * phylink_expects_phy() - Determine if phylink expects a phy to be attached * @pl: a pointer to a &struct phylink returned from phylink_create() * * When using fixed-link mode, or in-band mode with 1000base-X or 2500base-X, * no PHY is needed. * * Returns true if phylink will be expecting a PHY.
*/ bool phylink_expects_phy(struct phylink *pl)
{ if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
(pl->cfg_link_an_mode == MLO_AN_INBAND &&
phy_interface_mode_is_8023z(pl->link_interface))) returnfalse; returntrue;
}
EXPORT_SYMBOL_GPL(phylink_expects_phy);
/* Get the LPI state from phylib */
pl->phy_enable_tx_lpi = phydev->enable_tx_lpi;
pl->mac_tx_lpi_timer = phydev->eee_cfg.tx_lpi_timer;
mutex_unlock(&pl->state_mutex);
/* If the PHY provides a bitmap of the interfaces it will be using * depending on the negotiated media speeds, use this to validate * which ethtool link modes can be used.
*/ if (!phy_interface_empty(phy->possible_interfaces)) { /* We only care about the union of the PHY's interfaces and * those which the host supports.
*/
phy_interface_and(interfaces, phy->possible_interfaces,
pl->config->supported_interfaces);
if (phy_interface_empty(interfaces)) {
phylink_err(pl, "PHY has no common interfaces\n"); return -EINVAL;
}
if (phy_on_sfp(phy)) { /* If the PHY is on a SFP, limit the interfaces to * those that can be used with a SFP module.
*/
phy_interface_and(interfaces, interfaces,
phylink_sfp_interfaces);
if (phy_interface_empty(interfaces)) {
phylink_err(pl, "SFP PHY's possible interfaces becomes empty\n"); return -EINVAL;
}
}
phylink_dbg(pl, "PHY %s doesn't supply possible interfaces\n",
phydev_name(phy));
/* Check whether we would use rate matching for the proposed interface * mode.
*/
state->rate_matching = phy_get_rate_matching(phy, state->interface);
/* Clause 45 PHYs may switch their Serdes lane between, e.g. 10GBASE-R, * 5GBASE-R, 2500BASE-X and SGMII if they are not using rate matching. * For some interface modes (e.g. RXAUI, XAUI and USXGMII) switching * their Serdes is either unnecessary or not reasonable. * * For these which switch interface modes, we really need to know which * interface modes the PHY supports to properly work out which ethtool * linkmodes can be supported. For now, as a work-around, we validate * against all interface modes, which may lead to more ethtool link * modes being advertised than are actually supported.
*/ if (phy->is_c45 && state->rate_matching == RATE_MATCH_NONE &&
state->interface != PHY_INTERFACE_MODE_RXAUI &&
state->interface != PHY_INTERFACE_MODE_XAUI &&
state->interface != PHY_INTERFACE_MODE_USXGMII)
state->interface = PHY_INTERFACE_MODE_NA;
/* * This is the new way of dealing with flow control for PHYs, * as described by Timur Tabi in commit 529ed1275263 ("net: phy: * phy drivers should not set SUPPORTED_[Asym_]Pause") except * using our validate call to the MAC, we rely upon the MAC * clearing the bits from both supported and advertising fields.
*/
phy_support_asym_pause(phy);
ret = phylink_validate_phy(pl, phy, supported, &config); if (ret) {
phylink_warn(pl, "validation of %s with support %*pb and advertisement %*pb failed: %pe\n",
phy_modes(config.interface),
__ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported,
__ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising,
ERR_PTR(ret)); return ret;
}
/* Restrict the phy advertisement according to the MAC support. */
linkmode_copy(phy->advertising, config.advertising);
/* If the MAC supports phylink managed EEE, restrict the EEE * advertisement according to the MAC's LPI capabilities.
*/ if (pl->mac_supports_eee) { /* If EEE is enabled, then we need to call phy_support_eee() * to ensure that the advertising mask is appropriately set. * This also enables EEE at the PHY.
*/ if (pl->eee_cfg.eee_enabled)
phy_support_eee(phy);
/* Convert the MAC's LPI capabilities to linkmodes */
linkmode_zero(pl->supported_lpi);
phylink_caps_to_linkmodes(pl->supported_lpi,
pl->config->lpi_capabilities);
/* Restrict the PHYs EEE support/advertisement to the modes * that the MAC supports.
*/
linkmode_and(phy->advertising_eee, phy->advertising_eee,
pl->supported_lpi);
} elseif (pl->mac_supports_eee_ops) { /* MAC supports phylink EEE, but wants EEE always disabled. */
phy_disable_eee(phy);
}
if (pl->config->mac_managed_pm)
phy->mac_managed_pm = true;
/* Allow the MAC to stop its clock if the PHY has the capability */
pl->mac_tx_clk_stop = phy_eee_tx_clock_stop_capable(phy) > 0;
if (pl->mac_supports_eee_ops) { /* Explicitly configure whether the PHY is allowed to stop it's * receive clock.
*/
ret = phy_eee_rx_clock_stop(phy,
pl->config->eee_rx_clk_stop_enable); if (ret == -EOPNOTSUPP)
ret = 0;
}
if (ret == 0 && phy_interrupt_is_valid(phy))
phy_request_interrupt(phy);
/** * phylink_connect_phy() - connect a PHY to the phylink instance * @pl: a pointer to a &struct phylink returned from phylink_create() * @phy: a pointer to a &struct phy_device. * * Connect @phy to the phylink instance specified by @pl by calling * phy_attach_direct(). Configure the @phy according to the MAC driver's * capabilities, start the PHYLIB state machine and enable any interrupts * that the PHY supports. * * This updates the phylink's ethtool supported and advertising link mode * masks. * * Returns 0 on success or a negative errno.
*/ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
{ int ret;
/* Use PHY device/driver interface */ if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
pl->link_interface = phy->interface;
pl->link_config.interface = pl->link_interface;
}
ret = phylink_attach_phy(pl, phy, pl->link_interface); if (ret < 0) return ret;
ret = phylink_bringup_phy(pl, phy, pl->link_config.interface); if (ret)
phy_detach(phy);
/** * phylink_of_phy_connect() - connect the PHY specified in the DT mode. * @pl: a pointer to a &struct phylink returned from phylink_create() * @dn: a pointer to a &struct device_node. * @flags: PHY-specific flags to communicate to the PHY device driver * * Connect the phy specified in the device node @dn to the phylink instance * specified by @pl. Actions specified in phylink_connect_phy() will be * performed. * * Returns 0 on success or a negative errno.
*/ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
u32 flags)
{ return phylink_fwnode_phy_connect(pl, of_fwnode_handle(dn), flags);
}
EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
/** * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode.
--> --------------------
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.