Skip to content

Commit b7ad14c

Browse files
Russell Kingdavem330
authored andcommitted
net: phylink: re-implement interface configuration with PCS
With PCS support, how we implement interface reconfiguration (or other major reconfiguration) is not up to the job; we end up reconfiguring the PCS for an interface change while the link could potentially be up. In order to solve this, add two additional MAC methods for major configuration, one to prepare for the change, and one to finish the change. This allows mvneta and mvpp2 to shutdown what they require prior to the MAC and PCS configuration calls, and then restart as appropriate. This impacts ksettings_set(), which now needs to identify whether the change is a minor tweak to the advertisement masks or whether the interface mode has changed, and call the appropriate function for that update. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1571e70 commit b7ad14c

2 files changed

Lines changed: 100 additions & 23 deletions

File tree

‎drivers/net/phy/phylink.c‎

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,47 @@ static void phylink_mac_pcs_an_restart(struct phylink *pl)
433433
}
434434
}
435435

436-
static void phylink_pcs_config(struct phylink *pl, bool force_restart,
437-
const struct phylink_link_state *state)
436+
static void phylink_major_config(struct phylink *pl, bool restart,
437+
const struct phylink_link_state *state)
438438
{
439-
bool restart = force_restart;
439+
int err;
440+
441+
phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
440442

441-
if (pl->pcs_ops && pl->pcs_ops->pcs_config(pl->config,
442-
pl->cur_link_an_mode,
443-
state->interface,
444-
state->advertising,
445-
!!(pl->link_config.pause &
446-
MLO_PAUSE_AN)))
447-
restart = true;
443+
if (pl->mac_ops->mac_prepare) {
444+
err = pl->mac_ops->mac_prepare(pl->config, pl->cur_link_an_mode,
445+
state->interface);
446+
if (err < 0) {
447+
phylink_err(pl, "mac_prepare failed: %pe\n",
448+
ERR_PTR(err));
449+
return;
450+
}
451+
}
448452

449453
phylink_mac_config(pl, state);
450454

455+
if (pl->pcs_ops) {
456+
err = pl->pcs_ops->pcs_config(pl->config, pl->cur_link_an_mode,
457+
state->interface,
458+
state->advertising,
459+
!!(pl->link_config.pause &
460+
MLO_PAUSE_AN));
461+
if (err < 0)
462+
phylink_err(pl, "pcs_config failed: %pe\n",
463+
ERR_PTR(err));
464+
if (err > 0)
465+
restart = true;
466+
}
451467
if (restart)
452468
phylink_mac_pcs_an_restart(pl);
469+
470+
if (pl->mac_ops->mac_finish) {
471+
err = pl->mac_ops->mac_finish(pl->config, pl->cur_link_an_mode,
472+
state->interface);
473+
if (err < 0)
474+
phylink_err(pl, "mac_prepare failed: %pe\n",
475+
ERR_PTR(err));
476+
}
453477
}
454478

455479
/*
@@ -555,7 +579,7 @@ static void phylink_mac_initial_config(struct phylink *pl, bool force_restart)
555579
link_state.link = false;
556580

557581
phylink_apply_manual_flow(pl, &link_state);
558-
phylink_pcs_config(pl, force_restart, &link_state);
582+
phylink_major_config(pl, force_restart, &link_state);
559583
}
560584

561585
static const char *phylink_pause_to_str(int pause)
@@ -674,7 +698,7 @@ static void phylink_resolve(struct work_struct *w)
674698
phylink_link_down(pl);
675699
cur_link_state = false;
676700
}
677-
phylink_pcs_config(pl, false, &link_state);
701+
phylink_major_config(pl, false, &link_state);
678702
pl->link_config.interface = link_state.interface;
679703
} else if (!pl->pcs_ops) {
680704
/* The interface remains unchanged, only the speed,
@@ -1450,21 +1474,26 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
14501474
return -EINVAL;
14511475

14521476
mutex_lock(&pl->state_mutex);
1453-
linkmode_copy(pl->link_config.advertising, config.advertising);
1454-
pl->link_config.interface = config.interface;
14551477
pl->link_config.speed = config.speed;
14561478
pl->link_config.duplex = config.duplex;
14571479
pl->link_config.an_enabled = config.an_enabled;
14581480

1459-
if (pl->cur_link_an_mode == MLO_AN_INBAND &&
1460-
!test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) {
1461-
/* If in 802.3z mode, this updates the advertisement.
1462-
*
1463-
* If we are in SGMII mode without a PHY, there is no
1464-
* advertisement; the only thing we have is the pause
1465-
* modes which can only come from a PHY.
1466-
*/
1467-
phylink_pcs_config(pl, true, &pl->link_config);
1481+
if (pl->link_config.interface != config.interface) {
1482+
/* The interface changed, e.g. 1000base-X <-> 2500base-X */
1483+
/* We need to force the link down, then change the interface */
1484+
if (pl->old_link_state) {
1485+
phylink_link_down(pl);
1486+
pl->old_link_state = false;
1487+
}
1488+
if (!test_bit(PHYLINK_DISABLE_STOPPED,
1489+
&pl->phylink_disable_state))
1490+
phylink_major_config(pl, false, &config);
1491+
pl->link_config.interface = config.interface;
1492+
linkmode_copy(pl->link_config.advertising, config.advertising);
1493+
} else if (!linkmode_equal(pl->link_config.advertising,
1494+
config.advertising)) {
1495+
linkmode_copy(pl->link_config.advertising, config.advertising);
1496+
phylink_change_inband_advert(pl);
14681497
}
14691498
mutex_unlock(&pl->state_mutex);
14701499

