From patchwork Wed Apr 5 09:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 670424 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFEC1C7619A for ; Wed, 5 Apr 2023 09:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237469AbjDEJ2M (ORCPT ); Wed, 5 Apr 2023 05:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237482AbjDEJ2D (ORCPT ); Wed, 5 Apr 2023 05:28:03 -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 26F384EED for ; Wed, 5 Apr 2023 02:27:48 -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 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-acpi@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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);