From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796109699; b=WinPeRY6I8E+WAqBo9Y4o6NI5r1hj3vQgjyh8SdDvYv8rRivcdBa+fteuMuZOsTh3pnE eQz8rf7zp/a7ncFFUoWjl+Zg0HaUIvaSm7xPS88KNM9o1Tw9PvVrPd/RQOfAWL6pVQ7Nl J8OL+fKu5rYiyyY4ZCjTUmwJO6YAm/U61Sp1OiRUPFzUAfXpxpf+YlvG+AqvZULhWRLwh D9/sZX9y9c8/WlZPSiXuqxRXI/b85XWwh4Y/M8Y6VBVaIWDJF2vR5yL4vK+nnwiBvsCTv Dsvpmoi0FA6F7k6j/VApJ9eSVNSnuw/rmeEFuQ+9m9SLk5l4atRXej/Px/BDcRpyYiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796109699; 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=78wujSoBIzzNU4GbLi0R0YT0NkM82RVLoOE2Fsbd99o=; b=bzL6B1D490KXvaN52L15GHBpMRQXDFJMYJ+X4gFB7lJAiohhnpFrtvW0961MCQSUixg0 j23IBP2phpHbok+N8zBHewooRNfCt3l7errXdDs3jdP2rPW2VqjfvrzfLGASsKB+IBJU3 nADsT3gxbusFNN/1vwpyg1XvB5uodpPy4knoE8qjQYxcO3qepo6xi30rS1iIikYxLCt/B n7+Sh3pOSRM+vbyY+EJGbZ6HdcKzCn3QI4dUg8Vaicjp3zCF0y4JLTHfA+K+JNClaCIU+ oeZIpukaiHch3XYAxsCAH0jO9ZezTTrUcwgbeA0+L9Sp7bMTo6Ngj1BGdSb0Ruj+vtA== 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.128.175 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 BF7B9606A334 for ; Tue, 1 Dec 2026 07:21:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF7B9606A334 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-yw1-f175.google.com with SMTP id 00721157ae682-8b4d86f5328so76187987b3.0 for ; Mon, 30 Nov 2026 23:21:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796109696; x=1796714496; 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=78wujSoBIzzNU4GbLi0R0YT0NkM82RVLoOE2Fsbd99o=; b=T/ENtmUYj7yURVoohc9uHlHpUcdN8KH/WQqCqrt+7k83VObubs7jKv9/QborLh8RCs uz4gu88VJTpA8b6pDAX20Dsp84femvbYuR2I3A08LzKpu+SgmhUs423gHR4YuVEOVIio wGLM51m8AG1yql68BF1i6UosAf1ZKdJKMzWxEHZynbAIGVAkTZWQ+29LXSCdIeVwfxwR dRaBI49LNi9nUQfRcQRzELnzkr2sTVDOTPrg9pDTpdAp0UrSXXLU+6J13LF8H6LKu1S9 +BjDAfGLIUhoMaGBAXcsHlsrvswed+VkMbCwuWS0/prneISSbCcs8eTr3l+Cr4WYJgXR wMvw== X-Forwarded-Encrypted: i=1; AL+hErEy8H82566rJTuPvVJ0vxt6o73eo6570ZhLxA+KpJ8J1CE5b1y1fs8o1KYCwJINm/T/Q/IZxV1MPxJeSR8=@vger.kernel.org X-Gm-Message-State: APuU4Z/JiBpFoxlWrunyQBIBjReLf5+ZGnJgQl/KMXkWapOoZQvyqHPJ sKzmUInckgM5y4KgGJXksL/m3mzxk7LZZvHLSsGLzE0Ix/N9up3Mddtj X-Gm-Gg: AZFdTZemtWMd+KY4bOh9aysSVGHGTiclQ6hmjUicM4sOFyYivtQWi8b4RTi6KYLO3YU JXCAwNAXVCiR4w2hY2H5xaUIMrlArICCzUHrXpEOt6p/NUygYifPuq3g1kIQKQWvg5IaC8Nch8y g1Y9I6XH8SqoFk17QYB8tRHDsJ4GWCzLeFacNA4ah1b3txtFEY6g1f7pQPGtsGhIuncHYjy5MPD rG1RtP+jrxa0UKi91/QIj6iuqrF81xqny/uJpnD6ACxyqQzbXEr0X4RMqBwwUdG/NXGxRAVxFFD 1zG29fTq/+wkixnVxafcNgETRpGSajVgciLhBuKmaPYn7q5a0cUGxzZhfUNnfHdw4eVwAv/nVvd gkgcJX4sqX0auFm66n54Hiq8+NXVB6iqj/Q5XtWE5HrjTAo898Pb+EcCrLVEoMawdF5hw8dBpk0 TJPt40QkEDfxrAxu2m+rsrptimMiILmEmKfB12JvU9ozWx2qcPoxszhfsCZueqRTvGt/CTBehqe lbIuBAyVvSxYzfOjznBCq3vHJZcF5s/dHSJa6t+f5WHILnyU+obVfVEn5BW+F9/1i++j/vz+kXC 3EVqg4mW/9kdv85d5H2AE/Dc9Tqk776VzYOBboPnQV4TmWywfi6tY/FL4R7OcD7DAkK7EROY8dX Fj+uVZeCpUux1eBUji++vP20E7g5MJKrOSLwq1RLOYLbsOwNcw84zkmkWucy6xVGUPegEjXRsDD DKyEdnZ+KxAQhwHSnYWm78Ft0= X-Received: by 2002:a05:690c:a91:b0:8b4:dba5:f12c with SMTP id 00721157ae682-8b52047fd3fmr154783717b3.28.1796109695854; Mon, 30 Nov 2026 23:21:35 -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 00721157ae682-8b52028c7f5sm141501177b3.12.2026.11.30.23.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 23:21:34 -0800 (PST) From: Joseph Telaak Date: Tue, 01 Dec 2026 02:21:19 -0500 Subject: [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink 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: <20261201-e1000-phylink-v1-3-21e6f1c816a0@telaak.dev> References: <20261201-e1000-phylink-v1-0-21e6f1c816a0@telaak.dev> In-Reply-To: <20261201-e1000-phylink-v1-0-21e6f1c816a0@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 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 --- 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 #include #include +#include #include #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 +#include #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)