]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: mdio: add valid_port bitmask to structure
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sun, 22 Mar 2026 14:21:29 +0000 (15:21 +0100)
committerRobert Marko <robimarko@gmail.com>
Mon, 23 Mar 2026 10:18:03 +0000 (11:18 +0100)
Until now the driver determines the validity of a phy (or port)
by checking "smi_bus[] < 0". That is somehow confusing. Align
with upstream and add a valid_port bitmask that can be used for
this check with common kernel bit operations.

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

index 4d40a9b9c22d948ed5b41a71243cdf7c6f74de6b..2ea24390c42df6d4aef55be881a86a6257d4a557 100644 (file)
 #define RTMDIO_931X_SMI_10GPHY_POLLING_SEL4    (0x0D00)
 
 #define for_each_phy(ctrl, addr) \
-       for (int addr = 0; addr < (ctrl)->cfg->num_phys; addr++) \
-               if ((ctrl)->smi_bus[addr] >= 0)
+       for_each_set_bit(addr, ctrl->valid_ports, RTMDIO_MAX_PHY)
 
 /*
  * On all Realtek switch platforms the hardware periodically reads the link status of all
@@ -183,6 +182,7 @@ struct rtmdio_ctrl {
        int smi_addr[RTMDIO_MAX_PHY];
        struct device_node *phy_node[RTMDIO_MAX_PHY];
        bool smi_bus_isc45[RTMDIO_MAX_SMI_BUS];
+       DECLARE_BITMAP(valid_ports, RTMDIO_MAX_PHY);
 };
 
 struct rtmdio_config {
@@ -562,7 +562,7 @@ static int rtmdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
 static void rtmdio_setup_smi_topology(struct mii_bus *bus)
 {
        struct rtmdio_ctrl *ctrl = bus->priv;
-       u32 reg, mask, val;
+       u32 reg, mask, val, addr;
 
        for_each_phy(ctrl, addr) {
                if (ctrl->cfg->bus_map_base) {
@@ -677,7 +677,7 @@ static void rtmdio_838x_setup_polling(struct mii_bus *bus)
         * give the real media status (0=copper, 1=fibre). For now assume that if address 24 is
         * PHY driven, it must be a combo PHY and media detection is needed.
         */
-       combo_phy = ctrl->smi_bus[24] < 0 ? 0 : BIT(7);
+       combo_phy = test_bit(24, ctrl->valid_ports) ? BIT(7) : 0;
        regmap_update_bits(ctrl->map, RTMDIO_838X_SMI_GLB_CTRL, BIT(7), combo_phy);
 }
 
@@ -718,7 +718,7 @@ static void rtmdio_930x_setup_polling(struct mii_bus *bus)
 {
        struct rtmdio_ctrl *ctrl = bus->priv;
        struct rtmdio_phy_info phyinfo;
-       unsigned int mask, val;
+       unsigned int mask, val, addr;
 
        /* set everthing to "SerDes driven" */
        regmap_write(ctrl->map, RTMDIO_930X_SMI_MAC_TYPE_CTRL, 0);
@@ -776,6 +776,7 @@ static void rtmdio_931x_setup_polling(struct mii_bus *bus)
 {
        struct rtmdio_ctrl *ctrl = bus->priv;
        struct rtmdio_phy_info phyinfo;
+       u32 addr;
 
        /* set everything to "SerDes driven" */
        for (int reg = 0; reg < 4; reg++)
@@ -847,9 +848,6 @@ static int rtmdio_map_ports(struct device *dev)
                return dev_err_probe(dev, -ENODEV, "%pfwP missing ethernet-ports\n",
                                     of_fwnode_handle(switch_node));
 
-       for (addr = 0; addr < RTMDIO_MAX_PHY; addr++)
-               ctrl->smi_bus[addr] = -1;
-
        for_each_child_of_node_scoped(ports, port) {
                if (of_property_read_u32(port, "reg", &addr))
                        continue;
@@ -880,6 +878,7 @@ static int rtmdio_map_ports(struct device *dev)
 
                ctrl->smi_bus[addr] = bus_addr;
                ctrl->phy_node[addr] = of_node_get(phy);
+               __set_bit(addr, ctrl->valid_ports);
        }
 
        return 0;
@@ -890,7 +889,7 @@ static int rtmdio_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct rtmdio_ctrl *ctrl;
        struct mii_bus *bus;
-       int ret;
+       int ret, addr;
 
        bus = devm_mdiobus_alloc_size(dev, sizeof(*ctrl));
        if (!bus)