From 859a50bd82919fc6b0c53bb19415879f2a3c4dde Mon Sep 17 00:00:00 2001 From: chriz Date: Tue, 10 Feb 2026 23:17:04 +0100 Subject: [PATCH] fix-link-speed --- httpd/page_impl.c | 24 ++++++++++++++++++------ rtl837x_port.c | 28 ++++++++++++++++++++++------ rtl837x_regs.h | 2 ++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/httpd/page_impl.c b/httpd/page_impl.c index f8d810b..d89b26b 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -626,13 +626,25 @@ void send_status(void) } slen += strtox(outbuf + slen, ",\"link\":"); - - if (i < 8) - reg_read_m(RTL837X_REG_LINKS); + + uint8_t b = 0; + // Determine link state + reg_read_m(RTL837X_REG_LINKS_STS); + if(!((sfr_data[(i / 8) + 1] >> (i % 8 ) & 1))) + { + b = 0; //link down + } else - reg_read_m(RTL837X_REG_LINKS_89); - uint8_t b = sfr_data[3 - ((i & 7) >> 1)]; - b = (i & 1) ? b >> 4 : b & 0xf; + { + //Determine link speed + if (i < 8) + reg_read_m(RTL837X_REG_LINKS); + else + reg_read_m(RTL837X_REG_LINKS_89); + + b = sfr_data[3 - ((i & 7) >> 1)]; + b = ((i & 1) ? b >> 4 : b & 0xf) + 1; + } char_to_html('0' + b); STAT_GET(STAT_COUNTER_TX_PKTS, i); diff --git a/rtl837x_port.c b/rtl837x_port.c index 322e60d..4e12a6d 100644 --- a/rtl837x_port.c +++ b/rtl837x_port.c @@ -369,15 +369,28 @@ void port_stats_print(void) __banked } } - if (i < 8) - reg_read_m(RTL837X_REG_LINKS); + uint8_t b = 0; + + // Determine link state + reg_read_m(RTL837X_REG_LINKS_STS); + if(!((sfr_data[(i / 8) + 1] >> ( i % 8 ) & 1))) + { + b = 99; + } else - reg_read_m(RTL837X_REG_LINKS_89); - uint8_t b = sfr_data[3 - ((i & 7) >> 1)]; - b = (i & 1) ? b >> 4 : b & 0xf; + { + if (i < 8) + reg_read_m(RTL837X_REG_LINKS); + else + reg_read_m(RTL837X_REG_LINKS_89); + + b = sfr_data[3 - ((i & 7) >> 1)]; + b = (i & 1) ? b >> 4 : b & 0xf; + } + switch (b) { case 0: - print_string("Down\t"); + print_string("10M\t"); break; case 1: print_string("100M\t"); @@ -391,6 +404,9 @@ void port_stats_print(void) __banked case 5: print_string("2.5G\t"); break; + case 99: + print_string("Down\t"); + break; default: print_string("Up\t"); break; diff --git a/rtl837x_regs.h b/rtl837x_regs.h index b6d0e54..b9bc752 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -66,6 +66,8 @@ #define RTL837X_REG_LINKS 0x63f0 #define RTL837X_REG_LINKS_89 0x63f4 +#define RTL837X_REG_LINKS_STS 0x63E8 + /* Each nibble encodes the link state of a port. Port 0 appears to be the CPU port The RTL8372 serves ports 4-7, port 3 is the RTL8221