realtek: fix mdio parent/child locking issues
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sat, 17 May 2025 06:22:09 +0000 (02:22 -0400)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 8 Jun 2025 19:19:31 +0000 (21:19 +0200)
commit0f9ebe2da714f58c25185cfd32845249e61feaf2
tree9ca95f6482ad2b6e999ff5e34b6b1639afaf16e3
parent072fd4de3c689bf9740f93cc5a881fb67ba13d12
realtek: fix mdio parent/child locking issues

Since the early beginning of the Realtek DSA driver there is an uncovered
locking issue between the standard (parent) mdio bus and the DSA (child)
mdio bus. This comes from the fact that the DSA bus simply links to the
parent read and write functions and calls them directly. This leads to
the following lock issue.

- Child bus calls phy_read/write functions and uses its internal lock
- Parent bus calls phy_read/write functions and uses its internal lock

It becomes clear that critical section can be accessed twice without
knowing that a operation from the other bus is currently active. This
can lead to critical malfunctions because the mdio driver needs a lot of
internal magic to get page selection done right. Effects are:

- The original page is lost after a phy_write/read_paged() call
- dmesg like "Realtek RTL8218B (external) rtl838x slave mii-0:00:
  Expected external RTL8218B, found PHY-ID 6b23"

Other DSA drivers simply use the read/write functions from the parent bus
and thus avoid locking issues. Do it the same way.

Fixes: 2b88563ee5aafd9 ("realtek: update the tree to the latest refactored version")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/18824
Signed-off-by: Robert Marko <robimarko@gmail.com>
(cherry picked from commit 461fc06f9d72d032b2acc86fbb7662511e07dd3c)
Link: https://github.com/openwrt/openwrt/pull/18755
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/realtek/files-6.6/drivers/net/dsa/rtl83xx/common.c
target/linux/realtek/files-6.6/drivers/net/dsa/rtl83xx/rtl838x.h