‎include/linux/phylink.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ struct phylink_config {
7676
* struct phylink_mac_ops - MAC operations structure.
7777
* @validate: Validate and update the link configuration.
7878
* @mac_pcs_get_state: Read the current link state from the hardware.
79+
* @mac_prepare: prepare for a major reconfiguration of the interface.
7980
* @mac_config: configure the MAC for the selected mode and state.
81+
* @mac_finish: finish a major reconfiguration of the interface.
8082
* @mac_an_restart: restart 802.3z BaseX autonegotiation.
8183
* @mac_link_down: take the link down.
8284
* @mac_link_up: allow the link to come up.
@@ -89,8 +91,12 @@ struct phylink_mac_ops {
8991
struct phylink_link_state *state);
9092
void (*mac_pcs_get_state)(struct phylink_config *config,
9193
struct phylink_link_state *state);
94+
int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
95+
phy_interface_t iface);
9296
void (*mac_config)(struct phylink_config *config, unsigned int mode,
9397
const struct phylink_link_state *state);
98+
int (*mac_finish)(struct phylink_config *config, unsigned int mode,
99+
phy_interface_t iface);
94100
void (*mac_an_restart)(struct phylink_config *config);
95101
void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
96102
phy_interface_t interface);
@@ -145,6 +151,31 @@ void validate(struct phylink_config *config, unsigned long *supported,
145151
void mac_pcs_get_state(struct phylink_config *config,
146152
struct phylink_link_state *state);
147153

154+
/**
155+
* mac_prepare() - prepare to change the PHY interface mode
156+
* @config: a pointer to a &struct phylink_config.
157+
* @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
158+
* @iface: interface mode to switch to
159+
*
160+
* phylink will call this method at the beginning of a full initialisation
161+
* of the link, which includes changing the interface mode or at initial
162+
* startup time. It may be called for the current mode. The MAC driver
163+
* should perform whatever actions are required, e.g. disabling the
164+
* Serdes PHY.
165+
*
166+
* This will be the first call in the sequence:
167+
* - mac_prepare()
168+
* - mac_config()
169+
* - pcs_config()
170+
* - possible pcs_an_restart()
171+
* - mac_finish()
172+
*
173+
* Returns zero on success, or negative errno on failure which will be
174+
* reported to the kernel log.
175+
*/
176+
int mac_prepare(struct phylink_config *config, unsigned int mode,
177+
phy_interface_t iface);
178+
148179
/**
149180
* mac_config() - configure the MAC for the selected mode and state
150181
* @config: a pointer to a &struct phylink_config.
@@ -220,6 +251,23 @@ void mac_pcs_get_state(struct phylink_config *config,
220251
void mac_config(struct phylink_config *config, unsigned int mode,
221252
const struct phylink_link_state *state);
222253

254+
/**
255+
* mac_finish() - finish a to change the PHY interface mode
256+
* @config: a pointer to a &struct phylink_config.
257+
* @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
258+
* @iface: interface mode to switch to
259+
*
260+
* phylink will call this if it called mac_prepare() to allow the MAC to
261+
* complete any necessary steps after the MAC and PCS have been configured
262+
* for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
263+
* Serdes PHY here if it was previously disabled by mac_prepare().
264+
*
265+
* Returns zero on success, or negative errno on failure which will be
266+
* reported to the kernel log.
267+
*/
268+
int mac_finish(struct phylink_config *config, unsigned int mode,
269+
phy_interface_t iface);
270+
223271
/**
224272
* mac_an_restart() - restart 802.3z BaseX autonegotiation
225273
* @config: a pointer to a &struct phylink_config.

0 commit comments

Comments
 (0)