From 8fec8d1b0cec2cd8a2cdf4375d797ea6100ead89 Mon Sep 17 00:00:00 2001 From: Jani Paalijarvi Date: Wed, 20 Nov 2024 14:33:50 +0200 Subject: [PATCH 1/2] drivers/net/ksz9477.c: Errata 16, reset SGMII always on init --- drivers/net/ksz9477.c | 8 ++++++++ drivers/net/ksz9477_reg.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c index a8b58be976c41..d33dff1552ab6 100644 --- a/drivers/net/ksz9477.c +++ b/drivers/net/ksz9477.c @@ -640,6 +640,14 @@ int ksz9477_init(ksz9477_port_t master_port) return ret ? ret : -EINVAL; } + /* Errata 16: SGMII registers are not initialized by hardware reset + * To ensure clean environment, reset the switch now. + */ + + regval16 = SGMII_CONTROL_SOFT_RESET; + ret = ksz9477_sgmii_write_indirect(KSZ9477_SGMII_CONTROL, + ®val16, 1); + /* Check that indirect access to PHY MMD works. * Write LED mode to single-LED mode and verify access by * reading back the value. diff --git a/drivers/net/ksz9477_reg.h b/drivers/net/ksz9477_reg.h index 001a78a0e903b..142a1e4590be4 100644 --- a/drivers/net/ksz9477_reg.h +++ b/drivers/net/ksz9477_reg.h @@ -100,6 +100,10 @@ /* Register bit definitions */ +/* KSZ9477_SGMII_CONTROL */ + +#define SGMII_CONTROL_SOFT_RESET (1 << 15) + /* KSZ9477_ID2, KSZ9477_ID1 */ #define KSZ9477_ID 0x9477 From a894081255775494b2919176b34b653da6ae9cfc Mon Sep 17 00:00:00 2001 From: Jani Paalijarvi Date: Thu, 28 Nov 2024 08:55:34 +0200 Subject: [PATCH 2/2] net: Minor error handling improvements arch/risc-v/src/mpfs/mpfs_ethernet.c and drivers/net/ksz9477.c Signed-off-by: Jani Paalijarvi --- arch/risc-v/src/mpfs/mpfs_ethernet.c | 4 ++++ drivers/net/ksz9477.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/risc-v/src/mpfs/mpfs_ethernet.c b/arch/risc-v/src/mpfs/mpfs_ethernet.c index b985c7fedaf1c..5a3632a365ded 100644 --- a/arch/risc-v/src/mpfs/mpfs_ethernet.c +++ b/arch/risc-v/src/mpfs/mpfs_ethernet.c @@ -3390,6 +3390,10 @@ static int mpfs_phyinit(struct mpfs_ethmac_s *priv) { ret = ksz9477_i2c_init(bus, KSZ9477_PORT_SGMII); } + else + { + ret = -EINVAL; + } #endif diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c index d33dff1552ab6..6fa14ca09ac13 100644 --- a/drivers/net/ksz9477.c +++ b/drivers/net/ksz9477.c @@ -729,6 +729,12 @@ int ksz9477_init(ksz9477_port_t master_port) ret = ksz9477_sgmii_write_indirect(KSZ9477_SGMII_AUTONEG_CONTROL, ®val16, 1); + if (ret != OK) + { + nerr("Failed to set SGMII port into PHY mode, ret %d\n", ret); + return ret ? ret : -EINVAL; + } + /* Write to autonegotiation advertisement register activates the new * setting. Advertise only full duplex. */ @@ -736,6 +742,12 @@ int ksz9477_init(ksz9477_port_t master_port) regval16 = SGMII_AUTONEG_ADVERTISE_FD; ret = ksz9477_sgmii_write_indirect(KSZ9477_SGMII_AUTONEG_ADVERTISE, ®val16, 1); + + if (ret != OK) + { + nerr("Failed to set autoneg, ret %d\n", ret); + return ret ? ret : -EINVAL; + } } /* Configure the static port-based VLANs */ @@ -755,6 +767,12 @@ int ksz9477_init(ksz9477_port_t master_port) g_port_vlan_config[i]); } + if (ret != OK) + { + nerr("Failed to configure VLANs, ret %d\n", ret); + return ret ? ret : -EINVAL; + } + #endif #ifdef CONFIG_NET_KSZ9477_PORT_SNIFF @@ -768,6 +786,12 @@ int ksz9477_init(ksz9477_port_t master_port) g_port_mirror_config[i]); } + if (ret != OK) + { + nerr("Failed to configure sniffer port, ret %d\n", ret); + return ret ? ret : -EINVAL; + } + #endif return ret;