Add SFP quirk for devices that misreport DDM capability

On a QSFPTEK QT-SFP+-T (RTL8261C) 10GBase-T module, the diag type field
(92) comes back as 0x00, but there's actually some statistics available
like temperature. Other metrics may be hard-coded values.

Add a basic struct that allows matching on vendor and/or model, using a
bitfield to allow multiple quirks for a given SFP module. Only
SFP_QUIRK_DDM is implemented.

For modules matching SFP_QUIRK_DDM, attempt an I2C read of the MSB of
module voltage during probe if DDM is "unsupported" - if it's not 0xff,
override the reported options so we can pull the diagnostic data.

To allow simpler comparisons, convert the ASCII fields (vendor,
model, serial) from space-padded to standard NULL-terminated strings.

strcmp() is moved from httpd.c to rtlplayground.c alongside other string
functions and shared between them.

The __reentrant keyword is used for the new functions to avoid using up
additional OSEG space. This allocates the variables on the stack, which
is OK for this particular code path.

The JSON assembly in send_status() is slightly modified to treat the
sfp_module_* data as standard NULL-terminated strings, and a repeated
subtraction was moved into a uint8_t to declutter the code.
This commit is contained in:
Matt Merhar
2026-07-13 01:31:29 -04:00
parent 05d8c36afe
commit 2221f0fa32
5 changed files with 96 additions and 49 deletions
+25 -24
View File
@@ -660,52 +660,53 @@ void send_status(void)
slen += strtox(outbuf + slen, "\"");
if (machine.is_sfp[i]) {
uint8_t sfp = machine.is_sfp[i] - 1;
slen += strtox(outbuf + slen, ",\"isSFP\":1,\"enabled\":");
if (!(sfp_pins_last & (0x1 << ((machine.is_sfp[i] - 1) << 2)))) {
if (!(sfp_pins_last & (0x1 << (sfp << 2)))) {
bool_to_html(1);
slen += strtox(outbuf + slen,",\"sfp_options\":\"0x");
byte_to_html(sfp_options[machine.is_sfp[i]-1]);
if (sfp_options[machine.is_sfp[i]-1] & 0x40) {
byte_to_html(sfp_options[sfp]);
if (sfp_options[sfp] & 0x40) {
slen += strtox(outbuf + slen,"\",\"sfp_temp\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 224, 2);
sfp_send_data(sfp, 224, 2);
slen += strtox(outbuf + slen,"\",\"sfp_vcc\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 226, 2);
sfp_send_data(sfp, 226, 2);
slen += strtox(outbuf + slen,"\",\"sfp_txbias\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 228, 2);
sfp_send_data(sfp, 228, 2);
slen += strtox(outbuf + slen,"\",\"sfp_txpower\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 230, 2);
sfp_send_data(sfp, 230, 2);
slen += strtox(outbuf + slen,"\",\"sfp_rxpower\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 232, 2);
if (sfp_options[machine.is_sfp[i]-1] & 0x10) {
sfp_send_data(sfp, 232, 2);
if (sfp_options[sfp] & 0x10) {
slen += strtox(outbuf + slen,"\",\"sfp_temp_cal\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 212, 4);
sfp_send_data(sfp, 212, 4);
slen += strtox(outbuf + slen,"\",\"sfp_vcc_cal\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 216, 4);
sfp_send_data(sfp, 216, 4);
slen += strtox(outbuf + slen,"\",\"sfp_txbias_cal\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 204, 4);
sfp_send_data(sfp, 204, 4);
slen += strtox(outbuf + slen,"\",\"sfp_txpower_cal\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 208, 4);
sfp_send_data(sfp, 208, 4);
slen += strtox(outbuf + slen,"\",\"sfp_rxpower_cal\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 184, 16);
sfp_send_data(machine.is_sfp[i] - 1, 200, 4);
sfp_send_data(sfp, 184, 16);
sfp_send_data(sfp, 200, 4);
}
slen += strtox(outbuf + slen,"\",\"sfp_state\":\"0x");
sfp_send_data(machine.is_sfp[i] - 1, 238, 1);
sfp_send_data(sfp, 238, 1);
}
slen += strtox(outbuf + slen,"\",\"sfp_vendor\":\"");
for (register uint8_t s = 0; s < 16; s++)
outbuf[slen++] = sfp_module_vendor[machine.is_sfp[i]-1][s];
for (register uint8_t s = 0; s < 16 && sfp_module_vendor[sfp][s]; s++)
outbuf[slen++] = sfp_module_vendor[sfp][s];
slen += strtox(outbuf + slen,"\",\"sfp_model\":\"");
for (register uint8_t s = 0; s < 16; s++)
outbuf[slen++] = sfp_module_model[machine.is_sfp[i]-1][s];
for (register uint8_t s = 0; s < 16 && sfp_module_model[sfp][s]; s++)
outbuf[slen++] = sfp_module_model[sfp][s];
slen += strtox(outbuf + slen,"\",\"sfp_serial\":\"");
for (register uint8_t s = 0; s < 16; s++)
outbuf[slen++] = sfp_module_serial[machine.is_sfp[i]-1][s];
for (register uint8_t s = 0; s < 16 && sfp_module_serial[sfp][s]; s++)
outbuf[slen++] = sfp_module_serial[sfp][s];
slen += strtox(outbuf + slen,"\",\"sfp_los\":");
if (machine.sfp_port[machine.is_sfp[i]-1].pin_los == GPIO_NA) {
if (machine.sfp_port[sfp].pin_los == GPIO_NA) {
slen += strtox(outbuf + slen,"null");
} else {
bool_to_html(sfp_pins_last & (0x2 << (((machine.is_sfp[i]-1) << 2))));
bool_to_html(sfp_pins_last & (0x2 << (sfp << 2)));
}
} else {
bool_to_html(0);