From f2c6ac01d931360a4a5c2fe17193fa6b74baa436 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:20:01 +0200 Subject: [PATCH] port: read a trunk's members through one function The member mask of an aggregation group is decoded by hand in two places, the lag command and the JSON behind the aggregation page, and every branch that touches trunks adds another copy. port_lag_members_get() sits next to port_lag_members_set() and both readers call it. It answers from the hardware, so it covers a group configured with lag and one a protocol brought up, without either having to say so. It reads through reg_read() rather than reg_read_m(), so sfr_data is left alone. Neither caller looked at it afterwards; both read the hash register next. --- cmd_parser.c | 3 +-- httpd/page_impl.c | 3 +-- rtl837x_port.c | 13 +++++++++++++ rtl837x_port.h | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index 22a4c78..9e2be41 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -250,8 +250,7 @@ void parse_lag(void) print_string("LAG status:\n"); for (uint8_t i = 0; i < 4; i++) { write_char(' '); write_char('1' + i); - reg_read_m(RTL837X_TRK_MBR_CTRL_BASE + (i << 2)); - members = ((uint16_t)sfr_data[2]) << 8 | sfr_data[3]; + members = port_lag_members_get(i); if (!members) { print_string(" disabled\n"); continue; diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 44332e5..19796ed 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -518,8 +518,7 @@ void send_lag(void) slen += strtox(outbuf + slen, "{\"lagNum\":"); itoa_html(l); slen += strtox(outbuf + slen, ",\"members\":\""); - reg_read_m(RTL837X_TRK_MBR_CTRL_BASE + (l << 2)); - uint16_t ports = ((uint16_t)sfr_data[2] << 8) | sfr_data[3]; + uint16_t ports = port_lag_members_get(l); for (uint8_t i = 0; i < 16; i++) { bool_to_html(!!(ports & 0x8000)); ports <<= 1; diff --git a/rtl837x_port.c b/rtl837x_port.c index d203e12..4dfbbbc 100644 --- a/rtl837x_port.c +++ b/rtl837x_port.c @@ -733,6 +733,19 @@ void port_rldp_on(__xdata uint16_t p_ms) } +/* + * Reads the member port bitmask of a Link Aggregation Group. + * The groups have numbers 0-3; bit n is set when logical port n is a member. + * The bitmask reflects what the hardware holds, so it covers groups set up + * statically and groups a protocol brought up, without either having to say so. + */ +uint16_t port_lag_members_get(uint8_t lag) __banked +{ + reg_read(RTL837X_TRK_MBR_CTRL_BASE + (lag << 2)); + return ((uint16_t)SFR_DATA_8 << 8) | SFR_DATA_0; +} + + /* * Configure LAGs * Sets the members via port bitmask of a given Link Aggregation Group diff --git a/rtl837x_port.h b/rtl837x_port.h index a5ce278..b459832 100644 --- a/rtl837x_port.h +++ b/rtl837x_port.h @@ -61,6 +61,7 @@ void port_mirror_set(register uint8_t port, __xdata uint16_t rx_pmask, __xdata u void port_mirror_del(void) __banked; bool port_ingress_filter(__xdata uint8_t port, __xdata vlan_ingress_mode_t type) __banked; void port_l2_setup(void) __banked; +uint16_t port_lag_members_get(uint8_t lag) __banked; void port_lag_members_set(__xdata uint8_t lag, __xdata uint16_t members) __banked; void port_lag_hash_set(__xdata uint8_t lag, __xdata uint8_t hash) __banked; void port_eee_enable_all(__xdata uint8_t speed) __banked;