Skip to content

drivers: ethernet: vsc8541: various fixes #91726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 23, 2025

Conversation

robhancocksed
Copy link
Contributor

  • Added missing MDIO enable/disable calls around accessing PHY registers, to make sure the MDIO bus is active first
  • Cleaned up internal functions to use uint16_t for PHY register values
  • Fixed inverted reset GPIO line
  • Added SW reset timeout
  • Implemented cfg_link function required by some MAC drivers

@robhancocksed
Copy link
Contributor Author

It looks like the arch.interrupt.gen_isr_table_local.riscv test is failing on the ganymed_bob and ganymed_sk boards where I modified the .dts files. However, those build errors also seem to happen on the main branch, so they seem unrelated to these changes?

@@ -30,7 +30,7 @@
reg = <0x0>;
status = "okay";

reset-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a entry in the migration guide, stating that this got fixed, so users with custom boards know that they have to change it too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

*/
static int phy_mc_vsc8541_cfg_link(const struct device *dev, enum phy_link_speed speeds)
static int phy_mc_vsc8541_cfg_link(const struct device *dev, enum phy_link_speed adv_speeds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe wait until #91354 is merged, it will provide phy_mii_cfg_link_autoneg() to set the autoneg registers according to the ethernet specs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check out #91572 62e692e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on top of those changes - we can now make use of some of the common phy_mii code here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to cherry-pick b58b241 from #91572
and putting it before your changes

I fixed there some other things I noticed

if (count++ > 1000) {
LOG_ERR("phy reset timed out");
return -ETIMEDOUT;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/* we use limited advertising, to force gigabit speed */
	/* initial version of this driver supports only 1GB/s */
	/* 1000MBit/s + AUTO */
	ret = phy_mc_vsc8541_write(dev, PHY_REG_PAGE0_ADV, (1 << 8) | (1 << 6) | 0x01);
	if (ret) {
		return ret;
	}
	ret = phy_mc_vsc8541_write(dev, PHY_REG_PAGE0_CTRL1000, (1 << 12) | (1 << 11) | (1 << 9));
	if (ret) {
		return ret;
	}
	/* start auto negotiation */
	ret = phy_mc_vsc8541_write(dev, PHY_REG_PAGE0_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
	if (ret) {
		return ret;
}

this can probably be removed, autoneg is enabled by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@github-actions github-actions bot added the Release Notes To be mentioned in the release notes label Jun 17, 2025
if (ret) {
return ret;
}

/* start auto negotiation */
ret = phy_mc_vsc8541_write(dev, PHY_REG_PAGE0_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this linke is also no longer needed, as we don't change the autoneg regs on startup, so we don't need to restart it, autoneg is btw enabled by default

Comment on lines 394 to 400
/**
* @brief Reconfigure the link speed
*
* @param dev device structure to phy
* @param adv_speeds speeds to be advertised
* @param flags configuration flags
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these kind of descriptions for doxygen are only needed for public apis in their headers, not in the source files

*/
static int phy_mc_vsc8541_cfg_link(const struct device *dev, enum phy_link_speed speeds)
static int phy_mc_vsc8541_cfg_link(const struct device *dev, enum phy_link_speed adv_speeds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to cherry-pick b58b241 from #91572
and putting it before your changes

I fixed there some other things I noticed

@robhancocksed
Copy link
Contributor Author

@maass-hamburg I cherry-picked in the commit you mentioned, as well as one other with a mutex change, from your branch and rebased my changes on top of it. I think I have addressed your other comments as well.

@robhancocksed
Copy link
Contributor Author

As noted before, those ganymed_bob and ganymed_sk test failures are not new, they also are occurring on weekly builds on the main branch.

maass-hamburg
maass-hamburg previously approved these changes Jun 18, 2025
maass-hamburg
maass-hamburg previously approved these changes Jun 24, 2025
@robhancocksed
Copy link
Contributor Author

Rebased to main to pick up the change in #92336 which should hopefully fix the CI build error.

@danieldegrasse danieldegrasse added the backport v4.2-branch Request backport to the v4.2-branch label Jul 15, 2025
@danieldegrasse danieldegrasse modified the milestones: v4.2.0, v4.3.0 Jul 15, 2025
@maass-hamburg
Copy link
Member

@robhancocksed this needs a rebase to current main

maass-hamburg and others added 9 commits July 21, 2025 15:08
- implement configure link
- support half duplex
- use defines from mii.h
- fix check ret vals

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
use mutex to protect page register

phy_mc_vsc8541_get_link got removed from
phy_mc_vsc8541_link_cb_set so, that
phy_mc_vsc8541_link_monitor (own thread)
is the only one to change data->state

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Fixed some build warnings in the driver from previous changes by
removing an unused variable and hooking up the cfg_link function. Also
removes some implicit boolean conversions.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
The driver was not enabling the MDIO bus before trying to access
registers. Added enabling and disabling the bus around PHY register
accesses.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
The internal register read/write functions used uint32_t for the values
even though the registers are only 16 bits wide, resulting in a bunch of
casting. Change the internal functions to use uint16_t and wrap them for
the external read/write API which uses uint32_t.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
For GPIOs driving active-low signals, such as the VSC8541's reset pin,
they are supposed to be declared as active low in the device tree, and
set to 1 to assert and 0 to clear. Change the driver as such so that it
does not leave the PHY stuck in reset when so configured.

Also changed all in-tree board DTS files for this PHY to properly
declare the reset GPIO as active low.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Mention a change to the reset-gpios handling in the vsc8541 PHY driver.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
The driver previously could enter an infinite loop if the PHY software
reset failed to complete, which could happen due to hardware reset
issues or MDIO bus problems. Add a timeout of 1000 iterations so we
report an error in this scenario rather than causing a lockup.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Add support for disabling autonegotiation to the cfg_link callback, as
with the phy_mii driver.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Copy link

@robhancocksed
Copy link
Contributor Author

Rebased to main and moved the migration guide entry to 4.3 now that 4.2 has been released.

@kartben kartben merged commit 45eedaa into zephyrproject-rtos:main Jul 23, 2025
40 of 42 checks passed
@robhancocksed robhancocksed deleted the vsc8541-fixes branch August 5, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet backport v4.2-branch Request backport to the v4.2-branch platform: sensry Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vsc8541 Ethernet PHY driver issues
6 participants