* [PATCH net-next 0/3] net: mdio: realtek-rtl9300: add bus frequency handling
@ 2026-09-03 12:21 Markus Stockhausen
2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Markus Stockhausen @ 2026-09-03 12:21 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
chris.packham, robh, krzk+dt, conor+dt, devicetree
Cc: Markus Stockhausen
The Realtek Otto switch platform consists of four different series
- RTL838x aka maple : 28 port 1G Switches
- RTL839x aka cypress : 52 port 1G Switches
- RTL930x aka longan : 28 port 1G/2.5G/10G Switches
- RTL931x aka mango : 56 port 1G/2.5G/10G Switches
All of them support to change the bus frequency of the 1-4
ethernet MDIO buses. At least to some extend. Enhance the
driver to support this feature.
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Markus Stockhausen (3):
dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency
net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of"
net: mdio: realtek-rtl9300: Support non-default clock frequency
.../bindings/net/realtek,rtl9301-mdio.yaml | 3 +
drivers/net/mdio/mdio-realtek-rtl9300.c | 77 +++++++++++++++++--
2 files changed, 75 insertions(+), 5 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency 2026-09-03 12:21 [PATCH net-next 0/3] net: mdio: realtek-rtl9300: add bus frequency handling Markus Stockhausen @ 2026-09-03 12:21 ` Markus Stockhausen 2026-09-03 12:30 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 2026-09-03 12:21 ` [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" Markus Stockhausen 2026-09-03 12:21 ` [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency Markus Stockhausen 2 siblings, 2 replies; 10+ messages in thread From: Markus Stockhausen @ 2026-09-03 12:21 UTC (permalink / raw) To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree Cc: Markus Stockhausen The Realtek Otto Switch ethernet MDIO controller supports different MDC speeds ranging from 1.25MHz to 10MHz. Document the clock-frequency attribute for the device tree. There is neither an offical documentation nor any obvious registers that indicate a dependency to one of the hardware clocks. The usable setup bits are more like hardcoded values than dividers. Without further details do not add a clock reference. Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> --- .../devicetree/bindings/net/realtek,rtl9301-mdio.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml index 67e0b23a8470..6db3315ce96b 100644 --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml @@ -56,6 +56,9 @@ patternProperties: reg: maxItems: 1 + clock-frequency: + default: 2500000 + required: - reg -- 2.55.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency 2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen @ 2026-09-03 12:30 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: Andrew Lunn @ 2026-09-03 12:30 UTC (permalink / raw) To: Markus Stockhausen Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree On Thu, Sep 03, 2026 at 02:21:17PM +0200, Markus Stockhausen wrote: > The Realtek Otto Switch ethernet MDIO controller supports different MDC > speeds ranging from 1.25MHz to 10MHz. Document the clock-frequency > attribute for the device tree. > > There is neither an offical documentation nor any obvious registers that > indicate a dependency to one of the hardware clocks. The usable setup bits > are more like hardcoded values than dividers. Without further details do > not add a clock reference. > > Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> > --- > .../devicetree/bindings/net/realtek,rtl9301-mdio.yaml | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > index 67e0b23a8470..6db3315ce96b 100644 > --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > @@ -56,6 +56,9 @@ patternProperties: > reg: > maxItems: 1 > > + clock-frequency: > + default: 2500000 Please list the supported values. The fact this is messy, different devices supporting different frequencies, makes the validation more important. Andrew ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency 2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen 2026-09-03 12:30 ` Andrew Lunn @ 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-09-04 12:22 UTC (permalink / raw) To: Markus Stockhausen; +Cc: devicetree, conor+dt, robh Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The `clock-frequency` property in the device tree schema is missing required hardware bounds constraints. -- commit 740105b9d636a18be6fb1810649547d948475058 Author: Markus Stockhausen <markus.stockhausen@gmx.de> dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency The Realtek Otto Switch ethernet MDIO controller supports different MDC speeds ranging from 1.25MHz to 10MHz. Document the clock-frequency attribute for the device tree. > diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > index 67e0b23a8470e..6db3315ce96b3 100644 > --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml > @@ -56,6 +56,9 @@ patternProperties: > reg: > maxItems: 1 > > + clock-frequency: > + default: 2500000 > + [Severity: Low] Does this schema definition lack the required bounds constraints for the clock frequency? The commit message explicitly states the hardware supports MDC speeds ranging from 1.25MHz to 10MHz. However, without bounds constraints like minimum and maximum or an enum array, dt_binding_check will successfully validate device trees that specify physically impossible clock frequencies. If a device tree author sets an out-of-range clock-frequency (such as 200MHz) in a DTS file under patternProperties:^mdio-bus@[0-3]$, schema validation will incorrectly pass. Should this property definition enforce the physical hardware constraints with minimum: 1250000 and maximum: 10000000 (or a predefined enum list) to accurately enforce the described limitations? > required: > - reg -- Sashiko AI review · https://sashiko.dev/#/patchset/20260903122119.2638354-1-markus.stockhausen@gmx.de?part=1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" 2026-09-03 12:21 [PATCH net-next 0/3] net: mdio: realtek-rtl9300: add bus frequency handling Markus Stockhausen 2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen @ 2026-09-03 12:21 ` Markus Stockhausen 2026-09-03 12:26 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 2026-09-03 12:21 ` [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency Markus Stockhausen 2 siblings, 2 replies; 10+ messages in thread From: Markus Stockhausen @ 2026-09-03 12:21 UTC (permalink / raw) To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree Cc: Markus Stockhausen The latest developments of the MDIO driver consistently used the "of" API. Convert the remaining "fwnode" left-overs too. Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> --- drivers/net/mdio/mdio-realtek-rtl9300.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 11d078ef941c..429321e9114f 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -831,14 +831,14 @@ static void otto_emdio_notify_phy_detach(struct phy_device *phydev) } static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv, - struct fwnode_handle *node) + struct device_node *node) { struct otto_emdio_chan *chan; struct mii_bus *bus; u32 mdio_bus; int err; - err = fwnode_property_read_u32(node, "reg", &mdio_bus); + err = of_property_read_u32(node, "reg", &mdio_bus); if (err) return dev_err_probe(dev, err, "undefined smi bus number\n"); @@ -865,7 +865,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", dev_name(dev), mdio_bus); - err = devm_of_mdiobus_register(dev, bus, to_of_node(node)); + err = devm_of_mdiobus_register(dev, bus, node); if (err) return dev_err_probe(dev, err, "cannot register MDIO bus\n"); @@ -1027,7 +1027,7 @@ static int otto_emdio_probe(struct platform_device *pdev) return dev_err_probe(dev, err, "failed to setup MDIO bus controller\n"); } - device_for_each_child_node_scoped(dev, child) { + for_each_child_of_node_scoped(dev->of_node, child) { err = otto_emdio_probe_one(dev, priv, child); if (err) return err; -- 2.55.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" 2026-09-03 12:21 ` [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" Markus Stockhausen @ 2026-09-03 12:26 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: Andrew Lunn @ 2026-09-03 12:26 UTC (permalink / raw) To: Markus Stockhausen Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree On Thu, Sep 03, 2026 at 02:21:18PM +0200, Markus Stockhausen wrote: > The latest developments of the MDIO driver consistently used the > "of" API. Convert the remaining "fwnode" left-overs too. > > Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> > --- > drivers/net/mdio/mdio-realtek-rtl9300.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c > index 11d078ef941c..429321e9114f 100644 > --- a/drivers/net/mdio/mdio-realtek-rtl9300.c > +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c > @@ -831,14 +831,14 @@ static void otto_emdio_notify_phy_detach(struct phy_device *phydev) > } > > static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv, > - struct fwnode_handle *node) > + struct device_node *node) The indentation looks odd here. Andrew ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" 2026-09-03 12:21 ` [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" Markus Stockhausen 2026-09-03 12:26 ` Andrew Lunn @ 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-09-04 12:22 UTC (permalink / raw) To: Markus Stockhausen; +Cc: conor+dt, devicetree, robh Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: Pre-existing issues: - [High] Probing fails entirely if any child MDIO bus node is disabled. -- commit 9c3a52ecd349185743d66b8f8767bc5d73fad987 Author: Markus Stockhausen <markus.stockhausen@gmx.de> net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" This commit converts the remaining fwnode usages in the realtek-rtl9300 mdio driver to use the OF API. It updates the probe functions to iterate over and process device_node pointers instead of fwnode_handle pointers. > diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c > index 11d078ef941cd..429321e9114fd 100644 > --- a/drivers/net/mdio/mdio-realtek-rtl9300.c > +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c [ ... ] > @@ -1027,7 +1027,7 @@ static int otto_emdio_probe(struct platform_device *pdev) > return dev_err_probe(dev, err, "failed to setup MDIO bus controller\n"); > } > > - device_for_each_child_node_scoped(dev, child) { > + for_each_child_of_node_scoped(dev->of_node, child) { > err = otto_emdio_probe_one(dev, priv, child); > if (err) > return err; [Severity: High] This is a pre-existing issue, but does this loop cause the entire MDIO controller to fail to probe if any child MDIO bus node is disabled? Looking at otto_emdio_probe_one(), devm_of_mdiobus_register() will return -ENODEV for a node marked with status = "disabled". Because for_each_child_of_node_scoped() iterates over all child nodes including disabled ones, this error is propagated back and aborts the main otto_emdio_probe() function entirely. Would it be better to use for_each_available_child_of_node_scoped() here to skip disabled nodes, so that a valid device tree configuration with an unused MDIO bus does not break network connectivity for all active buses? -- Sashiko AI review · https://sashiko.dev/#/patchset/20260903122119.2638354-1-markus.stockhausen@gmx.de?part=2 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency 2026-09-03 12:21 [PATCH net-next 0/3] net: mdio: realtek-rtl9300: add bus frequency handling Markus Stockhausen 2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen 2026-09-03 12:21 ` [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" Markus Stockhausen @ 2026-09-03 12:21 ` Markus Stockhausen 2026-09-03 12:32 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 2 siblings, 2 replies; 10+ messages in thread From: Markus Stockhausen @ 2026-09-03 12:21 UTC (permalink / raw) To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree Cc: Markus Stockhausen The ethernet MDIO controller of the Realtek Otto switches has a default MDC clock frequency of 2.5MHz. Via configuration bits one can adapt this. Depending on the series the following can be set - RTL838x: 2.5Mhz, 10MHz - RTL839x, RTL930x, RTL931x: 1.25MHz, 2.5MHz, 5Mhz Enhance the driver so it allows to set the clock frequency via device tree. This helps to - simplify protocol analysis with a logic analyzer (lower speeds) - reduce MDIO access times during normal operation (higher speeds) Remark! While the devices normally support a per-bus frequency selection, the RTL839x is an exception from that. It can only select the speed for both buses globally. To avoid device tree special treatment for this, use the per-bus speeds for this series too. The driver sets the global speed according to the first probed bus and will issue warnings if the second probed bus wants to change that. Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> --- drivers/net/mdio/mdio-realtek-rtl9300.c | 69 ++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 429321e9114f..4af281b924ad 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -130,6 +130,7 @@ #define RTL8380_NUM_PAGES 4096 #define RTL8380_NUM_PORTS 28 #define RTL8380_SMI_GLB_CTRL 0xa100 +#define RTL8380_SMI_FREQ_SEL BIT(1) #define RTL8380_SMI_PHY_PATCH_DONE BIT(15) #define RTL8380_SMI_ACCESS_PHY_CTRL_0 0xa1b8 #define RTL8380_SMI_ACCESS_PHY_CTRL_1 0xa1bc @@ -169,12 +170,15 @@ #define RTL8390_PHYREG_PORT_CTRL_LOW 0x03e4 #define RTL8390_PHYREG_PORT_CTRL_HIGH 0x03e8 #define RTL8390_SMI_PORT_POLLING_CTRL 0x03fc +#define RTL8390_SMI_GLB_CTRL 0x03f8 +#define RTL8390_SMI_FREQ_SEL GENMASK(6, 5) #define RTL9300_NUM_BUSES 4 #define RTL9300_NUM_PAGES 4096 #define RTL9300_NUM_PORTS 28 #define RTL9300_SMI_GLB_CTRL 0xca00 #define RTL9300_GLB_CTRL_INTF_SEL(intf) BIT(16 + (intf)) +#define RTL9300_SMI_FREQ_SEL(intf) GENMASK((intf) * 2 + 9, (intf) * 2 + 8) #define RTL9300_SMI_PORT0_15_POLLING_SEL 0xca08 #define RTL9300_SMI_ACCESS_PHY_CTRL_0 0xcb70 #define RTL9300_SMI_ACCESS_PHY_CTRL_1 0xcb74 @@ -196,6 +200,8 @@ #define RTL9310_NUM_BUSES 4 #define RTL9310_NUM_PAGES 8192 #define RTL9310_NUM_PORTS 56 +#define RTL9310_SMI_GLB_CTRL0 0x0cc0 +#define RTL9310_SMI_FREQ_SEL(intf) GENMASK((intf) * 2 + 5, (intf) * 2 + 4) #define RTL9310_SMI_GLB_CTRL1 0x0cbc #define RTL9310_SMI_GLB_FMT_SEL_C45(intf) BIT((intf) * 2 + 1) #define RTL9310_SMI_INDRT_ACCESS_CTRL_0 0x0c00 @@ -251,6 +257,7 @@ struct otto_emdio_priv { struct regmap *regmap; struct mutex lock; /* protect HW access */ DECLARE_BITMAP(valid_ports, MAX_PORTS); + u32 global_freq; u16 page[MAX_PORTS]; u8 smi_bus[MAX_PORTS]; u8 smi_addr[MAX_PORTS]; @@ -269,6 +276,7 @@ struct otto_emdio_info { u8 num_ports; u16 num_pages; u32 poll_ctrl; + int (*set_bus_frequency)(struct mii_bus *bus, u32 freq); int (*setup_controller)(struct otto_emdio_priv *priv); int (*read_c22)(struct mii_bus *bus, int port, int regnum, u32 *value); int (*read_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u32 *value); @@ -740,6 +748,15 @@ static int otto_emdio_setup_topology(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_8380_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + + return regmap_assign_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, + RTL8380_SMI_FREQ_SEL, + freq >= 10000000); +} + static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) { /* @@ -749,6 +766,34 @@ static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) return regmap_set_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, RTL8380_SMI_PHY_PATCH_DONE); } +static int otto_emdio_8390_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + u32 val = FIELD_PREP(RTL8390_SMI_FREQ_SEL, min_t(u32, freq / 2500000, 2U)); + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + + if (priv->global_freq) { + /* With only one global frequency available skip setup for second bus. */ + if (freq != priv->global_freq) + dev_warn(&bus->dev, "Only one frequency for all buses supported"); + return 0; + } + priv->global_freq = freq; + + return regmap_update_bits(priv->regmap, RTL8390_SMI_GLB_CTRL, RTL8390_SMI_FREQ_SEL, val); +} + +static int otto_emdio_9300_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_chan *chan = bus->priv; + u32 mask, val; + + mask = RTL9300_SMI_FREQ_SEL(chan->mdio_bus); + val = field_prep(mask, min_t(u32, freq / 2500000, 2U)); + + return regmap_update_bits(priv->regmap, RTL9300_SMI_GLB_CTRL, mask, val); +} + static int otto_emdio_9300_setup_controller(struct otto_emdio_priv *priv) { u32 glb_ctrl_mask = 0, glb_ctrl_val = 0; @@ -769,6 +814,18 @@ static int otto_emdio_9300_setup_controller(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_9310_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_chan *chan = bus->priv; + u32 mask, val; + + mask = RTL9310_SMI_FREQ_SEL(chan->mdio_bus); + val = field_prep(mask, min_t(u32, freq / 2500000, 2U)); + + return regmap_update_bits(priv->regmap, RTL9310_SMI_GLB_CTRL0, mask, val); +} + static int otto_emdio_9310_setup_controller(struct otto_emdio_priv *priv) { int i, err; @@ -835,7 +892,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv { struct otto_emdio_chan *chan; struct mii_bus *bus; - u32 mdio_bus; + u32 mdio_bus, freq; int err; err = of_property_read_u32(node, "reg", &mdio_bus); @@ -865,6 +922,12 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", dev_name(dev), mdio_bus); + if (of_property_read_u32(node, "clock-frequency", &freq)) + freq = 2500000; + err = priv->info->set_bus_frequency(bus, freq); + if (err) + return dev_err_probe(dev, err, "cannot set frequency for MDIO bus %d\n", mdio_bus); + err = devm_of_mdiobus_register(dev, bus, node); if (err) return dev_err_probe(dev, err, "cannot register MDIO bus\n"); @@ -1051,6 +1114,7 @@ static const struct otto_emdio_info otto_emdio_8380_info = { .num_pages = RTL8380_NUM_PAGES, .num_ports = RTL8380_NUM_PORTS, .poll_ctrl = RTL8380_SMI_POLL_CTRL, + .set_bus_frequency = otto_emdio_8380_set_bus_frequency, .setup_controller = otto_emdio_8380_setup_controller, .read_c22 = otto_emdio_8380_read_c22, .read_c45 = otto_emdio_8380_read_c45, @@ -1075,6 +1139,7 @@ static const struct otto_emdio_info otto_emdio_8390_info = { .num_pages = RTL8390_NUM_PAGES, .num_ports = RTL8390_NUM_PORTS, .poll_ctrl = RTL8390_SMI_PORT_POLLING_CTRL, + .set_bus_frequency = otto_emdio_8390_set_bus_frequency, .read_c22 = otto_emdio_8390_read_c22, .read_c45 = otto_emdio_8390_read_c45, .write_c22 = otto_emdio_8390_write_c22, @@ -1097,6 +1162,7 @@ static const struct otto_emdio_info otto_emdio_9300_info = { .num_ports = RTL9300_NUM_PORTS, .num_pages = RTL9300_NUM_PAGES, .poll_ctrl = RTL9300_SMI_POLL_CTRL, + .set_bus_frequency = otto_emdio_9300_set_bus_frequency, .setup_controller = otto_emdio_9300_setup_controller, .read_c22 = otto_emdio_9300_read_c22, .read_c45 = otto_emdio_9300_read_c45, @@ -1123,6 +1189,7 @@ static const struct otto_emdio_info otto_emdio_9310_info = { .num_pages = RTL9310_NUM_PAGES, .num_ports = RTL9310_NUM_PORTS, .poll_ctrl = RTL9310_SMI_PORT_POLLING_CTRL, + .set_bus_frequency = otto_emdio_9310_set_bus_frequency, .setup_controller = otto_emdio_9310_setup_controller, .read_c22 = otto_emdio_9310_read_c22, .read_c45 = otto_emdio_9310_read_c45, -- 2.55.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency 2026-09-03 12:21 ` [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency Markus Stockhausen @ 2026-09-03 12:32 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: Andrew Lunn @ 2026-09-03 12:32 UTC (permalink / raw) To: Markus Stockhausen Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, chris.packham, robh, krzk+dt, conor+dt, devicetree > + if (of_property_read_u32(node, "clock-frequency", &freq)) > + freq = 2500000; > + err = priv->info->set_bus_frequency(bus, freq); Please validate the frequency, return EINVAL if it is not an exact match. Andrew --- pw-bot: cr ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency 2026-09-03 12:21 ` [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency Markus Stockhausen 2026-09-03 12:32 ` Andrew Lunn @ 2026-09-04 12:22 ` sashiko-bot 1 sibling, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-09-04 12:22 UTC (permalink / raw) To: Markus Stockhausen; +Cc: robh, conor+dt, devicetree Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Using an uninitialized `bus->dev` pointer for logging before the MDIO bus is registered, resulting in a '(null)' prefix. - [Low] The `global_freq` variable is overloaded as both an initialization flag and frequency storage, failing if `clock-frequency` is explicitly set to 0. -- commit 9b57074cdf8cafdf9765568d20f29655308463cf Author: Markus Stockhausen <markus.stockhausen@gmx.de> net: mdio: realtek-rtl9300: Support non-default clock frequency This commit enhances the realtek-rtl9300 MDIO driver to allow setting the MDC clock frequency via device tree. For the RTL839x series, which only supports global frequency selection, the driver configures the global speed based on the first probed bus and issues warnings for conflicts. > diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c > --- a/drivers/net/mdio/mdio-realtek-rtl9300.c > +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c [ ... ] > @@ -749,6 +766,34 @@ static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) > return regmap_set_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, RTL8380_SMI_PHY_PATCH_DONE); > } > > +static int otto_emdio_8390_set_bus_frequency(struct mii_bus *bus, u32 freq) > +{ > + u32 val = FIELD_PREP(RTL8390_SMI_FREQ_SEL, min_t(u32, freq / 2500000, 2U)); > + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); > + > + if (priv->global_freq) { [Severity: Low] Does this logic correctly handle a scenario where the device tree explicitly sets the clock-frequency to 0? Since priv->global_freq is used as both an initialization flag and for storing the frequency, a frequency of 0 would evaluate to false here. This could bypass the conflict detection for subsequent buses and silently overwrite the global hardware frequency. Would a dedicated initialization flag or sentinel value (like -1) be more robust to handle all integer inputs? > + /* With only one global frequency available skip setup for second bus. */ > + if (freq != priv->global_freq) > + dev_warn(&bus->dev, "Only one frequency for all buses supported"); [Severity: Medium] Will this dev_warn() print a (null) device name prefix? Looking at otto_emdio_probe_one(), set_bus_frequency() is called before the bus is registered via devm_of_mdiobus_register(): err = priv->info->set_bus_frequency(bus, freq); if (err) return dev_err_probe(...); err = devm_of_mdiobus_register(dev, bus, node); Because dev_set_name() hasn't been called on bus->dev yet, the logger won't have a valid name to display. Could this be resolved by logging with bus->parent instead? > + return 0; > + } > + priv->global_freq = freq; > + > + return regmap_update_bits(priv->regmap, RTL8390_SMI_GLB_CTRL, RTL8390_SMI_FREQ_SEL, val); > +} -- Sashiko AI review · https://sashiko.dev/#/patchset/20260903122119.2638354-1-markus.stockhausen@gmx.de?part=3 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-09-04 12:22 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-09-03 12:21 [PATCH net-next 0/3] net: mdio: realtek-rtl9300: add bus frequency handling Markus Stockhausen 2026-09-03 12:21 ` [PATCH net-next 1/3] dt-bindings: net: realtek,rtl9301-mdio: Add clock-frequency Markus Stockhausen 2026-09-03 12:30 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 2026-09-03 12:21 ` [PATCH net-next 2/3] net: mdio: realtek-rtl9300: Convert "fwnode" left-overs to "of" Markus Stockhausen 2026-09-03 12:26 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot 2026-09-03 12:21 ` [PATCH net-next 3/3] net: mdio: realtek-rtl9300: Support non-default clock frequency Markus Stockhausen 2026-09-03 12:32 ` Andrew Lunn 2026-09-04 12:22 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox