Commit Graph

439 Commits

Author SHA1 Message Date
Izabela Bakollari f93fc006d3 net: phy: Remove LED entry from LEDs list on unregister
JIRA: https://issues.redhat.com/browse/RHEL-57766
JIRA: https://issues.redhat.com/browse/RHEL-63771

CVE: CVE-2024-50023

commit f50b5d74c68e551667e265123659b187a30fe3a5
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Fri Oct 4 20:27:58 2024 +0200

    net: phy: Remove LED entry from LEDs list on unregister

    Commit c938ab4da0eb ("net: phy: Manual remove LEDs to ensure correct
    ordering") correctly fixed a problem with using devm_ but missed
    removing the LED entry from the LEDs list.

    This cause kernel panic on specific scenario where the port for the PHY
    is torn down and up and the kmod for the PHY is removed.

    On setting the port down the first time, the assosiacted LEDs are
    correctly unregistered. The associated kmod for the PHY is now removed.
    The kmod is now added again and the port is now put up, the associated LED
    are registered again.
    On putting the port down again for the second time after these step, the
    LED list now have 4 elements. With the first 2 already unregistered
    previously and the 2 new one registered again.

    This cause a kernel panic as the first 2 element should have been
    removed.

    Fix this by correctly removing the element when LED is unregistered.

    Reported-by: Daniel Golle <daniel@makrotopia.org>
    Tested-by: Daniel Golle <daniel@makrotopia.org>
    Cc: stable@vger.kernel.org
    Fixes: c938ab4da0eb ("net: phy: Manual remove LEDs to ensure correct ordering")
    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://patch.msgid.link/20241004182759.14032-1-ansuelsmth@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:59 +01:00
Izabela Bakollari 7fee3cc529 net: phy: Use for_each_available_child_of_node_scoped()
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 1dce520abd461efcaf4a5a942d8eb833eef52d0b
Author: Jinjie Ruan <ruanjinjie@huawei.com>
Date:   Fri Aug 30 11:13:20 2024 +0800

    net: phy: Use for_each_available_child_of_node_scoped()

    Avoid need to manually handle of_node_put() by using
    for_each_available_child_of_node_scoped(), which can simplfy code.

    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
    Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:57 +01:00
Izabela Bakollari 19c6bb1849 net: phy: Fix missing of_node_put() for leds
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 2560db6ede1aaf162a73b2df43e0b6c5ed8819f7
Author: Jinjie Ruan <ruanjinjie@huawei.com>
Date:   Fri Aug 30 10:20:25 2024 +0800

    net: phy: Fix missing of_node_put() for leds

    The call of of_get_child_by_name() will cause refcount incremented
    for leds, if it succeeds, it should call of_node_put() to decrease
    it, fix it.

    Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
    Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://patch.msgid.link/20240830022025.610844-1-ruanjinjie@huawei.com
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:57 +01:00
Izabela Bakollari e79ad01e70 net: phylib: do not disable autoneg for fixed speeds >= 1G
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 6ff3cddc365beae1fbe185fd470cc0b86e895574
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Thu Aug 8 12:41:22 2024 +0100

    net: phylib: do not disable autoneg for fixed speeds >= 1G

    We have an increasing number of drivers that are forcing
    auto-negotiation to be enabled for speeds of 1G or faster.

    It would appear that auto-negotiation is mandatory for speeds above
    100M. In 802.3, Annex 40C's state diagrams seems to imply that
    mr_autoneg_enable (BMCR AN ENABLE) doesn't affect whether or not the
    AN state machines work for 1000base-T, and some PHY datasheets (e.g.
    Marvell Alaska) state that disabling mr_autoneg_enable leaves AN
    enabled but forced to 1G full duplex.

    Other PHY datasheets imply that BMCR AN ENABLE should not be cleared
    for >= 1G.

    Thus, this should be handled in phylib rather than in each driver.

    Rather than erroring out, arrange to implement the Marvell Alaska
    solution but in software for all PHYs: generate an appropriate
    single-speed advertisement for the requested speed, and keep AN
    enabled to the PHY driver. However, to avoid userspace API breakage,
    continue to report to userspace that we have AN disabled.

    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:56 +01:00
Izabela Bakollari ef2a802b3d net: phy: phy_device: fix PHY WOL enabled, PM failed to suspend
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 4f534b7f0c8d2a9ec557f9c7d77f96d29518c666
Author: Youwan Wang <youwan@nfschina.com>
Date:   Wed Jul 31 17:15:37 2024 +0800

    net: phy: phy_device: fix PHY WOL enabled, PM failed to suspend

    If the PHY of the mido bus is enabled with Wake-on-LAN (WOL),
    we cannot suspend the PHY. Although the WOL status has been
    checked in phy_suspend(), returning -EBUSY(-16) would cause
    the Power Management (PM) to fail to suspend. Since
    phy_suspend() is an exported symbol (EXPORT_SYMBOL),
    timely error reporting is needed. Therefore, an additional
    check is performed here. If the PHY of the mido bus is enabled
    with WOL, we skip calling phy_suspend() to avoid PM failure.

    From the following logs, it has been observed that the phydev->attached_dev
    is NULL, phydev is "stmmac-0:01", it not attached, but it will affect suspend
    and resume.The actually attached "stmmac-0:00" will not dpm_run_callback():
    mdio_bus_phy_suspend().

    init log:
    [    5.932502] YT8521 Gigabit Ethernet stmmac-0:00: attached PHY driver
    (mii_bus:phy_addr=stmmac-0:00, irq=POLL)
    [    5.932512] YT8521 Gigabit Ethernet stmmac-0:01: attached PHY driver
    (mii_bus:phy_addr=stmmac-0:01, irq=POLL)
    [   24.566289] YT8521 Gigabit Ethernet stmmac-0:00: yt8521_read_status,
    link down, media: UTP

    suspend log:
    [  322.631362] OOM killer disabled.
    [  322.631364] Freezing remaining freezable tasks
    [  322.632536] Freezing remaining freezable tasks completed (elapsed 0.001 seconds)
    [  322.632540] printk: Suspending console(s) (use no_console_suspend to debug)
    [  322.633052] YT8521 Gigabit Ethernet stmmac-0:01:
    PM: dpm_run_callback(): mdio_bus_phy_suspend+0x0/0x110 [libphy] returns -16
    [  322.633071] YT8521 Gigabit Ethernet stmmac-0:01:
    PM: failed to suspend: error -16
    [  322.669699] PM: Some devices failed to suspend, or early wake event detected
    [  322.669949] OOM killer enabled.
    [  322.669951] Restarting tasks ... done.
    [  322.671008] random: crng reseeded on system resumption
    [  322.671014] PM: suspend exit

    Add a function that phylib can inquire of the driver whether WoL
    has been enabled at the PHY.

    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: Youwan Wang <youwan@nfschina.com>
    Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
    Link: https://patch.msgid.link/20240731091537.771391-1-youwan@nfschina.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:56 +01:00
Izabela Bakollari d7f65c8b5f net: phy: fix potential use of NULL pointer in phy_suspend()
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 19e6ad2c75782bd15b3df24df7982da457d702c5
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Jun 28 11:32:11 2024 +0100

    net: phy: fix potential use of NULL pointer in phy_suspend()

    phy_suspend() checks the WoL status, and then dereferences
    phydrv->flags if (and only if) we decided that WoL has been enabled
    on either the PHY or the netdev.

    We then check whether phydrv was NULL, but we've potentially already
    dereferenced the pointer.

    If phydrv is NULL, then phy_ethtool_get_wol() will return an error
    and leave wol.wolopts set to zero. However, if netdev->wol_enabled
    is true, then we would dereference a NULL pointer.

    Checking the PHY drivers, the only place that phydev->wol_enabled is
    checked by them is in their suspend/resume callbacks and nowhere else
    (which is correct, because phylib only updates this in phy_suspend()).

    So, move the NULL pointer check earlier to avoid a NULL pointer
    dereference. Leave the check for phydrv->suspend in place as a driver
    may populate the .resume method but not the .suspend method.

    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://patch.msgid.link/E1sN8tn-00GDCZ-Jj@rmk-PC.armlinux.org.uk
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:53 +01:00
Izabela Bakollari 952cc6902b net: phy: fix phy_get_internal_delay accessing an empty array
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 4469c0c5b14a0919f5965c7ceac96b523eb57b79
Author: Kévin L'hôpital <kevin.lhopital@savoirfairelinux.com>
Date:   Thu Mar 7 12:19:06 2024 +0100

    net: phy: fix phy_get_internal_delay accessing an empty array

    The phy_get_internal_delay function could try to access to an empty
    array in the case that the driver is calling phy_get_internal_delay
    without defining delay_values and rx-internal-delay-ps or
    tx-internal-delay-ps is defined to 0 in the device-tree.
    This will lead to "unable to handle kernel NULL pointer dereference at
    virtual address 0". To avoid this kernel oops, the test should be delay
    >= 0. As there is already delay < 0 test just before, the test could
    only be size == 0.

    Fixes: 92252eec91 ("net: phy: Add a helper to return the index for of the internal delay")
    Co-developed-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
    Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
    Signed-off-by: Kévin L'hôpital <kevin.lhopital@savoirfairelinux.com>
    Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:45 +01:00
Izabela Bakollari 1cd82e8aac net: phy: add PHY_EEE_CAP2_FEATURES
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit ef6ee3a31bdc699391f2db4eff407fdb06895809
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Wed Feb 14 21:17:11 2024 +0100

    net: phy: add PHY_EEE_CAP2_FEATURES

    As a prerequisite for adding EEE CAP2 register support, complement
    PHY_EEE_CAP1_FEATURES with PHY_EEE_CAP2_FEATURES.
    For now only 2500baseT and 5000baseT modes are supported.

    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:40 +01:00
Izabela Bakollari 3b75d870e7 net: mdio_bus: make mdio_bus_type const
JIRA: https://issues.redhat.com/browse/RHEL-57766

commit 81800aef0eba33df2b30f2e29a0137078b9ba256
Author: Ricardo B. Marliere <ricardo@marliere.net>
Date:   Tue Feb 13 11:48:00 2024 -0300

    net: mdio_bus: make mdio_bus_type const

    Since commit d492cc2573a0 ("driver core: device.h: make struct
    bus_type a const *"), the driver core can properly handle constant
    struct bus_type, move the mdio_bus_type variable to be a constant
    structure as well, placing it into read-only memory which can not be
    modified at runtime.

    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Link: https://lore.kernel.org/r/20240213-bus_cleanup-mdio-v1-1-f9e799da7fda@marliere.net
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-12-10 13:40:40 +01:00
Michal Schmidt 9dd76c1b6d net: phy: add helpers to handle sfp phy connect/disconnect
JIRA: https://issues.redhat.com/browse/RHEL-57751

commit b2db6f4ace72e71fa09b8d1354f8ac9854140d74
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
Date:   Wed Aug 21 17:09:57 2024 +0200

    net: phy: add helpers to handle sfp phy connect/disconnect

    There are a few PHY drivers that can handle SFP modules through their
    sfp_upstream_ops. Introduce Phylib helpers to keep track of connected
    SFP PHYs in a netdevice's namespace, by adding the SFP PHY to the
    upstream PHY's netdev's namespace.

    By doing so, these SFP PHYs can be enumerated and exposed to users,
    which will be able to use their capabilities.

    Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
2024-11-05 11:39:22 +01:00
Michal Schmidt b9bb091e5a net: phy: Introduce ethernet link topology representation
JIRA: https://issues.redhat.com/browse/RHEL-57751

commit 3849687869092094003ba009dc00e2e0237a3b8a
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
Date:   Wed Aug 21 17:09:55 2024 +0200

    net: phy: Introduce ethernet link topology representation

    Link topologies containing multiple network PHYs attached to the same
    net_device can be found when using a PHY as a media converter for use
    with an SFP connector, on which an SFP transceiver containing a PHY can
    be used.

    With the current model, the transceiver's PHY can't be used for
    operations such as cable testing, timestamping, macsec offload, etc.

    The reason being that most of the logic for these configuration, coming
    from either ethtool netlink or ioctls tend to use netdev->phydev, which
    in multi-phy systems will reference the PHY closest to the MAC.

    Introduce a numbering scheme allowing to enumerate PHY devices that
    belong to any netdev, which can in turn allow userspace to take more
    precise decisions with regard to each PHY's configuration.

    The numbering is maintained per-netdev, in a phy_device_list.
    The numbering works similarly to a netdevice's ifindex, with
    identifiers that are only recycled once INT_MAX has been reached.

    This prevents races that could occur between PHY listing and SFP
    transceiver removal/insertion.

    The identifiers are assigned at phy_attach time, as the numbering
    depends on the netdevice the phy is attached to. The PHY index can be
    re-used for PHYs that are persistent.

    Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
    Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Conflicts: Dropped a whitespace-only hunk.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
2024-11-05 11:38:22 +01:00
Michal Schmidt 0dd899a61a net: move ethtool-related netdev state into its own struct
JIRA: https://issues.redhat.com/browse/RHEL-57750

commit 3ebbd9f6de7ec6d538639ebb657246f629ace81e
Author: Edward Cree <ecree.xilinx@gmail.com>
Date:   Thu Jun 27 16:33:46 2024 +0100

    net: move ethtool-related netdev state into its own struct

    net_dev->ethtool is a pointer to new struct ethtool_netdev_state, which
     currently contains only the wol_enabled field.

    Suggested-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>
    Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
    Link: https://patch.msgid.link/293a562278371de7534ed1eb17531838ca090633.1719502239.git.ecree.xilinx@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Conflicts:
	drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c
	drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
	- The driver is not preset in RHEL 9.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
2024-10-01 12:19:13 +02:00
Izabela Bakollari ac21b7a08e net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 32fa4366cc4da1c97b725a0066adf43c6b298f37
Author: Nikita Kiryushin <kiryushin@ancud.ru>
Date:   Fri Mar 15 20:50:52 2024 +0300

    net: phy: fix phy_read_poll_timeout argument type in genphy_loopback

    read_poll_timeout inside phy_read_poll_timeout can set val negative
    in some cases (for example, __mdiobus_read inside phy_read can return
    -EOPNOTSUPP).

    Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
    should fix problems with wrong-signed vals, but I do not see how
    as val is sent to phy_read as is and __val = phy_read (not val)
    is checked for sign.

    Change val type for signed to allow better error handling as done in other
    phy_read_poll_timeout callers. This will not fix any error handling
    by itself, but allows, for example, to modify cond with appropriate
    sign check or check resulting val separately.

    Found by Linux Verification Center (linuxtesting.org) with SVACE.

    Fixes: 014068dcb5 ("net: phy: genphy_loopback: add link speed configuration")
    Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
    Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Link: https://lore.kernel.org/r/20240315175052.8049-1-kiryushin@ancud.ru
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:21 +02:00
Izabela Bakollari 38ff81cb8e net: phy: provide whether link has changed in c37_read_status
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 9b1d5e055508393561e26bd1720f4c2639b03b1a
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Tue Feb 6 18:31:09 2024 +0100

    net: phy: provide whether link has changed in c37_read_status

    Some PHY driver might require additional regs call after
    genphy_c37_read_status() is called.

    Expand genphy_c37_read_status to provide a bool wheather the link has
    changed or not to permit PHY driver to skip additional regs call if
    nothing has changed.

    Every user of genphy_c37_read_status() is updated with the new
    additional bool.

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:20 +02:00
Izabela Bakollari da86ee321f net: phy: add devm/of_phy_package_join helper
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 471e8fd3afcef5a9f9089f0bd21965ad9ba35c91
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Tue Feb 6 18:31:06 2024 +0100

    net: phy: add devm/of_phy_package_join helper

    Add devm/of_phy_package_join helper to join PHYs in a PHY package. These
    are variant of the manual phy_package_join with the difference that
    these will use DT nodes to derive the base_addr instead of manually
    passing an hardcoded value.

    An additional value is added in phy_package_shared, "np" to reference
    the PHY package node pointer in specific PHY driver probe_once and
    config_init_once functions to make use of additional specific properties
    defined in the PHY package node in DT.

    The np value is filled only with of_phy_package_join if a valid PHY
    package node is found. A valid PHY package node must have the node name
    set to "ethernet-phy-package".

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:20 +02:00
Izabela Bakollari 1cdcf5b3a7 net: phy: c45 scanning: Don't consider -ENODEV fatal
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 17b447539408a0feff81637c7cc1c4c68efa73c0
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Sun Feb 4 17:14:14 2024 -0600

    net: phy: c45 scanning: Don't consider -ENODEV fatal

    When scanning the MDIO bus for C22 devices, the driver returning
    -ENODEV is not considered fatal, it just indicates the MDIO bus master
    knows there is no device at that address, maybe because of hardware
    limitation.

    Make the C45 scan code act on -ENODEV the same way, to make C22 and
    C45 more uniform.

    It is expected all reads for a given address will return -ENODEV, so
    within get_phy_c45_ids() only the first place a read occurs has been
    changed.

    Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:19 +02:00
Izabela Bakollari f350bd3a94 net: phy: add helper phy_advertise_eee_all
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit b64691274f5d33fc9d93af73483162967f7ec5bb
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Sat Feb 3 20:53:15 2024 +0100

    net: phy: add helper phy_advertise_eee_all

    Per default phylib preserves the EEE advertising at the time of
    phy probing. The EEE advertising can be changed from user space,
    in addition this helper allows to set the EEE advertising to all
    supported modes from drivers in kernel space.

    Suggested-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20bfc471-aeeb-4ae4-ba09-7d6d4be6b86a@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:19 +02:00
Izabela Bakollari f91305d385 net: phy: constify phydev->drv
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 0bd199fd9c19aa545f677fd0a99f2be101cb6309
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Feb 2 17:41:45 2024 +0000

    net: phy: constify phydev->drv

    Device driver structures are shared between all devices that they
    match, and thus nothing should never write to the device driver
    structure through the phydev->drv pointer. Let's make this pointer
    const to catch code that attempts to do so.

    Suggested-by: Christian Marangi <ansuelsmth@gmail.com>
    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Link: https://lore.kernel.org/r/E1rVxXt-002YqY-9G@rmk-PC.armlinux.org.uk
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:18 +02:00
Izabela Bakollari ceaf6b20db net: phy: phy_device: Prevent nullptr exceptions on ISR
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 61c81872815f46006982bb80460c0c80a949b35b
Author: Andre Werner <andre.werner@systec-electronic.com>
Date:   Mon Jan 29 14:55:04 2024 +0100

    net: phy: phy_device: Prevent nullptr exceptions on ISR

    If phydev->irq is set unconditionally, check
    for valid interrupt handler or fall back to polling mode to prevent
    nullptr exceptions in interrupt service routine.

    Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20240129135734.18975-2-andre.werner@systec-electronic.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:17 +02:00
Izabela Bakollari ddd31148ff net: phy: add support for PHY LEDs polarity modes
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 7ae215ee7bb855f13c80565470fc7f67db4ba82f
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Thu Jan 25 21:36:59 2024 +0100

    net: phy: add support for PHY LEDs polarity modes

    Add support for PHY LEDs polarity modes. Some PHY require LED to be set
    to active low to be turned ON. Adds support for this by declaring
    active-low property in DT.

    PHY driver needs to declare .led_polarity_set() to configure LED
    polarity modes. Function will pass the index with the LED index and a
    bitmap with all the required modes to set.

    Current supported modes are:
    - active-low with the flag PHY_LED_ACTIVE_LOW. LED is set to active-low
      to turn it ON.
    - inactive-high-impedance with the flag PHY_LED_INACTIVE_HIGH_IMPEDANCE.
      LED is set to high impedance to turn it OFF.

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20240125203702.4552-4-ansuelsmth@gmail.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:16 +02:00
Izabela Bakollari 906941b9af net: phy: extend PHY package API to support multiple global address
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 9eea577eb1155fe4a183bc5e7bf269b0b2e7a6ba
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Fri Dec 15 14:15:32 2023 +0100

    net: phy: extend PHY package API to support multiple global address

    Current API for PHY package are limited to single address to configure
    global settings for the PHY package.

    It was found that some PHY package (for example the qca807x, a PHY
    package that is shipped with a bundle of 5 PHY) requires multiple PHY
    address to configure global settings. An example scenario is a PHY that
    have a dedicated PHY for PSGMII/serdes calibrarion and have a specific
    PHY in the package where the global PHY mode is set and affects every
    other PHY in the package.

    Change the API in the following way:
    - Change phy_package_join() to take the base addr of the PHY package
      instead of the global PHY addr.
    - Make __/phy_package_write/read() require an additional arg that
      select what global PHY address to use by passing the offset from the
      base addr passed on phy_package_join().

    Each user of this API is updated to follow this new implementation
    following a pattern where an enum is defined to declare the offset of the
    addr.

    We also drop the check if shared is defined as any user of the
    phy_package_read/write is expected to use phy_package_join first. Misuse
    of this will correctly trigger a kernel panic for NULL pointer
    exception.

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:12 +02:00
Izabela Bakollari 59a7537634 net: phy: skip LED triggers on PHYs on SFP modules
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit b1dfc0f76231bbf395c59d20a2070684620d5d0f
Author: Daniel Golle <daniel@makrotopia.org>
Date:   Tue Dec 12 00:05:35 2023 +0000

    net: phy: skip LED triggers on PHYs on SFP modules

    Calling led_trigger_register() when attaching a PHY located on an SFP
    module potentially (and practically) leads into a deadlock.
    Fix this by not calling led_trigger_register() for PHYs localted on SFP
    modules as such modules actually never got any LEDs.

    ======================================================
    WARNING: possible circular locking dependency detected
    6.7.0-rc4-next-20231208+ #0 Tainted: G           O
    ------------------------------------------------------
    kworker/u8:2/43 is trying to acquire lock:
    ffffffc08108c4e8 (triggers_list_lock){++++}-{3:3}, at: led_trigger_register+0x4c/0x1a8

    but task is already holding lock:
    ffffff80c5c6f318 (&sfp->sm_mutex){+.+.}-{3:3}, at: cleanup_module+0x2ba8/0x3120 [sfp]

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #3 (&sfp->sm_mutex){+.+.}-{3:3}:
           __mutex_lock+0x88/0x7a0
           mutex_lock_nested+0x20/0x28
           cleanup_module+0x2ae0/0x3120 [sfp]
           sfp_register_bus+0x5c/0x9c
           sfp_register_socket+0x48/0xd4
           cleanup_module+0x271c/0x3120 [sfp]
           platform_probe+0x64/0xb8
           really_probe+0x17c/0x3c0
           __driver_probe_device+0x78/0x164
           driver_probe_device+0x3c/0xd4
           __driver_attach+0xec/0x1f0
           bus_for_each_dev+0x60/0xa0
           driver_attach+0x20/0x28
           bus_add_driver+0x108/0x208
           driver_register+0x5c/0x118
           __platform_driver_register+0x24/0x2c
           init_module+0x28/0xa7c [sfp]
           do_one_initcall+0x70/0x2ec
           do_init_module+0x54/0x1e4
           load_module+0x1b78/0x1c8c
           __do_sys_init_module+0x1bc/0x2cc
           __arm64_sys_init_module+0x18/0x20
           invoke_syscall.constprop.0+0x4c/0xdc
           do_el0_svc+0x3c/0xbc
           el0_svc+0x34/0x80
           el0t_64_sync_handler+0xf8/0x124
           el0t_64_sync+0x150/0x154

    -> #2 (rtnl_mutex){+.+.}-{3:3}:
           __mutex_lock+0x88/0x7a0
           mutex_lock_nested+0x20/0x28
           rtnl_lock+0x18/0x20
           set_device_name+0x30/0x130
           netdev_trig_activate+0x13c/0x1ac
           led_trigger_set+0x118/0x234
           led_trigger_write+0x104/0x17c
           sysfs_kf_bin_write+0x64/0x80
           kernfs_fop_write_iter+0x128/0x1b4
           vfs_write+0x178/0x2a4
           ksys_write+0x58/0xd4
           __arm64_sys_write+0x18/0x20
           invoke_syscall.constprop.0+0x4c/0xdc
           do_el0_svc+0x3c/0xbc
           el0_svc+0x34/0x80
           el0t_64_sync_handler+0xf8/0x124
           el0t_64_sync+0x150/0x154

    -> #1 (&led_cdev->trigger_lock){++++}-{3:3}:
           down_write+0x4c/0x13c
           led_trigger_write+0xf8/0x17c
           sysfs_kf_bin_write+0x64/0x80
           kernfs_fop_write_iter+0x128/0x1b4
           vfs_write+0x178/0x2a4
           ksys_write+0x58/0xd4
           __arm64_sys_write+0x18/0x20
           invoke_syscall.constprop.0+0x4c/0xdc
           do_el0_svc+0x3c/0xbc
           el0_svc+0x34/0x80
           el0t_64_sync_handler+0xf8/0x124
           el0t_64_sync+0x150/0x154

    -> #0 (triggers_list_lock){++++}-{3:3}:
           __lock_acquire+0x12a0/0x2014
           lock_acquire+0x100/0x2ac
           down_write+0x4c/0x13c
           led_trigger_register+0x4c/0x1a8
           phy_led_triggers_register+0x9c/0x214
           phy_attach_direct+0x154/0x36c
           phylink_attach_phy+0x30/0x60
           phylink_sfp_connect_phy+0x140/0x510
           sfp_add_phy+0x34/0x50
           init_module+0x15c/0xa7c [sfp]
           cleanup_module+0x1d94/0x3120 [sfp]
           cleanup_module+0x2bb4/0x3120 [sfp]
           process_one_work+0x1f8/0x4ec
           worker_thread+0x1e8/0x3d8
           kthread+0x104/0x110
           ret_from_fork+0x10/0x20

    other info that might help us debug this:

    Chain exists of:
      triggers_list_lock --> rtnl_mutex --> &sfp->sm_mutex

     Possible unsafe locking scenario:

           CPU0                    CPU1
           ----                    ----
      lock(&sfp->sm_mutex);
                                   lock(rtnl_mutex);
                                   lock(&sfp->sm_mutex);
      lock(triggers_list_lock);

     *** DEADLOCK ***

    4 locks held by kworker/u8:2/43:
     #0: ffffff80c000f938 ((wq_completion)events_power_efficient){+.+.}-{0:0}, at: process_one_work+0x150/0x4ec
     #1: ffffffc08214bde8 ((work_completion)(&(&sfp->timeout)->work)){+.+.}-{0:0}, at: process_one_work+0x150/0x4ec
     #2: ffffffc0810902f8 (rtnl_mutex){+.+.}-{3:3}, at: rtnl_lock+0x18/0x20
     #3: ffffff80c5c6f318 (&sfp->sm_mutex){+.+.}-{3:3}, at: cleanup_module+0x2ba8/0x3120 [sfp]

    stack backtrace:
    CPU: 0 PID: 43 Comm: kworker/u8:2 Tainted: G           O       6.7.0-rc4-next-20231208+ #0
    Hardware name: Bananapi BPI-R4 (DT)
    Workqueue: events_power_efficient cleanup_module [sfp]
    Call trace:
     dump_backtrace+0xa8/0x10c
     show_stack+0x14/0x1c
     dump_stack_lvl+0x5c/0xa0
     dump_stack+0x14/0x1c
     print_circular_bug+0x328/0x430
     check_noncircular+0x124/0x134
     __lock_acquire+0x12a0/0x2014
     lock_acquire+0x100/0x2ac
     down_write+0x4c/0x13c
     led_trigger_register+0x4c/0x1a8
     phy_led_triggers_register+0x9c/0x214
     phy_attach_direct+0x154/0x36c
     phylink_attach_phy+0x30/0x60
     phylink_sfp_connect_phy+0x140/0x510
     sfp_add_phy+0x34/0x50
     init_module+0x15c/0xa7c [sfp]
     cleanup_module+0x1d94/0x3120 [sfp]
     cleanup_module+0x2bb4/0x3120 [sfp]
     process_one_work+0x1f8/0x4ec
     worker_thread+0x1e8/0x3d8
     kthread+0x104/0x110
     ret_from_fork+0x10/0x20

    Signed-off-by: Daniel Golle <daniel@makrotopia.org>
    Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
    Link: https://lore.kernel.org/r/102a9dce38bdf00215735d04cd4704458273ad9c.1702339354.git.daniel@makrotopia.org
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:12 +02:00
Izabela Bakollari 80c65f97b2 net: phy: add possible interfaces
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 243ad8df7a1bd24c2e01bd99d9f0bb88844dae91
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Nov 24 12:27:52 2023 +0000

    net: phy: add possible interfaces

    Add a possible_interfaces member to struct phy_device to indicate which
    interfaces a clause 45 PHY may switch between depending on the media.
    This must be populated by the PHY driver by the time the .config_init()
    method completes according to the PHYs host-side configuration.

    For example, the Marvell 88x3310 PHY can switch between 10GBASE-R,
    5GBASE-R, 2500BASE-X, and SGMII on the host side depending on the media
    side speed, so all these interface modes are set in the
    possible_interfaces member.

    This allows phylib users (such as phylink) to know in advance which
    interface modes to expect, which allows them to appropriately restrict
    the advertised link modes according to the capabilities of other parts
    of the link.

    Tested-by: Luo Jie <quic_luoj@quicinc.com>
    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/E1r6VHk-00DDLN-I7@rmk-PC.armlinux.org.uk
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:07 +02:00
Izabela Bakollari a0083e9dc7 net: phy: correctly check soft_reset ret ONLY if defined for PHY
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit aadbd27f9674d7f5457331fe0248b370d5c1f25d
Author: Christian Marangi <ansuelsmth@gmail.com>
Date:   Tue Nov 21 14:53:32 2023 +0100

    net: phy: correctly check soft_reset ret ONLY if defined for PHY

    Introduced by commit 6e2d85ec05 ("net: phy: Stop with excessive soft
    reset").

    soft_reset call for phy_init_hw had multiple revision across the years
    and the implementation goes back to 2014. Originally was a simple call
    to write the generic PHY reset BIT, it was then moved to a dedicated
    function. It was then added the option for PHY driver to define their
    own special way to reset the PHY. Till this change, checking for ret was
    correct as it was always filled by either the generic reset or the
    custom implementation. This changed tho with commit 6e2d85ec05 ("net:
    phy: Stop with excessive soft reset"), as the generic reset call to PHY
    was dropped but the ret check was never made entirely optional and
    dependent whether soft_reset was defined for the PHY driver or not.

    Luckly nothing was ever added before the soft_reset call so the ret
    check (in the case where a PHY didn't had soft_reset defined) although
    wrong, never caused problems as ret was init 0 at the start of
    phy_init_hw.

    To prevent any kind of problem and to make the function cleaner and more
    robust, correctly move the ret check if the soft_reset section making it
    optional and needed only with the function defined.

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com>
    Reviewed-by: Simon Horman <horms@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 22:56:07 +02:00
Izabela Bakollari cae14db229 net: phy: phy_device: Call into the PHY driver to set LED offload
JIRA: https://issues.redhat.com/browse/RHEL-33716

commit 1dcc03c9a7a824a31eaaecdfaa03542fb25feb6c
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Tue Aug 8 23:04:34 2023 +0200

    net: phy: phy_device: Call into the PHY driver to set LED offload

    Linux LEDs can be requested to perform hardware accelerated blinking
    to indicate link, RX, TX etc. Pass the rules for blinking to the PHY
    driver, if it implements the ops needed to determine if a given
    pattern can be offloaded, to offload it, and what the current offload
    is. Additionally implement the op needed to get what device the LED is
    for.

    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Tested-by: Daniel Golle <daniel@makrotopia.org>
    Link: https://lore.kernel.org/r/20230808210436.838995-3-andrew@lunn.ch
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-08-09 15:39:28 +02:00
Scott Weaver 758a7fae9f Merge: net: phy: mdio_device: Reset device only when necessary
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3613

JIRA: https://issues.redhat.com/browse/RHEL-21837

Backport a change to optimize the usage of the mdio_device reset. This saves
(2 * deassert time) to get the ethernet phy up. For sa8775p-ride, this saves at least
140 ms (out of the 2 second budget customer requirements mandate) to get ethernet up.

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>

Approved-by: Eric Chanudet <echanude@redhat.com>
Approved-by: Michal Schmidt <mschmidt@redhat.com>

Signed-off-by: Scott Weaver <scweaver@redhat.com>
2024-01-30 12:49:21 -05:00
Andrew Halaney c896598cd9 net: phy: mdio_device: Reset device only when necessary
JIRA: https://issues.redhat.com/browse/RHEL-21837

commit df16c1c51d8166958f533c0c886766f7ee9dd50f
Author: Andrew Halaney <ahalaney@redhat.com>
Date:   Mon Nov 27 15:41:10 2023 -0600

    net: phy: mdio_device: Reset device only when necessary

    Currently the phy reset sequence is as shown below for a
    devicetree described mdio phy on boot:

    1. Assert the phy_device's reset as part of registering
    2. Deassert the phy_device's reset as part of registering
    3. Deassert the phy_device's reset as part of phy_probe
    4. Deassert the phy_device's reset as part of phy_hw_init

    The extra two deasserts include waiting the deassert delay afterwards,
    which is adding unnecessary delay.

    This applies to both possible types of resets (reset controller
    reference and a reset gpio) that can be used.

    Here's some snipped tracing output using the following command line
    params "trace_event=gpio:* trace_options=stacktrace" illustrating
    the reset handling and where its coming from:

        /* Assert */
           systemd-udevd-283     [002] .....     6.780434: gpio_value: 544 set 0
           systemd-udevd-283     [002] .....     6.783849: <stack trace>
         => gpiod_set_raw_value_commit
         => gpiod_set_value_nocheck
         => gpiod_set_value_cansleep
         => mdio_device_reset
         => mdiobus_register_device
         => phy_device_register
         => fwnode_mdiobus_phy_device_register
         => fwnode_mdiobus_register_phy
         => __of_mdiobus_register
         => stmmac_mdio_register
         => stmmac_dvr_probe
         => stmmac_pltfr_probe
         => devm_stmmac_pltfr_probe
         => qcom_ethqos_probe
         => platform_probe

        /* Deassert */
           systemd-udevd-283     [002] .....     6.802480: gpio_value: 544 set 1
           systemd-udevd-283     [002] .....     6.805886: <stack trace>
         => gpiod_set_raw_value_commit
         => gpiod_set_value_nocheck
         => gpiod_set_value_cansleep
         => mdio_device_reset
         => phy_device_register
         => fwnode_mdiobus_phy_device_register
         => fwnode_mdiobus_register_phy
         => __of_mdiobus_register
         => stmmac_mdio_register
         => stmmac_dvr_probe
         => stmmac_pltfr_probe
         => devm_stmmac_pltfr_probe
         => qcom_ethqos_probe
         => platform_probe

        /* Deassert */
           systemd-udevd-283     [002] .....     6.882601: gpio_value: 544 set 1
           systemd-udevd-283     [002] .....     6.886014: <stack trace>
         => gpiod_set_raw_value_commit
         => gpiod_set_value_nocheck
         => gpiod_set_value_cansleep
         => mdio_device_reset
         => phy_probe
         => really_probe
         => __driver_probe_device
         => driver_probe_device
         => __device_attach_driver
         => bus_for_each_drv
         => __device_attach
         => device_initial_probe
         => bus_probe_device
         => device_add
         => phy_device_register
         => fwnode_mdiobus_phy_device_register
         => fwnode_mdiobus_register_phy
         => __of_mdiobus_register
         => stmmac_mdio_register
         => stmmac_dvr_probe
         => stmmac_pltfr_probe
         => devm_stmmac_pltfr_probe
         => qcom_ethqos_probe
         => platform_probe

        /* Deassert */
          NetworkManager-477     [000] .....     7.023144: gpio_value: 544 set 1
          NetworkManager-477     [000] .....     7.026596: <stack trace>
         => gpiod_set_raw_value_commit
         => gpiod_set_value_nocheck
         => gpiod_set_value_cansleep
         => mdio_device_reset
         => phy_init_hw
         => phy_attach_direct
         => phylink_fwnode_phy_connect
         => __stmmac_open
         => stmmac_open

    There's a lot of paths where the device is getting its reset
    asserted and deasserted. Let's track the state and only actually
    do the assert/deassert when it changes.

    Reported-by: Sagar Cheluvegowda <quic_scheluve@quicinc.com>
    Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20231127-net-phy-reset-once-v2-1-448e8658779e@redhat.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-01-17 15:32:53 -06:00
Izabela Bakollari 958ede7c3c net: phy: move marking PHY on SFP module into SFP code
JIRA: https://issues.redhat.com/browse/RHEL-946

commit f4bf467883f210d0bfbe784fffca52887de147fb
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Thu Aug 3 16:56:24 2023 +0100

    net: phy: move marking PHY on SFP module into SFP code

    Move marking the PHY as being on a SFP module into the SFP code between
    getting the PHY device (and thus initialising the phy_device structure)
    and registering the discovered device.

    This means that PHY drivers can use phy_on_sfp() in their match and
    get_features methods.

    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Link: https://lore.kernel.org/r/E1qRaga-001vKt-8X@rmk-PC.armlinux.org.uk
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-01-09 11:58:39 +01:00
Izabela Bakollari aceff71adf net: phy: provide phylib stubs for hardware timestamping operations
JIRA: https://issues.redhat.com/browse/RHEL-946

commit 60495b6622ca67f5180343b89bd932d28d23f63a
Author: Vladimir Oltean <vladimir.oltean@nxp.com>
Date:   Tue Aug 1 17:28:23 2023 +0300

    net: phy: provide phylib stubs for hardware timestamping operations

    net/core/dev_ioctl.c (built-in code) will want to call phy_mii_ioctl()
    for hardware timestamping purposes. This is not directly possible,
    because phy_mii_ioctl() is a symbol provided under CONFIG_PHYLIB.

    Do something similar to what was done in DSA in commit 5a17818682cf
    ("net: dsa: replace NETDEV_PRE_CHANGE_HWTSTAMP notifier with a stub"),
    and arrange some indirect calls to phy_mii_ioctl() through a stub
    structure containing function pointers, that's provided by phylib as
    built-in even when CONFIG_PHYLIB=m, and which phy_init() populates at
    runtime (module insertion).

    Note: maybe the ownership of the ethtool_phy_ops singleton is backwards,
    and the methods exposed by that should be later merged into phylib_stubs.

    Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Link: https://lore.kernel.org/r/20230801142824.1772134-12-vladimir.oltean@nxp.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-01-09 11:58:39 +01:00
Izabela Bakollari edb726666b net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller
JIRA: https://issues.redhat.com/browse/RHEL-946

commit 70ef7d87f62a86674c21a99341dabc175c19681a
Author: Vladimir Oltean <vladimir.oltean@nxp.com>
Date:   Tue Aug 1 17:28:22 2023 +0300

    net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller

    phy_init() and phy_exit() will have to do more stuff under rtnl_lock()
    in a future change. Since rtnl_unlock() -> netdev_run_todo() does a lot
    of stuff under the hood, it's a pity to lock and unlock the rtnetlink
    mutex twice in a row.

    Change the calling convention such that the only caller of
    ethtool_set_ethtool_phy_ops(), phy_device.c, provides a context where
    the rtnl_mutex is already acquired.

    Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Link: https://lore.kernel.org/r/20230801142824.1772134-11-vladimir.oltean@nxp.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
2024-01-09 11:58:39 +01:00
Adrien Thierry 8db6d7e1e8 net: phy: fix IRQ-based wake-on-lan over hibernate / power off
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit cc941e548bffc01b5816b4edc5cb432a137a58b3
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Aug 11 11:26:30 2023 +0100

    net: phy: fix IRQ-based wake-on-lan over hibernate / power off

    Uwe reports:
    "Most PHYs signal WoL using an interrupt. So disabling interrupts [at
    shutdown] breaks WoL at least on PHYs covered by the marvell driver."

    Discussing with Ioana, the problem which was trying to be solved was:
    "The board in question is a LS1021ATSN which has two AR8031 PHYs that
    share an interrupt line. In case only one of the PHYs is probed and
    there are pending interrupts on the PHY#2 an IRQ storm will happen
    since there is no entity to clear the interrupt from PHY#2's registers.
    PHY#1's driver will get stuck in .handle_interrupt() indefinitely."

    Further confirmation that "the two AR8031 PHYs are on the same MDIO
    bus."

    With WoL using interrupts to wake the system, in such a case, the
    system will begin booting with an asserted interrupt. Thus, we need to
    cope with an interrupt asserted during boot.

    Solve this instead by disabling interrupts during PHY probe. This will
    ensure in Ioana's situation that both PHYs of the same type sharing an
    interrupt line on a common MDIO bus will have their interrupt outputs
    disabled when the driver probes the device, but before we hook in any
    interrupt handlers - thus avoiding the interrupt storm.

    A better fix would be for platform firmware to disable the interrupting
    devices at source during boot, before control is handed to the kernel.

    Fixes: e2f016cf77 ("net: phy: add a shutdown procedure")
    Link: 20230804071757.383971-1-u.kleine-koenig@pengutronix.de
    Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:25:29 -04:00
Adrien Thierry bc4027110b net: phy: prevent stale pointer dereference in phy_init()
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 1c613beaf877c0c0d755853dc62687e2013e55c4
Author: Vladimir Oltean <vladimir.oltean@nxp.com>
Date:   Thu Jul 20 03:02:31 2023 +0300

    net: phy: prevent stale pointer dereference in phy_init()

    mdio_bus_init() and phy_driver_register() both have error paths, and if
    those are ever hit, ethtool will have a stale pointer to the
    phy_ethtool_phy_ops stub structure, which references memory from a
    module that failed to load (phylib).

    It is probably hard to force an error in this code path even manually,
    but the error teardown path of phy_init() should be the same as
    phy_exit(), which is now simply not the case.

    Fixes: 55d8f053ce ("net: phy: Register ethtool PHY operations")
    Link: https://lore.kernel.org/netdev/ZLaiJ4G6TaJYGJyU@shell.armlinux.org.uk/
    Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
    Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Link: https://lore.kernel.org/r/20230720000231.1939689-1-vladimir.oltean@nxp.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:25:29 -04:00
Adrien Thierry e9ab3ad139 net: phy: Manual remove LEDs to ensure correct ordering
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit c938ab4da0eb1620ae3243b0b24c572ddfc318fc
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Sat Jun 17 17:55:00 2023 +0200

    net: phy: Manual remove LEDs to ensure correct ordering

    If the core is left to remove the LEDs via devm_, it is performed too
    late, after the PHY driver is removed from the PHY. This results in
    dereferencing a NULL pointer when the LED core tries to turn the LED
    off before destroying the LED.

    Manually unregister the LEDs at a safe point in phy_remove.

    Cc: stable@vger.kernel.org
    Reported-by: Florian Fainelli <f.fainelli@gmail.com>
    Suggested-by: Florian Fainelli <f.fainelli@gmail.com>
    Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:21 -04:00
Adrien Thierry 44f461ca37 net: phy: add helpers for comparing phy IDs
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 4b159f5048b90844679dad08afb3240c1957aba1
Author: Russell King <rmk+kernel@armlinux.org.uk>
Date:   Fri May 19 14:03:59 2023 +0100

    net: phy: add helpers for comparing phy IDs

    There are several places which open code comparing PHY IDs. Provide a
    couple of helpers to assist with this, using a slightly simpler test
    than the original:

    - phy_id_compare() compares two arbitary PHY IDs and a mask of the
      significant bits in the ID.
    - phydev_id_compare() compares the bound phydev with the specified
      PHY ID, using the bound driver's mask.

    Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:18 -04:00
Adrien Thierry aa75b787c3 net: phy: Allow drivers to always call into ->suspend()
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit a7e3448086d580abadccff399316c6eb5ecdedbf
Author: Florian Fainelli <f.fainelli@gmail.com>
Date:   Thu May 11 10:21:08 2023 -0700

    net: phy: Allow drivers to always call into ->suspend()

    A few PHY drivers are currently attempting to not suspend the PHY when
    Wake-on-LAN is enabled, however that code is not currently executing at
    all due to an early check in phy_suspend().

    This prevents PHY drivers from making an appropriate decisions and put
    the hardware into a low power state if desired.

    In order to allow the PHY drivers to opt into getting their ->suspend
    routine to be called, add a PHY_ALWAYS_CALL_SUSPEND bit which can be
    set. A boolean that tracks whether the PHY or the attached MAC has
    Wake-on-LAN enabled is also provided for convenience.

    If phydev::wol_enabled then the PHY shall not prevent its own
    Wake-on-LAN detection logic from working and shall not prevent the
    Ethernet MAC from receiving packets for matching.

    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:17 -04:00
Adrien Thierry 2ec6df1d4c net: phy: Fix reading LED reg property
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit aed8fdad2152d946add50bec00a6b07c457bdcdf
Author: Alexander Stein <alexander.stein@ew.tq-group.com>
Date:   Mon Apr 24 16:16:48 2023 +0200

    net: phy: Fix reading LED reg property

    'reg' is always encoded in 32 bits, thus it has to be read using the
    function with the corresponding bit width.

    Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
    Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Link: https://lore.kernel.org/r/20230424141648.317944-1-alexander.stein@ew.tq-group.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:16 -04:00
Adrien Thierry 265ebcb6b6 net: phy: fix circular LEDS_CLASS dependencies
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 4bb7aac70b5d8a4bddf4ee0791b834f9f56883d2
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Thu Apr 20 10:45:51 2023 +0200

    net: phy: fix circular LEDS_CLASS dependencies

    The CONFIG_PHYLIB symbol is selected by a number of device drivers that
    need PHY support, but it now has a dependency on CONFIG_LEDS_CLASS,
    which may not be enabled, causing build failures.

    Avoid the risk of missing and circular dependencies by guarding the
    phylib LED support itself in another Kconfig symbol that can only be
    enabled if the dependency is met.

    This could be made a hidden symbol and always enabled when both CONFIG_OF
    and CONFIG_LEDS_CLASS are reachable from the phylib, but there may be an
    advantage in having users see this option when they have a misconfigured
    kernel without built-in LED support.

    Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20230420084624.3005701-1-arnd@kernel.org
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:16 -04:00
Adrien Thierry 7880254feb net: phy: phy_device: Call into the PHY driver to set LED blinking
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 4e901018432e38eab35d2a352661ce4727795be1
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Mon Apr 17 17:17:30 2023 +0200

    net: phy: phy_device: Call into the PHY driver to set LED blinking

    Linux LEDs can be requested to perform hardware accelerated
    blinking. Pass this to the PHY driver, if it implements the op.

    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:15 -04:00
Adrien Thierry 9c3f5e2b45 net: phy: phy_device: Call into the PHY driver to set LED brightness
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 684818189b04b095b34964ed4a3ea5249a840eab
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Mon Apr 17 17:17:28 2023 +0200

    net: phy: phy_device: Call into the PHY driver to set LED brightness

    Linux LEDs can be software controlled via the brightness file in /sys.
    LED drivers need to implement a brightness_set function which the core
    will call. Implement an intermediary in phy_device, which will call
    into the phy driver if it implements the necessary function.

    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:15 -04:00
Adrien Thierry fa750901c9 net: phy: Add a binding for PHY LEDs
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 01e5b728e9e43ae444e0369695a5f72209906464
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Mon Apr 17 17:17:27 2023 +0200

    net: phy: Add a binding for PHY LEDs

    Define common binding parsing for all PHY drivers with LEDs using
    phylib. Parse the DT as part of the phy_probe and add LEDs to the
    linux LED class infrastructure. For the moment, provide a dummy
    brightness function, which will later be replaced with a call into the
    PHY driver. This allows testing since the LED core might otherwise
    reject an LED whose brightness cannot be set.

    Add a dependency on LED_CLASS. It either needs to be built in, or not
    enabled, since a modular build can result in linker errors.

    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:15 -04:00
Adrien Thierry ead070abf6 net: phy: constify fwnode_get_phy_node() fwnode argument
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 4a0faa02d419a6728abef0f1d8a32d8c35ef95e6
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Mar 24 09:23:53 2023 +0000

    net: phy: constify fwnode_get_phy_node() fwnode argument

    fwnode_get_phy_node() does not motify the fwnode structure, so make
    the argument const,

    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:13 -04:00
Adrien Thierry daa663b063 net: phy: update obsolete comment about PHY_STARTING
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 83456576a42050cc0675aece14277a3cbdee9cbe
Author: Wolfram Sang <wsa+renesas@sang-engineering.com>
Date:   Tue Mar 14 13:48:56 2023 +0100

    net: phy: update obsolete comment about PHY_STARTING

    Commit 899a3cbbf7 ("net: phy: remove states PHY_STARTING and
    PHY_PENDING") missed to update a comment in phy_probe. Remove
    superfluous "Description:" prefix while we are here.

    Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
    Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>
    Link: https://lore.kernel.org/r/20230314124856.44878-1-wsa+renesas@sang-engineering.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:11 -04:00
Adrien Thierry 7c43ffc09c net: phylib: get rid of unnecessary locking
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit f4b47a2e9463950df3e7c8b70e017877c1d4eb11
Author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Date:   Fri Mar 3 16:37:54 2023 +0000

    net: phylib: get rid of unnecessary locking

    The locking in phy_probe() and phy_remove() does very little to prevent
    any races with e.g. phy_attach_direct(), but instead causes lockdep ABBA
    warnings. Remove it.

    ======================================================
    WARNING: possible circular locking dependency detected
    6.2.0-dirty #1108 Tainted: G        W   E
    ------------------------------------------------------
    ip/415 is trying to acquire lock:
    ffff5c268f81ef50 (&dev->lock){+.+.}-{3:3}, at: phy_attach_direct+0x17c/0x3a0 [libphy]

    but task is already holding lock:
    ffffaef6496cb518 (rtnl_mutex){+.+.}-{3:3}, at: rtnetlink_rcv_msg+0x154/0x560

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (rtnl_mutex){+.+.}-{3:3}:
           __lock_acquire+0x35c/0x6c0
           lock_acquire.part.0+0xcc/0x220
           lock_acquire+0x68/0x84
           __mutex_lock+0x8c/0x414
           mutex_lock_nested+0x34/0x40
           rtnl_lock+0x24/0x30
           sfp_bus_add_upstream+0x34/0x150
           phy_sfp_probe+0x4c/0x94 [libphy]
           mv3310_probe+0x148/0x184 [marvell10g]
           phy_probe+0x8c/0x200 [libphy]
           call_driver_probe+0xbc/0x15c
           really_probe+0xc0/0x320
           __driver_probe_device+0x84/0x120
           driver_probe_device+0x44/0x120
           __device_attach_driver+0xc4/0x160
           bus_for_each_drv+0x80/0xe0
           __device_attach+0xb0/0x1f0
           device_initial_probe+0x1c/0x2c
           bus_probe_device+0xa4/0xb0
           device_add+0x360/0x53c
           phy_device_register+0x60/0xa4 [libphy]
           fwnode_mdiobus_phy_device_register+0xc0/0x190 [fwnode_mdio]
           fwnode_mdiobus_register_phy+0x160/0xd80 [fwnode_mdio]
           of_mdiobus_register+0x140/0x340 [of_mdio]
           orion_mdio_probe+0x298/0x3c0 [mvmdio]
           platform_probe+0x70/0xe0
           call_driver_probe+0x34/0x15c
           really_probe+0xc0/0x320
           __driver_probe_device+0x84/0x120
           driver_probe_device+0x44/0x120
           __driver_attach+0x104/0x210
           bus_for_each_dev+0x78/0xdc
           driver_attach+0x2c/0x3c
           bus_add_driver+0x184/0x240
           driver_register+0x80/0x13c
           __platform_driver_register+0x30/0x3c
           xt_compat_calc_jump+0x28/0xa4 [x_tables]
           do_one_initcall+0x50/0x1b0
           do_init_module+0x50/0x1fc
           load_module+0x684/0x744
           __do_sys_finit_module+0xc4/0x140
           __arm64_sys_finit_module+0x28/0x34
           invoke_syscall+0x50/0x120
           el0_svc_common.constprop.0+0x6c/0x1b0
           do_el0_svc+0x34/0x44
           el0_svc+0x48/0xf0
           el0t_64_sync_handler+0xb8/0xc0
           el0t_64_sync+0x1a0/0x1a4

    -> #0 (&dev->lock){+.+.}-{3:3}:
           check_prev_add+0xb4/0xc80
           validate_chain+0x414/0x47c
           __lock_acquire+0x35c/0x6c0
           lock_acquire.part.0+0xcc/0x220
           lock_acquire+0x68/0x84
           __mutex_lock+0x8c/0x414
           mutex_lock_nested+0x34/0x40
           phy_attach_direct+0x17c/0x3a0 [libphy]
           phylink_fwnode_phy_connect.part.0+0x70/0xe4 [phylink]
           phylink_fwnode_phy_connect+0x48/0x60 [phylink]
           mvpp2_open+0xec/0x2e0 [mvpp2]
           __dev_open+0x104/0x214
           __dev_change_flags+0x1d4/0x254
           dev_change_flags+0x2c/0x7c
           do_setlink+0x254/0xa50
           __rtnl_newlink+0x430/0x514
           rtnl_newlink+0x58/0x8c
           rtnetlink_rcv_msg+0x17c/0x560
           netlink_rcv_skb+0x64/0x150
           rtnetlink_rcv+0x20/0x30
           netlink_unicast+0x1d4/0x2b4
           netlink_sendmsg+0x1a4/0x400
           ____sys_sendmsg+0x228/0x290
           ___sys_sendmsg+0x88/0xec
           __sys_sendmsg+0x70/0xd0
           __arm64_sys_sendmsg+0x2c/0x40
           invoke_syscall+0x50/0x120
           el0_svc_common.constprop.0+0x6c/0x1b0
           do_el0_svc+0x34/0x44
           el0_svc+0x48/0xf0
           el0t_64_sync_handler+0xb8/0xc0
           el0t_64_sync+0x1a0/0x1a4

    other info that might help us debug this:

     Possible unsafe locking scenario:

           CPU0                    CPU1
           ----                    ----
      lock(rtnl_mutex);
                                   lock(&dev->lock);
                                   lock(rtnl_mutex);
      lock(&dev->lock);

     *** DEADLOCK ***

    Fixes: 298e54fa81 ("net: phy: add core phylib sfp support")
    Reported-by: Marc Zyngier <maz@kernel.org>
    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Adrien Thierry fa4a5c5942 net: phy: unlock on error in phy_probe()
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 8f9850dd8d23c1290cb642ce9548a440da5771ec
Author: Dan Carpenter <error27@gmail.com>
Date:   Mon Feb 27 13:03:22 2023 +0300

    net: phy: unlock on error in phy_probe()

    If genphy_c45_read_eee_adv() fails then we need to do a reset and unlock
    the &phydev->lock mutex before returning.

    Fixes: 3eeca4e199ce ("net: phy: do not force EEE support")
    Signed-off-by: Dan Carpenter <error27@gmail.com>
    Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Link: https://lore.kernel.org/r/Y/x/6kHCjnQHqOpF@kili
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Adrien Thierry 6d944b8ef7 net: phy: do not force EEE support
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 3eeca4e199cee2066c65b872391cecee5cbbbb81
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Wed Feb 22 06:50:42 2023 +0100

    net: phy: do not force EEE support

    With following patches:
    commit 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
    commit 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")

    we set the advertisement to potentially supported values. This behavior
    may introduce new regressions on systems where EEE was disabled by
    default (BIOS or boot loader configuration or by other ways.)

    At same time, with this patches, we would overwrite EEE advertisement
    configuration made over ethtool.

    To avoid this issues, we need to cache initial and ethtool advertisement
    configuration and store it for later use.

    Fixes: 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
    Fixes: 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")
    Fixes: 022c3f87f88e ("net: phy: add genphy_c45_ethtool_get/set_eee() support")
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Adrien Thierry 06bc20d02e net: phy: c45: add genphy_c45_an_config_eee_aneg() function
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit b6478b8c93304fa0483e4657779b44634a1711c7
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Wed Feb 22 06:50:41 2023 +0100

    net: phy: c45: add genphy_c45_an_config_eee_aneg() function

    Add new genphy_c45_an_config_eee_aneg() function and replace some of
    genphy_c45_write_eee_adv() calls. This will be needed by the next patch.

    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Adrien Thierry cb41478a36 net: phy: Read EEE abilities when using .features
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit c2a978c171a6d44d4d9710e7e4455f75d34aecee
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Fri Feb 17 04:15:20 2023 +0100

    net: phy: Read EEE abilities when using .features

    A PHY driver can use a static integer value to indicate what link mode
    features it supports, i.e, its abilities.. This is the old way, but
    useful when dynamically determining the devices features does not
    work, e.g. support of fibre.

    EEE support has been moved into phydev->supported_eee. This needs to
    be set otherwise the code assumes EEE is not supported. It is normally
    set as part of reading the devices abilities. However if a static
    integer value was used, the dynamic reading of the abilities is not
    performed. Add a call to genphy_c45_read_eee_abilities() to read the
    EEE abilities.

    Fixes: 8b68710a3121 ("net: phy: start using genphy_c45_ethtool_get/set_eee()")
    Signed-off-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:09 -04:00
Adrien Thierry 6153d161d6 net: phy: c22: migrate to genphy_c45_write_eee_adv()
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 9b01c885be364526d8c05794f8358b3e563b7ff8
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Sat Feb 11 08:41:10 2023 +0100

    net: phy: c22: migrate to genphy_c45_write_eee_adv()

    Migrate from genphy_config_eee_advert() to genphy_c45_write_eee_adv().

    It should work as before except write operation to the EEE adv registers
    will be done only if some EEE abilities was detected.

    If some driver will have a regression, related driver should provide own
    .get_features callback. See micrel.c:ksz9477_get_features() as example.

    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:08 -04:00
Adrien Thierry f167baeee2 net: phy: add genphy_c45_read_eee_abilities() function
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 14e47d1fb8f9596acc90a06a66808657a9c512b5
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Sat Feb 11 08:41:06 2023 +0100

    net: phy: add genphy_c45_read_eee_abilities() function

    Add generic function for EEE abilities defined by IEEE 802.3
    specification. For now following registers are supported:
    - IEEE 802.3-2018 45.2.3.10 EEE control and capability 1 (Register 3.20)
    - IEEE 802.3cg-2019 45.2.1.186b 10BASE-T1L PMA status register
      (Register 1.2295)

    Since I was not able to find any flag signaling support of these
    registers, we should detect link mode abilities first and then based on
    these abilities doing EEE link modes detection.

    Results of EEE ability detection will be stored into new variable
    phydev->supported_eee.

    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:08 -04:00
Adrien Thierry d569fd9855 net: phy: fix null dereference in phy_attach_direct
JIRA: https://issues.redhat.com/browse/RHEL-2799

commit 73a876022273cbc9c1db7869a54444ce8b9d085e
Author: Colin Foster <colin.foster@in-advantage.com>
Date:   Fri Jan 27 09:14:27 2023 -0800

    net: phy: fix null dereference in phy_attach_direct

    Commit bc66fa87d4fd ("net: phy: Add link between phy dev and mac dev")
    introduced a link between net devices and phy devices. It fails to check
    whether dev is NULL, leading to a NULL dereference error.

    Fixes: bc66fa87d4fd ("net: phy: Add link between phy dev and mac dev")
    Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Adrien Thierry <athierry@redhat.com>
2023-09-19 14:18:06 -04:00