Commit f1ae32a7 authored by Russell King (Oracle)'s avatar Russell King (Oracle) Committed by Jakub Kicinski
Browse files

net: phylink: force link down on major_config failure



If we fail to configure the MAC or PCS according to the desired mode,
do not allow the network link to come up until we have successfully
configured the MAC and PCS. This improves phylink's behaviour when an
error occurs.

Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1twkqO-0006FI-Gm@rmk-PC.armlinux.org.uk


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent cc04ed50
Loading
Loading
Loading
Loading
+34 −8
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ struct phylink {
	unsigned int pcs_state;

	bool link_failed;
	bool major_config_failed;
	bool mac_supports_eee_ops;
	bool mac_supports_eee;
	bool phy_enable_tx_lpi;
@@ -1216,12 +1217,16 @@ static void phylink_major_config(struct phylink *pl, bool restart,
		    phylink_an_mode_str(pl->req_link_an_mode),
		    phy_modes(state->interface));

	pl->major_config_failed = false;

	if (pl->mac_ops->mac_select_pcs) {
		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
		if (IS_ERR(pcs)) {
			phylink_err(pl,
				    "mac_select_pcs unexpectedly failed: %pe\n",
				    pcs);

			pl->major_config_failed = true;
			return;
		}

@@ -1243,6 +1248,7 @@ static void phylink_major_config(struct phylink *pl, bool restart,
		if (err < 0) {
			phylink_err(pl, "mac_prepare failed: %pe\n",
				    ERR_PTR(err));
			pl->major_config_failed = true;
			return;
		}
	}
@@ -1266,19 +1272,27 @@ static void phylink_major_config(struct phylink *pl, bool restart,

	phylink_mac_config(pl, state);

	if (pl->pcs)
		phylink_pcs_post_config(pl->pcs, state->interface);
	if (pl->pcs) {
		err = phylink_pcs_post_config(pl->pcs, state->interface);
		if (err < 0) {
			phylink_err(pl, "pcs_post_config failed: %pe\n",
				    ERR_PTR(err));

			pl->major_config_failed = true;
		}
	}

	if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
		phylink_pcs_enable(pl->pcs);

	err = phylink_pcs_config(pl->pcs, pl->pcs_neg_mode, state,
				 !!(pl->link_config.pause & MLO_PAUSE_AN));
	if (err < 0)
		phylink_err(pl, "pcs_config failed: %pe\n",
			    ERR_PTR(err));
	else if (err > 0)
	if (err < 0) {
		phylink_err(pl, "pcs_config failed: %pe\n", ERR_PTR(err));
		pl->major_config_failed = true;
	} else if (err > 0) {
		restart = true;
	}

	if (restart)
		phylink_pcs_an_restart(pl);
@@ -1286,16 +1300,22 @@ static void phylink_major_config(struct phylink *pl, bool restart,
	if (pl->mac_ops->mac_finish) {
		err = pl->mac_ops->mac_finish(pl->config, pl->act_link_an_mode,
					      state->interface);
		if (err < 0)
		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)
		if (err < 0) {
			phylink_err(pl, "phy_config_inband: %pe\n",
				    ERR_PTR(err));

			pl->major_config_failed = true;
		}
	}

	if (pl->sfp_bus) {
@@ -1639,6 +1659,12 @@ static void phylink_resolve(struct work_struct *w)
		}
	}

	/* 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)