Merge pull request #114 from TylerDurden-23/eee-on-boot

Add EEE speed option and enable EEE with 2g5 as default at boot
This commit is contained in:
logicog
2026-02-07 16:49:49 +01:00
committed by GitHub
5 changed files with 114 additions and 34 deletions
+59 -21
View File
@@ -633,6 +633,64 @@ void parse_passwd(void)
}
void parse_eee(void)
{
__xdata int8_t port = -1;
__xdata uint8_t speed = EEE_2G5;
__xdata uint8_t speed_word = 0;
// Check if word 2 is a speed (contains 'g' or 'm') or a port number
if (cmd_words_b[3] > 0) {
uint8_t idx = cmd_words_b[2];
// Skip digits to check if there's a letter after
while (isnumber(cmd_buffer[idx]))
idx++;
if (cmd_buffer[idx] == 'g' || cmd_buffer[idx] == 'm') {
// Word 2 is a speed (e.g., "2g5", "100m", "1g")
speed_word = 2;
} else if (cmd_buffer[idx] == ' ' || cmd_buffer[idx] == '\0') {
// Word 2 is a port number
port = cmd_buffer[cmd_words_b[2]] - '1';
port = machine.phys_to_log_port[port];
// Check if word 3 is a speed
if (cmd_words_b[4] > 0)
speed_word = 3;
}
}
// Parse speed if found
if (speed_word > 0) {
if (cmd_compare(speed_word, "100m"))
speed = EEE_100;
else if (cmd_compare(speed_word, "1g"))
speed = EEE_1000;
else if (cmd_compare(speed_word, "2g5"))
speed = EEE_2G5;
else
{
print_string("Speed word invalid, use: [100m|1g|2g5]\n");
return;
}
}
if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) {
if (port >= 0)
port_eee_enable(port, speed);
else
port_eee_enable_all(speed);
} else if (cmd_words_b[1] > 0 && cmd_compare(1, "off")) {
if (port >= 0)
port_eee_disable(port);
else
port_eee_disable_all();
} else if (cmd_words_b[1] > 0 && cmd_compare(1, "status")) {
if (port >= 0)
port_eee_status(port);
else
port_eee_status_all();
} else {
print_string("eee [on|off|status] [port] [100m|1g|2g5]\n");
}
}
// Parse command into words
uint8_t cmd_tokenize(void) __banked
{
@@ -895,27 +953,7 @@ void cmd_parser(void) __banked
} else if (cmd_compare(0, "passwd")) {
parse_passwd();
} else if (cmd_compare(0, "eee")) {
int8_t port = -1;
if (cmd_words_b[3] > 0) {
port = cmd_buffer[cmd_words_b[2]] - '1';
port = machine.phys_to_log_port[port];
}
if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) {
if (port >= 0)
port_eee_enable(port);
else
port_eee_enable_all();
} else if (cmd_words_b[1] > 0 && cmd_compare(1, "off")) {
if (port >= 0)
port_eee_disable(port);
else
port_eee_disable_all();
} else if (cmd_words_b[1] > 0 && cmd_compare(1, "status")) {
if (port >= 0)
port_eee_status(port);
else
port_eee_status_all();
}
parse_eee();
} else if (cmd_compare(0, "version")) {
print_sw_version();
} else if (cmd_compare(0, "time")) {
+43 -11
View File
@@ -422,17 +422,49 @@ uint16_t port_isolation_get(register uint8_t port)
}
void port_eee_enable(uint8_t port) __banked
void port_eee_enable(__xdata uint8_t port,__xdata uint8_t speed) __banked
{
if (machine.is_sfp[port])
return;
REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), EEE_100 | EEE_1000 | EEE_2G5);
// Enable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, PHY_EEE_BIT_1G | PHY_EEE_BIT_100M);
// Enable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, PHY_EEE_BIT_2G5);
phy_reset(port);
if (machine.is_sfp[port])
{
print_string("EEE can't be enabled for SFP port "); print_byte(port); print_string("\n");
return;
}
print_string("EEE on for "); print_byte(port); print_string(" speed ");
// Enable all speeds up to the specified speed
if ((speed & (EEE_100 | EEE_1000 | EEE_2G5)) == EEE_100) {
print_string("100m\n");
REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), EEE_100);
// Enable EEE advertisement for 100BASE-T via EEE Advertisement Reg
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, PHY_EEE_BIT_100M);
if (!(speed & EEE_NORESET))
phy_reset(port);
return;
}
if ((speed & (EEE_100 | EEE_1000 | EEE_2G5)) == EEE_1000) {
print_string("1g\n");
REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), EEE_100 | EEE_1000);
// Disable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, 0);
// Enable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, PHY_EEE_BIT_1G | PHY_EEE_BIT_100M);
if (!(speed & EEE_NORESET))
phy_reset(port);
return;
}
if ((speed & (EEE_100 | EEE_1000 | EEE_2G5)) == EEE_2G5) {
print_string("2g5\n");
REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), EEE_100 | EEE_1000 | EEE_2G5);
// Enable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, PHY_EEE_BIT_1G | PHY_EEE_BIT_100M);
// Enable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2
phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, PHY_EEE_BIT_2G5);
if (!(speed & EEE_NORESET))
phy_reset(port);
return;
}
}
@@ -506,10 +538,10 @@ void port_eee_status(uint8_t port) __banked
}
void port_eee_enable_all(void) __banked
void port_eee_enable_all(__xdata uint8_t speed) __banked
{
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
port_eee_enable(i);
port_eee_enable(i, speed);
}
}
+2 -2
View File
@@ -28,10 +28,10 @@ void port_ingress_filter(register uint8_t port, uint8_t type) __banked;
void port_l2_setup(void) __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(void) __banked;
void port_eee_enable_all(__xdata uint8_t speed) __banked;
void port_eee_disable_all(void) __banked;
void port_eee_status_all(void) __banked;
void port_eee_enable(uint8_t port) __banked;
void port_eee_enable(__xdata uint8_t port, __xdata uint8_t speed) __banked;
void port_eee_disable(uint8_t port) __banked;
void port_eee_status(uint8_t port) __banked;
#endif
+1
View File
@@ -257,6 +257,7 @@
#define EEE_100 0x01
#define EEE_1000 0x04
#define EEE_2G5 0x10
#define EEE_NORESET 0x80
/*
* RANDOM
+9
View File
@@ -1637,6 +1637,9 @@ void rtl8373_init(void)
reg_bit_set(RTL837X_REG_HW_CONF, 0);
// enable EEE for all ports at 2.5G and 10G, but don't reset the PHYs
port_eee_enable_all(EEE_2G5 | EEE_NORESET);
// TODO: patch the PHYs
// Re-enable PHY after configuration
@@ -1700,6 +1703,10 @@ void rtl8372_init(void)
reg_bit_set(RTL837X_REG_HW_CONF, 0);
// enable EEE for all ports at 2.5G and 10G, but don't reset the PHYs
port_eee_enable_all(EEE_2G5 | EEE_NORESET);
// TODO: patch the PHYs
// Re-enable PHY after configuration
@@ -1954,6 +1961,8 @@ void bootloader(void)
REG_SET(RTL837X_PIN_MUX_2, 0x0); // Disable pins for ACL
init_smi();
rtl8373_revision();
if (machine_detected.isRTL8373)
rtl8373_init();