From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B68606A31A for ; Tue, 1 Dec 2026 09:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=z0Ac9i7r; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=pPsOgj6z Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8D050607D0; Tue, 1 Dec 2026 09:02:42 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id r054SnFiygsY; Tue, 1 Dec 2026 09:02:41 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org A1A77607F6 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796115761; b=m9OnqgLclSM7Nz9KV8zI/5Pp7tKHylmFZH4hBsei5jeWP4Ci1g0Wn+zqaa1c1e/lOlKs sRMmH2qfn/vrmG6P0hke59b8fTAkoAtKd+lNwGWnM/kbrqlMioKH8p/31jibIWeWWmZr8 DsNhA/6aWDGkIg5E5HY4786Mzvng1S98+/xEeXmOGbioT1Q3TWkRtgYWBHs6JuwkEJYzC nm9kVaLco4AqV1Y9b0sXXKP1TDAtCJWqyOvNB+B2cXiog2H93waKu6PzcdV8hrAN32VL2 /Vm1wPsVcFZKkmGbpjoR7XdCnODX0jtiG8TL570CfJtTOvysEbuTQrrli85MnADnUGw== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796115761; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: Received:Received:DKIM-Signature:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-Last-TLS-Session-Version: X-BeenThere:X-Mailman-Version:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:Errors-To; bh=4MuK1oVCcZ5VBbNY0YiSHsElkKS/YyvVEFrwJTWMYuQ=; b=YD47Rhj2xZoqoAICJm4/IWpdYgW1Mwn5ZLdCzO3m4RqY6BBgWCnLD9pTzbIuNNdYg90Z C9lKME4KdASjH+l/Qrq5oU6kbOg2DMVH+Y1pM3fpm1SuLaIn1Zg6PLFs9GaXOPLat+AOl lizCNGSrL16qPpsk9Bvy3AQHwjA2Wg4JC/wZ9bkZuBGI+0nAMz2FkPPTmo9zAVyN5YDPi g2SlUY3ou6VuYaORbKCqX8d6lt2ykHlJ/t3hvMPu9vZU0EEHAgtJfwy6gjmoTfT12KmLY ei3wDqJBgiflYRSnsil8cKujGL9ugSKPEFwowji+KlcIVjHNhi//k+Ca2GBxSFQVXVg== ARC-Authentication-Results: i=1; smtp3.osuosl.org; dmarc=pass header.from=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=pPsOgj6z; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1796115761; bh=4MuK1oVCcZ5VBbNY0YiSHsElkKS/YyvVEFrwJTWMYuQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=z0Ac9i7rPNVpaMe8OX/2a1scb5l8NFuLNB7G6T3bLknx4BThn76WTBnK+XJPRkWdi FudvSgJmqfiXI/5QM3eOH5zkQWQzdKjupYykOlVIWizq07nZSEzVkbzmQgKWb6h2EF 03GffMrvEkb5FDpo4AX+U0H9CGEkNSnSRcL3O+Xk0HdsLJPA1vOfluxOp+3ppo6evQ CqhWEkQJcSFQ+t+mO7enkOHjwEQ5xRJOsRAs4YB3fcofuNb92sEqHBETvEPBQxaq6M Gbn+NF9qmRu+pnltaCn4KHlcI/8sHic7UGXym1CmVbzoz9GAoSzXtzDDB5mxUpyIU6 lD1aoubb4HnwA== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id A1A77607F6; Tue, 1 Dec 2026 09:02:41 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists1.osuosl.org (Postfix) with ESMTP id E4FC93C0 for ; Tue, 1 Dec 2026 09:02:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CA5D1607D0 for ; Tue, 1 Dec 2026 09:02:39 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id HRfwbJC4-Sof for ; Tue, 1 Dec 2026 09:02:39 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org 8B2B0607F6 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=185.246.84.56 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.246.84.56; helo=smtpout-02.galae.net; envelope-from=maxime.chevallier@bootlin.com; receiver= Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=pPsOgj6z Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 8B2B0607F6 for ; Tue, 1 Dec 2026 09:02:38 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 342351A188F; Tue, 1 Dec 2026 09:02:36 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 01558603CB; Tue, 1 Dec 2026 09:02:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7765D11EA0AD9; Tue, 01 Dec 2026 10:02:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796115754; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=4MuK1oVCcZ5VBbNY0YiSHsElkKS/YyvVEFrwJTWMYuQ=; b=pPsOgj6za4JexaRFgNn77DcV9Ni8pSttdPZcRrx5ktSVzc1STb94DsCP0GC/eOMxkJ+5Av hZGbqnNwRaLpPQWAS7ZC+hXV2h26hMm2ojEf42PwE+MZf70AaA/VIXncgcGkkOE8iryHOM fJsBMkYZUd48//Ex7JPSm8o9qjZ2vYWY8VuefEko1PkOsqp1AdTN8HIfjhWW9mRUaw+qd9 d+jA+AwcAM01NadGffnru5EqvTrTWQ0TWPLLn0LGip2vE0S+NQJz6uTp244y2H6Wi7zRdX /mBUNjE3YLbUJYlDPSh8PyLEldpU4gFAPbCBDY3hE+Hw3ktktz6pcf+8oHAjmg== Message-ID: <80f76cd1-5fac-4809-8ab9-c6ccbce647fd@bootlin.com> Date: Tue, 1 Dec 2026 10:02:29 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH iwl-next 3/4] e1000: attach a CE4100 PHY through phylink 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@lists.osuosl.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261201-e1000-phylink-v1-0-21e6f1c816a0@telaak.dev> <20261201-e1000-phylink-v1-3-21e6f1c816a0@telaak.dev> From: Maxime Chevallier Content-Language: en-US In-Reply-To: <20261201-e1000-phylink-v1-3-21e6f1c816a0@telaak.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Last-TLS-Session-Version: TLSv1.3 X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 > --- > 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; 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