From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796278437; b=2x5YGkd0Vrse4nbThQTUIspL2jELyXC6APVDzS7hXeSqXP1VGmAN6RXJyTuOE9yraIPo knMAQxwbCzqgBYh+hZgh4/c4oa6tjlKGaPQy2u57sP2vEPL1qIRptWsdk/MBUWzXqovUV 1RpqJNLDvClcKlwZ4Ad6Kh7XTVtVn3OPIKwlto7tL9MEYKYMq9I2B0vw5GZu5ets+HdTr Zske3zPKZ/8WKwVdtHyW7ztmgb+Xp/2kv4Ri/rRWtfnygh4Uf8XD2RKdY4tjHYLAFZzlP iFlFkhuKvnyQJHWOu4H/qztPjmjuHk07d60fu/Ivi1zpd/gGF3EjKLhFfQwHVUxoyAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796278437; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer; bh=jHQ2586SGfqSYj+ouhWC81keMkoXYb+V8D8Xhw3OF0o=; b=V3r2ebG28dXWh01EyeEK5/Th9cmSg0qPDXaZ0jrrFC0R39kwz2lvCVIt2UTjb8m8ivRX Ma6DE8EUFYIFv0ul+Tkp2O4OW4PS8o/KS41vIvisUC8/27wjM+LiWGByulKQkt54rNYAx cfxL/C77083or/faghJ2AxMRiudartTmKBZWqfakUbHp8f9xs3MF6qeMMtU/+VdC3RN0N vbWP3SHLkHC56XAOpSRlpWwxnPiYKDCJM0mFRzuYq1shO90/BX+qcE6tIsaEq4HtvjF/L UZ9Ql7geV/Vi3msJm/TBAxQwRhyuQNsh9rqUlxjc3LJUSMNSQyzBpNGh/piCO6acLQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=telaak.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.remote-ip=209.85.222.172 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 785F1606A68E for ; Thu, 3 Dec 2026 06:13:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 785F1606A68E Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=telaak.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-9496473b511so79545585a.0 for ; Wed, 02 Dec 2026 22:13:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796278435; x=1796883235; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jHQ2586SGfqSYj+ouhWC81keMkoXYb+V8D8Xhw3OF0o=; b=MOgcVU2zmyh62MT39eBWwaQB4jM/1b0d4ruAc7lQE3x3obFJuGfC1aGT28qw43l3a3 9YUho645m9wGB932tybyzzSal52PeTcRQgkQHizqTsTE/rQyN67VKLMw6rr9rurOfgpk E0XePvpZ42HWd6vOG7YDOR+M/TWMczd+o4NOrUSTVW6etxnrqQsLBeQi5P+6omfKVvO9 Gx+Bm0mZ3RICBN2wRgZ22/+7tt84WeBJBN5An73xIuByM08kQu78Qq8Hj/vFa6aE33vB nAYyV+1xTgZGdTpqgQjF1Qi06gMwqD1VSXU62S+X3YhbM/2ChgSVlktqtFS/UsskMcma Pb9Q== X-Forwarded-Encrypted: i=1; AL+hErGuXHm7b0IUBn6T6avVIsSdT/GZXuj5kSgR18CfrObSInTkevBbdUoj3jMwjPqFv7CneeTAzptySdhSDcU=@vger.kernel.org X-Gm-Message-State: APuU4Z/Sd0en9iVVtwYF0PgJKw53JJdJqVuNsWC8gejkJ3M2X6qkLWQq ZWn4Ey5+licgFBRg13vcoucfpnHHH5w4SFqbmHUAmNj9rJlHx25WzNE6IH7JVkby4tk= X-Gm-Gg: AZFdTZdMzOtOKndAqoVYzJo/cCJYavr2kGEVGml481kbWkAitHAOkan1vlFWt11vgFv UJ3T23bbBZgovUoYG7srXrSQhiHtuw2VXglwvG4sk9QCFJ3aJZUuL3IjX9FQNtINiBqapzJTFwH rD01Ny5+qzMf0BI5I+K1huJzyUCC2YIiwCU6Fm58FlW+4O/b/sVJBbJ3ZkXzT7qPgZJ6Hg5/Iva wHFu8igG2O45z56O0FbIFvxI6A1T0j57b3C7zrcoRLTH52QBIFqej2EldDLe9g8IpF7+zDPbkOU eEBi5tDOmWxp5k7wA+k3Pa3+VDUR+/LB26r+I0XR6L8Hj0Mdj8I8Hw+Hftyjgv5FnT8V5p/aaZw vc0VAWEXG65R634DlpgTEgWxAYs5tAkGWkTGJsxbHEoxKOSNnZQyfjvp3++Nebf3ZFHdr66DrzM pRPeayxQnhqa2JaZ6E3BGsdmbH+8FCG0OB122cCl1G/DZN6IZsMSBrajgF/ZjwPa4may6VSoVod hbnq54zFdhPb3VUFfV0NSl3ufYiFZmDIyf7+SbT8sU2IkGlzPkeQkY6FflU02coaPW6wocn6E6b tdmPOMaFj3b7GvCl7t0hSke3GHA3bk34AydMjuybt2IYdmYooiM6gXfu5o6oQEhGnZaV1VoACYt deaeFPHoXiKZNjeQUdlJxCD7WV5o3WOicL8TcsV/Gk9SlQI75UZVtqSRZwMmm/PDZ49Vm6CqjAE Jd4CQrubELxQ+Q8GEPshASvidK X-Received: by 2002:a05:620a:2713:b0:949:8ee5:6faa with SMTP id af79cd13be357-94a72174925mr182201585a.4.1796278435403; Wed, 02 Dec 2026 22:13:55 -0800 (PST) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([71.68.170.161]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949ca98d9d6sm3077137885a.18.2026.12.02.22.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 22:13:55 -0800 (PST) From: Joseph Telaak Date: Thu, 03 Dec 2026 01:13:48 -0500 Subject: [PATCH iwl-next v2 2/4] e1000: use phylink for a CE4100 fixed link X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-e1000-phylink-v2-2-0a8f80515363@telaak.dev> References: <20261203-e1000-phylink-v2-0-0a8f80515363@telaak.dev> In-Reply-To: <20261203-e1000-phylink-v2-0-0a8f80515363@telaak.dev> 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@lists.osuosl.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Joseph Telaak X-Mailer: b4 0.16.0 The CE4100 GbE MAC can be wired straight to a switch port over RGMII. It then 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: the MAC's RMII mode, which e1000 uses for an RTL8201N, stays with e1000's own PHY code. Probe drops the carrier before registering the netdev rather than after, where it could override a carrier phylink already raised. 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 --- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/e1000/e1000.h | 16 ++ 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 | 4 + drivers/net/ethernet/intel/e1000/e1000_main.c | 243 +++++++++++++++++++++-- 6 files changed, 363 insertions(+), 16 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..d01944eda1a1 100644 --- a/drivers/net/ethernet/intel/e1000/e1000.h +++ b/drivers/net/ethernet/intel/e1000/e1000.h @@ -42,6 +42,7 @@ #include #include #include +#include #define BAR_0 0 #define BAR_1 1 @@ -272,6 +273,13 @@ 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; + /* set by up/open, cleared by e1000_down(): link-up may enable TX */ + bool phylink_tx; struct e1000_hw_stats stats; struct e1000_phy_info phy_info; struct e1000_phy_stats phy_stats; @@ -301,6 +309,14 @@ struct e1000_adapter { struct delayed_work phy_info_task; }; +/* phylink manages the link, so e1000's own PHY code stays off the PHY */ +static inline bool e1000_uses_phylink(struct e1000_hw *hw) +{ + struct e1000_adapter *adapter = hw->back; + + return adapter->phylink; +} + enum e1000_state_t { __E1000_TESTING, __E1000_RESETTING, 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..f367b87938f1 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 (e1000_uses_phylink(hw)) + 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 (e1000_uses_phylink(hw)) { + 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 (e1000_uses_phylink(hw)) + 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 (e1000_uses_phylink(hw)) + 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 (e1000_uses_phylink(hw)) + 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..31a916be4ec0 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,8 @@ struct e1000_hw { e1000_dsp_config dsp_config_state; bool get_link_status; bool serdes_has_link; + 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..f07afc451d09 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include char e1000_driver_name[] = "e1000"; static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; @@ -357,6 +359,7 @@ static void e1000_release_manageability(struct e1000_adapter *adapter) static void e1000_configure(struct e1000_adapter *adapter) { struct net_device *netdev = adapter->netdev; + bool phylink = adapter->phylink; int i; e1000_set_rx_mode(netdev); @@ -364,7 +367,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 (phylink) + mutex_lock(&adapter->phylink_lock); e1000_configure_tx(adapter); + if (phylink) + mutex_unlock(&adapter->phylink_lock); e1000_setup_rctl(adapter); e1000_configure_rx(adapter); /* call E1000_DESC_UNUSED which always leaves @@ -393,6 +401,15 @@ 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 (adapter->phylink) { + mutex_lock(&adapter->phylink_lock); + adapter->phylink_tx = true; + 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; @@ -482,6 +499,7 @@ void e1000_down(struct e1000_adapter *adapter) { struct e1000_hw *hw = &adapter->hw; struct net_device *netdev = adapter->netdev; + bool phylink = adapter->phylink; u32 rctl, tctl; /* disable receives in the hardware */ @@ -491,10 +509,17 @@ void e1000_down(struct e1000_adapter *adapter) netif_tx_disable(netdev); - /* disable transmits in the hardware */ + /* disable transmits in the hardware, and keep phylink's link-up + * from enabling them again + */ + if (phylink) + mutex_lock(&adapter->phylink_lock); + adapter->phylink_tx = false; tctl = er32(TCTL); tctl &= ~E1000_TCTL_EN; ew32(TCTL, tctl); + if (phylink) + mutex_unlock(&adapter->phylink_lock); /* flush both disables and wait for them to finish */ E1000_WRITE_FLUSH(); msleep(10); @@ -505,8 +530,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 (!adapter->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 +547,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 (!adapter->phylink) { + adapter->link_speed = 0; + adapter->link_duplex = 0; + } e1000_reset(adapter); e1000_clean_all_tx_rings(adapter); @@ -542,7 +572,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 +727,18 @@ void e1000_reset(struct e1000_adapter *adapter) e1000_release_manageability(adapter); } +void e1000_reset(struct e1000_adapter *adapter) +{ + if (!adapter->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 +943,130 @@ 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 (adapter->phylink_tx) + 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("phy-mode must be an rgmii 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->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 +1348,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 && !adapter->phylink) { for (i = 0; i < 32; i++) { hw->phy_addr = i; e1000_read_phy_reg(hw, PHY_ID2, &tmp); @@ -1192,13 +1364,20 @@ 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 */ e1000_reset(adapter); + /* carrier off reporting is important to ethtool even BEFORE open; set + * before the netdev is visible, as phylink may raise it once opened + */ + netif_carrier_off(netdev); + strcpy(netdev->name, "eth%d"); err = register_netdev(netdev); if (err) @@ -1216,9 +1395,6 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ((hw->bus_width == e1000_bus_width_64) ? 64 : 32), netdev->dev_addr); - /* carrier off reporting is important to ethtool even BEFORE open */ - netif_carrier_off(netdev); - e_info(probe, "Intel(R) PRO/1000 Network Connection\n"); cards_found++; @@ -1227,6 +1403,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_register: err_eeprom: e1000_phy_hw_reset(hw); + e1000_phylink_destroy(adapter); if (hw->flash_address) iounmap(hw->flash_address); @@ -1275,6 +1452,7 @@ static void e1000_remove(struct pci_dev *pdev) cancel_work_sync(&adapter->reset_task); e1000_phy_hw_reset(hw); + e1000_phylink_destroy(adapter); kfree(adapter->tx_ring); kfree(adapter->rx_ring); @@ -1316,6 +1494,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 +1593,13 @@ 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) { + mutex_lock(&adapter->phylink_lock); + adapter->phylink_tx = true; + mutex_unlock(&adapter->phylink_lock); + phylink_start(adapter->phylink); + } + return E1000_SUCCESS; err_req_irq: @@ -1453,6 +1639,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 +2586,9 @@ bool e1000_has_link(struct e1000_adapter *adapter) struct e1000_hw *hw = &adapter->hw; bool link_active = false; + if (adapter->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 +2636,7 @@ static void e1000_watchdog(struct work_struct *work) u32 link, tctl; link = e1000_has_link(adapter); - if ((netif_carrier_ok(netdev)) && link) + if (adapter->phylink || (netif_carrier_ok(netdev) && link)) goto link_up; if (link) { @@ -4777,6 +4969,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; @@ -4904,8 +5099,12 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, netdev_features_t features) { struct e1000_hw *hw = &adapter->hw; + bool phylink = adapter->phylink; u32 ctrl; + /* phylink's link-up rewrites CTRL too */ + if (phylink) + mutex_lock(&adapter->phylink_lock); ctrl = er32(CTRL); if (features & NETIF_F_HW_VLAN_CTAG_RX) { /* enable VLAN tag insert/strip */ @@ -4915,6 +5114,8 @@ static void __e1000_vlan_mode(struct e1000_adapter *adapter, ctrl &= ~E1000_CTRL_VME; } ew32(CTRL, ctrl); + if (phylink) + mutex_unlock(&adapter->phylink_lock); } static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter, bool filter_on) @@ -5091,6 +5292,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 +5407,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 +5470,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 +5541,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)