stp: vendor-style per-port config + status (path cost, p2p, designated info)

Bring the Spanning Tree page in line with a typical managed switch's
per-port panel. Configuration gains the full-range path cost (raw
0..200000000, 0 = auto, replacing the old 1000x-scaled byte), a
point-to-point admin control (auto/on/off), and the priority is now a
0..240 step-16 dropdown. A new status table shows, per port, the Port
State, Role, Designated Bridge / Port ID / Cost (learned from received
BPDUs, kept per port and aged via the BPDU age), Operational Edge and
Operational Point-to-Point.

The designated fields fall back to presenting this switch as the
segment's designated bridge when no fresh BPDU has been heard (so a
quiet port shows our own bridge-id, as the vendor UIs do). /stp.json
carries the packed hex fields plus our own MAC for that fallback.

Space: reclaim BANK2 for the above by moving rtl837x_pins to HOME and
compacting leds_dump into a register-address table (~800B); bandwidth
returns to BANK1. No BANK3 - hardware-verified that PSBANK > 2 crashes
this SoC at boot (a bricked unit and an SPI-programmer recovery earlier
today); a warning to that effect is now in rtl837x_lldp.c.

Hardware-verified: cost 200000000 and p2p off round-trip through the CLI
and JSON, the status table populates correctly with STP enabled (all
ports Forwarding/Designated, oper-edge and oper-p2p True), LACP 3f/3f
and the LAN unaffected.

(cherry picked from commit 2ec62072f061dc9e78bc821ba1c297cb6819e206)
This commit is contained in:
d00f
2026-08-04 03:28:07 +02:00
parent 6fcb8ef11f
commit 7ec0286d69
7 changed files with 144 additions and 41 deletions
+27 -2
View File
@@ -74,6 +74,11 @@ extern volatile __xdata uint8_t mgmt_alive; /* set by httpd on any request */
__xdata uint8_t stp_pflags[10];
__xdata uint32_t stp_pcost[10];
__xdata uint8_t stp_pprio[10];
__xdata uint8_t stp_pp2p[10];
__xdata struct bridge stp_dbridge[10];
__xdata uint16_t stp_dpid[10];
__xdata uint32_t stp_dcost[10];
/* ---- Status / runtime ---- */
__xdata struct bridge root_bridge;
@@ -600,9 +605,29 @@ void stp_parse(void) __banked __reentrant
else if (!cmd_compare(4, "off"))
goto err;
} else if (cmd_compare(3, "cost")) {
if (atoi_byte(&stp_scratch, cmd_words_b[4]))
/* raw 802.1D value, 0..200000000; 0 = auto (speed-based) */
stp_cost_scratch = 0;
{
__xdata uint8_t *cp = &cmd_buffer[cmd_words_b[4]];
if (*cp < '0' || *cp > '9')
goto err;
while (*cp >= '0' && *cp <= '9') {
stp_cost_scratch = stp_cost_scratch * 10 + (*cp - '0');
cp++;
}
}
if (stp_cost_scratch > 200000000UL)
goto err;
stp_pcost[port] = stp_cost_scratch;
} else if (cmd_compare(3, "p2p")) {
if (cmd_compare(4, "auto"))
stp_pp2p[port] = 0;
else if (cmd_compare(4, "on"))
stp_pp2p[port] = 1;
else if (cmd_compare(4, "off"))
stp_pp2p[port] = 2;
else
goto err;
stp_pcost[port] = (uint32_t)stp_scratch * 1000;
} else if (cmd_compare(3, "prio")) {
if (atoi_byte(&stp_scratch, cmd_words_b[4]))
goto err;