• Andrew Halaney's avatar
    net: stmmac: don't create a MDIO bus if unnecessary · f3c2caac
    Andrew Halaney authored
    Currently a MDIO bus is created if the devicetree description is either:
    
        1. Not fixed-link
        2. fixed-link but contains a MDIO bus as well
    
    The "1" case above isn't always accurate. If there's a phy-handle,
    it could be referencing a phy on another MDIO controller's bus[1]. In
    this case, where the MDIO bus is not described at all, currently
    stmmac will make a MDIO bus and scan its address space to discover
    phys (of which there are none). This process takes time scanning a bus
    that is known to be empty, delaying time to complete probe.
    
    There are also a lot of upstream devicetrees[2] that expect a MDIO bus
    to be created, scanned for phys, and the first one found connected
    to the MAC. This case can be inferred from the platform description by
    not having a phy-handle && not being fixed-link. This hits case "1" in
    the current driver's logic, and must be handled in any logic change here
    since it is a valid legacy dt-binding.
    
    Let's improve the logic to create a MDIO bus if either:
    
        - Devicetree contains a MDIO bus
        - !fixed-link && !phy-handle (legacy handling)
    
    This way the case where no MDIO bus should be made is handled, as well
    as retaining backwards compatibility with the valid cases.
    
    Below devicetree snippets can be found that explain some of
    the cases above more concretely.
    
    Here's[0] a devicetree example where the MAC is both fixed-link and
    driving a switch on MDIO (case "2" above). This needs a MDIO bus to
    be created:
    
        &fec1 {
                phy-mode = "rmii";
    
                fixed-link {
                        speed = <100>;
                        full-duplex;
                };
    
                mdio1: mdio {
                        switch0: switch0@0 {
                                compatible = "marvell,mv88e6190";
                                pinctrl-0 = <&pinctrl_gpio_switch0>;
                        };
                };
        };
    
    Here's[1] an example where there is no MDIO bus or fixed-link for
    the ethernet1 MAC, so no MDIO bus should be created since ethernet0
    is the MDIO master for ethernet1's phy:
    
        &ethernet0 {
                phy-mode = "sgmii";
                phy-handle = <&sgmii_phy0>;
    
                mdio {
                        compatible = "snps,dwmac-mdio";
                        sgmii_phy0: phy@8 {
                                compatible = "ethernet-phy-id0141.0dd4";
                                reg = <0x8>;
                                device_type = "ethernet-phy";
                        };
    
                        sgmii_phy1: phy@a {
                                compatible = "ethernet-phy-id0141.0dd4";
                                reg = <0xa>;
                                device_type = "ethernet-phy";
                        };
                };
        };
    
        &ethernet1 {
                phy-mode = "sgmii";
                phy-handle = <&sgmii_phy1>;
        };
    
    Finally there's descriptions like this[2] which don't describe the
    MDIO bus but expect it to be created and the whole address space
    scanned for a phy since there's no phy-handle or fixed-link described:
    
        &gmac {
                phy-supply = <&vcc_lan>;
                phy-mode = "rmii";
                snps,reset-gpio = <&gpio3 RK_PB4 GPIO_ACTIVE_HIGH>;
                snps,reset-active-low;
                snps,reset-delays-us = <0 10000 1000000>;
        };
    
    [0] https://elixir.bootlin.com/linux/v6.5-rc5/source/arch/arm/boot/dts/nxp/vf/vf610-zii-ssmb-dtu.dts
    [1] https://elixir.bootlin.com/linux/v6.6-rc5/source/arch/arm64/boot/dts/qcom/sa8775p-ride.dts
    [2] https://elixir.bootlin.com/linux/v6.6-rc5/source/arch/arm64/boot/dts/rockchip/rk3368-r88.dts#L164Reviewed-by: default avatarSerge Semin <fancer.lancer@gmail.com>
    Co-developed-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
    Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
    Signed-off-by: default avatarAndrew Halaney <ahalaney@redhat.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    f3c2caac
stmmac_platform.c 28 KB