* [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration
@ 2026-09-29 17:22 Roman Khromenok
2026-09-29 17:22 ` [PATCH 1/2] " Roman Khromenok
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Roman Khromenok @ 2026-09-29 17:22 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Thomas Monjalon, Andrew Rybchenko
The SFF-8472 decoder does not apply the external Rx power calibration
as defined by the specification: the fourth order polynomial is reduced
to RX_PWR(0) + x * (RX_PWR(1) + RX_PWR(2) + RX_PWR(3)) and RX_PWR(4)
is never used. The code came from ethtool sfpdiag.c.
This was pointed out by Stephen during the review of the module EEPROM
decoding series; this series is based on it (dpdk-next-net).
Patch 1 fixes the formula and is intended for stable.
It also clamps the result to the 16-bit range, as the polynomial
easily overflows it with unexpected coefficients and converting
an out of range double to an integer is undefined behavior.
Patch 2 adds a unit test with all coefficients set.
Note: the calibration formula 1 (Tx bias, Tx power, temperature,
voltage) has the same out of range conversion issue; it is left
for a separate patch.
Depends-on: series-39436 ("ethdev: add API to decode module EEPROM")
Roman Khromenok (2):
ethdev: fix SFF-8472 external Rx power calibration
test: check SFF-8472 external Rx power calibration
app/test/test_ethdev_module_eeprom.c | 37 ++++++++++++++++++++++++++++
lib/ethdev/sff_8472.c | 27 +++++++++++++-------
2 files changed, 55 insertions(+), 9 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] ethdev: fix SFF-8472 external Rx power calibration
2026-09-29 17:22 [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration Roman Khromenok
@ 2026-09-29 17:22 ` Roman Khromenok
2026-09-29 17:22 ` [PATCH 2/2] test: check " Roman Khromenok
2026-09-30 16:27 ` [PATCH 0/2] ethdev: fix " Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Roman Khromenok @ 2026-09-29 17:22 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Thomas Monjalon, Andrew Rybchenko, stable
With external calibration, SFF-8472 defines the received power
as a fourth order polynomial of the raw reading x:
RX_PWR(4) * x^4 + RX_PWR(3) * x^3 + RX_PWR(2) * x^2 +
RX_PWR(1) * x + RX_PWR(0)
The decoder computed RX_PWR(0) + x * (RX_PWR(1) + RX_PWR(2) + RX_PWR(3))
and ignored RX_PWR(4), so the reported power was wrong for modules
using the higher order coefficients.
Evaluate the polynomial in double precision and clamp the result
to the 16-bit range of the stored value, as converting an out of range
floating point value to an integer is undefined behavior.
Fixes: 0caf7f376b08 ("ethdev: support SFF-8472 module telemetry")
Cc: stable@dpdk.org
Signed-off-by: Roman Khromenok <roma55592@yandex.ru>
---
lib/ethdev/sff_8472.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/lib/ethdev/sff_8472.c b/lib/ethdev/sff_8472.c
index cdb6ef1f7e..3c73a829a8 100644
--- a/lib/ethdev/sff_8472.c
+++ b/lib/ethdev/sff_8472.c
@@ -189,7 +189,8 @@ static float befloattoh(const uint8_t *source)
static void sff_8472_calibration(const uint8_t *data, struct sff_diags *sd)
{
unsigned long i;
- uint16_t rx_reading;
+ double rx_reading;
+ double rx_power;
/* Calibration should occur for all values (threshold and current) */
for (i = 0; i < RTE_DIM(sd->bias_cur); ++i) {
@@ -207,16 +208,24 @@ static void sff_8472_calibration(const uint8_t *data, struct sff_diags *sd)
sd->sfp_temp[i] += A2_OFFSET_TO_OFF(SFF_A2_CAL_T_OFF);
/*
- * Apply calibration formula 2 (Rx Power only)
+ * Apply calibration formula 2 (Rx Power only):
+ * RX_PWR(4) * x^4 + RX_PWR(3) * x^3 + RX_PWR(2) * x^2 +
+ * RX_PWR(1) * x + RX_PWR(0)
*/
rx_reading = sd->rx_power[i];
- sd->rx_power[i] = A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR0);
- sd->rx_power[i] += rx_reading *
- A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR1);
- sd->rx_power[i] += rx_reading *
- A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR2);
- sd->rx_power[i] += rx_reading *
- A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR3);
+ rx_power = A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR4);
+ rx_power = rx_power * rx_reading + A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR3);
+ rx_power = rx_power * rx_reading + A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR2);
+ rx_power = rx_power * rx_reading + A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR1);
+ rx_power = rx_power * rx_reading + A2_OFFSET_TO_RXPWRx(SFF_A2_CAL_RXPWR0);
+
+ /* the result is stored in 0.1 uW units, out of range is not representable */
+ if (!(rx_power > 0))
+ sd->rx_power[i] = 0;
+ else if (rx_power >= UINT16_MAX)
+ sd->rx_power[i] = UINT16_MAX;
+ else
+ sd->rx_power[i] = rx_power;
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] test: check SFF-8472 external Rx power calibration
2026-09-29 17:22 [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration Roman Khromenok
2026-09-29 17:22 ` [PATCH 1/2] " Roman Khromenok
@ 2026-09-29 17:22 ` Roman Khromenok
2026-09-30 16:27 ` [PATCH 0/2] ethdev: fix " Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Roman Khromenok @ 2026-09-29 17:22 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Thomas Monjalon, Andrew Rybchenko
Add a test case with all the SFF-8472 Rx power calibration
coefficients set, so that the whole fourth order polynomial
is checked, including RX_PWR(4).
Signed-off-by: Roman Khromenok <roma55592@yandex.ru>
---
app/test/test_ethdev_module_eeprom.c | 37 ++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/app/test/test_ethdev_module_eeprom.c b/app/test/test_ethdev_module_eeprom.c
index d76bdc0060..b07a18aa06 100644
--- a/app/test/test_ethdev_module_eeprom.c
+++ b/app/test/test_ethdev_module_eeprom.c
@@ -269,6 +269,42 @@ test_module_eeprom_sfp_8472_ext_cal_unaligned(void)
return TEST_SUCCESS;
}
+static void
+put_be_float(uint8_t *data, unsigned int offset, uint32_t bits)
+{
+ data[offset] = bits >> 24;
+ data[offset + 1] = (bits >> 16) & 0xff;
+ data[offset + 2] = (bits >> 8) & 0xff;
+ data[offset + 3] = bits & 0xff;
+}
+
+static int
+test_module_eeprom_sfp_8472_rx_power_polynomial(void)
+{
+ uint8_t data[RTE_ETH_MODULE_SFF_8472_LEN];
+ uint8_t *a2 = data + RTE_ETH_MODULE_SFF_8079_LEN;
+
+ fill_sfp(data);
+ /* diagnostics implemented, externally calibrated, average RX power */
+ data[92] = 0x58;
+ a2[76] = 1; /* TX bias slope */
+ a2[80] = 1; /* TX power slope */
+ a2[84] = 1; /* temperature slope */
+ a2[88] = 1; /* voltage slope */
+ put_u16(a2, 104, 10); /* raw RX power x = 10 */
+ /* 0.125 x^4 + 0.25 x^3 + 0.5 x^2 + x = 1250 + 250 + 50 + 10 = 1560 */
+ put_be_float(a2, 56, 0x3e000000); /* RX_PWR(4) = 0.125 */
+ put_be_float(a2, 60, 0x3e800000); /* RX_PWR(3) = 0.25 */
+ put_be_float(a2, 64, 0x3f000000); /* RX_PWR(2) = 0.5 */
+ put_be_float(a2, 68, 0x3f800000); /* RX_PWR(1) = 1.0 */
+ put_be_float(a2, 72, 0); /* RX_PWR(0) = 0 */
+
+ TEST_ASSERT_SUCCESS(parse(RTE_ETH_MODULE_SFF_8472, data, sizeof(data)),
+ "Failed to parse externally calibrated SFF-8472 data");
+ CHECK_FIELD("Receiver signal average optical power", "0.1560 mW / -8.07 dBm");
+ return TEST_SUCCESS;
+}
+
static int
test_module_eeprom_invalid(void)
{
@@ -318,6 +354,7 @@ static struct unit_test_suite module_eeprom_testsuite = {
TEST_CASE(test_module_eeprom_sfp_8472),
TEST_CASE(test_module_eeprom_sfp_8472_short),
TEST_CASE(test_module_eeprom_sfp_8472_ext_cal_unaligned),
+ TEST_CASE(test_module_eeprom_sfp_8472_rx_power_polynomial),
TEST_CASE(test_module_eeprom_qsfp_8636),
TEST_CASE(test_module_eeprom_qsfp_8636_thresholds),
TEST_CASE(test_module_eeprom_invalid),
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration
2026-09-29 17:22 [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration Roman Khromenok
2026-09-29 17:22 ` [PATCH 1/2] " Roman Khromenok
2026-09-29 17:22 ` [PATCH 2/2] test: check " Roman Khromenok
@ 2026-09-30 16:27 ` Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2026-09-30 16:27 UTC (permalink / raw)
To: Roman Khromenok; +Cc: dev, Thomas Monjalon, Andrew Rybchenko
On Tue, 29 Sep 2026 19:22:08 +0200
Roman Khromenok <roma55592@yandex.ru> wrote:
> The SFF-8472 decoder does not apply the external Rx power calibration
> as defined by the specification: the fourth order polynomial is reduced
> to RX_PWR(0) + x * (RX_PWR(1) + RX_PWR(2) + RX_PWR(3)) and RX_PWR(4)
> is never used. The code came from ethtool sfpdiag.c.
>
> This was pointed out by Stephen during the review of the module EEPROM
> decoding series; this series is based on it (dpdk-next-net).
>
> Patch 1 fixes the formula and is intended for stable.
> It also clamps the result to the 16-bit range, as the polynomial
> easily overflows it with unexpected coefficients and converting
> an out of range double to an integer is undefined behavior.
> Patch 2 adds a unit test with all coefficients set.
>
> Note: the calibration formula 1 (Tx bias, Tx power, temperature,
> voltage) has the same out of range conversion issue; it is left
> for a separate patch.
>
> Depends-on: series-39436 ("ethdev: add API to decode module EEPROM")
>
> Roman Khromenok (2):
> ethdev: fix SFF-8472 external Rx power calibration
> test: check SFF-8472 external Rx power calibration
>
> app/test/test_ethdev_module_eeprom.c | 37 ++++++++++++++++++++++++++++
> lib/ethdev/sff_8472.c | 27 +++++++++++++-------
> 2 files changed, 55 insertions(+), 9 deletions(-)
>
Looks ok as is, applied to next-net.
Detailed AI review had a bunch of feedback about range checking.
Review: [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration
Patch 1 applies to main on its own and builds with -Dwerror=true, so
it backports as is. Patch 2 needs test_ethdev_module_eeprom.c from
the module EEPROM decoding API series.
The test input decodes to "0.1560 mW / -8.07 dBm" with the fix and
"0.0017 mW / -27.70 dBm" without it, so the test catches the bug.
Patch 1/2 ethdev: fix SFF-8472 external Rx power calibration
Info
- The final conversion truncates:
sd->rx_power[i] = rx_power;
Coefficients that are not exact in binary land just below the
integer. RX_PWR(1) = 0.7 is stored as 0.69999999, so x = 1000
decodes to 699 (0.0699 mW) instead of 700. rx_power is known
positive in that branch, so round instead:
sd->rx_power[i] = rx_power + 0.5;
The UINT16_MAX check still holds, anything below 65535 rounds to
at most 65535.
- Pre-existing, not introduced by this patch: formula 1 just above
has the same out of range float to integer conversion the commit
message describes.
sd->bias_cur[i] *= A2_OFFSET_TO_SLP(SFF_A2_CAL_TXI_SLP);
The slope is a double up to 255.996, so a large reading leaves
the uint16_t range. Same for tx_power and sfp_voltage, and for
sfp_temp (int16_t) in both directions. Worth a follow up patch
with the same clamping.
Patch 2/2 test: check SFF-8472 external Rx power calibration
Info
- The test covers the polynomial but neither clamp branch. Two more
cases would cover them:
x = 10, RX_PWR(1) = -1.0 -> "0.0000 mW / -inf dBm"
x = 65535, RX_PWR(4) = 1.0 -> "6.5535 mW / 8.16 dBm"
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-30 16:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-29 17:22 [PATCH 0/2] ethdev: fix SFF-8472 external Rx power calibration Roman Khromenok
2026-09-29 17:22 ` [PATCH 1/2] " Roman Khromenok
2026-09-29 17:22 ` [PATCH 2/2] test: check " Roman Khromenok
2026-09-30 16:27 ` [PATCH 0/2] ethdev: fix " Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox