Commit 02eaf5a7 authored by Russell King (Oracle)'s avatar Russell King (Oracle) Committed by Jakub Kicinski

net: sfp: check firmware provided max power

Check that the firmware provided maximum power is at least 1W, which
is the minimum power level for any SFP module.

Now that we enforce the minimum of 1W, we can exit early from
sfp_module_parse_power() if the module power is 1W or less.
Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a272bcb9
...@@ -1766,6 +1766,12 @@ static int sfp_module_parse_power(struct sfp *sfp) ...@@ -1766,6 +1766,12 @@ static int sfp_module_parse_power(struct sfp *sfp)
if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL)) if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL))
power_mW = 2000; power_mW = 2000;
/* Power level 1 modules (max. 1W) are always supported. */
if (power_mW <= 1000) {
sfp->module_power_mW = power_mW;
return 0;
}
supports_a2 = sfp->id.ext.sff8472_compliance != supports_a2 = sfp->id.ext.sff8472_compliance !=
SFP_SFF8472_COMPLIANCE_NONE || SFP_SFF8472_COMPLIANCE_NONE ||
sfp->id.ext.diagmon & SFP_DIAGMON_DDM; sfp->id.ext.diagmon & SFP_DIAGMON_DDM;
...@@ -1789,12 +1795,6 @@ static int sfp_module_parse_power(struct sfp *sfp) ...@@ -1789,12 +1795,6 @@ static int sfp_module_parse_power(struct sfp *sfp)
} }
} }
if (power_mW <= 1000) {
/* Modules below 1W do not require a power change sequence */
sfp->module_power_mW = power_mW;
return 0;
}
if (!supports_a2) { if (!supports_a2) {
/* The module power level is below the host maximum and the /* The module power level is below the host maximum and the
* module appears not to implement bus address 0xa2, so assume * module appears not to implement bus address 0xa2, so assume
...@@ -2729,8 +2729,12 @@ static int sfp_probe(struct platform_device *pdev) ...@@ -2729,8 +2729,12 @@ static int sfp_probe(struct platform_device *pdev)
device_property_read_u32(&pdev->dev, "maximum-power-milliwatt", device_property_read_u32(&pdev->dev, "maximum-power-milliwatt",
&sfp->max_power_mW); &sfp->max_power_mW);
if (!sfp->max_power_mW) if (sfp->max_power_mW < 1000) {
if (sfp->max_power_mW)
dev_warn(sfp->dev,
"Firmware bug: host maximum power should be at least 1W\n");
sfp->max_power_mW = 1000; sfp->max_power_mW = 1000;
}
dev_info(sfp->dev, "Host maximum power %u.%uW\n", dev_info(sfp->dev, "Host maximum power %u.%uW\n",
sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10);
......
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