]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: mdio: pull bus/ctrl dependency apart
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Wed, 25 Mar 2026 13:48:43 +0000 (14:48 +0100)
committerRobert Marko <robimarko@gmail.com>
Fri, 27 Mar 2026 19:51:43 +0000 (20:51 +0100)
Until now the central control structure is allocated via a call to
devm_mdiobus_alloc_size(). This will not be possible any longer when
multiple busses will be implemented in a future commit.

Relax that as follows:

- Define a new private "channel" structure for a mdio bus
- Allocate the central control structure with a dedicated alloc()
- Allocate only the channel structure during bus setup
- Link the channel to the central structure via chan->ctrl

Reorganize the probing function so that it becomes clearer that
the control structure is setup first and afterwards the bus is
registered.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/22604
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c

index c9cb494cad5718cbcc30d7a61e89d65b639c1925..73012d2fdc0b5bd32e143430a5029baef0ec6ce7 100644 (file)
        for_each_set_bit(addr, ctrl->valid_ports, RTMDIO_MAX_PHY)
 
 #define rtmdio_ctrl_from_bus(bus) \
-       ((struct rtmdio_ctrl *)(bus)->priv)
-
+       (((struct rtmdio_chan *)(bus)->priv)->ctrl)
 
 /*
  * On all Realtek switch platforms the hardware periodically reads the link status of all
@@ -196,6 +195,10 @@ struct rtmdio_ctrl {
        DECLARE_BITMAP(valid_ports, RTMDIO_MAX_PHY);
 };
 
+struct rtmdio_chan {
+       struct rtmdio_ctrl *ctrl;
+};
+
 struct rtmdio_config {
        int num_phys;
        int raw_page;
@@ -909,20 +912,20 @@ static int rtmdio_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct rtmdio_ctrl *ctrl;
+       struct rtmdio_chan *chan;
        struct mii_bus *bus;
        int ret, addr;
 
-       bus = devm_mdiobus_alloc_size(dev, sizeof(*ctrl));
-       if (!bus)
+       ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
+       if (!ctrl)
                return -ENOMEM;
 
-       ctrl = bus->priv;
+       platform_set_drvdata(pdev, ctrl);
        ctrl->cfg = (const struct rtmdio_config *)device_get_match_data(dev);
        ctrl->map = syscon_node_to_regmap(pdev->dev.of_node->parent);
        if (IS_ERR(ctrl->map))
                return PTR_ERR(ctrl->map);
 
-       platform_set_drvdata(pdev, ctrl);
        ret = rtmdio_map_ports(dev);
        if (ret) {
                for_each_phy(ctrl, addr)
@@ -931,6 +934,13 @@ static int rtmdio_probe(struct platform_device *pdev)
        }
        rtmdio_setup_smi_topology(ctrl);
 
+       bus = devm_mdiobus_alloc_size(dev, sizeof(*chan));
+       if (!bus)
+               return -ENOMEM;
+
+       chan = bus->priv;
+       chan->ctrl = ctrl;
+
        bus->name = "Realtek MDIO bus";
        bus->reset = rtmdio_reset;
        bus->read = rtmdio_read;
@@ -940,7 +950,6 @@ static int rtmdio_probe(struct platform_device *pdev)
        bus->parent = dev;
        bus->phy_mask = ~0;
        snprintf(bus->id, MII_BUS_ID_SIZE, "realtek-mdio");
-
        device_set_node(&bus->dev, of_fwnode_handle(dev->of_node));
 
        ret = devm_mdiobus_register(dev, bus);