-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Introducing stm32 MDIO driver #71012
Conversation
Do you need to remove all the phy related stuff from the STM32 Ethernet drivers? edit: that is it seems like the phy would be managed by both the phy and Ethernet drivers (and without synchronisation) |
Hi @gramsay0 thanks for the feedbacks,
Well, adin2111/1110 are spi-based only, adin1100 (and adin1300 that will follow) are rmii interface based, and industrial ethernet stuff. A PHY driver for them is asked by ADI, since generic-phy (that i tested) is not working properly for them.
Yes, correct, if it's an issue i can remove PHY HAL access for H5/H7 from eth_stm32_hal.c in case, and use a MDIO API call in that place. |
phy_adin2111.c does not use SPI, it uses the MDIO API which could be implemented by any MDIO driver. So it should be possible to use phy_adin2111.c (possibly with extensions for adin1100) with your stm32 MDIO driver.
Someone more familiar with this area would be best to give you advice on this |
drivers/mdio/mdio_stm32_hal.c
Outdated
|
||
k_sem_take(&dev_data->sem, K_FOREVER); | ||
|
||
ret = HAL_ETH_WritePHYRegister(hmdio, prtad, regad, data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the stm32 hal looks for definition of ETH_MDIO_BUS_TIMEOUT to decide how long to block and I am wondering if it would be worth any value to provide this definition based on the value of a kconfig so that it is configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is,
#define ETH_MDIO_BUS_TIMEOUT 1000U
So it's actually 1 second max. It's a max limit, so busy flag is cleared to 0 much before. Seems not simple for me to replace this value, since part of stm32cube module repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could make a kconfig and give zephyr_compile_definitions in the cmake based on that config, but if you don't think this is worth it then I don't think it is a big deal to skip it in this PR
drivers/ethernet/phy/Kconfig
Outdated
depends on DT_HAS_ADI_ADIN1100_PHY_ENABLED | ||
depends on ETH_STM32_HAL | ||
depends on MDIO | ||
depends on MDIO_ST_STM32_HAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be dependent on the implementations being stm32 hal, in principle the phy driver should be able to fit with any mdio controller or ethernet device
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks, removed both MDIO_ST_STM32_HAL and ETH_STM32_HAL, since stm32 mdio driver goes trough stm32 HAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems they are still there, is it intentional
drivers/ethernet/phy/phy_adin1100.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other reviewer is right that the most important consumer of the phy abstraction layer is the ethernet mac driver itself, and honestly it would not be a good idea to have a separate phy driver while having basically another phy driver embedded/hardcoded per se in the mac driver, they could conflict without knowing about each other... I havent looked at the stm32 driver but if it really does use the stm hal phy calls then it would probably be in your interest to convert it to using the zephyr phy api and go through this driver (or whatever phy driver, since that is the idea)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@decsny and all, thanks for all the feedbacks,
so, based on the above suggestions, i would go in this direction now for a v2:
- see if i can use same phy driver for adin2111 and adin1100
- on the stm32 eth driver, will use the Zephyr phy api to avoid conflicts
- keeping/fixing all your suggested points above
Let me know if you see any issue.
Thanks a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats fine
As of now, cannot use adin2111/1110 phy driver for adin1100, since several accesses are Clause 45, and stm32 mdio cannot implement it (missing HAL functions). I pushed a PR to ST HAL for this. STMicroelectronics/stm32h7xx-hal-driver#52 So right now, only way for me to proceed is to keep in adin1100 phy driver. If ST HAL will be accepted, i can cleanup code removing the phy driver. |
Both adin2111 and adin1110 support clause 22 and 45. So writing an adin1110 phy driver just to support clause 22 (because the existing adin2111 uses clause 45) does not seem like a good path forward. IMO a Kconfig to enable C45 support would seem more appropriate. Although adding clause 45 support to the STM HAL is a great alternative too 👍 |
thanks, well, ADI naming is quite funny :) there are ADIN2111/1110 (same eth/mdio/phy driver, spi based) and this new ADIN1100 that is rmii. It requires right now a new driver since from there i can access MMD registers using the "bridge, indirect accerss" feature of it, simulating Clause 45, that cannot be implemented now in STM32 mdio. So for now keeping in adin1100-phy. If ST guys will accept HAL changhes, i promise clean up and to remove the adin1100 phy driver. |
If a new variant supports a new feature, then you can add that to the device tree, and check / make use of the new feature in the driver, no need to duplicate the other functionality.
👍 |
Ack, will try to keep adin1110 phy with some conditionals for rmii |
7a2ec09
to
74aec57
Compare
MDIO is part of the ETH IP, but some phy chip may need a specific phy driver to set up certain vendor registers enabling particular features. Add support for stm32 mdio access. Signed-off-by: Angelo Dureghello <[email protected]>
Add mdio node for h5 and h7 series. Since MDIO registers are part of the same ETH hw IP, keeping mdio node just as a child of mac/eth, cannot see as appropriate to assign an adddress to it. Signed-off-by: Angelo Dureghello <[email protected]>
Add mdio and phy nodes for h5/h7 families. Signed-off-by: Angelo Dureghello <[email protected]>
Introducing MDIO and PHY support for stm32, phy driver gets error (-116) if it tries to read phy chip id, since MDIO IP is part of ETH IP, and eth hw module is still not initialized. Forcing a priority that allows possibly connected PHY chip to be detected properly at initial boot. Signed-off-by: Angelo Dureghello <[email protected]>
Use PHY apis to access the PHY, to avoid any kind of collisions with other tasks using the PHY apis. Signed-off-by: Angelo Dureghello <[email protected]>
Add support for similar adin1100 phy, boath are 10Base-T1L, only difference is that adin1100 connects through r/mii. Signed-off-by: Angelo Dureghello <[email protected]>
863ade9
to
047024c
Compare
Changes for v5:
|
@MaureenHelm @erwango so fixed last issue reported, could you please re-accept, if all ok ? Thanks. |
I'd like @marwaiehm-st to confirm this has no impact on F7 series first. Otherwise it's fine for me. |
Test ok on board nucleo_f767zi , there is no impact on F7 series first. |
@spectrum70 can you send a follow up PR adding a line to the release notes? Thanks in advance. |
Introducing stm32 MDIO driver, needed for all ethernet phy drivers on top of it, as actually needed from adin1100.
MDIO hw module is part of the ETH IP module in both stm32 h5/h7 families (and also likely f, not interested from this patch-set).
This patch-set abstracts-out the MDIO related registers control, in a separate MDIO driver, so that further PHY drivers can be implemented, and MDIO and PHY apis can be used.
Below a simple unit test, where i write and read registers, testing the contents with previously written values:
Waiting for comments.
Thanks