stp: full RSTP and a reworked Spanning Tree page

* stp: select the root port by cost and block redundant links
* stp: move the protocol to BANK4 and keep the command line in BANK2
* stp: implement the RSTP state machines of 802.1D-2004 clause 17
* stp: counters, more settings and a fuller Spanning Tree page
* stp: make a link aggregation group one port of the RSTP tree
* web: serve the Spanning Tree JSON from BANK4 as well

Kept in BANK1, the larger Spanning Tree page would leave under 1 kB
there for the rest of the web server and every page still to come, so
send_stp() and send_stp_counters() move to httpd/page_stp.c in BANK4
with the protocol, as banked calls, with their own copies of the few output
helpers and of the JSON header, so nothing in BANK4 calls into BANK1
directly or hands it a pointer into its code space. BANK4 takes the
free flash between BANK3 and the web files.

KP_9000_6XHML_X2: BANK1 44336, BANK2 36969, BANK3 11942, BANK4 20965
bytes of 49152.
This commit is contained in:
DrDoof authored and d00f committed 2026-10-27 22:11:24 +01:00
1 parent 6c62791d23
commit aff6ac0923
20 files changed
+3282 -696

No files matched your search

+6
View File
@@ -121,6 +121,12 @@ uint8_t stp_pflags[STP_ENTITIES];
uint8_t stp_pp2p[STP_ENTITIES];
uint8_t stp_pprio[STP_ENTITIES];
uint8_t stp_prio = 0x80, stp_root_port = 0xff, stp_rstp = 1, stp_txhold = 6;
uint8_t stp_bpdu_filter, stp_pcost_short, stp_root_fwd = 15, stp_root_maxage = 20;
uint16_t stp_legacy, stp_link_prev = 0x3ff;
uint16_t stp_info_while[STP_ENTITIES];
uint32_t stp_cnt[STP_CNT_N][STP_ENTITIES];
uint32_t stp_tc_secs;
uint8_t stp_ent_id(uint8_t e) { return e >= STP_LAG_BASE ? e + 101 - STP_LAG_BASE : machine.log_to_phys_port[e]; }
/* ---- SFP: no module present, reads fail ---- */
uint8_t sfp_buf[16];
+21
View File
@@ -0,0 +1,21 @@
CC ?= cc
CFLAGS = -std=c11 -Wall -Wextra -Wno-unknown-pragmas \
-D__xdata= -D__code= -D__banked= -D__reentrant= \
-Ishim -I../..
all: build/stp_sim
./build/stp_sim
verbose: build/stp_sim
./build/stp_sim -v
build/stp_sim: stp_sim.c ../../rtl837x_stp.c ../../rtl837x_stp_cli.c ../../rtl837x_stp.h shim/*.h
mkdir -p build
cp ../../rtl837x_stp.c build/stp_under_test.c
cp ../../rtl837x_stp_cli.c build/stp_cli_under_test.c
$(CC) $(CFLAGS) -o $@ stp_sim.c build/stp_under_test.c build/stp_cli_under_test.c
clean:
rm -rf build
.PHONY: all verbose clean
+12
View File
@@ -0,0 +1,12 @@
#ifndef _SHIM_MACHINE_H_
#define _SHIM_MACHINE_H_
#include <stdint.h>
#define MACHINE_MIN_PORT 0
#define MACHINE_MAX_PORT 8
#define MACHINE_PORT_VALID(p) \
((uint8_t)((p) - MACHINE_MIN_PORT) <= (MACHINE_MAX_PORT - MACHINE_MIN_PORT))
struct machine { uint8_t log_to_phys_port[9]; };
extern const struct machine machine;
struct machine_runtime { uint8_t isRTL8373; };
extern struct machine_runtime machine_detected;
#endif
+50
View File
@@ -0,0 +1,50 @@
#ifndef _SHIM_RTL837X_COMMON_H_
#define _SHIM_RTL837X_COMMON_H_
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
struct rtl_tag {
uint16_t tag;
uint8_t version;
uint8_t reason;
uint16_t flags;
uint16_t pmask; /* TX: port bitmask; RX: 4-bit port number */
};
struct vlan_tag {
uint16_t svlan;
uint16_t vlan;
};
#define RTL_FRAME_TAG_ID 0x8899
#define RTL_FRAME_TAG_VERSION 0x04
#define RTL_FRAME_DESC_SIZE 12
#define RTL_TAG_LEARN_DIS 0x0020
#define PMASK_9 0x1ff
#define PMASK_6 0x1f8
#define PMASK_CPU 0x200
#define CMD_BUF_SIZE 128
#define CPU_PORT 9
#define ERR_OK 0
#define ERR_INVALID_ARGUMENT 3
#define HTONS(n) ((uint16_t)((((uint16_t)(n)) << 8) | (((uint16_t)(n)) >> 8)))
extern bool stp_enabled;
void print_string(char *s);
void print_byte(uint8_t b);
void print_short(uint16_t v);
void print_long(uint32_t v);
void write_char(char c);
void itoa(uint8_t v);
void print_reg(uint16_t reg);
void reg_read_m(uint16_t addr);
void reg_write_m(uint16_t addr);
void tcpip_output(void);
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef _SHIM_RTL837X_PORT_H_
#define _SHIM_RTL837X_PORT_H_
#include <stdint.h>
#define VLAN_TAGGED 1
int8_t vlan_get(uint16_t vlan);
uint16_t port_pvid_get(uint8_t port);
void port_l2mc_set(uint8_t mac_last, uint16_t vid, uint16_t pmask);
void port_l2_forget_port(uint8_t port);
uint16_t port_lag_members_get(uint8_t lag);
uint8_t port_ingress_filter_get(uint8_t port);
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef _SHIM_RTL837X_REGS_H_
#define _SHIM_RTL837X_REGS_H_
#define RTL837X_MSTP_STATES 0x5310
#define RTL837X_REG_LINKS_STS 0x63E8
#define RTL837X_REG_LINKS 0x63f0
#define RTL837X_REG_LINKS_89 0x63f4
#endif
+6
View File
@@ -0,0 +1,6 @@
#ifndef _SHIM_RTL837X_SFR_H_
#define _SHIM_RTL837X_SFR_H_
extern unsigned char sfr_data[4];
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef _SHIM_UIP_H_
#define _SHIM_UIP_H_
#include <stdint.h>
#define UIP_CONF_BUFFER_SIZE 600
struct uip_eth_addr { uint8_t addr[6]; };
extern uint16_t uip_len;
void tcpip_output(void);
#endif
+1633
View File
File diff suppressed because it is too large. Load diff