From patchwork Fri Jun 23 10:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5676008vqr; Fri, 23 Jun 2023 03:46:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KuTa2cnJe2NSsyxu3UDQbbTa4h9Q2LGj0z8AFZj3cNPVhetJbEVbx4T/eUrQvGV1kFO9C X-Received: by 2002:a17:902:f545:b0:1b6:6751:95f5 with SMTP id h5-20020a170902f54500b001b6675195f5mr20506448plf.25.1687517204563; Fri, 23 Jun 2023 03:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687517204; cv=none; d=google.com; s=arc-20160816; b=uBhUt4xQdHSg8dKqY4t0OyuguBwdHqMs1/GwpS8rk5SL9hhxgSn6uKa0QX6rie1Pf+ F3kNxsLaMpA7cNflrcwhgispr6WAsgCPYZkxWC4Y9oMHSx9+/Eg1WK63/Ptmrelg2t3c sEcj84/zC90udeoXjHQIXkV/fXrqpQbJL9Im8sWo5D9VPYBIS/eFhHIvIPvshZ+8ZHJK Q+Y6b50tAV9gkb3GzD7954tCcphDc/nDD+exuLzXYiY3EPpzTV0SLSePC6wu+Qb7XEpF otQ/uaY1nM2Pd+BYEBPIWGopuVb259eVl/Ji2Ea7c/M0+WBEQ69ZDDKWb8ozRzrTDF9u nQIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=QrYNqZUvhgT7uYiFoNOw4w75pT272hSBonYWzh06JTY=; b=y8ZWJpiIxr4hW7VlnJiQC17ekriW9471J08/hqyECvawFsgXupYG31QKup1tip26nq SVh5rEAg8aCE3GAWJnxL8W+Pnk7ge8x+cUhB60elx2Vr63w7x9idi9NM78WOKkcT1ryG CjfO6ktjPTfSNqFaLpNpVGxpMXWC0pR2XkmRJlC5IYd3zyXBINyAy/1ms/G1xrpEF5zc 3vblS8RShxVC3AzYOBUQ4DBLHkuhTdq6hb6GX+fiVuGRWXBa/adX8JmtQ5W+9DHEPlCh 5M47s7smSWIriWBEkWHLfGY0NfPq3VC5BwZhPAPQ5EZ6/wF92pmvvAOwDWBtW2NFBDA/ ji0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lfBY0m7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a170902d19200b001a52db202c7si4702098plb.382.2023.06.23.03.46.30; Fri, 23 Jun 2023 03:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lfBY0m7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232273AbjFWKat (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjFWKaT (ORCPT ); Fri, 23 Jun 2023 06:30:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A718B1BCA for ; Fri, 23 Jun 2023 03:29:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 218D061A18 for ; Fri, 23 Jun 2023 10:29:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5574AC433C0; Fri, 23 Jun 2023 10:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516197; bh=baWU82tteE6wohLuYV2acd4eWNdncxCiiHvc8i4RT7E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lfBY0m7e5+WEmW8SojOvSZKUaHdINeF5dAbAzVwmShBp4Ch39m8pmZzcmnn5ueahr bEocoJVB1oQXM6z6WtbQbcubQ95dqTeK24a3RqI//l9KdNZpXBL0GD13+/OcXlQPO5 2NLK0PnWN9VvvsOmDnpTr9nZYMT5whgjexHy1l2fV7EPJS4pEeF8SJI1VC+6VNfgds cjuqqNp/ieqTyXIVoQuzuJQFrwakExMUnJvHs2v75QBcDJ7WrklgyXoHnGvV+IxkE0 iSSje+PGesKnwYkQNJQlVagp3SDn+g1Vye6GYUY1EZjINU1kFtDEMgsn4h2EDMvPn3 q/jV6zxJNP41A== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:19 +0200 Subject: [PATCH net-next v2 10/10] net: mdio: support C45-over-C22 when probed via OF MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-10-def0ab9ccee2@kernel.org> References: <20230620-feature-c45-over-c22-v2-0-def0ab9ccee2@kernel.org> In-Reply-To: <20230620-feature-c45-over-c22-v2-0-def0ab9ccee2@kernel.org> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yisen Zhuang , Salil Mehta , Florian Fainelli , Broadcom internal kernel review list , =?utf-8?q?Marek_Beh=C3=BAn?= , Xu Liang Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Walle X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769490040505127824?= X-GMAIL-MSGID: =?utf-8?q?1769490040505127824?= Fall back to C45-over-C22 when the MDIO bus isn't capable of doing C45 transfers. This might be the case if there are broken PHYs on the bus or if the MDIO controller cannot do C45 transactions at all. For this to work, split the PHY registration into three steps, as done in the generic PHY probing code: (1) add C22 PHYs (2) scan for broken C22 PHYs (3) add C45 PHYs If step (2) detects a broken PHY, any PHYs will be added with C45-over-C22 access in step (3). Step (3) also ensures, that C45-over-C22 is used if C45 access is not supported at all on the bus. Signed-off-by: Michael Walle --- drivers/net/mdio/of_mdio.c | 63 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 7eb32ebb846d..e9d3cf6b68ee 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -100,6 +100,11 @@ static const struct of_device_id whitelist_phys[] = { {} }; +static bool of_mdiobus_child_is_c45_phy(struct device_node *child) +{ + return of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); +} + /* * Return true if the child node is for a phy. It must either: * o Compatible string of "ethernet-phy-idX.X" @@ -118,7 +123,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child) if (of_get_phy_id(child, &phy_id) != -EINVAL) return true; - if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) + if (of_mdiobus_child_is_c45_phy(child)) return true; if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22")) @@ -138,6 +143,32 @@ bool of_mdiobus_child_is_phy(struct device_node *child) } EXPORT_SYMBOL(of_mdiobus_child_is_phy); +static int of_mdiobus_register_child(struct mii_bus *mdio, + struct device_node *child, bool *scanphys) +{ + int addr, rc; + + addr = of_mdio_parse_addr(&mdio->dev, child); + if (addr < 0) { + *scanphys = true; + return 0; + } + + if (mdiobus_is_registered_device(mdio, addr)) + return 0; + + if (of_mdiobus_child_is_phy(child)) + rc = of_mdiobus_register_phy(mdio, child, addr); + else + rc = of_mdiobus_register_device(mdio, child, addr); + + if (rc == -ENODEV) + dev_err(&mdio->dev, "MDIO device at address %d is missing.\n", + addr); + + return rc; +} + /** * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure @@ -178,24 +209,26 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, if (rc) return rc; - /* Loop over the child nodes and register a phy_device for each phy */ + /* Loop over the child nodes, skipping C45 PHYs so we can scan for + * broken C22 PHYs. The C45 PHYs will be registered afterwards. + */ for_each_available_child_of_node(np, child) { - addr = of_mdio_parse_addr(&mdio->dev, child); - if (addr < 0) { - scanphys = true; + if (of_mdiobus_child_is_c45_phy(child)) continue; - } + rc = of_mdiobus_register_child(mdio, child, &scanphys); + if (rc) + goto unregister; + } - if (of_mdiobus_child_is_phy(child)) - rc = of_mdiobus_register_phy(mdio, child, addr); - else - rc = of_mdiobus_register_device(mdio, child, addr); + /* Some C22 PHYs are broken with C45 transactions. */ + mdiobus_scan_for_broken_c45_access(mdio); - if (rc == -ENODEV) - dev_err(&mdio->dev, - "MDIO device at address %d is missing.\n", - addr); - else if (rc) + /* Now add any missing C45 PHYs. If C45 access is not allowed, they + * will be registered with C45-over-C22 access. + */ + for_each_available_child_of_node(np, child) { + rc = of_mdiobus_register_child(mdio, child, &scanphys); + if (rc) goto unregister; }