Commit 624407d2 authored by Russell King's avatar Russell King Committed by Jakub Kicinski

net: sfp: cope with SFPs that set both LOS normal and LOS inverted

The SFP MSA defines two option bits in byte 65 to indicate how the
Rx_LOS signal on SFP pin 8 behaves:

bit 2 - Loss of Signal implemented, signal inverted from standard
        definition in SFP MSA (often called "Signal Detect").
bit 1 - Loss of Signal implemented, signal as defined in SFP MSA
        (often called "Rx_LOS").

Clearly, setting both bits results in a meaningless situation: it would
mean that LOS is implemented in both the normal sense (1 = signal loss)
and inverted sense (0 = signal loss).

Unfortunately, there are modules out there which set both bits, which
will be initially interpret as "inverted" sense, and then, if the LOS
signal changes state, we will toggle between LINK_UP and WAIT_LOS
states.

Change our LOS handling to give well defined behaviour: only interpret
these bits as meaningful if exactly one is set, otherwise treat it as
if LOS is not implemented.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/E1kyYQa-0004iR-CU@rmk-PC.armlinux.org.ukSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 537e2b88
...@@ -1482,15 +1482,19 @@ static void sfp_sm_link_down(struct sfp *sfp) ...@@ -1482,15 +1482,19 @@ static void sfp_sm_link_down(struct sfp *sfp)
static void sfp_sm_link_check_los(struct sfp *sfp) static void sfp_sm_link_check_los(struct sfp *sfp)
{ {
unsigned int los = sfp->state & SFP_F_LOS; const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED);
const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL);
__be16 los_options = sfp->id.ext.options & (los_inverted | los_normal);
bool los = false;
/* If neither SFP_OPTIONS_LOS_INVERTED nor SFP_OPTIONS_LOS_NORMAL /* If neither SFP_OPTIONS_LOS_INVERTED nor SFP_OPTIONS_LOS_NORMAL
* are set, we assume that no LOS signal is available. * are set, we assume that no LOS signal is available. If both are
* set, we assume LOS is not implemented (and is meaningless.)
*/ */
if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED)) if (los_options == los_inverted)
los ^= SFP_F_LOS; los = !(sfp->state & SFP_F_LOS);
else if (!(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL))) else if (los_options == los_normal)
los = 0; los = !!(sfp->state & SFP_F_LOS);
if (los) if (los)
sfp_sm_next(sfp, SFP_S_WAIT_LOS, 0); sfp_sm_next(sfp, SFP_S_WAIT_LOS, 0);
...@@ -1500,18 +1504,22 @@ static void sfp_sm_link_check_los(struct sfp *sfp) ...@@ -1500,18 +1504,22 @@ static void sfp_sm_link_check_los(struct sfp *sfp)
static bool sfp_los_event_active(struct sfp *sfp, unsigned int event) static bool sfp_los_event_active(struct sfp *sfp, unsigned int event)
{ {
return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) && const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED);
event == SFP_E_LOS_LOW) || const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL);
(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) && __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal);
event == SFP_E_LOS_HIGH);
return (los_options == los_inverted && event == SFP_E_LOS_LOW) ||
(los_options == los_normal && event == SFP_E_LOS_HIGH);
} }
static bool sfp_los_event_inactive(struct sfp *sfp, unsigned int event) static bool sfp_los_event_inactive(struct sfp *sfp, unsigned int event)
{ {
return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) && const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED);
event == SFP_E_LOS_HIGH) || const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL);
(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) && __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal);
event == SFP_E_LOS_LOW);
return (los_options == los_inverted && event == SFP_E_LOS_HIGH) ||
(los_options == los_normal && event == SFP_E_LOS_LOW);
} }
static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn) static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment