* [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE
@ 2026-12-01 7:21 Joseph Telaak
2026-12-01 7:21 ` [PATCH iwl-next 1/4] dt-bindings: net: add " Joseph Telaak
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Joseph Telaak @ 2026-12-01 7:21 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Russell King
Cc: intel-wired-lan, netdev, devicetree, linux-kernel, Joseph Telaak
The GbE of the Intel CE4100 family (PCI 8086:2e6e) has an RGMII interface
and its own MDIO controller. e1000 only handles a PHY it drives itself,
so a MAC wired straight to a switch port fails to probe, and a PHY on the
bus never gets its own driver.
This series lets the device tree describe the link. Patch 1 documents
the node, patch 2 hands a fixed link to phylink, patch 3 attaches a PHY
on the MAC's MDIO bus through phylink, and patch 4 disables EEE, which
the MAC cannot do. Without these properties nothing changes at run time;
E1000 now selects PHYLINK.
Tested on two CE5300 boards, on a backport to 7.3: one with an RTL8211E
(1G and 100M, MTU changes, ifdown/ifup, VLAN filter and offload changes,
pause, autoneg restart, PHY LEDs offloaded to the netdev trigger), and
one wired to a BCM53125 switch with a fixed link (1G through the switch,
STP). Both also ran with lockdep and CONFIG_DEBUG_ATOMIC_SLEEP, without
warnings. Suspend/resume and PCI error recovery were not tested; with
Wake-on-LAN enabled only by the EEPROM default, phylink does not keep
the link up across suspend.
---
Joseph Telaak (4):
dt-bindings: net: add the Intel CE4100 GbE
e1000: use phylink for a CE4100 fixed link
e1000: attach a CE4100 PHY through phylink
e1000: disable EEE on a CE4100 PHY under phylink
.../devicetree/bindings/net/intel,ce4100-gbe.yaml | 90 ++++++
MAINTAINERS | 1 +
drivers/net/ethernet/intel/Kconfig | 1 +
drivers/net/ethernet/intel/e1000/e1000.h | 8 +
drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 36 +++
drivers/net/ethernet/intel/e1000/e1000_hw.c | 135 ++++++++-
drivers/net/ethernet/intel/e1000/e1000_hw.h | 7 +
drivers/net/ethernet/intel/e1000/e1000_main.c | 325 ++++++++++++++++++++-
8 files changed, 591 insertions(+), 12 deletions(-)
---
base-commit: eacacbbea61ffb13e053f9dca732f007b924ef8a
change-id: 20261116-e1000-phylink-9d5ccc98baf9
Best regards,
--
Joseph Telaak <joseph@telaak.dev>
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH iwl-next 1/4] dt-bindings: net: add the Intel CE4100 GbE 2026-12-01 7:21 [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak @ 2026-12-01 7:21 ` Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link Joseph Telaak ` (2 subsequent siblings) 3 siblings, 0 replies; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 7:21 UTC (permalink / raw) To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel, Joseph Telaak The Gigabit Ethernet MAC of the Intel CE4100 family (CE4100, CE4200, CE5300) is a PCI function, 8086:2e6e, driven by e1000. It has an RGMII interface and its own MDIO controller. Boards put a PHY on that bus or wire the MAC straight to a switch port, which the device tree describes on the PCI device's node with phy-mode and a phy-handle with an mdio node, or a fixed-link. Document the node so those properties have a schema. The existing falconfalls CE4100 tree lists the full PCI bus binding set in compatible ("pci8086,2e6e.2", "pci8086,2e6e", "pciclass020000", "pciclass0200"); only the vendor/device form is documented here, and its IOAPIC interrupts do not fit the INTx pin pci-device.yaml allows either. Signed-off-by: Joseph Telaak <joseph@telaak.dev> --- .../devicetree/bindings/net/intel,ce4100-gbe.yaml | 90 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 91 insertions(+) diff --git a/Documentation/devicetree/bindings/net/intel,ce4100-gbe.yaml b/Documentation/devicetree/bindings/net/intel,ce4100-gbe.yaml new file mode 100644 index 000000000000..98b56e9bb516 --- /dev/null +++ b/Documentation/devicetree/bindings/net/intel,ce4100-gbe.yaml @@ -0,0 +1,90 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/intel,ce4100-gbe.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Intel CE4100 family Gigabit Ethernet MAC + +maintainers: + - Joseph Telaak <joseph@telaak.dev> + +description: + The Gigabit Ethernet MAC built into the Intel CE4100 family of media SoCs + (CE4100, CE4200, CE5300), a PCI function on the SoC's internal bus. It has + an RGMII interface and its own MDIO controller. A board either puts a PHY + on that MDIO bus or wires the MAC straight to a switch port. + +allOf: + - $ref: /schemas/pci/pci-device.yaml# + - $ref: ethernet-controller.yaml# + +properties: + compatible: + const: pci8086,2e6e + + reg: + maxItems: 1 + + phy-mode: + enum: + - rgmii + - rgmii-id + - rgmii-rxid + - rgmii-txid + + managed: false + + mdio: + $ref: mdio.yaml# + unevaluatedProperties: false + +required: + - compatible + - reg + +dependencies: + fixed-link: [ phy-mode ] + phy-handle: [ phy-mode, mdio ] + mdio: [ phy-handle ] + +unevaluatedProperties: false + +examples: + - | + pci { + #address-cells = <3>; + #size-cells = <2>; + + ethernet@c,0 { + compatible = "pci8086,2e6e"; + reg = <0x6000 0 0 0 0>; + phy-mode = "rgmii-id"; + phy-handle = <&phy1>; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + phy1: ethernet-phy@1 { + reg = <1>; + }; + }; + }; + }; + - | + pci { + #address-cells = <3>; + #size-cells = <2>; + + ethernet@c,0 { + compatible = "pci8086,2e6e"; + reg = <0x6000 0 0 0 0>; + phy-mode = "rgmii"; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 9336fa93ce38..5573e4204746 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13424,6 +13424,7 @@ W: https://www.intel.com/content/www/us/en/support.html Q: https://patchwork.ozlabs.org/project/intel-wired-lan/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue.git +F: Documentation/devicetree/bindings/net/intel,ce4100-gbe.yaml F: Documentation/networking/device_drivers/ethernet/intel/ F: drivers/net/ethernet/intel/ F: drivers/net/ethernet/intel/*/ -- Git-155) ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link 2026-12-01 7:21 [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 1/4] dt-bindings: net: add " Joseph Telaak @ 2026-12-01 7:21 ` Joseph Telaak 2026-12-01 8:58 ` Maxime Chevallier 2026-12-01 7:21 ` [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink Joseph Telaak 3 siblings, 1 reply; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 7:21 UTC (permalink / raw) To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel, Joseph Telaak The CE4100 GbE MAC's only interface is RGMII. Wired straight to a switch port, it has no PHY on its MDIO bus: the PHY scan finds nothing and probe fails. If the device's OF node has a fixed-link, create a phylink instance from the node and let it own the link. The MAC is forced to the speed, duplex and pause phylink resolves, with transmit enabled on link up and disabled on link down; a mutex orders this against MAC resets and the driver's VLAN and transmit setup. Link state, ethtool link and pause settings, autonegotiation restart and the MII ioctls go to phylink, which is started and stopped with the interface, across suspend and in PCI error recovery. e1000's own PHY accesses are refused. Only rgmii phy modes are accepted, since the MAC's only interface is RGMII. A failed PHY scan now returns -EIO itself, as phylink setup leaves err cleared. Without a fixed-link, nothing changes at run time; E1000 now selects PHYLINK. Signed-off-by: Joseph Telaak <joseph@telaak.dev> --- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/e1000/e1000.h | 6 + drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 36 ++++ drivers/net/ethernet/intel/e1000/e1000_hw.c | 79 +++++++- drivers/net/ethernet/intel/e1000/e1000_hw.h | 5 + drivers/net/ethernet/intel/e1000/e1000_main.c | 220 ++++++++++++++++++++++- 6 files changed, 335 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig index bd0dd8c28352..afc11b93bbd6 100644 --- a/drivers/net/ethernet/intel/Kconfig +++ b/drivers/net/ethernet/intel/Kconfig @@ -45,6 +45,7 @@ config E100 config E1000 tristate "Intel(R) PRO/1000 Gigabit Ethernet support" depends on PCI && HAS_IOPORT + select PHYLINK help This driver supports Intel(R) PRO/1000 gigabit ethernet family of adapters. For more information on how to identify your adapter, go diff --git a/drivers/net/ethernet/intel/e1000/e1000.h b/drivers/net/ethernet/intel/e1000/e1000.h index ea6ccf4b728b..0c1986e16d76 100644 --- a/drivers/net/ethernet/intel/e1000/e1000.h +++ b/drivers/net/ethernet/intel/e1000/e1000.h @@ -42,6 +42,7 @@ #include <linux/mii.h> #include <linux/ethtool.h> #include <linux/if_vlan.h> +#include <linux/phylink.h> #define BAR_0 0 #define BAR_1 1 @@ -272,6 +273,11 @@ struct e1000_adapter { /* structs defined in e1000_hw.h */ struct e1000_hw hw; + struct phylink *phylink; + struct phylink_config phylink_config; + /* phylink's link state vs. MAC resets and TX enable */ + struct mutex phylink_lock; + bool phylink_up; struct e1000_hw_stats stats; struct e1000_phy_info phy_info; struct e1000_phy_stats phy_stats; diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c index 925f10206cdd..2ba7ce255c66 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c +++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c @@ -90,6 +90,9 @@ static int e1000_get_link_ksettings(struct net_device *netdev, struct e1000_hw *hw = &adapter->hw; u32 supported, advertising; + if (adapter->phylink) + return phylink_ethtool_ksettings_get(adapter->phylink, cmd); + if (hw->media_type == e1000_media_type_copper) { supported = (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | @@ -168,6 +171,9 @@ static int e1000_set_link_ksettings(struct net_device *netdev, struct e1000_hw *hw = &adapter->hw; u32 advertising; + if (adapter->phylink) + return phylink_ethtool_ksettings_set(adapter->phylink, cmd); + ethtool_convert_link_mode_to_legacy_u32(&advertising, cmd->link_modes.advertising); @@ -250,6 +256,11 @@ static void e1000_get_pauseparam(struct net_device *netdev, struct e1000_adapter *adapter = netdev_priv(netdev); struct e1000_hw *hw = &adapter->hw; + if (adapter->phylink) { + phylink_ethtool_get_pauseparam(adapter->phylink, pause); + return; + } + pause->autoneg = (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); @@ -270,6 +281,9 @@ static int e1000_set_pauseparam(struct net_device *netdev, struct e1000_hw *hw = &adapter->hw; int retval = 0; + if (adapter->phylink) + return phylink_ethtool_set_pauseparam(adapter->phylink, pause); + adapter->fc_autoneg = pause->autoneg; while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) @@ -349,6 +363,9 @@ static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs, regs_buff[11] = er32(TIDV); regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */ + if (adapter->phylink) /* no PHY of the MAC's: leave its words zero */ + goto no_phy; + if (hw->phy_type == e1000_phy_igp) { e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, IGP01E1000_PHY_AGC_A); @@ -403,6 +420,7 @@ static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs, e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); regs_buff[24] = (u32)phy_data; /* phy local receiver status */ regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ +no_phy: if (hw->mac_type >= e1000_82540 && hw->media_type == e1000_media_type_copper) { regs_buff[26] = er32(MANC); @@ -1452,6 +1470,14 @@ static int e1000_run_loopback_test(struct e1000_adapter *adapter) static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) { + /* Under phylink the MAC has no PHY of its own to loop back + * through, so the test is skipped and reports a pass. + */ + if (adapter->phylink) { + *data = 0; + return 0; + } + *data = e1000_setup_desc_rings(adapter); if (*data) goto out; @@ -1470,6 +1496,13 @@ static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) { struct e1000_hw *hw = &adapter->hw; + + /* Under phylink the MAC's link is forced; ask phylink */ + if (adapter->phylink) { + *data = !adapter->phylink_up; + return *data; + } + *data = 0; if (hw->media_type == e1000_media_type_internal_serdes) { int i = 0; @@ -1802,6 +1835,9 @@ static int e1000_nway_reset(struct net_device *netdev) { struct e1000_adapter *adapter = netdev_priv(netdev); + if (adapter->phylink) + return phylink_ethtool_nway_reset(adapter->phylink); + if (netif_running(netdev)) e1000_reinit_locked(adapter); return 0; diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c index 0e5de52b1067..58e2d23009a7 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c @@ -747,8 +747,12 @@ s32 e1000_setup_link(struct e1000_hw *hw) } /* Call the necessary subroutine to configure the link. */ - ret_val = (hw->media_type == e1000_media_type_copper) ? - e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); + if (hw->phylink) + ret_val = e1000_setup_forced_link(hw); + else if (hw->media_type == e1000_media_type_copper) + ret_val = e1000_setup_copper_link(hw); + else + ret_val = e1000_setup_fiber_serdes_link(hw); /* Initialize the flow control address, type, and PAUSE timer * registers to their default values. This is done even if flow @@ -763,6 +767,17 @@ s32 e1000_setup_link(struct e1000_hw *hw) ew32(FCTTV, hw->fc_pause_time); + e1000_set_fc_watermarks(hw); + + return ret_val; +} + +/** + * e1000_set_fc_watermarks - set the flow control receive thresholds + * @hw: Struct containing variables accessed by shared code + */ +void e1000_set_fc_watermarks(struct e1000_hw *hw) +{ /* Set the flow control receive threshold registers. Normally, * these registers will be set to a default threshold that may be * adjusted later by the driver's runtime code. However, if the @@ -785,7 +800,6 @@ s32 e1000_setup_link(struct e1000_hw *hw) ew32(FCRTH, hw->fc_high_water); } } - return ret_val; } /** @@ -1407,6 +1421,50 @@ static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) return E1000_SUCCESS; } +/** + * e1000_setup_forced_link - force the MAC to the link phylink resolved + * @hw: Struct containing variables accessed by shared code + * + * phylink owns the link, so set speed, duplex and link up in the MAC from + * what it last reported rather than from autonegotiation. + * + * Return: E1000_SUCCESS, or the error from setting flow control. + */ +s32 e1000_setup_forced_link(struct e1000_hw *hw) +{ + u32 ctrl, ctrl_aux; + + ctrl_aux = er32(CTL_AUX); + ctrl_aux &= ~E1000_CTL_AUX_RMII; + ew32(CTL_AUX, ctrl_aux); + + ctrl = er32(CTRL); + ctrl &= ~(E1000_CTRL_ASDE | E1000_CTRL_SPD_SEL | E1000_CTRL_FD); + ctrl |= E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX; + + switch (hw->forced_speed) { + case SPEED_1000: + ctrl |= E1000_CTRL_SPD_1000; + break; + case SPEED_100: + ctrl |= E1000_CTRL_SPD_100; + break; + default: + ctrl |= E1000_CTRL_SPD_10; + break; + } + + if (hw->forced_full_duplex) + ctrl |= E1000_CTRL_FD; + + ew32(CTRL, ctrl); + E1000_WRITE_FLUSH(); + + e1000_config_collision_dist(hw); + + return e1000_force_mac_fc(hw); +} + /** * e1000_setup_copper_link - phy/speed/duplex setting * @hw: Struct containing variables accessed by shared code @@ -2375,6 +2433,12 @@ s32 e1000_check_for_link(struct e1000_hw *hw) s32 ret_val; u16 phy_data; + /* phylink tracks the link, with no PHY access from here */ + if (hw->phylink) { + hw->get_link_status = false; + return E1000_SUCCESS; + } + er32(CTRL); status = er32(STATUS); @@ -2787,6 +2851,9 @@ s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data) u32 ret_val; unsigned long flags; + if (hw->phylink) + return -E1000_ERR_PHY; + spin_lock_irqsave(&e1000_phy_lock, flags); if ((hw->phy_type == e1000_phy_igp) && @@ -2924,6 +2991,9 @@ s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data) u32 ret_val; unsigned long flags; + if (hw->phylink) + return -E1000_ERR_PHY; + spin_lock_irqsave(&e1000_phy_lock, flags); if ((hw->phy_type == e1000_phy_igp) && @@ -3041,6 +3111,9 @@ s32 e1000_phy_hw_reset(struct e1000_hw *hw) u32 ctrl, ctrl_ext; u32 led_ctrl; + if (hw->phylink) + return E1000_SUCCESS; + e_dbg("Resetting Phy...\n"); if (hw->mac_type > e1000_82543) { diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.h b/drivers/net/ethernet/intel/e1000/e1000_hw.h index 95cdd17134e5..c28f811fadb0 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_hw.h +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.h @@ -271,6 +271,8 @@ void e1000_set_media_type(struct e1000_hw *hw); /* Link Configuration */ s32 e1000_setup_link(struct e1000_hw *hw); +s32 e1000_setup_forced_link(struct e1000_hw *hw); +void e1000_set_fc_watermarks(struct e1000_hw *hw); s32 e1000_phy_setup_autoneg(struct e1000_hw *hw); void e1000_config_collision_dist(struct e1000_hw *hw); s32 e1000_check_for_link(struct e1000_hw *hw); @@ -1388,6 +1390,9 @@ struct e1000_hw { e1000_dsp_config dsp_config_state; bool get_link_status; bool serdes_has_link; + bool phylink; /* link managed by phylink */ + bool forced_full_duplex; + u16 forced_speed; bool tbi_compatibility_en; bool tbi_compatibility_on; bool laa_is_present; diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index a52fff0259a1..2343252b89fa 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -7,6 +7,8 @@ #include <linux/prefetch.h> #include <linux/bitops.h> #include <linux/if_vlan.h> +#include <linux/of_mdio.h> +#include <linux/of_net.h> char e1000_driver_name[] = "e1000"; static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; @@ -364,7 +366,12 @@ static void e1000_configure(struct e1000_adapter *adapter) e1000_restore_vlan(adapter); e1000_init_manageability(adapter); + /* phylink's link-up rewrites TCTL too */ + if (adapter->hw.phylink) + mutex_lock(&adapter->phylink_lock); e1000_configure_tx(adapter); + if (adapter->hw.phylink) + mutex_unlock(&adapter->phylink_lock); e1000_setup_rctl(adapter); e1000_configure_rx(adapter); /* call E1000_DESC_UNUSED which always leaves @@ -393,6 +400,14 @@ int e1000_up(struct e1000_adapter *adapter) netif_wake_queue(adapter->netdev); + /* phylink does not report a link it still has after a reset */ + if (hw->phylink) { + mutex_lock(&adapter->phylink_lock); + if (adapter->phylink_up) + ew32(TCTL, er32(TCTL) | E1000_TCTL_EN); + mutex_unlock(&adapter->phylink_lock); + } + /* fire a link change interrupt to start the watchdog */ ew32(ICS, E1000_ICS_LSC); return 0; @@ -505,8 +520,10 @@ void e1000_down(struct e1000_adapter *adapter) * bit to decide whether it should enable transmits again). Such * a race condition would result into transmission being disabled * in the hardware until the next IFF_DOWN+IFF_UP cycle. + * With phylink, the carrier is phylink's. */ - netif_carrier_off(netdev); + if (!hw->phylink) + netif_carrier_off(netdev); netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_RX, NULL); netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_TX, NULL); @@ -520,8 +537,11 @@ void e1000_down(struct e1000_adapter *adapter) */ e1000_down_and_stop(adapter); - adapter->link_speed = 0; - adapter->link_duplex = 0; + /* phylink reports no new link after the reset: keep this one */ + if (!hw->phylink) { + adapter->link_speed = 0; + adapter->link_duplex = 0; + } e1000_reset(adapter); e1000_clean_all_tx_rings(adapter); @@ -542,7 +562,7 @@ void e1000_reinit_locked(struct e1000_adapter *adapter) clear_bit(__E1000_RESETTING, &adapter->flags); } -void e1000_reset(struct e1000_adapter *adapter) +static void __e1000_reset(struct e1000_adapter *adapter) { struct e1000_hw *hw = &adapter->hw; u32 pba = 0, tx_space, min_tx_space, min_rx_space; @@ -697,6 +717,18 @@ void e1000_reset(struct e1000_adapter *adapter) e1000_release_manageability(adapter); } +void e1000_reset(struct e1000_adapter *adapter) +{ + if (!adapter->hw.phylink) { + __e1000_reset(adapter); + return; + } + + mutex_lock(&adapter->phylink_lock); + __e1000_reset(adapter); + mutex_unlock(&adapter->phylink_lock); +} + /* Dump the eeprom for users having checksum issues */ static void e1000_dump_eeprom(struct e1000_adapter *adapter) { @@ -901,6 +933,131 @@ static int e1000_init_hw_struct(struct e1000_adapter *adapter, return 0; } +static struct e1000_adapter *e1000_from_phylink(struct phylink_config *config) +{ + return netdev_priv(to_net_dev(config->dev)); +} + +static void e1000_mac_config(struct phylink_config *config, unsigned int mode, + const struct phylink_link_state *state) +{ +} + +static void e1000_mac_link_down(struct phylink_config *config, + unsigned int mode, phy_interface_t interface) +{ + struct e1000_adapter *adapter = e1000_from_phylink(config); + struct e1000_hw *hw = &adapter->hw; + + mutex_lock(&adapter->phylink_lock); + adapter->phylink_up = false; + adapter->link_speed = 0; + adapter->link_duplex = 0; + ew32(TCTL, er32(TCTL) & ~E1000_TCTL_EN); + mutex_unlock(&adapter->phylink_lock); +} + +static void e1000_mac_link_up(struct phylink_config *config, + struct phy_device *phy, unsigned int mode, + phy_interface_t interface, int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct e1000_adapter *adapter = e1000_from_phylink(config); + struct e1000_hw *hw = &adapter->hw; + + mutex_lock(&adapter->phylink_lock); + hw->forced_speed = speed; + hw->forced_full_duplex = duplex == DUPLEX_FULL; + if (tx_pause && rx_pause) + hw->fc = E1000_FC_FULL; + else if (tx_pause) + hw->fc = E1000_FC_TX_PAUSE; + else if (rx_pause) + hw->fc = E1000_FC_RX_PAUSE; + else + hw->fc = E1000_FC_NONE; + hw->original_fc = hw->fc; + + e1000_setup_forced_link(hw); + e1000_set_fc_watermarks(hw); + + adapter->link_speed = speed; + adapter->link_duplex = duplex == DUPLEX_FULL ? FULL_DUPLEX : + HALF_DUPLEX; + adapter->tx_timeout_factor = speed == SPEED_10 ? 16 : 1; + adapter->phylink_up = true; + + if (!test_bit(__E1000_DOWN, &adapter->flags)) + ew32(TCTL, er32(TCTL) | E1000_TCTL_EN); + mutex_unlock(&adapter->phylink_lock); +} + +static const struct phylink_mac_ops e1000_phylink_mac_ops = { + .mac_config = e1000_mac_config, + .mac_link_down = e1000_mac_link_down, + .mac_link_up = e1000_mac_link_up, +}; + +/** + * e1000_phylink_init - hand the link of a CE4100 to phylink + * @adapter: board private structure + * + * If the device's OF node has a fixed-link, let phylink manage the link + * and force the MAC to whatever it resolves. Without one, the MAC + * manages its PHY itself as before. + * + * Return: 0 if phylink is not used or is set up, else an error. + */ +static int e1000_phylink_init(struct e1000_adapter *adapter) +{ + struct device_node *np = adapter->pdev->dev.of_node; + struct phylink_config *config = &adapter->phylink_config; + struct e1000_hw *hw = &adapter->hw; + phy_interface_t interface; + struct phylink *phylink; + + if (!np || !of_phy_is_fixed_link(np)) + return 0; + + if (of_get_phy_mode(np, &interface) || + !phy_interface_mode_is_rgmii(interface)) { + e_dev_err("phylink needs an rgmii phy-mode\n"); + return -EINVAL; + } + + config->dev = &adapter->netdev->dev; + config->type = PHYLINK_NETDEV; + config->mac_managed_pm = true; + config->mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | MAC_10 | + MAC_100 | MAC_1000FD; + phy_interface_set_rgmii(config->supported_interfaces); + + phylink = phylink_create(config, of_fwnode_handle(np), interface, + &e1000_phylink_mac_ops); + if (IS_ERR(phylink)) + return PTR_ERR(phylink); + + adapter->phylink = phylink; + hw->phylink = true; + hw->forced_speed = SPEED_1000; + hw->forced_full_duplex = true; + hw->autoneg = 0; + adapter->fc_autoneg = 0; + hw->fc = E1000_FC_NONE; + hw->original_fc = hw->fc; + + return 0; +} + +static void e1000_phylink_destroy(struct e1000_adapter *adapter) +{ + if (!adapter->phylink) + return; + + phylink_destroy(adapter->phylink); + adapter->phylink = NULL; +} + /** * e1000_probe - Device Initialization Routine * @pdev: PCI device information struct @@ -1182,8 +1339,14 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) adapter->wol = adapter->eeprom_wol; device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); - /* Auto detect PHY address */ if (hw->mac_type == e1000_ce4100) { + err = e1000_phylink_init(adapter); + if (err) + goto err_eeprom; + } + + /* Auto detect PHY address */ + if (hw->mac_type == e1000_ce4100 && !hw->phylink) { for (i = 0; i < 32; i++) { hw->phy_addr = i; e1000_read_phy_reg(hw, PHY_ID2, &tmp); @@ -1192,8 +1355,10 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) break; } - if (i >= 32) + if (i >= 32) { + err = -EIO; goto err_eeprom; + } } /* reset the hardware with the new settings */ @@ -1225,6 +1390,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return 0; err_register: + e1000_phylink_destroy(adapter); err_eeprom: e1000_phy_hw_reset(hw); @@ -1270,6 +1436,8 @@ static void e1000_remove(struct pci_dev *pdev) unregister_netdev(netdev); + e1000_phylink_destroy(adapter); + /* Only kill reset task if adapter is not resetting */ if (!test_bit(__E1000_RESETTING, &adapter->flags)) cancel_work_sync(&adapter->reset_task); @@ -1316,6 +1484,7 @@ static int e1000_sw_init(struct e1000_adapter *adapter) e1000_irq_disable(adapter); spin_lock_init(&adapter->stats_lock); + mutex_init(&adapter->phylink_lock); set_bit(__E1000_DOWN, &adapter->flags); @@ -1414,6 +1583,9 @@ int e1000_open(struct net_device *netdev) /* fire a link status change interrupt to start the watchdog */ ew32(ICS, E1000_ICS_LSC); + if (adapter->phylink) + phylink_start(adapter->phylink); + return E1000_SUCCESS; err_req_irq: @@ -1453,6 +1625,9 @@ int e1000_close(struct net_device *netdev) set_bit(__E1000_DOWN, &adapter->flags); clear_bit(__E1000_RESETTING, &adapter->flags); + if (adapter->phylink) + phylink_stop(adapter->phylink); + e1000_down(adapter); e1000_power_down_phy(adapter); e1000_free_irq(adapter); @@ -2397,6 +2572,9 @@ bool e1000_has_link(struct e1000_adapter *adapter) struct e1000_hw *hw = &adapter->hw; bool link_active = false; + if (hw->phylink) + return adapter->phylink_up; + /* get_link_status is set on LSC (link status) interrupt or rx * sequence error interrupt (except on intel ce4100). * get_link_status will stay false until the @@ -2444,7 +2622,7 @@ static void e1000_watchdog(struct work_struct *work) u32 link, tctl; link = e1000_has_link(adapter); - if ((netif_carrier_ok(netdev)) && link) + if (hw->phylink || (netif_carrier_ok(netdev) && link)) goto link_up; if (link) { @@ -4777,6 +4955,9 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, u16 mii_reg; unsigned long flags; + if (adapter->phylink) + return phylink_mii_ioctl(adapter->phylink, ifr, cmd); + if (hw->media_type != e1000_media_type_copper) return -EOPNOTSUPP; @@ -4906,6 +5087,9 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, struct e1000_hw *hw = &adapter->hw; u32 ctrl; + /* phylink's link-up rewrites CTRL too */ + if (hw->phylink) + mutex_lock(&adapter->phylink_lock); ctrl = er32(CTRL); if (features & NETIF_F_HW_VLAN_CTAG_RX) { /* enable VLAN tag insert/strip */ @@ -4915,6 +5099,8 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, ctrl &= ~E1000_CTRL_VME; } ew32(CTRL, ctrl); + if (hw->phylink) + mutex_unlock(&adapter->phylink_lock); } static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter, bool filter_on) @@ -5091,6 +5277,8 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); rtnl_lock(); + if (adapter->phylink) + phylink_suspend(adapter->phylink, !!adapter->wol); e1000_down(adapter); rtnl_unlock(); } @@ -5204,8 +5392,14 @@ static int e1000_resume(struct device *dev) e1000_init_manageability(adapter); - if (netif_running(netdev)) + if (netif_running(netdev)) { e1000_up(adapter); + if (adapter->phylink) { + rtnl_lock(); + phylink_resume(adapter->phylink); + rtnl_unlock(); + } + } netif_device_attach(netdev); @@ -5261,8 +5455,11 @@ static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_DISCONNECT; } - if (netif_running(netdev)) + if (netif_running(netdev)) { + if (adapter->phylink) + phylink_stop(adapter->phylink); e1000_down(adapter); + } if (!test_and_set_bit(__E1000_DISABLED, &adapter->flags)) pci_disable_device(pdev); @@ -5329,6 +5526,11 @@ static void e1000_io_resume(struct pci_dev *pdev) pr_info("can't bring device back up after reset\n"); return; } + if (adapter->phylink) { + rtnl_lock(); + phylink_start(adapter->phylink); + rtnl_unlock(); + } } netif_device_attach(netdev); -- Git-155) ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link 2026-12-01 7:21 ` [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link Joseph Telaak @ 2026-12-01 8:58 ` Maxime Chevallier 2026-12-01 9:20 ` Joseph Telaak 0 siblings, 1 reply; 10+ messages in thread From: Maxime Chevallier @ 2026-12-01 8:58 UTC (permalink / raw) To: Joseph Telaak, Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel Hi Joseph, On 12/1/26 08:21, Joseph Telaak wrote: > The CE4100 GbE MAC's only interface is RGMII. Wired straight to a switch > port, it has no PHY on its MDIO bus: the PHY scan finds nothing and probe > fails. > > If the device's OF node has a fixed-link, create a phylink instance from > the node and let it own the link. The MAC is forced to the speed, duplex > and pause phylink resolves, with transmit enabled on link up and > disabled on link down; a mutex orders this against MAC resets and the > driver's VLAN and transmit setup. Link state, ethtool link and pause > settings, autonegotiation restart and the MII ioctls go to phylink, > which is started and stopped with the interface, across suspend and in > PCI error recovery. e1000's own PHY accesses are refused. Only rgmii phy > modes are accepted, since the MAC's only interface is RGMII. > > A failed PHY scan now returns -EIO itself, as phylink setup leaves err > cleared. Without a fixed-link, nothing changes at run time; E1000 now > selects PHYLINK. Nice to see some steps to use phylink in these drivers. I wonder what's the amount of work to port "the rest" of the PHY logoc to phylink too here, likely quite a bit with the NIC handling the PHY in most cases... > > Signed-off-by: Joseph Telaak <joseph@telaak.dev> > --- > drivers/net/ethernet/intel/Kconfig | 1 + > drivers/net/ethernet/intel/e1000/e1000.h | 6 + > drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 36 ++++ > drivers/net/ethernet/intel/e1000/e1000_hw.c | 79 +++++++- > drivers/net/ethernet/intel/e1000/e1000_hw.h | 5 + > drivers/net/ethernet/intel/e1000/e1000_main.c | 220 ++++++++++++++++++++++- > 6 files changed, 335 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig > index bd0dd8c28352..afc11b93bbd6 100644 > --- a/drivers/net/ethernet/intel/Kconfig > +++ b/drivers/net/ethernet/intel/Kconfig > @@ -45,6 +45,7 @@ config E100 > config E1000 > tristate "Intel(R) PRO/1000 Gigabit Ethernet support" > depends on PCI && HAS_IOPORT > + select PHYLINK > help > This driver supports Intel(R) PRO/1000 gigabit ethernet family of > adapters. For more information on how to identify your adapter, go > diff --git a/drivers/net/ethernet/intel/e1000/e1000.h b/drivers/net/ethernet/intel/e1000/e1000.h > index ea6ccf4b728b..0c1986e16d76 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000.h > +++ b/drivers/net/ethernet/intel/e1000/e1000.h > @@ -42,6 +42,7 @@ > #include <linux/mii.h> > #include <linux/ethtool.h> > #include <linux/if_vlan.h> > +#include <linux/phylink.h> > > #define BAR_0 0 > #define BAR_1 1 > @@ -272,6 +273,11 @@ struct e1000_adapter { > > /* structs defined in e1000_hw.h */ > struct e1000_hw hw; > + struct phylink *phylink; > + struct phylink_config phylink_config; > + /* phylink's link state vs. MAC resets and TX enable */ > + struct mutex phylink_lock; > + bool phylink_up; > struct e1000_hw_stats stats; > struct e1000_phy_info phy_info; > struct e1000_phy_stats phy_stats; > diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c > index 925f10206cdd..2ba7ce255c66 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c > +++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c > @@ -90,6 +90,9 @@ static int e1000_get_link_ksettings(struct net_device *netdev, > struct e1000_hw *hw = &adapter->hw; > u32 supported, advertising; > > + if (adapter->phylink) > + return phylink_ethtool_ksettings_get(adapter->phylink, cmd); > + > if (hw->media_type == e1000_media_type_copper) { > supported = (SUPPORTED_10baseT_Half | > SUPPORTED_10baseT_Full | > @@ -168,6 +171,9 @@ static int e1000_set_link_ksettings(struct net_device *netdev, > struct e1000_hw *hw = &adapter->hw; > u32 advertising; > > + if (adapter->phylink) > + return phylink_ethtool_ksettings_set(adapter->phylink, cmd); > + > ethtool_convert_link_mode_to_legacy_u32(&advertising, > cmd->link_modes.advertising); > > @@ -250,6 +256,11 @@ static void e1000_get_pauseparam(struct net_device *netdev, > struct e1000_adapter *adapter = netdev_priv(netdev); > struct e1000_hw *hw = &adapter->hw; > > + if (adapter->phylink) { > + phylink_ethtool_get_pauseparam(adapter->phylink, pause); > + return; > + } > + > pause->autoneg = > (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); > > @@ -270,6 +281,9 @@ static int e1000_set_pauseparam(struct net_device *netdev, > struct e1000_hw *hw = &adapter->hw; > int retval = 0; > > + if (adapter->phylink) > + return phylink_ethtool_set_pauseparam(adapter->phylink, pause); > + > adapter->fc_autoneg = pause->autoneg; > > while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) > @@ -349,6 +363,9 @@ static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs, > regs_buff[11] = er32(TIDV); > > regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */ > + if (adapter->phylink) /* no PHY of the MAC's: leave its words zero */ > + goto no_phy; > + > if (hw->phy_type == e1000_phy_igp) { > e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, > IGP01E1000_PHY_AGC_A); > @@ -403,6 +420,7 @@ static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs, > e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); > regs_buff[24] = (u32)phy_data; /* phy local receiver status */ > regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ > +no_phy: > if (hw->mac_type >= e1000_82540 && > hw->media_type == e1000_media_type_copper) { > regs_buff[26] = er32(MANC); > @@ -1452,6 +1470,14 @@ static int e1000_run_loopback_test(struct e1000_adapter *adapter) > > static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) > { > + /* Under phylink the MAC has no PHY of its own to loop back > + * through, so the test is skipped and reports a pass. > + */ > + if (adapter->phylink) { > + *data = 0; > + return 0; > + } > + > *data = e1000_setup_desc_rings(adapter); > if (*data) > goto out; > @@ -1470,6 +1496,13 @@ static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) > static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) > { > struct e1000_hw *hw = &adapter->hw; > + > + /* Under phylink the MAC's link is forced; ask phylink */ > + if (adapter->phylink) { > + *data = !adapter->phylink_up; > + return *data; > + } > + > *data = 0; > if (hw->media_type == e1000_media_type_internal_serdes) { > int i = 0; > @@ -1802,6 +1835,9 @@ static int e1000_nway_reset(struct net_device *netdev) > { > struct e1000_adapter *adapter = netdev_priv(netdev); > > + if (adapter->phylink) > + return phylink_ethtool_nway_reset(adapter->phylink); > + > if (netif_running(netdev)) > e1000_reinit_locked(adapter); > return 0; > diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c > index 0e5de52b1067..58e2d23009a7 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c > +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c > @@ -747,8 +747,12 @@ s32 e1000_setup_link(struct e1000_hw *hw) > } > > /* Call the necessary subroutine to configure the link. */ > - ret_val = (hw->media_type == e1000_media_type_copper) ? > - e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); > + if (hw->phylink) > + ret_val = e1000_setup_forced_link(hw); > + else if (hw->media_type == e1000_media_type_copper) > + ret_val = e1000_setup_copper_link(hw); > + else > + ret_val = e1000_setup_fiber_serdes_link(hw); > > /* Initialize the flow control address, type, and PAUSE timer > * registers to their default values. This is done even if flow > @@ -763,6 +767,17 @@ s32 e1000_setup_link(struct e1000_hw *hw) > > ew32(FCTTV, hw->fc_pause_time); > > + e1000_set_fc_watermarks(hw); > + > + return ret_val; > +} > + > +/** > + * e1000_set_fc_watermarks - set the flow control receive thresholds > + * @hw: Struct containing variables accessed by shared code > + */ > +void e1000_set_fc_watermarks(struct e1000_hw *hw) > +{ > /* Set the flow control receive threshold registers. Normally, > * these registers will be set to a default threshold that may be > * adjusted later by the driver's runtime code. However, if the > @@ -785,7 +800,6 @@ s32 e1000_setup_link(struct e1000_hw *hw) > ew32(FCRTH, hw->fc_high_water); > } > } > - return ret_val; > } > > /** > @@ -1407,6 +1421,50 @@ static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) > return E1000_SUCCESS; > } > > +/** > + * e1000_setup_forced_link - force the MAC to the link phylink resolved > + * @hw: Struct containing variables accessed by shared code > + * > + * phylink owns the link, so set speed, duplex and link up in the MAC from > + * what it last reported rather than from autonegotiation. > + * > + * Return: E1000_SUCCESS, or the error from setting flow control. > + */ > +s32 e1000_setup_forced_link(struct e1000_hw *hw) > +{ > + u32 ctrl, ctrl_aux; > + > + ctrl_aux = er32(CTL_AUX); > + ctrl_aux &= ~E1000_CTL_AUX_RMII; > + ew32(CTL_AUX, ctrl_aux); > + > + ctrl = er32(CTRL); > + ctrl &= ~(E1000_CTRL_ASDE | E1000_CTRL_SPD_SEL | E1000_CTRL_FD); > + ctrl |= E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX; > + > + switch (hw->forced_speed) { > + case SPEED_1000: > + ctrl |= E1000_CTRL_SPD_1000; > + break; > + case SPEED_100: > + ctrl |= E1000_CTRL_SPD_100; > + break; > + default: > + ctrl |= E1000_CTRL_SPD_10; > + break; > + } > + > + if (hw->forced_full_duplex) > + ctrl |= E1000_CTRL_FD; > + > + ew32(CTRL, ctrl); > + E1000_WRITE_FLUSH(); > + > + e1000_config_collision_dist(hw); > + > + return e1000_force_mac_fc(hw); > +} > + > /** > * e1000_setup_copper_link - phy/speed/duplex setting > * @hw: Struct containing variables accessed by shared code > @@ -2375,6 +2433,12 @@ s32 e1000_check_for_link(struct e1000_hw *hw) > s32 ret_val; > u16 phy_data; > > + /* phylink tracks the link, with no PHY access from here */ > + if (hw->phylink) { > + hw->get_link_status = false; > + return E1000_SUCCESS; > + } > + > er32(CTRL); > status = er32(STATUS); > > @@ -2787,6 +2851,9 @@ s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data) > u32 ret_val; > unsigned long flags; > > + if (hw->phylink) > + return -E1000_ERR_PHY; > + > spin_lock_irqsave(&e1000_phy_lock, flags); > > if ((hw->phy_type == e1000_phy_igp) && > @@ -2924,6 +2991,9 @@ s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data) > u32 ret_val; > unsigned long flags; > > + if (hw->phylink) > + return -E1000_ERR_PHY; > + > spin_lock_irqsave(&e1000_phy_lock, flags); > > if ((hw->phy_type == e1000_phy_igp) && > @@ -3041,6 +3111,9 @@ s32 e1000_phy_hw_reset(struct e1000_hw *hw) > u32 ctrl, ctrl_ext; > u32 led_ctrl; > > + if (hw->phylink) > + return E1000_SUCCESS; > + > e_dbg("Resetting Phy...\n"); > > if (hw->mac_type > e1000_82543) { > diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.h b/drivers/net/ethernet/intel/e1000/e1000_hw.h > index 95cdd17134e5..c28f811fadb0 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_hw.h > +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.h > @@ -271,6 +271,8 @@ void e1000_set_media_type(struct e1000_hw *hw); > > /* Link Configuration */ > s32 e1000_setup_link(struct e1000_hw *hw); > +s32 e1000_setup_forced_link(struct e1000_hw *hw); > +void e1000_set_fc_watermarks(struct e1000_hw *hw); > s32 e1000_phy_setup_autoneg(struct e1000_hw *hw); > void e1000_config_collision_dist(struct e1000_hw *hw); > s32 e1000_check_for_link(struct e1000_hw *hw); > @@ -1388,6 +1390,9 @@ struct e1000_hw { > e1000_dsp_config dsp_config_state; > bool get_link_status; > bool serdes_has_link; > + bool phylink; /* link managed by phylink */ Not extremely familiar with that driver, but can't we just check if the struct phylink *phylink pointer is set in the e1000_adapter struct instead of maintaining a bool here ? > + bool forced_full_duplex; > + u16 forced_speed; > bool tbi_compatibility_en; > bool tbi_compatibility_on; > bool laa_is_present; > diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c > index a52fff0259a1..2343252b89fa 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_main.c > +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c > @@ -7,6 +7,8 @@ > #include <linux/prefetch.h> > #include <linux/bitops.h> > #include <linux/if_vlan.h> > +#include <linux/of_mdio.h> > +#include <linux/of_net.h> > > char e1000_driver_name[] = "e1000"; > static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; > @@ -364,7 +366,12 @@ static void e1000_configure(struct e1000_adapter *adapter) > e1000_restore_vlan(adapter); > e1000_init_manageability(adapter); > > + /* phylink's link-up rewrites TCTL too */ > + if (adapter->hw.phylink) > + mutex_lock(&adapter->phylink_lock); > e1000_configure_tx(adapter); > + if (adapter->hw.phylink) > + mutex_unlock(&adapter->phylink_lock); > e1000_setup_rctl(adapter); > e1000_configure_rx(adapter); > /* call E1000_DESC_UNUSED which always leaves > @@ -393,6 +400,14 @@ int e1000_up(struct e1000_adapter *adapter) > > netif_wake_queue(adapter->netdev); > > + /* phylink does not report a link it still has after a reset */ > + if (hw->phylink) { > + mutex_lock(&adapter->phylink_lock); > + if (adapter->phylink_up) > + ew32(TCTL, er32(TCTL) | E1000_TCTL_EN); > + mutex_unlock(&adapter->phylink_lock); > + } > + > /* fire a link change interrupt to start the watchdog */ > ew32(ICS, E1000_ICS_LSC); > return 0; > @@ -505,8 +520,10 @@ void e1000_down(struct e1000_adapter *adapter) > * bit to decide whether it should enable transmits again). Such > * a race condition would result into transmission being disabled > * in the hardware until the next IFF_DOWN+IFF_UP cycle. > + * With phylink, the carrier is phylink's. > */ > - netif_carrier_off(netdev); > + if (!hw->phylink) > + netif_carrier_off(netdev); > > netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_RX, NULL); > netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_TX, NULL); > @@ -520,8 +537,11 @@ void e1000_down(struct e1000_adapter *adapter) > */ > e1000_down_and_stop(adapter); > > - adapter->link_speed = 0; > - adapter->link_duplex = 0; > + /* phylink reports no new link after the reset: keep this one */ > + if (!hw->phylink) { > + adapter->link_speed = 0; > + adapter->link_duplex = 0; > + } > > e1000_reset(adapter); > e1000_clean_all_tx_rings(adapter); > @@ -542,7 +562,7 @@ void e1000_reinit_locked(struct e1000_adapter *adapter) > clear_bit(__E1000_RESETTING, &adapter->flags); > } > > -void e1000_reset(struct e1000_adapter *adapter) > +static void __e1000_reset(struct e1000_adapter *adapter) > { > struct e1000_hw *hw = &adapter->hw; > u32 pba = 0, tx_space, min_tx_space, min_rx_space; > @@ -697,6 +717,18 @@ void e1000_reset(struct e1000_adapter *adapter) > e1000_release_manageability(adapter); > } > > +void e1000_reset(struct e1000_adapter *adapter) > +{ > + if (!adapter->hw.phylink) { > + __e1000_reset(adapter); > + return; > + } > + > + mutex_lock(&adapter->phylink_lock); > + __e1000_reset(adapter); > + mutex_unlock(&adapter->phylink_lock); > +} > + > /* Dump the eeprom for users having checksum issues */ > static void e1000_dump_eeprom(struct e1000_adapter *adapter) > { > @@ -901,6 +933,131 @@ static int e1000_init_hw_struct(struct e1000_adapter *adapter, > return 0; > } > > +static struct e1000_adapter *e1000_from_phylink(struct phylink_config *config) > +{ > + return netdev_priv(to_net_dev(config->dev)); > +} > + > +static void e1000_mac_config(struct phylink_config *config, unsigned int mode, > + const struct phylink_link_state *state) > +{ > +} > + > +static void e1000_mac_link_down(struct phylink_config *config, > + unsigned int mode, phy_interface_t interface) > +{ > + struct e1000_adapter *adapter = e1000_from_phylink(config); > + struct e1000_hw *hw = &adapter->hw; > + > + mutex_lock(&adapter->phylink_lock); > + adapter->phylink_up = false; > + adapter->link_speed = 0; > + adapter->link_duplex = 0; > + ew32(TCTL, er32(TCTL) & ~E1000_TCTL_EN); > + mutex_unlock(&adapter->phylink_lock); > +} > + > +static void e1000_mac_link_up(struct phylink_config *config, > + struct phy_device *phy, unsigned int mode, > + phy_interface_t interface, int speed, int duplex, > + bool tx_pause, bool rx_pause) > +{ > + struct e1000_adapter *adapter = e1000_from_phylink(config); > + struct e1000_hw *hw = &adapter->hw; > + > + mutex_lock(&adapter->phylink_lock); > + hw->forced_speed = speed; > + hw->forced_full_duplex = duplex == DUPLEX_FULL; > + if (tx_pause && rx_pause) > + hw->fc = E1000_FC_FULL; > + else if (tx_pause) > + hw->fc = E1000_FC_TX_PAUSE; > + else if (rx_pause) > + hw->fc = E1000_FC_RX_PAUSE; > + else > + hw->fc = E1000_FC_NONE; > + hw->original_fc = hw->fc; > + > + e1000_setup_forced_link(hw); > + e1000_set_fc_watermarks(hw); > + > + adapter->link_speed = speed; > + adapter->link_duplex = duplex == DUPLEX_FULL ? FULL_DUPLEX : > + HALF_DUPLEX; > + adapter->tx_timeout_factor = speed == SPEED_10 ? 16 : 1; > + adapter->phylink_up = true; > + > + if (!test_bit(__E1000_DOWN, &adapter->flags)) > + ew32(TCTL, er32(TCTL) | E1000_TCTL_EN); > + mutex_unlock(&adapter->phylink_lock); > +} > + > +static const struct phylink_mac_ops e1000_phylink_mac_ops = { > + .mac_config = e1000_mac_config, > + .mac_link_down = e1000_mac_link_down, > + .mac_link_up = e1000_mac_link_up, > +}; > + > +/** > + * e1000_phylink_init - hand the link of a CE4100 to phylink > + * @adapter: board private structure > + * > + * If the device's OF node has a fixed-link, let phylink manage the link > + * and force the MAC to whatever it resolves. Without one, the MAC > + * manages its PHY itself as before. > + * > + * Return: 0 if phylink is not used or is set up, else an error. > + */ > +static int e1000_phylink_init(struct e1000_adapter *adapter) > +{ > + struct device_node *np = adapter->pdev->dev.of_node; > + struct phylink_config *config = &adapter->phylink_config; > + struct e1000_hw *hw = &adapter->hw; > + phy_interface_t interface; > + struct phylink *phylink; > + > + if (!np || !of_phy_is_fixed_link(np)) > + return 0; > + > + if (of_get_phy_mode(np, &interface) || > + !phy_interface_mode_is_rgmii(interface)) { > + e_dev_err("phylink needs an rgmii phy-mode\n"); phylink is an internal framework, mentionning it in an error log is only going to bring confusion :) > + return -EINVAL; > + } > + > + config->dev = &adapter->netdev->dev; > + config->type = PHYLINK_NETDEV; > + config->mac_managed_pm = true; > + config->mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | MAC_10 | > + MAC_100 | MAC_1000FD; > + phy_interface_set_rgmii(config->supported_interfaces); > + > + phylink = phylink_create(config, of_fwnode_handle(np), interface, > + &e1000_phylink_mac_ops); > + if (IS_ERR(phylink)) > + return PTR_ERR(phylink); > + > + adapter->phylink = phylink; > + hw->phylink = true; > + hw->forced_speed = SPEED_1000; > + hw->forced_full_duplex = true; > + hw->autoneg = 0; > + adapter->fc_autoneg = 0; > + hw->fc = E1000_FC_NONE; > + hw->original_fc = hw->fc; > + > + return 0; > +} > + > +static void e1000_phylink_destroy(struct e1000_adapter *adapter) > +{ > + if (!adapter->phylink) > + return; > + > + phylink_destroy(adapter->phylink); > + adapter->phylink = NULL; > +} > + > /** > * e1000_probe - Device Initialization Routine > * @pdev: PCI device information struct > @@ -1182,8 +1339,14 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > adapter->wol = adapter->eeprom_wol; > device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); > > - /* Auto detect PHY address */ > if (hw->mac_type == e1000_ce4100) { > + err = e1000_phylink_init(adapter); > + if (err) > + goto err_eeprom; > + } > + > + /* Auto detect PHY address */ > + if (hw->mac_type == e1000_ce4100 && !hw->phylink) { > for (i = 0; i < 32; i++) { > hw->phy_addr = i; > e1000_read_phy_reg(hw, PHY_ID2, &tmp); > @@ -1192,8 +1355,10 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > break; > } > > - if (i >= 32) > + if (i >= 32) { > + err = -EIO; > goto err_eeprom; > + } > } > > /* reset the hardware with the new settings */ > @@ -1225,6 +1390,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > return 0; > > err_register: > + e1000_phylink_destroy(adapter); > err_eeprom: > e1000_phy_hw_reset(hw); > > @@ -1270,6 +1436,8 @@ static void e1000_remove(struct pci_dev *pdev) > > unregister_netdev(netdev); > > + e1000_phylink_destroy(adapter); > + > /* Only kill reset task if adapter is not resetting */ > if (!test_bit(__E1000_RESETTING, &adapter->flags)) > cancel_work_sync(&adapter->reset_task); > @@ -1316,6 +1484,7 @@ static int e1000_sw_init(struct e1000_adapter *adapter) > e1000_irq_disable(adapter); > > spin_lock_init(&adapter->stats_lock); > + mutex_init(&adapter->phylink_lock); > > set_bit(__E1000_DOWN, &adapter->flags); > > @@ -1414,6 +1583,9 @@ int e1000_open(struct net_device *netdev) > /* fire a link status change interrupt to start the watchdog */ > ew32(ICS, E1000_ICS_LSC); > > + if (adapter->phylink) > + phylink_start(adapter->phylink); > + > return E1000_SUCCESS; > > err_req_irq: > @@ -1453,6 +1625,9 @@ int e1000_close(struct net_device *netdev) > set_bit(__E1000_DOWN, &adapter->flags); > clear_bit(__E1000_RESETTING, &adapter->flags); > > + if (adapter->phylink) > + phylink_stop(adapter->phylink); > + > e1000_down(adapter); > e1000_power_down_phy(adapter); > e1000_free_irq(adapter); > @@ -2397,6 +2572,9 @@ bool e1000_has_link(struct e1000_adapter *adapter) > struct e1000_hw *hw = &adapter->hw; > bool link_active = false; > > + if (hw->phylink) > + return adapter->phylink_up; > + > /* get_link_status is set on LSC (link status) interrupt or rx > * sequence error interrupt (except on intel ce4100). > * get_link_status will stay false until the > @@ -2444,7 +2622,7 @@ static void e1000_watchdog(struct work_struct *work) > u32 link, tctl; > > link = e1000_has_link(adapter); > - if ((netif_carrier_ok(netdev)) && link) > + if (hw->phylink || (netif_carrier_ok(netdev) && link)) > goto link_up; > > if (link) { > @@ -4777,6 +4955,9 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, > u16 mii_reg; > unsigned long flags; > > + if (adapter->phylink) > + return phylink_mii_ioctl(adapter->phylink, ifr, cmd); > + > if (hw->media_type != e1000_media_type_copper) > return -EOPNOTSUPP; > > @@ -4906,6 +5087,9 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, > struct e1000_hw *hw = &adapter->hw; > u32 ctrl; > > + /* phylink's link-up rewrites CTRL too */ > + if (hw->phylink) > + mutex_lock(&adapter->phylink_lock); > ctrl = er32(CTRL); > if (features & NETIF_F_HW_VLAN_CTAG_RX) { > /* enable VLAN tag insert/strip */ > @@ -4915,6 +5099,8 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, > ctrl &= ~E1000_CTRL_VME; > } > ew32(CTRL, ctrl); > + if (hw->phylink) > + mutex_unlock(&adapter->phylink_lock); > } > static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter, > bool filter_on) > @@ -5091,6 +5277,8 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) > > WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); > rtnl_lock(); > + if (adapter->phylink) > + phylink_suspend(adapter->phylink, !!adapter->wol); > e1000_down(adapter); > rtnl_unlock(); > } > @@ -5204,8 +5392,14 @@ static int e1000_resume(struct device *dev) > > e1000_init_manageability(adapter); > > - if (netif_running(netdev)) > + if (netif_running(netdev)) { > e1000_up(adapter); > + if (adapter->phylink) { > + rtnl_lock(); > + phylink_resume(adapter->phylink); > + rtnl_unlock(); > + } > + } > > netif_device_attach(netdev); > > @@ -5261,8 +5455,11 @@ static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, > return PCI_ERS_RESULT_DISCONNECT; > } > > - if (netif_running(netdev)) > + if (netif_running(netdev)) { > + if (adapter->phylink) > + phylink_stop(adapter->phylink); > e1000_down(adapter); > + } > > if (!test_and_set_bit(__E1000_DISABLED, &adapter->flags)) > pci_disable_device(pdev); > @@ -5329,6 +5526,11 @@ static void e1000_io_resume(struct pci_dev *pdev) > pr_info("can't bring device back up after reset\n"); > return; > } > + if (adapter->phylink) { > + rtnl_lock(); > + phylink_start(adapter->phylink); > + rtnl_unlock(); > + } > } > > netif_device_attach(netdev); > Overall this is a step in the right direction. It's still a bit sad that this is only a partial port to phylink, and given the tests I've been running on Intel drivers, it's likely that features such as FC, eee, WoL and so on will behave pretty differently now depending on wether the phylink path is used or not. In an ideal world, we'd go all-in and have the whole thing switched to phylink and add what's currently missing in phylink to cover that, but OTOH it's still bringing some value, so let's see how this goes :) Thanks, Maxime ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link 2026-12-01 8:58 ` Maxime Chevallier @ 2026-12-01 9:20 ` Joseph Telaak 0 siblings, 0 replies; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 9:20 UTC (permalink / raw) To: Maxime Chevallier Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King, intel-wired-lan, netdev, devicetree, linux-kernel Hi Maxime, Thanks for the review. On 12/1/26 09:58, Maxime Chevallier wrote: > Nice to see some steps to use phylink in these drivers. I wonder what's > the amount of work to port "the rest" of the PHY logoc to phylink too here, > likely quite a bit with the NIC handling the PHY in most cases... Quite a bit, I think. The 8254x parts drive their PHYs through MDIC and also have fiber and SerDes modes, and I only have CE4100 boards to test on. So I limited this to the CE4100, where a fixed link to a switch currently fails to probe. Without a fixed-link or phy-handle the old path runs unchanged. > Not extremely familiar with that driver, but can't we just > check if the struct phylink *phylink pointer is set in the > e1000_adapter struct instead of maintaining a bool here ? Yes. I added the bool because e1000_hw.c only gets struct e1000_hw, but it can reach the adapter through hw->back, as e1000_get_hw_dev() already does. I will drop the bool in v2 and check adapter->phylink everywhere. > phylink is an internal framework, mentionning it in an error log > is only going to bring confusion :) Good point, I will change it to "phy-mode must be an rgmii mode". Thanks, Joseph ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink 2026-12-01 7:21 [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 1/4] dt-bindings: net: add " Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link Joseph Telaak @ 2026-12-01 7:21 ` Joseph Telaak 2026-12-01 9:02 ` Maxime Chevallier 2026-12-01 7:21 ` [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink Joseph Telaak 3 siblings, 1 reply; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 7:21 UTC (permalink / raw) To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel, Joseph Telaak If the device's OF node has a phy-handle, register the MAC's MDIO bus from the node's "mdio" child and let phylink connect the PHY when the interface is opened. The bus is registered only when phylink manages the link, and e1000's own PHY accesses are refused then, so the bus lock alone serializes MDIO accesses and they can sleep while they wait. The bus is unregistered before the MDIO registers are unmapped. The MAC adds no RGMII delays: phy-mode goes to the PHY as is, and the RTL8211E test board runs 1G with rgmii-id. Without a phy-handle, nothing changes. Signed-off-by: Joseph Telaak <joseph@telaak.dev> --- drivers/net/ethernet/intel/e1000/e1000.h | 2 + drivers/net/ethernet/intel/e1000/e1000_hw.c | 56 ++++++++++++++ drivers/net/ethernet/intel/e1000/e1000_hw.h | 2 + drivers/net/ethernet/intel/e1000/e1000_main.c | 101 ++++++++++++++++++++++++-- 4 files changed, 155 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000.h b/drivers/net/ethernet/intel/e1000/e1000.h index 0c1986e16d76..348e2ab71f29 100644 --- a/drivers/net/ethernet/intel/e1000/e1000.h +++ b/drivers/net/ethernet/intel/e1000/e1000.h @@ -42,6 +42,7 @@ #include <linux/mii.h> #include <linux/ethtool.h> #include <linux/if_vlan.h> +#include <linux/phy.h> #include <linux/phylink.h> #define BAR_0 0 @@ -273,6 +274,7 @@ struct e1000_adapter { /* structs defined in e1000_hw.h */ struct e1000_hw hw; + struct mii_bus *mii_bus; struct phylink *phylink; struct phylink_config phylink_config; /* phylink's link state vs. MAC resets and TX enable */ diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c index 58e2d23009a7..181e684e4a0e 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c @@ -6,6 +6,7 @@ */ #include <linux/bitfield.h> +#include <linux/iopoll.h> #include "e1000.h" static s32 e1000_check_downshift(struct e1000_hw *hw); @@ -2837,6 +2838,61 @@ static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) return data; } +/* The CE4100 MDIO bus is only registered while phylink owns the PHY, and + * e1000's own PHY accesses are refused then: the bus lock serializes these. + */ +static int e1000_ce4100_mdio_cmd(struct e1000_hw *hw, u32 cmd) +{ + u32 val; + + writel(cmd | INTEL_CE_GBE_MDIC_GO, E1000_MDIO_CMD); + + return readl_poll_timeout(E1000_MDIO_CMD, val, + !(val & INTEL_CE_GBE_MDIC_GO), 50, 3200); +} + +/** + * e1000_ce4100_mdio_read - read a register of a PHY on the CE4100 MDIO bus + * @hw: Struct containing variables accessed by shared code + * @addr: PHY address + * @reg: register number + * + * Return: the register value, or a negative error code. + */ +int e1000_ce4100_mdio_read(struct e1000_hw *hw, int addr, int reg) +{ + int ret; + u32 sts; + + ret = e1000_ce4100_mdio_cmd(hw, (reg << E1000_MDIC_REG_SHIFT) | + (addr << E1000_MDIC_PHY_SHIFT) | + INTEL_CE_GBE_MDIC_OP_READ); + if (ret) + return ret; + + sts = readl(E1000_MDIO_STS); + if (sts & INTEL_CE_GBE_MDIC_READ_ERROR) + return -EIO; + + return sts & 0xffff; +} + +/** + * e1000_ce4100_mdio_write - write a register of a PHY on the CE4100 MDIO bus + * @hw: Struct containing variables accessed by shared code + * @addr: PHY address + * @reg: register number + * @val: value to write + * + * Return: 0, or a negative error code. + */ +int e1000_ce4100_mdio_write(struct e1000_hw *hw, int addr, int reg, u16 val) +{ + return e1000_ce4100_mdio_cmd(hw, val | (reg << E1000_MDIC_REG_SHIFT) | + (addr << E1000_MDIC_PHY_SHIFT) | + INTEL_CE_GBE_MDIC_OP_WRITE); +} + /** * e1000_read_phy_reg - read a phy register * @hw: Struct containing variables accessed by shared code diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.h b/drivers/net/ethernet/intel/e1000/e1000_hw.h index c28f811fadb0..acdd12a1320e 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_hw.h +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.h @@ -273,6 +273,8 @@ void e1000_set_media_type(struct e1000_hw *hw); s32 e1000_setup_link(struct e1000_hw *hw); s32 e1000_setup_forced_link(struct e1000_hw *hw); void e1000_set_fc_watermarks(struct e1000_hw *hw); +int e1000_ce4100_mdio_read(struct e1000_hw *hw, int addr, int reg); +int e1000_ce4100_mdio_write(struct e1000_hw *hw, int addr, int reg, u16 val); s32 e1000_phy_setup_autoneg(struct e1000_hw *hw); void e1000_config_collision_dist(struct e1000_hw *hw); s32 e1000_check_for_link(struct e1000_hw *hw); diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index 2343252b89fa..60ccfce3c889 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -933,6 +933,72 @@ static int e1000_init_hw_struct(struct e1000_adapter *adapter, return 0; } +static int e1000_mdio_read(struct mii_bus *bus, int addr, int reg) +{ + return e1000_ce4100_mdio_read(bus->priv, addr, reg); +} + +static int e1000_mdio_write(struct mii_bus *bus, int addr, int reg, u16 val) +{ + return e1000_ce4100_mdio_write(bus->priv, addr, reg, val); +} + +/** + * e1000_mdio_register - register the CE4100 MDIO bus from the device tree + * @adapter: board private structure + * + * Register the MAC's MDIO bus with the PHYs its "mdio" child node + * describes, so that their drivers probe. The bus goes before the MAC's + * registers are unmapped, so it is not device-managed. + * + * Return: 0 on success, else an error. + */ +static int e1000_mdio_register(struct e1000_adapter *adapter) +{ + struct device *dev = &adapter->pdev->dev; + struct device_node *np; + struct mii_bus *bus; + int err; + + np = of_get_child_by_name(dev->of_node, "mdio"); + if (!np) { + e_dev_err("phy-handle needs an mdio node\n"); + return -EINVAL; + } + + bus = mdiobus_alloc(); + if (!bus) { + err = -ENOMEM; + goto out; + } + + bus->name = "e1000 CE4100 MDIO"; + snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pci_name(adapter->pdev)); + bus->priv = &adapter->hw; + bus->parent = dev; + bus->read = e1000_mdio_read; + bus->write = e1000_mdio_write; + + err = of_mdiobus_register(bus, np); + if (err) + mdiobus_free(bus); + else + adapter->mii_bus = bus; +out: + of_node_put(np); + return err; +} + +static void e1000_mdio_unregister(struct e1000_adapter *adapter) +{ + if (!adapter->mii_bus) + return; + + mdiobus_unregister(adapter->mii_bus); + mdiobus_free(adapter->mii_bus); + adapter->mii_bus = NULL; +} + static struct e1000_adapter *e1000_from_phylink(struct phylink_config *config) { return netdev_priv(to_net_dev(config->dev)); @@ -1002,9 +1068,10 @@ static const struct phylink_mac_ops e1000_phylink_mac_ops = { * e1000_phylink_init - hand the link of a CE4100 to phylink * @adapter: board private structure * - * If the device's OF node has a fixed-link, let phylink manage the link - * and force the MAC to whatever it resolves. Without one, the MAC - * manages its PHY itself as before. + * If the device's OF node has a fixed-link or a phy-handle, let phylink + * manage the link and force the MAC to whatever it resolves. A PHY is + * found on the MAC's own MDIO bus, which is registered for it. Without + * either property, the MAC manages its PHY itself as before. * * Return: 0 if phylink is not used or is set up, else an error. */ @@ -1015,8 +1082,10 @@ static int e1000_phylink_init(struct e1000_adapter *adapter) struct e1000_hw *hw = &adapter->hw; phy_interface_t interface; struct phylink *phylink; + int err; - if (!np || !of_phy_is_fixed_link(np)) + if (!np || (!of_phy_is_fixed_link(np) && + !of_property_present(np, "phy-handle"))) return 0; if (of_get_phy_mode(np, &interface) || @@ -1032,10 +1101,18 @@ static int e1000_phylink_init(struct e1000_adapter *adapter) MAC_100 | MAC_1000FD; phy_interface_set_rgmii(config->supported_interfaces); + if (of_property_present(np, "phy-handle")) { + err = e1000_mdio_register(adapter); + if (err) + return err; + } + phylink = phylink_create(config, of_fwnode_handle(np), interface, &e1000_phylink_mac_ops); - if (IS_ERR(phylink)) + if (IS_ERR(phylink)) { + e1000_mdio_unregister(adapter); return PTR_ERR(phylink); + } adapter->phylink = phylink; hw->phylink = true; @@ -1056,6 +1133,7 @@ static void e1000_phylink_destroy(struct e1000_adapter *adapter) phylink_destroy(adapter->phylink); adapter->phylink = NULL; + e1000_mdio_unregister(adapter); } /** @@ -1539,6 +1617,13 @@ int e1000_open(struct net_device *netdev) netif_carrier_off(netdev); + if (adapter->phylink) { + err = phylink_of_phy_connect(adapter->phylink, + adapter->pdev->dev.of_node, 0); + if (err) + return err; + } + /* allocate transmit descriptors */ err = e1000_setup_all_tx_resources(adapter); if (err) @@ -1595,6 +1680,8 @@ int e1000_open(struct net_device *netdev) e1000_free_all_tx_resources(adapter); err_setup_tx: e1000_reset(adapter); + if (adapter->phylink) + phylink_disconnect_phy(adapter->phylink); return err; } @@ -1625,8 +1712,10 @@ int e1000_close(struct net_device *netdev) set_bit(__E1000_DOWN, &adapter->flags); clear_bit(__E1000_RESETTING, &adapter->flags); - if (adapter->phylink) + if (adapter->phylink) { phylink_stop(adapter->phylink); + phylink_disconnect_phy(adapter->phylink); + } e1000_down(adapter); e1000_power_down_phy(adapter); -- Git-155) ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink 2026-12-01 7:21 ` [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink Joseph Telaak @ 2026-12-01 9:02 ` Maxime Chevallier 0 siblings, 0 replies; 10+ messages in thread From: Maxime Chevallier @ 2026-12-01 9:02 UTC (permalink / raw) To: Joseph Telaak, Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel On 12/1/26 08:21, Joseph Telaak wrote: > If the device's OF node has a phy-handle, register the MAC's MDIO bus > from the node's "mdio" child and let phylink connect the PHY when the > interface is opened. The bus is registered only when phylink manages the > link, and e1000's own PHY accesses are refused then, so the bus lock > alone serializes MDIO accesses and they can sleep while they wait. The > bus is unregistered before the MDIO registers are unmapped. The MAC adds > no RGMII delays: phy-mode goes to the PHY as is, and the RTL8211E test > board runs 1G with rgmii-id. > > Without a phy-handle, nothing changes. > > Signed-off-by: Joseph Telaak <joseph@telaak.dev> > --- > drivers/net/ethernet/intel/e1000/e1000.h | 2 + > drivers/net/ethernet/intel/e1000/e1000_hw.c | 56 ++++++++++++++ > drivers/net/ethernet/intel/e1000/e1000_hw.h | 2 + > drivers/net/ethernet/intel/e1000/e1000_main.c | 101 ++++++++++++++++++++++++-- > 4 files changed, 155 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/ethernet/intel/e1000/e1000.h b/drivers/net/ethernet/intel/e1000/e1000.h > index 0c1986e16d76..348e2ab71f29 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000.h > +++ b/drivers/net/ethernet/intel/e1000/e1000.h > @@ -42,6 +42,7 @@ > #include <linux/mii.h> > #include <linux/ethtool.h> > #include <linux/if_vlan.h> > +#include <linux/phy.h> > #include <linux/phylink.h> > > #define BAR_0 0 > @@ -273,6 +274,7 @@ struct e1000_adapter { > > /* structs defined in e1000_hw.h */ > struct e1000_hw hw; > + struct mii_bus *mii_bus; > struct phylink *phylink; > struct phylink_config phylink_config; > /* phylink's link state vs. MAC resets and TX enable */ > diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c > index 58e2d23009a7..181e684e4a0e 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c > +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c > @@ -6,6 +6,7 @@ > */ > > #include <linux/bitfield.h> > +#include <linux/iopoll.h> > #include "e1000.h" > > static s32 e1000_check_downshift(struct e1000_hw *hw); > @@ -2837,6 +2838,61 @@ static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) > return data; > } > > +/* The CE4100 MDIO bus is only registered while phylink owns the PHY, and > + * e1000's own PHY accesses are refused then: the bus lock serializes these. > + */ > +static int e1000_ce4100_mdio_cmd(struct e1000_hw *hw, u32 cmd) > +{ > + u32 val; > + > + writel(cmd | INTEL_CE_GBE_MDIC_GO, E1000_MDIO_CMD); > + > + return readl_poll_timeout(E1000_MDIO_CMD, val, > + !(val & INTEL_CE_GBE_MDIC_GO), 50, 3200); > +} > + > +/** > + * e1000_ce4100_mdio_read - read a register of a PHY on the CE4100 MDIO bus > + * @hw: Struct containing variables accessed by shared code > + * @addr: PHY address > + * @reg: register number > + * > + * Return: the register value, or a negative error code. > + */ > +int e1000_ce4100_mdio_read(struct e1000_hw *hw, int addr, int reg) > +{ > + int ret; > + u32 sts; > + > + ret = e1000_ce4100_mdio_cmd(hw, (reg << E1000_MDIC_REG_SHIFT) | > + (addr << E1000_MDIC_PHY_SHIFT) | > + INTEL_CE_GBE_MDIC_OP_READ); > + if (ret) > + return ret; > + > + sts = readl(E1000_MDIO_STS); > + if (sts & INTEL_CE_GBE_MDIC_READ_ERROR) > + return -EIO; > + > + return sts & 0xffff; > +} > + > +/** > + * e1000_ce4100_mdio_write - write a register of a PHY on the CE4100 MDIO bus > + * @hw: Struct containing variables accessed by shared code > + * @addr: PHY address > + * @reg: register number > + * @val: value to write > + * > + * Return: 0, or a negative error code. > + */ > +int e1000_ce4100_mdio_write(struct e1000_hw *hw, int addr, int reg, u16 val) > +{ > + return e1000_ce4100_mdio_cmd(hw, val | (reg << E1000_MDIC_REG_SHIFT) | > + (addr << E1000_MDIC_PHY_SHIFT) | > + INTEL_CE_GBE_MDIC_OP_WRITE); > +} > + > /** > * e1000_read_phy_reg - read a phy register > * @hw: Struct containing variables accessed by shared code > diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.h b/drivers/net/ethernet/intel/e1000/e1000_hw.h > index c28f811fadb0..acdd12a1320e 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_hw.h > +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.h > @@ -273,6 +273,8 @@ void e1000_set_media_type(struct e1000_hw *hw); > s32 e1000_setup_link(struct e1000_hw *hw); > s32 e1000_setup_forced_link(struct e1000_hw *hw); > void e1000_set_fc_watermarks(struct e1000_hw *hw); > +int e1000_ce4100_mdio_read(struct e1000_hw *hw, int addr, int reg); > +int e1000_ce4100_mdio_write(struct e1000_hw *hw, int addr, int reg, u16 val); > s32 e1000_phy_setup_autoneg(struct e1000_hw *hw); > void e1000_config_collision_dist(struct e1000_hw *hw); > s32 e1000_check_for_link(struct e1000_hw *hw); > diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c > index 2343252b89fa..60ccfce3c889 100644 > --- a/drivers/net/ethernet/intel/e1000/e1000_main.c > +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c > @@ -933,6 +933,72 @@ static int e1000_init_hw_struct(struct e1000_adapter *adapter, > return 0; > } > > +static int e1000_mdio_read(struct mii_bus *bus, int addr, int reg) > +{ > + return e1000_ce4100_mdio_read(bus->priv, addr, reg); > +} > + > +static int e1000_mdio_write(struct mii_bus *bus, int addr, int reg, u16 val) > +{ > + return e1000_ce4100_mdio_write(bus->priv, addr, reg, val); > +} > + > +/** > + * e1000_mdio_register - register the CE4100 MDIO bus from the device tree > + * @adapter: board private structure > + * > + * Register the MAC's MDIO bus with the PHYs its "mdio" child node > + * describes, so that their drivers probe. The bus goes before the MAC's > + * registers are unmapped, so it is not device-managed. > + * > + * Return: 0 on success, else an error. > + */ > +static int e1000_mdio_register(struct e1000_adapter *adapter) > +{ > + struct device *dev = &adapter->pdev->dev; > + struct device_node *np; > + struct mii_bus *bus; > + int err; > + > + np = of_get_child_by_name(dev->of_node, "mdio"); > + if (!np) { > + e_dev_err("phy-handle needs an mdio node\n"); > + return -EINVAL; > + } > + > + bus = mdiobus_alloc(); > + if (!bus) { > + err = -ENOMEM; > + goto out; > + } > + > + bus->name = "e1000 CE4100 MDIO"; > + snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pci_name(adapter->pdev)); > + bus->priv = &adapter->hw; > + bus->parent = dev; > + bus->read = e1000_mdio_read; > + bus->write = e1000_mdio_write; > + > + err = of_mdiobus_register(bus, np); > + if (err) > + mdiobus_free(bus); > + else > + adapter->mii_bus = bus; > +out: > + of_node_put(np); > + return err; > +} > + > +static void e1000_mdio_unregister(struct e1000_adapter *adapter) > +{ > + if (!adapter->mii_bus) > + return; > + > + mdiobus_unregister(adapter->mii_bus); > + mdiobus_free(adapter->mii_bus); > + adapter->mii_bus = NULL; > +} > + > static struct e1000_adapter *e1000_from_phylink(struct phylink_config *config) > { > return netdev_priv(to_net_dev(config->dev)); > @@ -1002,9 +1068,10 @@ static const struct phylink_mac_ops e1000_phylink_mac_ops = { > * e1000_phylink_init - hand the link of a CE4100 to phylink > * @adapter: board private structure > * > - * If the device's OF node has a fixed-link, let phylink manage the link > - * and force the MAC to whatever it resolves. Without one, the MAC > - * manages its PHY itself as before. > + * If the device's OF node has a fixed-link or a phy-handle, let phylink > + * manage the link and force the MAC to whatever it resolves. A PHY is > + * found on the MAC's own MDIO bus, which is registered for it. Without > + * either property, the MAC manages its PHY itself as before. > * > * Return: 0 if phylink is not used or is set up, else an error. > */ > @@ -1015,8 +1082,10 @@ static int e1000_phylink_init(struct e1000_adapter *adapter) > struct e1000_hw *hw = &adapter->hw; > phy_interface_t interface; > struct phylink *phylink; > + int err; > > - if (!np || !of_phy_is_fixed_link(np)) > + if (!np || (!of_phy_is_fixed_link(np) && > + !of_property_present(np, "phy-handle"))) > return 0; > > if (of_get_phy_mode(np, &interface) || > @@ -1032,10 +1101,18 @@ static int e1000_phylink_init(struct e1000_adapter *adapter) > MAC_100 | MAC_1000FD; > phy_interface_set_rgmii(config->supported_interfaces); > > + if (of_property_present(np, "phy-handle")) { > + err = e1000_mdio_register(adapter); > + if (err) > + return err; Nothing mandates that the PHY you've attached to the MAC is driven by the MAC's mdio bus. If you have an "mdio" node, register the bus and that's it no ? Maxime ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink 2026-12-01 7:21 [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak ` (2 preceding siblings ...) 2026-12-01 7:21 ` [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink Joseph Telaak @ 2026-12-01 7:21 ` Joseph Telaak 2026-12-01 9:04 ` Maxime Chevallier 3 siblings, 1 reply; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 7:21 UTC (permalink / raw) To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel, Joseph Telaak The MAC has no LPI support. phylink only disables EEE in a PHY when the MAC implements the LPI operations, so the PHY keeps its default EEE advertisement. With EEE negotiated, an RTL8211E blinks its link LED about once a second while the link idles, and a link LED offloaded to the PHY no longer shows the link state. Implement the LPI operations with no LPI capabilities, so that phylink disables EEE in the PHY. Signed-off-by: Joseph Telaak <joseph@telaak.dev> --- drivers/net/ethernet/intel/e1000/e1000_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index 60ccfce3c889..914482f5256e 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -1058,10 +1058,26 @@ static void e1000_mac_link_up(struct phylink_config *config, mutex_unlock(&adapter->phylink_lock); } +/* The MAC has no LPI. LPI operations with no LPI capabilities tell + * phylink so, and it disables EEE in the PHY. + */ +static void e1000_mac_disable_tx_lpi(struct phylink_config *config) +{ +} + +static int e1000_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, + bool tx_clk_stop) +{ + /* Never called: no LPI capabilities */ + return 0; +} + static const struct phylink_mac_ops e1000_phylink_mac_ops = { .mac_config = e1000_mac_config, .mac_link_down = e1000_mac_link_down, .mac_link_up = e1000_mac_link_up, + .mac_disable_tx_lpi = e1000_mac_disable_tx_lpi, + .mac_enable_tx_lpi = e1000_mac_enable_tx_lpi, }; /** -- Git-155) ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink 2026-12-01 7:21 ` [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink Joseph Telaak @ 2026-12-01 9:04 ` Maxime Chevallier 2026-12-01 9:24 ` Joseph Telaak 0 siblings, 1 reply; 10+ messages in thread From: Maxime Chevallier @ 2026-12-01 9:04 UTC (permalink / raw) To: Joseph Telaak, Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King Cc: intel-wired-lan, netdev, devicetree, linux-kernel Hi, On 12/1/26 08:21, Joseph Telaak wrote: > The MAC has no LPI support. phylink only disables EEE in a PHY when the > MAC implements the LPI operations, so the PHY keeps its default EEE > advertisement. With EEE negotiated, an RTL8211E blinks its link LED about > once a second while the link idles, and a link LED offloaded to the PHY > no longer shows the link state. > > Implement the LPI operations with no LPI capabilities, so that phylink > disables EEE in the PHY. I haven't looked too much into that part yet, but this seems like a shortcoming in phylink itself. Can you look into why phylink behaves this way, and if there's no justification, maybe address this in phylink ? Maxime ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink 2026-12-01 9:04 ` Maxime Chevallier @ 2026-12-01 9:24 ` Joseph Telaak 0 siblings, 0 replies; 10+ messages in thread From: Joseph Telaak @ 2026-12-01 9:24 UTC (permalink / raw) To: Maxime Chevallier Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Russell King, intel-wired-lan, netdev, devicetree, linux-kernel Hi Maxime, On 12/1/26, Maxime Chevallier wrote: > I haven't looked too much into that part yet, but this seems like a shortcoming > in phylink itself. Can you look into why phylink behaves this way, and > if there's no justification, maybe address this in phylink ? I looked, and it is on purpose. When phylink gained EEE management in 03abf2a7c654 ("net: phylink: add EEE management"), it kept the old behavior for MACs without the LPI operations, since those may still handle EEE themselves and pass get_eee/set_eee straight to the PHY. Disabling EEE in the PHY would break them. The same commit describes providing the operations with no LPI capabilities as the way for a MAC to say it has no EEE, which is what this patch does. Thanks, Joseph ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-01 9:25 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-01 7:21 [PATCH iwl-next 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 1/4] dt-bindings: net: add " Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 2/4] e1000: use phylink for a CE4100 fixed link Joseph Telaak 2026-12-01 8:58 ` Maxime Chevallier 2026-12-01 9:20 ` Joseph Telaak 2026-12-01 7:21 ` [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink Joseph Telaak 2026-12-01 9:02 ` Maxime Chevallier 2026-12-01 7:21 ` [PATCH iwl-next 4/4] e1000: disable EEE on a CE4100 PHY under phylink Joseph Telaak 2026-12-01 9:04 ` Maxime Chevallier 2026-12-01 9:24 ` Joseph Telaak
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox