From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796278438; b=Tn0es/01al/oyEa/2Io6F8yNwO9lZvd7QIwrxUe/hc4WrLeKPm1nmbnXAlG9vHWZbvH0 54KQpEndMxv1qcpF4QROFWUwYD6+aPzoX0n3Cw30mUoDHFHqn1IPverAsqftfqtALiKUG 8tLZdfAnk6enZgjVQh6YavhFK1SCYcN2UEksX5gltS39KqRTpC3udlXHaa5QxQzpZLXD4 blynhtZs78oTmidGZ6u6uvUmks2ZgVX9/HFOly9tDedQH+hQHevJD7SBPBBvV9OCB7Htb sHygulYtRo8ljeqzip/yR1Y/6Fu7I5y6aC0KG6b29SegFAI0Z7rA9XR+vDeBdRcb2uA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796278438; 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=5UXa7QCMfc33Wq1Z5VTd6gEn2r/zyOCTuzCGPxHd8cE=; b=20k80YS8UzDz/rEV/VF5SLlD+nyuDd6Z/3xdH9daCKJczaRyoIn8i50CSMYq6qiQnsa4 yxjBCx7YXet6SCCPg7cuhtO+5Lg4s4dJWFR3kp1R13BYRnwxaomUldeDC8pMkmbeL/Jez uFYlP8+Uz4OgvaT5wvVwbLOYQkcNQOiVdoLwQIr4Hr4vS9qaHAujbktgBOQqgWALXyHEH 9O8wIb2Jl02Z82lNKIVYw8w5z1YX5PsUxqTCNsNYdr5hJduL3fWKh7dBwmlK4ONNmxOx5 vSSbP9B499n8K1ci8/WFvzWJc8qZnCT3mwxBBgNmXKEzEFiBundBCSXmP3M1Un6cIWQ== 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.174 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 B5840606A68A for ; Thu, 3 Dec 2026 06:13:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5840606A68A 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-f174.google.com with SMTP id af79cd13be357-93f3c616c84so1055339085a.1 for ; Wed, 02 Dec 2026 22:13:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796278437; x=1796883237; 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=5UXa7QCMfc33Wq1Z5VTd6gEn2r/zyOCTuzCGPxHd8cE=; b=iyGUi75M/N74ZI8I3OYw+oJtLX/EsViZdX5p7gZcCTprCO3I99JHxaTjI3FywjMZmC yKcU4aTF5D1YdGDCXQNv6rt+3wenoALi8KjLfo0rtO8T9r7yXJx01Z0Veu63jB5pLeHs JrebejjWFRMCHJClpN/YRkBbDyjpgiKIQ6Yq4fA0CcCSlyF0JvoH1L8GJrlVMM2GtgT9 8bZ+mFcMC9CDFdu73CdM2sVRq/EDJMkksHZt92iV8Qy7/YulssRXL+NsMzms52AC/S9Z KreP7IE+wdG1J5TJTD3KHC6krvkVX0oB+wuNULKo+yfouASCl4z2lRtbMF7zx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:620a:2a05:b0:93e:942f:b8b1 with SMTP id af79cd13be357-949bab0eb61mr8308338085a.64.1796278436647; Wed, 02 Dec 2026 22:13:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 22:13:56 -0800 (PST) From: Joseph Telaak Date: Thu, 03 Dec 2026 01:13:49 -0500 Subject: [PATCH iwl-next v2 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: <20261203-e1000-phylink-v2-3-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 If the device's OF node has a phy-handle, let phylink connect the PHY when the interface is opened; the PHY can be on any bus. The MAC adds no RGMII delays: phy-mode goes to the PHY as is, and the RTL8211E test board runs 1G with rgmii-id. If the node has an "mdio" child, register the MAC's MDIO bus with the devices it describes, with a fixed-link as well as a phy-handle. phylink is set up first, so a deferred probe doesn't register the bus and bind its devices on every retry. An mdio child with neither property is refused: e1000's own PHY code, which scans the bus for a PHY, would drive the bus too. With phylink, e1000's own PHY accesses are refused, 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. Without an "mdio" child or a phy-handle, nothing changes. Signed-off-by: Joseph Telaak --- drivers/net/ethernet/intel/e1000/e1000.h | 1 + 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 | 103 ++++++++++++++++++++++++-- 4 files changed, 157 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000.h b/drivers/net/ethernet/intel/e1000/e1000.h index d01944eda1a1..9d98051a80a6 100644 --- a/drivers/net/ethernet/intel/e1000/e1000.h +++ b/drivers/net/ethernet/intel/e1000/e1000.h @@ -273,6 +273,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 f367b87938f1..3a2a9713e3b2 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 along with phylink, 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 31a916be4ec0..74fec6518818 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 f07afc451d09..1ac21f2c18b8 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -943,6 +943,80 @@ 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 + * + * If the device's OF node has an "mdio" child, register the MAC's MDIO + * bus with the devices it describes, so that their drivers probe. That + * takes phylink, set up first: e1000's own PHY code stays off the bus + * then. The bus goes before the MAC's registers are unmapped, so it is not + * device-managed. + * + * Return: 0 if there is no bus to register or it is registered, 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_available_child_by_name(dev->of_node, "mdio"); + if (!np) + return 0; + + /* Without phylink, e1000's own PHY code would drive the bus too */ + if (!adapter->phylink) { + e_dev_err("an mdio node needs a phy-handle or a fixed-link\n"); + err = -EINVAL; + goto out; + } + + bus = mdiobus_alloc(); + if (!bus) { + err = -ENOMEM; + goto out; + } + + bus->name = "e1000 CE4100 MDIO"; + strscpy(bus->id, pci_name(adapter->pdev), MII_BUS_ID_SIZE); + 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)); @@ -1012,9 +1086,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. The + * phy-handle may point to a PHY on any MDIO bus. 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. */ @@ -1026,7 +1101,8 @@ static int e1000_phylink_init(struct e1000_adapter *adapter) phy_interface_t interface; struct phylink *phylink; - 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) || @@ -1352,6 +1428,10 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = e1000_phylink_init(adapter); if (err) goto err_eeprom; + + err = e1000_mdio_register(adapter); + if (err) + goto err_eeprom; } /* Auto detect PHY address */ @@ -1404,6 +1484,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_eeprom: e1000_phy_hw_reset(hw); e1000_phylink_destroy(adapter); + e1000_mdio_unregister(adapter); if (hw->flash_address) iounmap(hw->flash_address); @@ -1453,6 +1534,7 @@ static void e1000_remove(struct pci_dev *pdev) e1000_phy_hw_reset(hw); e1000_phylink_destroy(adapter); + e1000_mdio_unregister(adapter); kfree(adapter->tx_ring); kfree(adapter->rx_ring); @@ -1549,6 +1631,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) @@ -1609,6 +1698,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; } @@ -1639,8 +1730,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)