Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp412678rwl; Wed, 5 Apr 2023 02:30:16 -0700 (PDT) X-Google-Smtp-Source: AKy350bPMF9CgGqBK//DMtgUhoGLqxp+k6LtCGh8cfyCQVmpUYI2wx5i15GM59OSv3qn+3N7heEa X-Received: by 2002:a05:6a20:65a2:b0:da:7d8a:2cc9 with SMTP id p34-20020a056a2065a200b000da7d8a2cc9mr4093184pzh.24.1680687016442; Wed, 05 Apr 2023 02:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680687016; cv=none; d=google.com; s=arc-20160816; b=zWY+o68+zw0C0izu2OapmiV+rNlGyDNbnpynsa7fqSqvwVnTLJQzqz09Nzmul7seso l+UJMCcnHmZoGitCBsOQC7SLgaOQQJPGM3kUNgYuNEUKjOl+9Zk+PpBzdu84bwcWqVYB jM7bFWXoXu+c4ACqNulCuuTsNoSz8rKIBWqbJYM+VBNvQU4H1xtehIhEdHGEZwO6Eutu eiGg1/WdTp6orY9/WqngDNRc75NG+XwIT5+cQKtCjbqfjh6jfrHmUEvy0fZw49/us/0v LKA/IoSR5Kd2GvQkbCS9ROQZ4LTRjHIFGRS2pREEhey3zYH3RW8knvIdyAdmF9fHjj+2 SPqQ== 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; bh=UK7HVlN6pQ5vVb39ik7NXVazJniI2gfTlUd8SKunDBo=; b=RAbpN58v4SsvNIUWEWNaLkZzriHSnLyElI3MHr2OMau5gSrbAPe9clkFkZMmE8OggJ Mf6eVV/gwdZ8eJzrYz0qe3pc5SBEDxdx08WWcpHBwg5Vgdw5Phhfl4lGTNqPXYhI3o0U C1T8yJuysJ9mi+s2pE4ebGVe7JVQF4rIbN4UHc9zqy46hYc4W3A2EqK6bJgMSz6CdzFB cLgzVRFWQNwZvFevwSpueiCClVQ83yVwyYK+EsKWkBXDuPa6dZITcmanCEJYkdCisfg7 76Jfi6EbEcnwnqZRNDe9sRUqA+XxeZAwgSrahezYt2Y1gGgX8tL8OI4t6ZrevktyD0Jh TECw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020aa795b4000000b00625637c1699si12018554pfk.34.2023.04.05.02.29.19; Wed, 05 Apr 2023 02:30:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237442AbjDEJ26 (ORCPT + 99 others); Wed, 5 Apr 2023 05:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237404AbjDEJ2d (ORCPT ); Wed, 5 Apr 2023 05:28:33 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826A15274 for ; Wed, 5 Apr 2023 02:28:05 -0700 (PDT) Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1pjzPz-0004pA-Ue; Wed, 05 Apr 2023 11:27:03 +0200 From: Marco Felsch Date: Wed, 05 Apr 2023 11:26:53 +0200 Subject: [PATCH 02/12] net: phy: refactor get_phy_device function MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230405-net-next-topic-net-phy-reset-v1-2-7e5329f08002@pengutronix.de> References: <20230405-net-next-topic-net-phy-reset-v1-0-7e5329f08002@pengutronix.de> In-Reply-To: <20230405-net-next-topic-net-phy-reset-v1-0-7e5329f08002@pengutronix.de> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Broadcom internal kernel review list , Richard Cochran , Radu Pirea , Shyam Sundar S K , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , "Rafael J. Wysocki" , Len Brown , Rob Herring , Frank Rowand Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de X-Mailer: b4 0.12.1 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Split get_phy_device() into local helper function. This commit is in preparation of fixing the phy reset handling. No functional changes for the public API users. Signed-off-by: Marco Felsch --- drivers/net/phy/phy_device.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index dd0aaa866d17..64292e47e3fc 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -938,6 +938,32 @@ int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id) } EXPORT_SYMBOL(fwnode_get_phy_id); +static int phy_device_detect(struct mii_bus *bus, int addr, bool *is_c45, + u32 *phy_id, struct phy_c45_device_ids *c45_ids) +{ + int r; + + if (*is_c45) + r = get_phy_c45_ids(bus, addr, c45_ids); + else + r = get_phy_c22_id(bus, addr, phy_id); + + if (r) + return r; + + /* PHY device such as the Marvell Alaska 88E2110 will return a PHY ID + * of 0 when probed using get_phy_c22_id() with no error. Proceed to + * probe with C45 to see if we're able to get a valid PHY ID in the C45 + * space, if successful, create the C45 PHY device. + */ + if (!*is_c45 && *phy_id == 0 && bus->read_c45) { + *is_c45 = true; + return get_phy_c45_ids(bus, addr, c45_ids); + } + + return 0; +} + /** * get_phy_device - reads the specified PHY device and returns its @phy_device * struct @@ -967,26 +993,10 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) c45_ids.mmds_present = 0; memset(c45_ids.device_ids, 0xff, sizeof(c45_ids.device_ids)); - if (is_c45) - r = get_phy_c45_ids(bus, addr, &c45_ids); - else - r = get_phy_c22_id(bus, addr, &phy_id); - + r = phy_device_detect(bus, addr, &is_c45, &phy_id, &c45_ids); if (r) return ERR_PTR(r); - /* PHY device such as the Marvell Alaska 88E2110 will return a PHY ID - * of 0 when probed using get_phy_c22_id() with no error. Proceed to - * probe with C45 to see if we're able to get a valid PHY ID in the C45 - * space, if successful, create the C45 PHY device. - */ - if (!is_c45 && phy_id == 0 && bus->read_c45) { - r = get_phy_c45_ids(bus, addr, &c45_ids); - if (!r) - return phy_device_create(bus, addr, phy_id, - true, &c45_ids); - } - return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); } EXPORT_SYMBOL(get_phy_device); -- 2.39.2