Add lag show command

This commit is contained in:
logicog
2025-12-06 23:38:41 +01:00
parent e7301dc39f
commit 68405f70d2
2 changed files with 64 additions and 60 deletions
+61 -60
View File
@@ -192,6 +192,37 @@ void parse_lag(void)
__xdata uint8_t group; __xdata uint8_t group;
__xdata uint16_t members = 0; __xdata uint16_t members = 0;
if (cmd_words_b[1] > 0 && cmd_compare(1, "show")) {
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];
if (!members) {
print_string(" disabled\n");
continue;
}
print_string(" member ports: ");
for (uint8_t j = 0; j < 10; j++) {
if (members & 1) {
if (!isRTL8373)
write_char('0' + log_to_phys_port[j]);
else
write_char('1' + j);
write_char(' ');
}
members >>= 1;
}
print_string(" (hash: 0x");
reg_read_m(RTL837X_TRK_HASH_CTRL_BASE + (i << 2));
print_byte(sfr_data[3]);
print_string(")\n");
}
return;
}
if (cmd_words_b[2] <= 0 || !isnumber(cmd_buffer[cmd_words_b[1]]))
goto err;
group = cmd_buffer[cmd_words_b[1]] - '0'; group = cmd_buffer[cmd_words_b[1]] - '0';
uint8_t w = 2; uint8_t w = 2;
@@ -595,8 +626,7 @@ void cmd_parser(void) __banked
if (cmd_compare(0, "reset")) { if (cmd_compare(0, "reset")) {
print_string("\nRESET\n\n"); print_string("\nRESET\n\n");
reset_chip(); reset_chip();
} } else if (cmd_compare(0, "sfp")) {
if (cmd_compare(0, "sfp")) {
uint8_t rate = sfp_read_reg(0, 12); uint8_t rate = sfp_read_reg(0, 12);
print_string("\nRate: "); print_byte(rate); print_string("\nRate: "); print_byte(rate);
print_string(" Encoding: "); print_byte(sfp_read_reg(0, 11)); print_string(" Encoding: "); print_byte(sfp_read_reg(0, 11));
@@ -606,11 +636,9 @@ void cmd_parser(void) __banked
if (c) if (c)
write_char(c); write_char(c);
} }
} } else if (cmd_compare(0, "stat")) {
if (cmd_compare(0, "stat")) {
port_stats_print(); port_stats_print();
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'r') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'r') {
print_string("\nPRINT SECURITY REGISTERS\n"); print_string("\nPRINT SECURITY REGISTERS\n");
// The following will only show something else than 0xff if it was programmed for a managed switch // The following will only show something else than 0xff if it was programmed for a managed switch
flash_region.addr = 0x0001000; flash_region.addr = 0x0001000;
@@ -622,44 +650,36 @@ void cmd_parser(void) __banked
flash_region.addr = 0x0003000; flash_region.addr = 0x0003000;
flash_region.len = 40; flash_region.len = 40;
flash_read_security(); flash_read_security();
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'd') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'd') {
print_string("\nDUMPING FLASH\n"); print_string("\nDUMPING FLASH\n");
flash_region.addr = 0; flash_region.addr = 0;
flash_region.len = 255; flash_region.len = 255;
flash_dump(255); flash_dump(255);
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'j') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'j') {
print_string("\nJEDEC ID\n"); print_string("\nJEDEC ID\n");
flash_read_jedecid(); flash_read_jedecid();
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'u') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'u') {
print_string("\nUNIQUE ID\n"); print_string("\nUNIQUE ID\n");
flash_read_uid(); flash_read_uid();
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 's') {
// Switch to flash 62.5 MHz mode print_string("\nFLASH FAST MODE\n"); // Switch to flash 62.5 MHz mode
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 's') {
print_string("\nFLASH FAST MODE\n");
flash_init(1); flash_init(1);
print_string("\nNow dumping flash\n"); print_string("\nNow dumping flash\n");
flash_region.addr = 0; flash_region.addr = 0;
flash_region.len = 255; flash_region.len = 255;
flash_dump(255); flash_dump(255);
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'e') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'e') {
print_string("\nFLASH erase\n"); print_string("\nFLASH erase\n");
flash_region.addr = 0x20000; flash_region.addr = 0x20000;
flash_sector_erase(); flash_sector_erase();
} } else if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'w') {
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && cmd_buffer[cmd_words_b[1]] == 'w') {
print_string("\nFLASH write\n"); print_string("\nFLASH write\n");
for (uint8_t i = 0; i < 20; i++) for (uint8_t i = 0; i < 20; i++)
flash_buf[i] = greeting[i]; flash_buf[i] = greeting[i];
flash_region.addr = 0x200000; flash_region.addr = 0x200000;
flash_region.len = 20; flash_region.len = 20;
flash_write_bytes(flash_buf); flash_write_bytes(flash_buf);
} } else if (cmd_compare(0, "port") && cmd_words_b[1] > 0) {
if (cmd_compare(0, "port") && cmd_words_b[1] > 0) {
print_string("\nPORT "); print_string("\nPORT ");
uint8_t p = cmd_buffer[cmd_words_b[1]] - '1'; uint8_t p = cmd_buffer[cmd_words_b[1]] - '1';
print_byte(p); print_byte(p);
@@ -679,8 +699,7 @@ void cmd_parser(void) __banked
print_string(" OFF\n"); print_string(" OFF\n");
phy_set_mode(p, PHY_OFF, 0, 0); phy_set_mode(p, PHY_OFF, 0, 0);
} }
} } else if (cmd_compare(0, "ip")) {
if (cmd_compare(0, "ip")) {
print_string("Got ip command: "); print_string("Got ip command: ");
if (!parse_ip(cmd_words_b[1])) if (!parse_ip(cmd_words_b[1]))
uip_ipaddr(&uip_hostaddr, ip[0], ip[1], ip[2], ip[3]); uip_ipaddr(&uip_hostaddr, ip[0], ip[1], ip[2], ip[3]);
@@ -688,8 +707,7 @@ void cmd_parser(void) __banked
print_string("Invalid IP address\n"); print_string("Invalid IP address\n");
print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]); print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]);
write_char('\n'); write_char('\n');
} } else if (cmd_compare(0, "gw")) {
if (cmd_compare(0, "gw")) {
print_string("Got gw command: "); print_string("Got gw command: ");
if (!parse_ip(cmd_words_b[1])) if (!parse_ip(cmd_words_b[1]))
uip_ipaddr(&uip_draddr, ip[0], ip[1], ip[2], ip[3]); uip_ipaddr(&uip_draddr, ip[0], ip[1], ip[2], ip[3]);
@@ -697,8 +715,7 @@ void cmd_parser(void) __banked
print_string("Invalid IP address\n"); print_string("Invalid IP address\n");
print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]); print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]);
write_char('\n'); write_char('\n');
} } else if (cmd_compare(0, "netmask")) {
if (cmd_compare(0, "netmask")) {
print_string("Got netmask command: "); print_string("Got netmask command: ");
if (!parse_ip(cmd_words_b[1])) if (!parse_ip(cmd_words_b[1]))
uip_ipaddr(&uip_netmask, ip[0], ip[1], ip[2], ip[3]); uip_ipaddr(&uip_netmask, ip[0], ip[1], ip[2], ip[3]);
@@ -706,14 +723,12 @@ void cmd_parser(void) __banked
print_string("Invalid IP address\n"); print_string("Invalid IP address\n");
print_byte(ip[0]);print_byte(ip[1]);print_byte(ip[2]);print_byte(ip[3]); print_byte(ip[0]);print_byte(ip[1]);print_byte(ip[2]);print_byte(ip[3]);
write_char('\n'); write_char('\n');
} } else if (cmd_compare(0, "l2")) {
if (cmd_compare(0, "l2")) {
if (cmd_words_b[1] > 0 && cmd_compare(1, "forget")) if (cmd_words_b[1] > 0 && cmd_compare(1, "forget"))
port_l2_forget(); port_l2_forget();
else else
port_l2_learned(); port_l2_learned();
} } else if (cmd_compare(0, "stp")) {
if (cmd_compare(0, "stp")) {
if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) { if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) {
print_string("STP enabled\n"); print_string("STP enabled\n");
stpEnabled = 1; stpEnabled = 1;
@@ -723,8 +738,7 @@ void cmd_parser(void) __banked
stp_off(); stp_off();
stpEnabled = 0; stpEnabled = 0;
} }
} } else if (cmd_compare(0, "pvid") && cmd_words_b[1] > 0 && cmd_words_b[2] > 0) {
if (cmd_compare(0, "pvid") && cmd_words_b[1] > 0 && cmd_words_b[2] > 0) {
__xdata uint16_t pvid; __xdata uint16_t pvid;
uint8_t port; uint8_t port;
port = cmd_buffer[cmd_words_b[1]] - '1'; port = cmd_buffer[cmd_words_b[1]] - '1';
@@ -732,38 +746,27 @@ void cmd_parser(void) __banked
port = phys_to_log_port[port]; port = phys_to_log_port[port];
if (!atoi_short(&pvid, cmd_words_b[2])) if (!atoi_short(&pvid, cmd_words_b[2]))
port_pvid_set(port, pvid); port_pvid_set(port, pvid);
} } else if (cmd_compare(0, "vlan")) {
if (cmd_compare(0, "vlan")) {
parse_vlan(); parse_vlan();
} } else if (cmd_compare(0, "mirror")) {
if (cmd_compare(0, "mirror")) {
parse_mirror(); parse_mirror();
} } else if (cmd_compare(0, "lag")) {
if (cmd_compare(0, "lag")) {
parse_lag(); parse_lag();
} } else if (cmd_compare(0, "laghash")) {
if (cmd_compare(0, "laghash")) {
parse_lag_hash(); parse_lag_hash();
} } else if (cmd_compare(0, "sds")) {
if (cmd_compare(0, "sds")) {
print_reg(RTL837X_REG_SDS_MODES); print_reg(RTL837X_REG_SDS_MODES);
} } else if (cmd_compare(0, "gpio")) {
if (cmd_compare(0, "gpio")) {
print_gpio_status(); print_gpio_status();
} } else if (cmd_compare(0, "regget")) {
if (cmd_compare(0, "regget")) {
parse_regget(); parse_regget();
} } else if (cmd_compare(0, "regset")) {
if (cmd_compare(0, "regset")) {
parse_regset(); parse_regset();
} } else if (cmd_compare(0, "rnd")) {
if (cmd_compare(0, "rnd")) {
parse_rnd(); parse_rnd();
} } else if (cmd_compare(0, "passwd")) {
if (cmd_compare(0, "passwd")) {
parse_passwd(); parse_passwd();
} } else if (cmd_compare(0, "eee")) {
if (cmd_compare(0, "eee")) {
int8_t port = -1; int8_t port = -1;
if (cmd_words_b[3] > 0) { if (cmd_words_b[3] > 0) {
port = cmd_buffer[cmd_words_b[2]] - '1'; port = cmd_buffer[cmd_words_b[2]] - '1';
@@ -786,11 +789,9 @@ void cmd_parser(void) __banked
else else
port_eee_status_all(); port_eee_status_all();
} }
} } else if (cmd_compare(0, "version")) {
if (cmd_compare(0, "version")) {
print_sw_version(); print_sw_version();
} } else if (cmd_compare(0, "history")) {
if (cmd_compare(0, "history")) {
__xdata uint16_t p = (cmd_history_ptr + 1) & CMD_HISTORY_MASK; __xdata uint16_t p = (cmd_history_ptr + 1) & CMD_HISTORY_MASK;
__xdata uint8_t found_begin = 0; __xdata uint8_t found_begin = 0;
// print_string("History ptr: "); // print_string("History ptr: ");
+3
View File
@@ -52,6 +52,9 @@ For testing the following commands are provided on the serial console:
Create or set a LAG. Trunk-ID is 1 or 2. Ports are physical ports Create or set a LAG. Trunk-ID is 1 or 2. Ports are physical ports
If only the LAG-ID is given but no members, the LAG is deleted If only the LAG-ID is given but no members, the LAG is deleted
> lag show
Shows information on all 4 lags
> laghash 0 [hash1] [hash2]... > laghash 0 [hash1] [hash2]...
Uses the given packet properties when hashing the packet to select the link Uses the given packet properties when hashing the packet to select the link
Names for the hashes are spa, smac, dmac, sip, dip, sport, dport Names for the hashes are spa, smac, dmac, sip, dip, sport, dport