Skip to content

Commit

Permalink
Merge branch 'net-sfp-add-support-for-control-of-rate-selection'
Browse files Browse the repository at this point in the history
Russell King says:

====================
net: sfp: add support for control of rate selection

This series introduces control of the rate selection SFP pins (or
their soft state in the I2C diagnostics EEPROM). Several SNIA documents
(referenced in the commits) describe the various different modes for
these, and we implement them all for maximum compatibility, but as
we know, SFP modules tend to do their own thing, so that may not be
sufficient.

In order to implement this, we need to change the locking arrangement
in the SFP layer - we need to make st_mutex (state mutex) able to be
taken from within the rtnl lock and sm_mutex (state machine mutex).
Essentially, st_mutex protects the hard (gpio) and soft state signals.

So, patches 2 through 5 rejig the locking so that st_mutex is only
ever taken when we want to fiddle with the signal state variables,
read or write the GPIOs, or read or write the soft state.

Patch 1 adds a helper that makes the locking rejig a little easier
as it combines the update of sfp->state with setting the updated
control state to the module.

Patch 6 adds code to phylink to give the signalling rate for various
PHY interface modes that are relevant to SFPs - this is the baud rate
of the encoded signal, not the data rate, which is what matters for
SFPs. This rate is passed through the SFP bus layer into the SFP
socket driver, which initially has a stub sfp_set_signal_rate().

Patch 7 adds the code to the SFP socket driver to parse the rate
selection data in the EEPROM, configure which RS signals need to be
driven, and the signalling rate threshold. We fill in
sfp_set_signal_rate() to set the rate select pins as appropriate.
====================

Link: https://lore.kernel.org/r/ZGSuTY8GqjM+sqta@shell.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed May 19, 2023
2 parents 90223c1 + fc082b3 commit 643510c
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 52 deletions.
24 changes: 24 additions & 0 deletions drivers/net/phy/phylink.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ static const char *phylink_an_mode_str(unsigned int mode)
return mode < ARRAY_SIZE(modestr) ? modestr[mode] : "unknown";
}

static unsigned int 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
Expand Down Expand Up @@ -1025,6 +1042,7 @@ static void phylink_major_config(struct phylink *pl, bool restart,
{
struct phylink_pcs *pcs = NULL;
bool pcs_changed = false;
unsigned int rate_kbd;
int err;

phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
Expand Down Expand Up @@ -1084,6 +1102,12 @@ static void phylink_major_config(struct phylink *pl, bool restart,
ERR_PTR(err));
}

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);
}

Expand Down
20 changes: 20 additions & 0 deletions drivers/net/phy/sfp-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,26 @@ static void sfp_upstream_clear(struct sfp_bus *bus)
bus->upstream = NULL;
}

/**
* sfp_upstream_set_signal_rate() - set data signalling rate
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
* @rate_kbd: signalling rate in units of 1000 baud
*
* Configure the rate select settings on the SFP module for the signalling
* rate (not the same as the data rate).
*
* Locks that may be held:
* Phylink's state_mutex
* rtnl lock
* SFP's sm_mutex
*/
void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd)
{
if (bus->registered)
bus->socket_ops->set_signal_rate(bus->sfp, rate_kbd);
}
EXPORT_SYMBOL_GPL(sfp_upstream_set_signal_rate);

/**
* sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
* @fwnode: firmware node for the parent device (MAC or PHY)
Expand Down
Loading

0 comments on commit 643510c

Please sign in to comment.