Skip to content

Commit

Permalink
net: sfp: add A2h presence flag
Browse files Browse the repository at this point in the history
The hwmon code wants to know when it is safe to access the A2h data
stored in a separate address. We indicate that this is present when
we have SFF-8472 compliance and the lack of an address-change
sequence.,

The same conditions are also true if we want to access other controls
and status in the A2h address. So let's make a flag to indicate whether
we can access it, instead of repeating the conditions throughout the
code.

For now, only convert the hwmon code.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Russell King (Oracle) authored and Jakub Kicinski committed Mar 11, 2023
1 parent c568a8d commit f94b9be
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions drivers/net/phy/sfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ struct sfp {
unsigned int module_power_mW;
unsigned int module_t_start_up;
unsigned int module_t_wait;

bool have_a2;
bool tx_fault_ignore;

const struct sfp_quirk *quirk;
Expand Down Expand Up @@ -1453,20 +1455,10 @@ static void sfp_hwmon_probe(struct work_struct *work)

static int sfp_hwmon_insert(struct sfp *sfp)
{
if (sfp->id.ext.sff8472_compliance == SFP_SFF8472_COMPLIANCE_NONE)
return 0;

if (!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM))
return 0;

if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
/* This driver in general does not support address
* change.
*/
return 0;

mod_delayed_work(system_wq, &sfp->hwmon_probe, 1);
sfp->hwmon_tries = R_PROBE_RETRY_SLOW;
if (sfp->have_a2 && sfp->id.ext.diagmon & SFP_DIAGMON_DDM) {
mod_delayed_work(system_wq, &sfp->hwmon_probe, 1);
sfp->hwmon_tries = R_PROBE_RETRY_SLOW;
}

return 0;
}
Expand Down Expand Up @@ -1916,6 +1908,18 @@ static int sfp_cotsworks_fixup_check(struct sfp *sfp, struct sfp_eeprom_id *id)
return 0;
}

static int sfp_module_parse_sff8472(struct sfp *sfp)
{
/* If the module requires address swap mode, warn about it */
if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
dev_warn(sfp->dev,
"module address swap to access page 0xA2 is not supported.\n");
else
sfp->have_a2 = true;

return 0;
}

static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
{
/* SFP module inserted - read I2C data */
Expand Down Expand Up @@ -2053,10 +2057,11 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
return -EINVAL;
}

/* If the module requires address swap mode, warn about it */
if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
dev_warn(sfp->dev,
"module address swap to access page 0xA2 is not supported.\n");
if (sfp->id.ext.sff8472_compliance != SFP_SFF8472_COMPLIANCE_NONE) {
ret = sfp_module_parse_sff8472(sfp);
if (ret < 0)
return ret;
}

/* Parse the module power requirement */
ret = sfp_module_parse_power(sfp);
Expand Down Expand Up @@ -2103,6 +2108,7 @@ static void sfp_sm_mod_remove(struct sfp *sfp)

memset(&sfp->id, 0, sizeof(sfp->id));
sfp->module_power_mW = 0;
sfp->have_a2 = false;

dev_info(sfp->dev, "module removed\n");
}
Expand Down

0 comments on commit f94b9be

Please sign in to comment.